| Ticket UUID: | 3ed5b66989a05482cf65cff598944ea19ecdda59 | |||
| Title: | Malpositioned root window with highlighthickness > 0 | |||
| Type: | Bug | Version: | 8.6 | |
| Submitter: | erikleunissen | Created on: | 2019-09-14 17:41:17 | |
| Subsystem: | 65. Generic Window Operations | Assigned To: | fvogel | |
| Priority: | 3 Low | Severity: | Minor | |
| Status: | Closed | Last Modified: | 2019-10-03 08:10:05 | |
| Resolution: | Fixed | Closed By: | jan.nijtmans | |
| Closed on: | 2019-10-03 08:10:05 | |||
| Description: |
Configuring the root window with a highlight border of non-zero thickness leads to severe misbehaviour. This has been observed under Windows[*] and has not been observed under Linux. [*] exercised on Windows 7 only Observations: a. Extra <Enter> and <Leave> events are triggered when they should not, and they occur at the wrong mouse positions on the display. b. Following a <Configure> event, redrawing of the root window (excluding window decorations) happens at a wrong screen position. The offset depends on the original position of the root window on the display, which must not be [0,0] in order to trigger the bug. My tentative interpretation of this misbehaviour: I think that symptoms a. and b. have the same cause: Internally, Tk moves the root window to a wrong position. Maybe because it doesn't count on the possibility that the root window can have a highlight border, and its computation of screen positions is turned upside down by that neglect. The user is completely fooled/disoriented about the position where Tk moved the root window, because the redraw on screen is only partial. For example, the window decorations remain in place, and [wm geometry .] does not report the wrong offset. It seems that the window manager (or whatever that is under MS Windows) is unaware of Tk mistreating the root window under the hood. The attached script exercises the bug. Bindongs on the root window for <Enter> and <Leave> events report the actual events on stdout with mouse coordinates. Colors are used to facilitate observation of the misbehaviour. Just move the mouse around the root window, see what happens on screen and what's being reported on stdout. And if reproduced: have a good laugh! Erik Leunissen. -- | |||
| User Comments: |
jan.nijtmans added on 2019-10-03 08:10:05:
I'm convinced ;-). So, closing .... Committed to core-8-6-branch and up. fvogel added on 2019-10-03 06:21:44: Sorry to generate such worries by my poor wording. 'I have found a fix', yes, because there could be different fixes achieving the same goal, my proposal is only one of them. But, yes I know why it's happening and why the fix works. As demonstrated by Brad, the problem does not only affect the root '.' window, but really any toplevel. When configuring the toplevel with a non-zero -highlightthickness ConfigureFrame() is called in tkFrame.c. This processes the option/value list and sets the options accordingly. ConfigureFrame() then calls FrameWorldChanged() to recompute the graphics of the frame and schedule an idle redraw. FrameWorldChanged() notably calls Tk_SetInternalBorderEx() in tkGeometry.c. The job of Tk_SetInternalBorderEx() is to notify geometry managers that the window has a border with some width that should not be overlapped by contained windows. Before my fix it achieved this job by calling Tk_ResizeWindow() with unchanged width,height of the window because in that function the net result was to run TkDoConfigureNotify(). See the comments that were in Tk_SetInternalBorderEx(). Tk_ResizeWindow() does two things: it calls XResizeWindow() and then TkDoConfigureNotify(). Note that the only thing we really want is the latter. The former is useless since the window doesn't have a changed size. Pursueing the call chain, on Linux XResizeWindow is an X function but on Windows it is implemented as a call to the Win API MoveWindow() function. It is this call to MoveWindow that wrongly moves the toplevel. It uses x,y coordinates winPtr->changes.x, winPtr->changes.y which were not set upper in the call chain. This should not be necessary, they still contain the x,y from the recent 'wm geometry' command, but nevertheless the window moves. This point is still obscure, but I don't think we need to clarify this (read further). Therefore the fix: we don't need to move the window, so don't call MoveWindow(). We only need the geometry managers to be notified of the new border, so call TkDoConfigureNotify() directly instead of calling it through Tk_ResizeWindow(), so that the anyway useless call to XResizeWindow() is not executed, and the window will not move whereas the geometry managers will still be notified of the highlightthickness change. Does this sound convincing to you? bll added on 2019-10-03 00:22:14: Er, that could be misread. Occurs with the *unpatched* code. bll added on 2019-10-03 00:13:55: Well, it seems to occur in some instances with other toplevels:
package require Tk
toplevel .z
.z configure -highlightbackground red
wm geometry . 400x400+100+100
wm geometry .z 400x400+100+100
raise .z .
update
after 2000 {.z configure -bg #55CCFF -highlightthickness 20}
When I tried placing .z at 400x400+450+100, the background didn't show up.
I assume(!) that the offset was so far off, it did not show at all.
erikleunissen added on 2019-10-02 21:41:00: First off: personally I'm happy with a resolution of this ticket through the fix by François. Nevertheless: The misbehaviour was observed with the root window. *I* never encountered the issue for other windows in a more complex GUI. But that's is not a guarantee that the malpositioning doesn't show up in another circumstances for other widgets. I didn't carry out an systematic inspection of other circumstances simply because I have no idea about what the possible relevant other circumstances could be. It would be more convincing though if we could come up with a plausible reasoning (not to mention the word "proof"), for: - this issue to affect the root window only; - the fix to cover all other imaginable circumstances. I don't have the insight into Tk to be able to come up with such reasoning. Even if we cannot come up with such a plausible logic, I can imagine that we can still be very satisfied and decide to apply this fix. I just don't know what's wise/policy in a case like this. B.t.w. My reaction is also triggered by the wording by François: "I have found a fix", which is different from "I have found the cause". jan.nijtmans added on 2019-10-02 20:13:45: +1. Good work! erikleunissen added on 2019-10-02 19:08:38: Confirmation of the fix: I've tested the fix against 8.6.9: - patched the source for the Tk release 8.6.9 - compiled that against a regular Tcl8.6.9 build - execute the new wish on Windows 7, and source the exercise.tcl script. Result: the root window was positioned where it should, and there were no more faulty <Enter> and <Leave> events. Thanks! fvogel added on 2019-10-01 20:37:36: In the test script there is no need for a button or anything, just use:
package require Tk
. configure -highlightbackground red
wm geometry . 400x400+100+100
update
after idle {. configure -bg #55CCFF -highlightthickness 20}
I have found a fix, see [c128b80ee6]. It consists in calling No test newly fails with this fix, at least in the bugfix branch. bll added on 2019-09-14 19:19:02: #!/usr/bin/tclsh
package require Tk
proc seth { } {
. configure -bg #55CCFF -highlightthickness 2
}
. configure -highlightbackground red
ttk::button .b -text {Set} -command seth
pack .b
wm geometry . 400x400+100+100
bll added on 2019-09-14 19:10:48: Confirmed. Yes, it is certainly weird, but is there a use case for changing the highlight thickness of the root window? a) A highlight on the root window is not common. b) Changing the highlight thickness is even less common. I'm not saying there is not a problem. Indeed, it seems that configuring the highlight thickness within the event handler after the root window has been displayed causes the redisplay problem. I also tried with a button and command handler and the same issue. Generally to turn off a highlight, the highlight color would be changed to match the widget background. Otherwise a redraw event occurs. As this is rather obscure, uncommon, easy to work around, I have set this to low priority, minor severity. | |||
Attachments:
- exercise.tcl [download] added by erikleunissen on 2019-09-14 17:42:02. [details]
