| Ticket UUID: | bee96b4e80c5c26763a0a09be4e57f41a1473386 | |||
| Title: | Mouse position warping and tk busy problems on Windows | |||
| Type: | Bug | Version: | 8.6.12 | |
| Submitter: | cjmcdonald | Created on: | 2022-05-04 13:19:23 | |
| Subsystem: | 68. Win Window Operations | Assigned To: | fvogel | |
| Priority: | 5 Medium | Severity: | Severe | |
| Status: | Closed | Last Modified: | 2022-05-22 20:08:26 | |
| Resolution: | Fixed | Closed By: | cjmcdonald | |
| Closed on: | 2022-05-22 20:08:26 | |||
| Description: |
Mouse warping and tk busy don't work on Windows systems with multiple screens which have different Windows scaling settings. This is similar to problem [a9ee4410], but not the same - that was reporting a problem with positioning windows, whereas this is incorrectly positioning the mouse. As helpfully explained by chrstphrchvz in [a9ee4410], the issue is dealing with "logical" pixel density, i.e. the pretend DPI that Windows provides to software; and not the actual measured "physical" pixel density of some particular model display/monitor. My computer setup is running Windows 10 20H2 on a Dell laptop, with an external monitor attached. In the Windows Settings app, on the Display setup page, the Dell laptop screen has Scale and Layout set to 150%. The external monitor has Windows Display setup set to 100%. Both of these are the Windows default "Recommended" settings. I think this type of configuration is quite common when using an older external monitor with a laptop, e.g. in the corporate world where there hasn't been money spent on newer higher resolution monitors. I have the external monitor set as the main screen, and the laptop the secondary screen. To show the problem with mouse warping, start wish. This will normally start on the primary screen. In the wish console enter:
event generate . <Motion> -warp 1 -rootx [winfo x .] -rooty [winfo y .]
This will successfully move the mouse pointer to the top left of the window client area, underneath the window manager title bar.
Now drag the wish window onto the secondary monitor with a different Windows scaling. Repeating the event generate command positions the mouse at the wrong location. The tk busy problem is due to a hidden mouse move in the busy code. To demonstrate, start wish on the primary screen. Then, with keyboard focus in the wish console move the mouse to someplace on the secondary screen. It isn't necessary to move the wish main window. Type the following in the wish console:
tk busy hold .
tk busy forget .
When each command is entered the mouse cursor on the secondary screen will jump position. Very surprising behaviour. The jumps are in the same direction, i.e. they don't cancel each other.
This problem makes the mouse warping and the tk busy both unusable on multi-screen computers with different Windows scaling settings. For that reason I'd classify it as severe. I use the tk busy quite a lot in applications. | |||
| User Comments: |
cjmcdonald added on 2022-05-22 20:08:26:
Thank you for your careful consideration and work on this. fvogel added on 2022-05-22 19:12:43: Merged into core-8-6-branch and trunk. Thanks! fvogel added on 2022-05-12 19:48:26: Thank you for your feedback. Regarding this: > Regarding [69b48f427e] I'm not sure. There's a lot of discussion in > that ticket, and I may not be understanding all of the detail, but > I think that the reason for introducing TkSetCursorPos was in order > to get reliable synchronous operation in the test suite. Not > because of any problems with SetCursor setting the mouse in > applications (at least I haven't seen any). TkSetCursorPos was introduced to restore immediate cursor move, yes. In Windows 10 Creators Fall Update, a ~50 ms delay was introduced between the call to the Windows API function SetCursorPos and the triggering of the corresponding Windows WM_MOVEMOUSE message. This delay indeed made test textTag-18.1 fail, but further than that, the new delay was a change in Windows that made warping largely delayed. So your proposed change restores this 50 ms delay for non-primary screens. Can we live with this delay? And with textTag-18.1 failing on secondary screens? Probably. Comments, anyone? Regarding the other topic about which I have asked, your answer makes sense to me, thanks. cjmcdonald added on 2022-05-09 09:42:33: Regarding [69b48f427e] I'm not sure. There's a lot of discussion in that ticket, and I may not be understanding all of the detail, but I think that the reason for introducing TkSetCursorPos was in order to get reliable synchronous operation in the test suite. Not because of any problems with SetCursor setting the mouse in applications (at least I haven't seen any). So I'm hoping that using the TkSetCursorPos method on the primary screen will allow the test suite to still run reliably, but using SetCursor on the secondary screen will avoid the serious warping/tk busy misbehaviour there. But some guess work on my part, I must admit. I have tested the primary screen with different scalings set, 100% and 150%, and that is all OK. Tk is declared in the manifest to be "system dpi aware", but not "per-monitor dpi aware". My understanding is that Windows then uses the primary screen setting as the "true scale", and will draw everything there pixel for pixel as requested, and it is the secondary screens which get the logical pixel scaling to match. Changing the Windows Scaling on the primary screen affects Windows' idea of the physical size of a pixel, so for example a 9 point font may draw more or less pixels because the points to pixels scaling changes. But it does not affect how individual pixels are drawn on the primary screen, or the number of pixels on that screen - so the TkSetCursorPos method works OK there. However, on the secondary screen Windows outputs logical pixels which may be scaled up or down, and SetCursor is needed as it is aware of that. It's all very confusing. fvogel added on 2022-05-08 19:23:33: I have committed your proposed patch in [3918e477af]. Indeed it fixes the described problem for me too (I have reproduced a scale factor of more than 100% on my secondary screen - same layout as yours). What I'm not fully grasping is:
fvogel added on 2022-05-06 05:47:24: Thanks you for this clear report and fix proposal. I can reproduce the problem and will analyze the situation and the proposed fix (which seems correct to me at first sight). cjmcdonald added on 2022-05-04 13:22:12: The problem lies in the TkSetCursorPos helper routine which was added to win/tkWinPointer.c in tk8.6.10 as a replacement for Windows SetCursor, to address ticket [69b48f427e]. It doesn't handle different Windows scale settings on multiple monitors, which SetCursor does. I doubt that it is possible to fix the TkSetCursorPos calculations to handle that, since the Windows scaling logic is very opaque. Instead, I have modified TkSetCursorPos from Tk8.6.12 so that it uses its own method when the requested mouse position is on the primary screen, but falls back to using SetCursor on other screens. This fixes the problem for me:
--- win/tkWinPointer.c-tk8.6.12 2021-10-29 18:08:24.000000000 +0100
+++ win/tkWinPointer.c 2022-05-04 11:31:44.911010489 +0100
@@ -360,6 +360,17 @@
int xscreen = (int)(GetSystemMetrics(SM_CXSCREEN) - 1);
int yscreen = (int)(GetSystemMetrics(SM_CYSCREEN) - 1);
| |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki