From 359df028be7b1dae76a1abb9bad8a3b86a648765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Tue, 7 Aug 2018 21:29:21 +0000 Subject: [PATCH] GDK W32: Support smooth scrolling Set delta_x or delta_y for GdkScrollEvent. HIWORD (wParam) in WM_MOUSE(H)WHEEL is the scroll delta. A delta value of WHEEL_DELTA (which is 120) means scrolling one full unit of something (for example, a line). The delta should also be multiplied by the value that the SystemParametersInfo (SPI_GETWHEELSCROLL(LINES|CHARS), 0, &value, 0) call gives back, unless it gives back 0xffffffff, in which case it indicates that scrolling is page- or screen-based, not line-based (GDK doesn't support that at the moment). Also, all deltas should be inverted, since MS sends negative deltas when scrolling down (rotating the wheel back, in the direction of the user). With deltas set the mode should be set to GDK_SCROLL_SMOOTH. Fixes issue 1263. --- gdk/win32/gdkevents-win32.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c index c050b9d64c..beaac53f49 100644 --- a/gdk/win32/gdkevents-win32.c +++ b/gdk/win32/gdkevents-win32.c @@ -3071,13 +3071,35 @@ gdk_event_translate (MSG *msg, event = gdk_event_new (GDK_SCROLL); event->scroll.window = window; + event->scroll.direction = GDK_SCROLL_SMOOTH; if (msg->message == WM_MOUSEWHEEL) - event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ? - GDK_SCROLL_UP : GDK_SCROLL_DOWN; + { + UINT lines_multiplier = 3; + event->scroll.delta_y = (gdouble) GET_WHEEL_DELTA_WPARAM (msg->wParam) / (gdouble) WHEEL_DELTA; + /* -1 means that we should scroll in screens, not lines. + * Right now GDK doesn't support that. + */ + if (SystemParametersInfo (SPI_GETWHEELSCROLLLINES, 0, &lines_multiplier, 0) && + lines_multiplier != (UINT) -1) + event->scroll.delta_y *= (gdouble) lines_multiplier; + } else if (msg->message == WM_MOUSEHWHEEL) - event->scroll.direction = (((short) HIWORD (msg->wParam)) > 0) ? - GDK_SCROLL_RIGHT : GDK_SCROLL_LEFT; + { + UINT chars_multiplier = 3; + event->scroll.delta_x = (gdouble) GET_WHEEL_DELTA_WPARAM (msg->wParam) / (gdouble) WHEEL_DELTA; + /* There doesn't seem to be any indication that + * h-scroll has an equivalent of the "screen" mode, + * indicated by multiplier being (UINT) -1. + */ + if (SystemParametersInfo (SPI_GETWHEELSCROLLCHARS, 0, &chars_multiplier, 0)) + event->scroll.delta_x *= (gdouble) chars_multiplier; + } + /* It seems that delta values given by Windows are + * inverted (positive delta scrolls up, not down). + */ + event->scroll.delta_x *= -1.0; + event->scroll.delta_y *= -1.0; event->scroll.time = _gdk_win32_get_next_tick (msg->time); event->scroll.x = (gint16) point.x / impl->window_scale; event->scroll.y = (gint16) point.y / impl->window_scale;