summaryrefslogtreecommitdiffstats
path: root/win/tkWinX.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2021-03-23 11:04:46 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2021-03-23 11:04:46 (GMT)
commit44b27a38423482f476ea90f9d0719a4058fcdb83 (patch)
tree39fb899698403f66a3d501efa246e49c9302ce30 /win/tkWinX.c
parent70e646fa5e76a56a60ca07b3b95a0eaad45983a7 (diff)
downloadtk-44b27a38423482f476ea90f9d0719a4058fcdb83.zip
tk-44b27a38423482f476ea90f9d0719a4058fcdb83.tar.gz
tk-44b27a38423482f476ea90f9d0719a4058fcdb83.tar.bz2
Make the algorithm for handling high-resolution Mousewheel on Windows EXACTLY the same as on MacOS. See [c2be406526].
Diffstat (limited to 'win/tkWinX.c')
-rw-r--r--win/tkWinX.c58
1 files changed, 34 insertions, 24 deletions
diff --git a/win/tkWinX.c b/win/tkWinX.c
index 7361df6..4a2e514 100644
--- a/win/tkWinX.c
+++ b/win/tkWinX.c
@@ -80,10 +80,9 @@ typedef struct {
* screen. */
int updatingClipboard; /* If 1, we are updating the clipboard. */
int surrogateBuffer; /* Buffer for first of surrogate pair. */
- DWORD vWheelTickPrev; /* For high resolution wheels (vertical). */
- DWORD hWheelTickPrev; /* For high resolution wheels (horizontal). */
- short vWheelAcc; /* For high resolution wheels (vertical). */
- short hWheelAcc; /* For high resolution wheels (horizontal). */
+ DWORD wheelTickPrev; /* For high resolution wheels. */
+ int vWheelAcc; /* For high resolution wheels (vertical). */
+ int hWheelAcc; /* For high resolution wheels (horizontal). */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
@@ -521,7 +520,6 @@ TkpOpenDisplay(
Display *display;
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
- DWORD initialWheelTick;
if (tsdPtr->winDisplay != NULL) {
if (!strcmp(tsdPtr->winDisplay->display->display_name, display_name)) {
@@ -538,9 +536,7 @@ TkpOpenDisplay(
ZeroMemory(tsdPtr->winDisplay, sizeof(TkDisplay));
tsdPtr->winDisplay->display = display;
tsdPtr->updatingClipboard = FALSE;
- initialWheelTick = GetTickCount();
- tsdPtr->vWheelTickPrev = initialWheelTick;
- tsdPtr->hWheelTickPrev = initialWheelTick;
+ tsdPtr->wheelTickPrev = GetTickCount();
tsdPtr->vWheelAcc = 0;
tsdPtr->hWheelAcc = 0;
@@ -1141,14 +1137,15 @@ GenerateXEvent(
*/
DWORD wheelTick = GetTickCount();
+ BOOL timeout = wheelTick - tsdPtr->wheelTickPrev >= 300;
+ int intDelta;
- if (wheelTick - tsdPtr->vWheelTickPrev < 1500) {
- tsdPtr->vWheelAcc += (short) HIWORD(wParam);
- } else {
- tsdPtr->vWheelAcc = (short) HIWORD(wParam);
+ tsdPtr->wheelTickPrev = wheelTick;
+ if (timeout) {
+ tsdPtr->vWheelAcc = tsdPtr->hWheelAcc = 0;
}
- tsdPtr->vWheelTickPrev = wheelTick;
- if (abs(tsdPtr->vWheelAcc) < WHEEL_DELTA) {
+ tsdPtr->vWheelAcc += (short) HIWORD(wParam);
+ if (!tsdPtr->vWheelAcc || (!timeout && abs(tsdPtr->vWheelAcc) < WHEEL_DELTA * 6 / 10)) {
return;
}
@@ -1160,11 +1157,17 @@ GenerateXEvent(
* TkpGetString. [Bug 1118340].
*/
+ intDelta = (abs(tsdPtr->vWheelAcc) + WHEEL_DELTA/2) / WHEEL_DELTA * WHEEL_DELTA;
+ if (intDelta == 0) {
+ intDelta = (tsdPtr->vWheelAcc < 0) ? -WHEEL_DELTA : WHEEL_DELTA;
+ } else if (tsdPtr->vWheelAcc < 0) {
+ intDelta = -intDelta;
+ }
event.x.type = MouseWheelEvent;
event.x.xany.send_event = -1;
event.key.nbytes = 0;
- event.x.xkey.keycode = tsdPtr->vWheelAcc / WHEEL_DELTA * WHEEL_DELTA;
- tsdPtr->vWheelAcc = tsdPtr->vWheelAcc % WHEEL_DELTA;
+ event.x.xkey.keycode = intDelta;
+ tsdPtr->vWheelAcc -= intDelta;
break;
}
case WM_MOUSEHWHEEL: {
@@ -1173,14 +1176,15 @@ GenerateXEvent(
*/
DWORD wheelTick = GetTickCount();
+ BOOL timeout = wheelTick - tsdPtr->wheelTickPrev >= 300;
+ int intDelta;
- if (wheelTick - tsdPtr->hWheelTickPrev < 1500) {
- tsdPtr->hWheelAcc -= (short) HIWORD(wParam);
- } else {
- tsdPtr->hWheelAcc = -((short) HIWORD(wParam));
+ tsdPtr->wheelTickPrev = wheelTick;
+ if (timeout) {
+ tsdPtr->vWheelAcc = tsdPtr->hWheelAcc = 0;
}
- tsdPtr->hWheelTickPrev = wheelTick;
- if (abs(tsdPtr->hWheelAcc) < WHEEL_DELTA) {
+ tsdPtr->hWheelAcc -= (short) HIWORD(wParam);
+ if (!tsdPtr->hWheelAcc || (!timeout && abs(tsdPtr->hWheelAcc) < WHEEL_DELTA * 6 / 10)) {
return;
}
@@ -1192,12 +1196,18 @@ GenerateXEvent(
* TkpGetString. [Bug 1118340].
*/
+ intDelta = (abs(tsdPtr->hWheelAcc) + WHEEL_DELTA/2) / WHEEL_DELTA * WHEEL_DELTA;
+ if (intDelta == 0) {
+ intDelta = (tsdPtr->hWheelAcc < 0) ? -WHEEL_DELTA : WHEEL_DELTA;
+ } else if (tsdPtr->hWheelAcc < 0) {
+ intDelta = -intDelta;
+ }
event.x.type = MouseWheelEvent;
event.x.xany.send_event = -1;
event.key.nbytes = 0;
event.x.xkey.state |= ShiftMask;
- event.x.xkey.keycode = tsdPtr->hWheelAcc / WHEEL_DELTA * WHEEL_DELTA;
- tsdPtr->hWheelAcc = tsdPtr->hWheelAcc % WHEEL_DELTA;
+ event.x.xkey.keycode = intDelta;
+ tsdPtr->hWheelAcc -= intDelta;
break;
}
case WM_SYSKEYDOWN: