From 9d2df003a3295a0143ae8512ce74c45bf3c1f4cf Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sun, 6 May 2012 13:48:17 +0200 Subject: [PATCH] Use gdk_threads_add_idle for adjust_window --- shortcuts.c | 53 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/shortcuts.c b/shortcuts.c index bba11fd..539d027 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -50,14 +50,22 @@ sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument), return false; } -bool -sc_adjust_window(girara_session_t* session, girara_argument_t* argument, - girara_event_t* UNUSED(event), unsigned int UNUSED(t)) +typedef struct zathura_adjust_window_s { + girara_session_t* session; + zathura_t* zathura; + int adjust; +} zathura_adjust_window_t; + +static gboolean +adjust_window_impl(gpointer data) { - 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); + if (data == NULL) { + return 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; 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); - zathura_document_set_adjust_mode(zathura->document, argument->n); - if (argument->n == ZATHURA_ADJUST_NONE) { + zathura_document_set_adjust_mode(zathura->document, aw->adjust); + if (aw->adjust == ZATHURA_ADJUST_NONE) { /* there is nothing todo */ 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); - if (argument->n == ZATHURA_ADJUST_WIDTH) { + if (aw->adjust == ZATHURA_ADJUST_WIDTH) { if (rotation == 0 || rotation == 180) { zathura_document_set_scale(zathura->document, width / total_width); } else { 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) { zathura_document_set_scale(zathura->document, height / max_height); } else { @@ -136,7 +144,28 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument, 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