Move keyboard_scroll_calc() to layout-util
authorArkadiy Illarionov <qarkai@gmail.com>
Sun, 7 Apr 2024 12:16:16 +0000 (15:16 +0300)
committerColin Clark <colin.clark@cclark.uk>
Sun, 7 Apr 2024 15:37:23 +0000 (16:37 +0100)
Convert parameters from pointers to references.
Move Shift processing inside keyboard_scroll_calc().

src/img-view.cc
src/layout-util.cc
src/layout-util.h
src/main.cc
src/main.h
src/pan-view/pan-view.cc

index f71e1b1..e78cbeb 100644 (file)
@@ -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);
                }
 
index 1a0d5af..7d37164 100644 (file)
@@ -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<LayoutWindow *>(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));
                }
 
index a82aa0e..00115f3 100644 (file)
@@ -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);
index a12b5e4..a0b7332 100644 (file)
 #include <execinfo.h>
 #endif
 
+#include <gdk/gdk.h>
 #include <gio/gio.h>
 #include <glib-object.h>
+#include <gtk/gtk.h>
 
 #ifdef ENABLE_NLS
 #  include <libintl.h>
@@ -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?
index b61c0c8..de31427 100644 (file)
@@ -22,9 +22,7 @@
 #ifndef MAIN_H
 #define MAIN_H
 
-#include <gdk/gdk.h>
 #include <glib.h>
-#include <gtk/gtk.h>
 
 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)) )
index 3d39828..d6ce6f3 100644 (file)
@@ -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);
                        }
                }