From: Arkadiy Illarionov Date: Sun, 7 Apr 2024 12:16:16 +0000 (+0300) Subject: Move keyboard_scroll_calc() to layout-util X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=commitdiff_plain;h=425eb031a23ac0ed8d3a736caef42e0493b00f9e Move keyboard_scroll_calc() to layout-util Convert parameters from pointers to references. Move Shift processing inside keyboard_scroll_calc(). --- diff --git a/src/img-view.cc b/src/img-view.cc index f71e1b15..e78cbeb8 100644 --- a/src/img-view.cc +++ b/src/img-view.cc @@ -41,7 +41,6 @@ #include "layout-util.h" #include "layout.h" #include "main-defines.h" -#include "main.h" #include "menu.h" #include "misc.h" #include "options.h" @@ -442,13 +441,7 @@ static gboolean view_window_key_press_cb(GtkWidget * (widget), GdkEventKey *even if (x != 0 || y!= 0) { - if (event->state & GDK_SHIFT_MASK) - { - x *= 3; - y *= 3; - } - - keyboard_scroll_calc(&x, &y, event); + keyboard_scroll_calc(x, y, event); image_scroll(imd, x, y); } diff --git a/src/layout-util.cc b/src/layout-util.cc index 1a0d5af5..7d371643 100644 --- a/src/layout-util.cc +++ b/src/layout-util.cc @@ -114,6 +114,51 @@ static gboolean layout_key_match(guint keyval) return FALSE; } +void keyboard_scroll_calc(gint &x, gint &y, const GdkEventKey *event) +{ + static gint delta = 0; + static guint32 time_old = 0; + static guint keyval_old = 0; + + if (event->state & GDK_SHIFT_MASK) + { + x *= 3; + y *= 3; + } + + if (event->state & GDK_CONTROL_MASK) + { + if (x < 0) x = G_MININT / 2; + if (x > 0) x = G_MAXINT / 2; + if (y < 0) y = G_MININT / 2; + if (y > 0) y = G_MAXINT / 2; + + return; + } + + if (options->progressive_key_scrolling) + { + guint32 time_diff; + + time_diff = event->time - time_old; + + /* key pressed within 125ms ? (1/8 second) */ + if (time_diff > 125 || event->keyval != keyval_old) delta = 0; + + time_old = event->time; + keyval_old = event->keyval; + + delta += 2; + } + else + { + delta = 8; + } + + x *= delta * options->keyboard_scroll_step; + y *= delta * options->keyboard_scroll_step; +} + gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) { auto lw = static_cast(data); @@ -200,12 +245,7 @@ gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat if (x != 0 || y!= 0) { - if (event->state & GDK_SHIFT_MASK) - { - x *= 3; - y *= 3; - } - keyboard_scroll_calc(&x, &y, event); + keyboard_scroll_calc(x, y, event); layout_image_scroll(lw, x, y, (event->state & GDK_SHIFT_MASK)); } diff --git a/src/layout-util.h b/src/layout-util.h index a82aa0e0..00115f3e 100644 --- a/src/layout-util.h +++ b/src/layout-util.h @@ -30,6 +30,8 @@ struct LayoutWindow; +void keyboard_scroll_calc(gint &x, gint &y, const GdkEventKey *event); + gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data); void layout_util_sync_thumb(LayoutWindow *lw); diff --git a/src/main.cc b/src/main.cc index a12b5e4b..a0b73325 100644 --- a/src/main.cc +++ b/src/main.cc @@ -40,8 +40,10 @@ #include #endif +#include #include #include +#include #ifdef ENABLE_NLS # include @@ -220,53 +222,6 @@ void sig_handler_cb(int) } #endif /* defined(SA_SIGINFO) */ -/* - *----------------------------------------------------------------------------- - * keyboard functions - *----------------------------------------------------------------------------- - */ - -void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event) -{ - static gint delta = 0; - static guint32 time_old = 0; - static guint keyval_old = 0; - - if (event->state & GDK_CONTROL_MASK) - { - if (*x < 0) *x = G_MININT / 2; - if (*x > 0) *x = G_MAXINT / 2; - if (*y < 0) *y = G_MININT / 2; - if (*y > 0) *y = G_MAXINT / 2; - - return; - } - - if (options->progressive_key_scrolling) - { - guint32 time_diff; - - time_diff = event->time - time_old; - - /* key pressed within 125ms ? (1/8 second) */ - if (time_diff > 125 || event->keyval != keyval_old) delta = 0; - - time_old = event->time; - keyval_old = event->keyval; - - delta += 2; - } - else - { - delta = 8; - } - - *x = *x * delta * options->keyboard_scroll_step; - *y = *y * delta * options->keyboard_scroll_step; -} - - - /* *----------------------------------------------------------------------------- * command line parser (private) hehe, who needs popt anyway? diff --git a/src/main.h b/src/main.h index b61c0c82..de31427c 100644 --- a/src/main.h +++ b/src/main.h @@ -22,9 +22,7 @@ #ifndef MAIN_H #define MAIN_H -#include #include -#include extern gboolean thumb_format_changed; @@ -38,8 +36,6 @@ extern gchar *gq_executable_path; extern gchar *desktop_file_template; extern gchar *instance_identifier; -void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event); - void exit_program(); #define CASE_SORT(a, b) ( (options->file_sort.case_sensitive) ? strcmp((a), (b)) : strcasecmp((a), (b)) ) diff --git a/src/pan-view/pan-view.cc b/src/pan-view/pan-view.cc index 3d398289..d6ce6f3c 100644 --- a/src/pan-view/pan-view.cc +++ b/src/pan-view/pan-view.cc @@ -46,7 +46,6 @@ #include "layout-util.h" #include "layout.h" #include "main-defines.h" -#include "main.h" #include "menu.h" #include "metadata.h" #include "options.h" @@ -1250,12 +1249,7 @@ static gboolean pan_window_key_press_cb(GtkWidget *widget, GdkEventKey *event, g if (x != 0 || y!= 0) { - if (event->state & GDK_SHIFT_MASK) - { - x *= 3; - y *= 3; - } - keyboard_scroll_calc(&x, &y, event); + keyboard_scroll_calc(x, y, event); pixbuf_renderer_scroll(pr, x, y); } }