mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-01 08:26:01 +01:00
Improve widget size fix for sc_adjust_window
This commit is contained in:
parent
9d2df003a3
commit
13711243f4
1 changed files with 19 additions and 41 deletions
60
shortcuts.c
60
shortcuts.c
|
@ -50,22 +50,14 @@ sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct zathura_adjust_window_s {
|
bool
|
||||||
girara_session_t* session;
|
sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
||||||
zathura_t* zathura;
|
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
||||||
int adjust;
|
|
||||||
} zathura_adjust_window_t;
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
adjust_window_impl(gpointer data)
|
|
||||||
{
|
{
|
||||||
if (data == NULL) {
|
g_return_val_if_fail(session != NULL, false);
|
||||||
return FALSE;
|
g_return_val_if_fail(session->global.data != NULL, false);
|
||||||
}
|
zathura_t* zathura = session->global.data;
|
||||||
|
g_return_val_if_fail(argument != NULL, false);
|
||||||
zathura_adjust_window_t* aw = (zathura_adjust_window_t*) data;
|
|
||||||
zathura_t* zathura = aw->zathura;
|
|
||||||
girara_session_t* session = aw->session;
|
|
||||||
|
|
||||||
unsigned int pages_per_row = 1;
|
unsigned int pages_per_row = 1;
|
||||||
girara_setting_get(session, "pages-per-row", &pages_per_row);
|
girara_setting_get(session, "pages-per-row", &pages_per_row);
|
||||||
|
@ -75,8 +67,8 @@ adjust_window_impl(gpointer data)
|
||||||
}
|
}
|
||||||
|
|
||||||
float old_zoom = zathura_document_get_scale(zathura->document);
|
float old_zoom = zathura_document_get_scale(zathura->document);
|
||||||
zathura_document_set_adjust_mode(zathura->document, aw->adjust);
|
zathura_document_set_adjust_mode(zathura->document, argument->n);
|
||||||
if (aw->adjust == ZATHURA_ADJUST_NONE) {
|
if (argument->n == ZATHURA_ADJUST_NONE) {
|
||||||
/* there is nothing todo */
|
/* there is nothing todo */
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
}
|
}
|
||||||
|
@ -87,6 +79,13 @@ adjust_window_impl(gpointer data)
|
||||||
gint width = allocation.width;
|
gint width = allocation.width;
|
||||||
gint height = allocation.height;
|
gint height = allocation.height;
|
||||||
|
|
||||||
|
/* correct view size */
|
||||||
|
if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)) == true) {
|
||||||
|
gtk_widget_get_allocation(session->gtk.inputbar, &allocation);
|
||||||
|
width += allocation.width;
|
||||||
|
height += allocation.height;
|
||||||
|
}
|
||||||
|
|
||||||
/* calculate total width and max-height */
|
/* calculate total width and max-height */
|
||||||
double total_width = 0;
|
double total_width = 0;
|
||||||
double total_height = 0;
|
double total_height = 0;
|
||||||
|
@ -120,13 +119,13 @@ adjust_window_impl(gpointer data)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int rotation = zathura_document_get_rotation(zathura->document);
|
unsigned int rotation = zathura_document_get_rotation(zathura->document);
|
||||||
if (aw->adjust == ZATHURA_ADJUST_WIDTH) {
|
if (argument->n == ZATHURA_ADJUST_WIDTH) {
|
||||||
if (rotation == 0 || rotation == 180) {
|
if (rotation == 0 || rotation == 180) {
|
||||||
zathura_document_set_scale(zathura->document, width / total_width);
|
zathura_document_set_scale(zathura->document, width / total_width);
|
||||||
} else {
|
} else {
|
||||||
zathura_document_set_scale(zathura->document, width / total_height);
|
zathura_document_set_scale(zathura->document, width / total_height);
|
||||||
}
|
}
|
||||||
} else if (aw->adjust == ZATHURA_ADJUST_BESTFIT) {
|
} else if (argument->n == ZATHURA_ADJUST_BESTFIT) {
|
||||||
if (rotation == 0 || rotation == 180) {
|
if (rotation == 0 || rotation == 180) {
|
||||||
zathura_document_set_scale(zathura->document, height / max_height);
|
zathura_document_set_scale(zathura->document, height / max_height);
|
||||||
} else {
|
} else {
|
||||||
|
@ -144,28 +143,7 @@ adjust_window_impl(gpointer data)
|
||||||
|
|
||||||
error_ret:
|
error_ret:
|
||||||
|
|
||||||
g_free(aw);
|
return false;
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
|
||||||
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
|
||||||
{
|
|
||||||
g_return_val_if_fail(session != NULL, false);
|
|
||||||
g_return_val_if_fail(session->global.data != NULL, false);
|
|
||||||
zathura_t* zathura = session->global.data;
|
|
||||||
g_return_val_if_fail(argument != NULL, false);
|
|
||||||
|
|
||||||
zathura_adjust_window_t* aw = g_malloc0(sizeof(zathura_adjust_window_t));
|
|
||||||
aw->zathura = zathura;
|
|
||||||
aw->session = session;
|
|
||||||
aw->adjust = argument->n;
|
|
||||||
|
|
||||||
gdk_threads_add_idle(adjust_window_impl, aw);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
Loading…
Reference in a new issue