From 93e2edf4c9bdb0ef5609ae383ba47680fb62a2c7 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Mon, 24 Jan 2011 19:54:20 +0800 Subject: [PATCH] sc_scroll --- config.c | 1 - shortcuts.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 8a5fee6..c957def 100644 --- a/config.c +++ b/config.c @@ -62,7 +62,6 @@ config_load_default(void) girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_f, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_b, NULL, sc_scroll, NORMAL, FULL_UP, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_space, NULL, sc_scroll, NORMAL, FULL_DOWN, NULL); - girara_shortcut_add(Zathura.UI.session, 0, 0, "%", sc_scroll, NORMAL, 0, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_n, NULL, sc_search, NORMAL, FORWARD, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_N, NULL, sc_search, NORMAL, BACKWARD, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_0, NULL, sc_switch_goto_mode, NORMAL, 0, NULL); diff --git a/shortcuts.c b/shortcuts.c index db0ef77..82cf482 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -111,6 +111,52 @@ sc_rotate(girara_session_t* session, girara_argument_t* argument) bool sc_scroll(girara_session_t* session, girara_argument_t* argument) { + GtkAdjustment* adjustment = NULL; + if( (argument->n == LEFT) || (argument->n == RIGHT) ) + adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + else + adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(Zathura.UI.session->gtk.view)); + + gdouble view_size = gtk_adjustment_get_page_size(adjustment); + gdouble value = gtk_adjustment_get_value(adjustment); + gdouble max = gtk_adjustment_get_upper(adjustment) - view_size; + gdouble scroll_step = 40; + + gdouble new_value; + switch(argument->n) + { + case FULL_UP: + new_value = (value - view_size) < 0 ? 0 : (value - view_size); + break; + case FULL_DOWN: + new_value = (value + view_size) > max ? max : (value + view_size); + break; + case HALF_UP: + new_value = (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2)); + break; + case HALF_DOWN: + new_value = (value + (view_size / 2)) > max ? max : (value + (view_size / 2)); + break; + case LEFT: + case UP: + new_value = (value - scroll_step) < 0 ? 0 : (value - scroll_step); + break; + case RIGHT: + case DOWN: + new_value = (value + scroll_step) > max ? max : (value + scroll_step); + break; + case TOP: + new_value = 0; + break; + case BOTTOM: + new_value = max; + break; + default: + new_value = 0; + } + + gtk_adjustment_set_value(adjustment, new_value); + return false; }