diff options
-rw-r--r-- | tests/bind.test | 40 | ||||
-rw-r--r-- | win/tkWinInt.h | 6 | ||||
-rw-r--r-- | win/tkWinPointer.c | 35 | ||||
-rw-r--r-- | win/tkWinWindow.c | 4 |
4 files changed, 77 insertions, 8 deletions
diff --git a/tests/bind.test b/tests/bind.test index 5f45ffc..6eb806a 100644 --- a/tests/bind.test +++ b/tests/bind.test @@ -6597,6 +6597,46 @@ test bind-33.15 {prefer last in case of homogeneous equal patterns} -setup { # must be preferred. } -result {last} +test bind-34.1 {-warp works relatively to a window} -setup { + toplevel .top +} -body { + # In order to avoid platform-dependent coordinate results due to + # decorations and borders, this test warps the pointer twice + # relatively to a window that moved in the meantime, and checks + # how much the pointer moved + wm geometry .top +200+200 + update + event generate .top <Motion> -x 20 -y 20 -warp 1 + update idletasks ; # DoWarp is an idle callback + set pointerPos1 [winfo pointerxy .t] + wm geometry .top +600+600 + update + event generate .top <Motion> -x 20 -y 20 -warp 1 + update idletasks ; # DoWarp is an idle callback + set pointerPos2 [winfo pointerxy .t] + # from the first warped position to the second one, the mouse + # pointer should have moved the same amount as the window moved + set res 1 + foreach pos1 $pointerPos1 pos2 $pointerPos2 { + if {$pos1 != [expr {$pos2 - 400}]} { + set res 0 + } + } + set res +} -cleanup { + destroy .top +} -result {1} +test bind-34.2 {-warp works relatively to the screen} -setup { +} -body { + # Contrary to bind-32.2, we're directly checking screen coordinates + event generate {} <Motion> -x 20 -y 20 -warp 1 + update idletasks ; # DoWarp is an idle callback + set res [winfo pointerxy .] + event generate {} <Motion> -x 200 -y 200 -warp 1 + update idletasks ; # DoWarp is an idle callback + lappend res {*}[winfo pointerxy .] +} -cleanup { +} -result {20 20 200 200} # cleanup cleanupTests diff --git a/win/tkWinInt.h b/win/tkWinInt.h index 0e2c844..9cd49cd 100644 --- a/win/tkWinInt.h +++ b/win/tkWinInt.h @@ -201,6 +201,12 @@ MODULE_SCOPE void TkpWinToplevelDetachWindow(TkWindow *winPtr); MODULE_SCOPE int TkpWmGetState(TkWindow *winPtr); /* + * The following is implemented in tkWinPointer.c and also used in tkWinWindow.c + */ + +MODULE_SCOPE void TkSetCursorPos(int x, int y); + +/* * Common routines used in Windows implementation */ MODULE_SCOPE Tcl_Obj * TkWin32ErrorObj(HRESULT hrError); diff --git a/win/tkWinPointer.c b/win/tkWinPointer.c index 251b5b9..8ab512c 100644 --- a/win/tkWinPointer.c +++ b/win/tkWinPointer.c @@ -336,10 +336,10 @@ XQueryPointer( /* *---------------------------------------------------------------------- * - * XWarpPointer -- + * XWarpPointer, TkpWarpPointer -- * - * Move pointer to new location. This is not a complete implementation of - * this function. + * Move pointer to new location. Note that implementation of XWarpPointer + * is incomplete. * * Results: * None. @@ -350,6 +350,29 @@ XQueryPointer( *---------------------------------------------------------------------- */ +/* + * TkSetCursorPos is a helper function replacing SetCursorPos since this + * latter Windows function appears to have been broken by Microsoft + * since Win10 Falls Creator Update - See ticket [69b48f427e] along with + * several other Internet reports about this breakage. + */ + +void TkSetCursorPos( + int x, + int y) +{ + INPUT input; + + input.type = INPUT_MOUSE; + input.mi.dx = x * (65535.0 / (GetSystemMetrics(SM_CXSCREEN) - 1)); + input.mi.dy = y * (65535.0 / (GetSystemMetrics(SM_CYSCREEN) - 1)); + input.mi.mouseData = 0; + input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE; + input.mi.time = 0; + input.mi.dwExtraInfo = 0; + SendInput(1, &input, sizeof(input)); +} + int XWarpPointer( Display *display, @@ -365,7 +388,7 @@ XWarpPointer( RECT r; GetWindowRect(Tk_GetHWND(dest_w), &r); - SetCursorPos(r.left+dest_x, r.top+dest_y); + TkSetCursorPos(r.left+dest_x, r.top+dest_y); return Success; } @@ -377,9 +400,9 @@ TkpWarpPointer( RECT r; GetWindowRect(Tk_GetHWND(Tk_WindowId(dispPtr->warpWindow)), &r); - SetCursorPos(r.left + dispPtr->warpX, r.top + dispPtr->warpY); + TkSetCursorPos(r.left + dispPtr->warpX, r.top + dispPtr->warpY); } else { - SetCursorPos(dispPtr->warpX, dispPtr->warpY); + TkSetCursorPos(dispPtr->warpX, dispPtr->warpY); } } diff --git a/win/tkWinWindow.c b/win/tkWinWindow.c index 445ff9c..57c948e 100644 --- a/win/tkWinWindow.c +++ b/win/tkWinWindow.c @@ -882,7 +882,7 @@ TkpShowBusyWindow( */ GetCursorPos(&point); - SetCursorPos(point.x, point.y); + TkSetCursorPos(point.x, point.y); } /* @@ -924,7 +924,7 @@ TkpHideBusyWindow( */ GetCursorPos(&point); - SetCursorPos(point.x, point.y); + TkSetCursorPos(point.x, point.y); } /* |