aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-06-12 21:06:42 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-06-12 21:33:09 +0200
commit2f448c976889fe60aba8557b5aa4aa0a0d939281 (patch)
treefc3c9b01be6fb08d4ad8d9f1444d6730273d21d1 /src
parentaaa1d51a4c85fcc627e88ef7cf5292d9c5f5f840 (diff)
downloadsciteco-2f448c976889fe60aba8557b5aa4aa0a0d939281.tar.gz
GTK: fixed scrolling on systems that only support smooth scrolling
* Apparently, we cannot disable smooth scrolling on a per-application basis, so I have to handle both discrete and smooth scrolling events. * Since SciTECO's scroll API (-EJ) is based on discrete scrolling, we now emulate discrete scroll events by accumulating the delta_y of smooth scroll events. The threshold value of 12 is chosen arbitrarily, but based on an example in the Gtk documentation.
Diffstat (limited to 'src')
-rw-r--r--src/interface-gtk/interface.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c
index 9241767..3a2a971 100644
--- a/src/interface-gtk/interface.c
+++ b/src/interface-gtk/interface.c
@@ -253,7 +253,7 @@ teco_interface_init(void)
gint events = gtk_widget_get_events(teco_interface.event_box_widget);
events |= GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
- GDK_SCROLL_MASK;
+ GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK;
gtk_widget_set_events(teco_interface.event_box_widget, events);
g_signal_connect(teco_interface.event_box_widget, "button-press-event",
@@ -1114,11 +1114,10 @@ teco_interface_handle_mouse_button(GdkEventButton *event, GError **error)
static gboolean
teco_interface_handle_scroll(GdkEventScroll *event, GError **error)
{
+ static gdouble delta_y = 0;
+
g_assert(event->type == GDK_SCROLL);
- /*
- * FIXME: Do we have to support GDK_SCROLL_SMOOTH?
- */
switch (event->direction) {
case GDK_SCROLL_UP:
teco_mouse.type = TECO_MOUSE_SCROLLUP;
@@ -1126,6 +1125,15 @@ teco_interface_handle_scroll(GdkEventScroll *event, GError **error)
case GDK_SCROLL_DOWN:
teco_mouse.type = TECO_MOUSE_SCROLLDOWN;
break;
+ case GDK_SCROLL_SMOOTH:
+ /* emulate discrete scrolling */
+ delta_y += event->delta_y;
+ if (ABS(delta_y) < 12)
+ return TRUE;
+ teco_mouse.type = delta_y < 0 ? TECO_MOUSE_SCROLLUP
+ : TECO_MOUSE_SCROLLDOWN;
+ delta_y = 0;
+ break;
default:
return TRUE;
}