Tk Source Code

Artifact [d17029d3]
Login

Artifact d17029d3e306c15de515d68ed33c70ae795e2bc60f59dcbbcf5f81ce9e145c52:

Attachment "tkWinX.patch" to ticket [75d38f86] added by chw 2018-03-27 18:57:50.
Index: jni/sdl2tk/win/tkWinX.c
==================================================================
--- jni/sdl2tk/win/tkWinX.c
+++ jni/sdl2tk/win/tkWinX.c
@@ -86,10 +86,12 @@
 typedef struct ThreadSpecificData {
     TkDisplay *winDisplay;	/* TkDisplay structure that represents Windows
 				 * screen. */
     int updatingClipboard;	/* If 1, we are updating the clipboard. */
     int surrogateBuffer;	/* Buffer for first of surrogate pair. */
+    DWORD wheelTickPrev;	/* For high resolution wheels. */
+    short wheelAcc;		/* For high resolution wheels. */
 } ThreadSpecificData;
 static Tcl_ThreadDataKey dataKey;
 
 /*
  * Forward declarations of functions used in this file.
@@ -612,10 +614,12 @@
 
     tsdPtr->winDisplay = ckalloc(sizeof(TkDisplay));
     ZeroMemory(tsdPtr->winDisplay, sizeof(TkDisplay));
     tsdPtr->winDisplay->display = display;
     tsdPtr->updatingClipboard = FALSE;
+    tsdPtr->wheelTickPrev = GetTickCount();
+    tsdPtr->wheelAcc = 0;
 
     return tsdPtr->winDisplay;
 }
 
 /*
@@ -1142,11 +1146,27 @@
 	/*
 	 * Now set up event specific fields.
 	 */
 
 	switch (message) {
-	case WM_MOUSEWHEEL:
+	case WM_MOUSEWHEEL: {
+	    /*
+	     * Support for high resolution wheels.
+	     */
+
+	    DWORD wheelTick = GetTickCount();
+
+	    if (wheelTick - tsdPtr->wheelTickPrev < 1500) {
+		tsdPtr->wheelAcc += (short) HIWORD(wParam);
+	    } else {
+		tsdPtr->wheelAcc = (short) HIWORD(wParam);
+	    }
+	    tsdPtr->wheelTickPrev = wheelTick;
+	    if (abs(tsdPtr->wheelAcc) < WHEEL_DELTA) {
+		return;
+	    }
+
 	    /*
 	     * We have invented a new X event type to handle this event. It
 	     * still uses the KeyPress struct. However, the keycode field has
 	     * been overloaded to hold the zDelta of the wheel. Set nbytes to
 	     * 0 to prevent conversion of the keycode to a keysym in
@@ -1154,12 +1174,14 @@
 	     */
 
 	    event.type = MouseWheelEvent;
 	    event.xany.send_event = -1;
 	    event.xkey.nbytes = 0;
-	    event.xkey.keycode = (short) HIWORD(wParam);
+	    event.xkey.keycode = tsdPtr->wheelAcc / WHEEL_DELTA * WHEEL_DELTA;
+	    tsdPtr->wheelAcc = tsdPtr->wheelAcc % WHEEL_DELTA;
 	    break;
+	}
 	case WM_SYSKEYDOWN:
 	case WM_KEYDOWN:
 	    /*
 	     * Check for translated characters in the event queue. Setting
 	     * xany.send_event to -1 indicates to the Windows implementation