From 0fd30113f14657448ce455b7f72104d884f39e6d Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 3 Apr 2020 17:56:30 +0100 Subject: [PATCH] gtk: fill in missing case in scroll_event(). If gdk_event_get_scroll_deltas() return failure for a given GdkEventScroll, it doesn't follow that that event has no usable scrolling action in it at all. The fallback is to call gdk_event_get_scroll_direction() instead, which is less precise but still gives _something_ you can use. So in that situation, instead of just returning false, we can fall through to the handling we use for pre-GTK3 scroll events (which are always imprecise). In particular, I've noticed recently that if you run GTK 3 PuTTY in the virtual X display created by vnc4server, and connect to it using xtightvncviewer, then scroll-wheel actions passed through from the VNC client will cause scroll_event() to receive low-res GdkEventScroll structures of exactly this kind. So scroll-wheel activity on the terminal window wasn't causing a scroll in that environment, and with this patch, it does. --- unix/gtkwin.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 473584c0..7ac2f2ef 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -2185,21 +2185,26 @@ gboolean button_event(GtkWidget *widget, GdkEventButton *event, gpointer data) gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data) { GtkFrontend *inst = (GtkFrontend *)data; + GdkScrollDirection dir; #if GTK_CHECK_VERSION(3,4,0) gdouble dx, dy; if (gdk_event_get_scroll_deltas((GdkEvent *)event, &dx, &dy)) { return scroll_internal(inst, dy, event->state, event->x, event->y); - } else + } else if (!gdk_event_get_scroll_direction((GdkEvent *)event, &dir)) { return false; + } #else + dir = event->direction; +#endif + guint button; GdkEventButton *event_button; gboolean ret; - if (event->direction == GDK_SCROLL_UP) + if (dir == GDK_SCROLL_UP) button = 4; - else if (event->direction == GDK_SCROLL_DOWN) + else if (dir == GDK_SCROLL_DOWN) button = 5; else return false; @@ -2219,7 +2224,6 @@ gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data) ret = button_internal(inst, event_button); gdk_event_free((GdkEvent *)event_button); return ret; -#endif } #endif