mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-06 02:56:00 +01:00
Use gdk_threads_add_idle for adjust_window
This commit is contained in:
parent
47686b3d47
commit
9d2df003a3
1 changed files with 41 additions and 12 deletions
53
shortcuts.c
53
shortcuts.c
|
@ -50,14 +50,22 @@ sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
typedef struct zathura_adjust_window_s {
|
||||||
sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
girara_session_t* session;
|
||||||
girara_event_t* UNUSED(event), unsigned int UNUSED(t))
|
zathura_t* zathura;
|
||||||
|
int adjust;
|
||||||
|
} zathura_adjust_window_t;
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
adjust_window_impl(gpointer data)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail(session != NULL, false);
|
if (data == NULL) {
|
||||||
g_return_val_if_fail(session->global.data != NULL, false);
|
return 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);
|
||||||
|
@ -67,8 +75,8 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
||||||
}
|
}
|
||||||
|
|
||||||
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, argument->n);
|
zathura_document_set_adjust_mode(zathura->document, aw->adjust);
|
||||||
if (argument->n == ZATHURA_ADJUST_NONE) {
|
if (aw->adjust == ZATHURA_ADJUST_NONE) {
|
||||||
/* there is nothing todo */
|
/* there is nothing todo */
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
}
|
}
|
||||||
|
@ -112,13 +120,13 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int rotation = zathura_document_get_rotation(zathura->document);
|
unsigned int rotation = zathura_document_get_rotation(zathura->document);
|
||||||
if (argument->n == ZATHURA_ADJUST_WIDTH) {
|
if (aw->adjust == 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 (argument->n == ZATHURA_ADJUST_BESTFIT) {
|
} else if (aw->adjust == 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 {
|
||||||
|
@ -136,7 +144,28 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
||||||
|
|
||||||
error_ret:
|
error_ret:
|
||||||
|
|
||||||
return false;
|
g_free(aw);
|
||||||
|
|
||||||
|
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