From 2c69937ef581fdf434192201785cc3b32ad9b2e5 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sun, 24 Jul 2022 21:36:57 +0200 Subject: sdgui: use smooth scrolling --- src/stardict-view.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/stardict-view.c b/src/stardict-view.c index 1e65b0c..a6f7733 100644 --- a/src/stardict-view.c +++ b/src/stardict-view.c @@ -395,9 +395,8 @@ stardict_view_realize (GtkWidget *widget) // but it merely seems to involve more work. .wclass = GDK_INPUT_OUTPUT, .visual = gtk_widget_get_visual (widget), - - // GDK_SMOOTH_SCROLL_MASK is useless, will stop sending UP/DOWN - .event_mask = gtk_widget_get_events (widget) | GDK_SCROLL_MASK, + .event_mask = gtk_widget_get_events (widget) | GDK_SCROLL_MASK + | GDK_SMOOTH_SCROLL_MASK, }; // We need this window to receive input events at all. @@ -487,9 +486,14 @@ stardict_view_scroll_event (GtkWidget *widget, GdkEventScroll *event) stardict_view_scroll (self, GTK_SCROLL_STEPS, +3); return TRUE; case GDK_SCROLL_SMOOTH: - self->top_offset += event->delta_y; - adjust_for_offset (self); + { + // On GDK/Wayland, the mouse wheel will typically create 1.5 deltas, + // after dividing a 15 degree click angle from libinput by 10. + // On X11, as libinput(4) indicates, the delta will always be 1.0. + double delta = CLAMP(event->delta_y, -1, +1); + stardict_view_scroll (self, GTK_SCROLL_STEPS, 3 * delta); return TRUE; + } default: return FALSE; } -- cgit v1.2.3-70-g09d2