Tk Source Code

View Ticket
Login
2026-10-24
08:38 • Open ticket [220856ff]: winfo containing doesn't work on non-root E desktops plus 4 other changes artifact: 8b679723 user: serhiy.storchaka
2019-01-04
03:41 • Closed ticket [18a4ba19]: Incorrect information reported by "winfo containing" in linux. plus 7 other changes artifact: e0bf8c0d user: marc_culler
01:01
Resolve bug [18a4ba19bd]. Make winfo containing behave consistently across platforms and fix a bug with embedded toplevels. check-in: 359434f3 user: culler tags: trunk
00:49
Resolve bug [18a4ba19bd]. Make winfo containing behave consistently across platforms and fix a bug with embedded toplevels. check-in: 6942f5af user: culler tags: core-8-6-branch
2018-12-17
17:20 • Ticket [18a4ba19] Incorrect information reported by "winfo containing" in linux. status still Open with 4 other changes artifact: 88ce0cac user: marc_culler
17:18 • Ticket [18a4ba19]: 4 changes artifact: edd43f91 user: marc_culler
2018-12-15
20:22 • Ticket [18a4ba19]: 3 changes artifact: e65f0c01 user: bll
17:41 • Ticket [18a4ba19]: 3 changes artifact: 93071118 user: marc_culler
17:13 • Ticket [18a4ba19]: 3 changes artifact: 969ed384 user: bll
17:01 • Ticket [18a4ba19]: 3 changes artifact: 5372866e user: bll
17:00 • Ticket [18a4ba19]: 3 changes artifact: 87f062f0 user: bll
16:06 • Ticket [18a4ba19]: 4 changes artifact: 85dc498c user: marc_culler
01:42 • Ticket [18a4ba19]: 4 changes artifact: 0f0f45e5 user: marc_culler
00:10 • Ticket [18a4ba19]: 3 changes artifact: ba1d4b76 user: bll
2018-12-14
17:23 • Ticket [18a4ba19]: 4 changes artifact: 255f5098 user: marc_culler
2018-12-13
23:20 • Ticket [18a4ba19]: 4 changes artifact: 40c8b5ae user: marc_culler
19:31 • Ticket [18a4ba19]: 4 changes artifact: 7d693a02 user: marc_culler
18:57 • Ticket [18a4ba19]: 3 changes artifact: 67bec170 user: bll
18:54 • Ticket [18a4ba19]: 3 changes artifact: 54c78f1d user: bll
18:41 • Ticket [18a4ba19]: 3 changes artifact: e44e65b8 user: bll
18:35 • Ticket [18a4ba19]: 3 changes artifact: e28ff557 user: bll
16:58 • Ticket [18a4ba19]: 4 changes artifact: a45fd126 user: marc_culler
16:53 • Ticket [18a4ba19]: 4 changes artifact: f95cdf71 user: marc_culler
05:31 • Ticket [18a4ba19]: 3 changes artifact: 848f9ce7 user: bll
04:18 • Ticket [18a4ba19]: 4 changes artifact: 8fd35241 user: marc_culler
2018-12-12
16:19 • Ticket [18a4ba19]: 3 changes artifact: 95f0be18 user: bll
04:42 • Ticket [18a4ba19]: 4 changes artifact: 97fb573b user: marc_culler
01:09 • Ticket [18a4ba19]: 3 changes artifact: ddf90c52 user: bll
2018-12-11
19:55
fix bug [18a4ba19bd]: winfo containing gives wrong answer on linux. check-in: 0ce471e4 user: culler tags: bug-18a4ba19bd
17:10 • Ticket [18a4ba19] Incorrect information reported by "winfo containing" in linux. status still Open with 4 other changes artifact: a09eadba user: marc_culler
14:53 • Ticket [18a4ba19]: 3 changes artifact: b86515a9 user: bll
14:31 • Ticket [18a4ba19]: 3 changes artifact: 4717dff8 user: bll
14:03 • Ticket [18a4ba19]: 3 changes artifact: d514ca2a user: bll
13:41 • Ticket [18a4ba19]: 3 changes artifact: c85f8c51 user: bll
13:28 • Ticket [18a4ba19]: 5 changes artifact: 448816b2 user: marc_culler
2018-12-10
23:26 • Ticket [18a4ba19]: 3 changes artifact: cd2324ec user: bll
20:38 • New ticket [18a4ba19]. artifact: 8ee57e96 user: marc_culler

Ticket UUID: 18a4ba19bd0eb3af8f69afb7ef9c0af0938f2ba2
Title: Incorrect information reported by "winfo containing" in linux.
Type: Bug Version: 8.6.9
Submitter: marc_culler Created on: 2018-12-10 20:38:06
Subsystem: 67. Unix Window Operations Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2019-01-04 03:41:14
Resolution: Fixed Closed By: marc_culler
    Closed on: 2019-01-04 03:41:14
Description:

I found a bug in the macOS implementation of "winfo containing". But when I fixed it, the tests in unixWm.c still failed. Digging deeper, I found that the tests unixWm-50.1 and unixWm-50.2 are checking for behavior which is counter-intuitive and not consistent with the manual, but which does actually occur in linux. When one window is in front of another, there is a 10 pixel zone around the front window where "winfo containing" reports no window containing the point, even when the point is inside the back window. Here is an example using wish in Ubuntu 18.04 with the core-8-6-branch tip:

% toplevel .t -width 200 -height 200 -bg red
.t
% wm geometry . 400x400+100+100
% wm geometry .t 200x200+200+200
% winfo containing 150 300 # correct: inside . but not inside .t
.
% winfo containing 190 300 # wrong: inside . but no window reported
% winfo containing 200 300 # correct: the left edge of .t is inside .t
.t
% winfo containing 399 300 # correct: this is the last point in .t
.t
% winfo containing 400 300 # wrong: on the right edge of .t and inside . but no window reported
% winfo containing 409 300 # wrong: inside . but no window reported
% winfo containing 410 300 # correct: 10 pixels to the right of .t we are back in .
.

User Comments: marc_culler (claiming to be Marc Culler) added on 2019-01-04 03:41:14:

This ticket is resolved by check-in 6942f5af. On unix the behavior of "winfo containing" with respect to borders (including invisible borders) is preserved, but documented. The same behavior is implemented for macOS. And a bug involving toplevels embedded in a window belonging to a different interpreter was fixed.


marc_culler (claiming to be Marc Culler) added on 2018-12-17 17:20:56:
Missed one: 44.8 also fails on Ubuntu 18.04 with Unity.

marc_culler (claiming to be Marc Culler) added on 2018-12-17 17:18:08:
It turns out that the Gnome 3 behavior is completely consistent with other X11
window managers, once you realize that the windows *do* have borders which just
happen to be invisible.

Given that, I decided that rather than change the behavior which returns an
empty string for points in the border or title bar, the behavior should just be
documented.  So I reverted the behavior, added a few lines to the "winfo
containing" man page and made the Mac behave the same way.

There was aother linux bug related to embedded toplevels belonging to a
different application, which did not become apparent until I rewrote unixWM-50.4
to use a slave interpreter instead of dobg (which doesn't work at all on the
Mac).  I think that is fixed.

Now all of the unixWm tests pass on the Mac.  On Ubuntu 18.04 I am seeing
failures of 4.1, 4.2, 4.3, 8.4, 9.3, 16.3, 23.5, 23.6, 42.1, 44.7, 45.2, 45.4.
I don't think any of these are related to "winfo containing".

I think this project is finished.  Can anyone confirm that this works?

bll added on 2018-12-15 20:22:15:
Forgot to answer that.
I think it will be ok to return a pathname,
as my guess is that winfo containing is mostly used for other purposes.
Could ask on comp.lang.tcl or core-tcl mailing list.

marc_culler added on 2018-12-15 17:41:50:
But what about the question of whether to return an empty string or a
pathname when the point is in the border?

bll added on 2018-12-15 17:13:54:
The menu tests pass for me.

unixWm failing tests are 4.1, 4.3, 42.1, 44.7, 44.8, 45.2, 45.4 (MX Linux).
none of which are winfo containing.

bll added on 2018-12-15 17:01:19:
Well, it's a shame [702ef0de] did not work out.

The tests for menu need to be run -- it uses winfo containing, and
the menus are toplevels.  I don't know what uses it internally at
the C level.

bll added on 2018-12-15 17:00:04:
Well, it's a shame [702ef0de] did not work out.

The tests for menu need to be run -- it uses winfo containing, and
the menus are toplevels.  I don't know what uses it internally at
the C level.

marc_culler (claiming to be Marc Culler) added on 2018-12-15 16:06:34:
Wow.  This is painful, not to mention time-consuming.

The question of whether to return {} when the point is contained in the border
or title bar of the highest containing window is not some side issue.  It is
the whole story.  The reason that Gnome 3 seemed to be behaving so strangely is
that Gnome 3 windows actually have borders that are 10 pixels wide.  The borders
just happen to be transparent.  The implementation of these borders is simple.
They just set

 wmPtr->xInParent = 10,
 wmPtr->parentWidth = winPtr->changes.width + 20,
 etc.

The tests are written under the assumption that every window will have a border
of width at least 1 px, and that the answer should be {} if the point is in the
border.  Modern Mac windows, of course, truly have no borders.  So they fail
the test.

Here is where things stand.  We now have two implementations of "winfo containing".
When the point is in the title bar or border of the top containing window one
implementation returns {} and the other returns the name of the next lower
window containing the point.

So the question is: which one should we use?    The manual is no help since it
does not mention borders or title bars at all (and that missing documentation
is really the root cause of this whole problem, along with the fact that
invisible borders are invisible). Obviously the current core-8-6-branch
version will be more backwards compatible.  It is arguable that the new one
makes more sense, but that point is certainly debatable.

marc_culler (claiming to be Marc Culler) added on 2018-12-15 01:42:37:
I'd say it is good enough, unless you think it is important and preferable to
restore the old behavior with title bars and borders.

All tests pass on Ubuntu 18.04 with Gnome3.  One test fails on macOS. That seems
to be some sort of bug with embedded toplevels, probably unrelated to the
"winfo containing" command.

bll added on 2018-12-15 00:10:35:
Ugh. The recommended way of installing kde really mucked up my VM.
Restored from backup.  I think I will download a kubuntu 18.04 and create a 
separate VM.

But it works on KDE.  They have relatively wide borders on their windows (6px).

So now the underlying window gets reported for title bar and borders.
e.g. winfo containing 200 250 returns .  rather than {} as before.

Gnome-3's invisible window is ignored of course with this method.

Is this good enough?  Are all the tests passing?

marc_culler (claiming to be Marc Culler) added on 2018-12-14 17:23:57:

Ouch! I was foolishly assuming that the list of windows was sorted in stack order. Of course it isn't. So I had to rework the algorithm yet another time. This may really be the last time.

The code is in check-in: [705e64b5] to the bug-18a4ba19bd branch.


marc_culler (claiming to be Marc Culler) added on 2018-12-13 23:20:13:

I reworked the logic a bit in the latest check-in [702ef0de]. That seems to make things work when one of the windows containing the point is the root.

But this is not the end of the story, needless to say. After that change some of the tests started failing. The failure was that "winfo containing" was reporting . when it should have been reporting {}. This is impossible, however, since . is icnoified before running those tests. Well, except it turned out that it was not being iconified in spite of the call to "wm inconify .". I was able to get the tests to pass by moving the root window far away from the action. But now we have to figure out how a change in the "winfo containing" command could possibly have broken the totally unrelated "wm iconify" command. Of course "wm iconify" works fine in the shell, so this is probably a timing issue of some sort.


marc_culler (claiming to be Marc Culler) added on 2018-12-13 19:31:14:

Interesting! It is not as bad as it looks, though. Apparently it has something to do with one of the windows being the root. It works fine with two non root windows. (Which is how I was testing. Sigh.)

% toplevel .t1 -width 400 -height 400 -bg green
.t1
% toplevel .t2 -width 200 -height 200 -bg red
.t2
% wm geometry .t1 +100+100
% wm geometry .t2 +200+200
% winfo containing 150 250
.t1
% winfo containing 190 250
.t1
% winfo containing 199 250
.t1
% winfo containing 200 250
.t2
% winfo containing 399 250
.t2
% winfo containing 400 250
.t1


bll added on 2018-12-13 18:57:49:
Should have said winPtr->mainPtr is not equal.

bll added on 2018-12-13 18:54:50:
The code determines there is a valid nextptr, goes to gottoplevel, but
winPtr->mainPtr is null.

bll added on 2018-12-13 18:41:35:
For gnome-3:

% winfo containing 189 250
189 >= 101 && 189 < 501 && 250 >= 128 && 250 < 528
.
% winfo containing 190 250
190 >= 201 && 190 < 401 && 250 >= 228 && 250 < 428

bll added on 2018-12-13 18:35:23:
This seems to be the same as the original.
I see a 10 pixel wide border with gnome-3 when using winfo containing.
I put in some debug statements to make sure I got the new compiled code.
I checked on macOS also and it seems ok there, title handling is different,
of course.

Gnome-3:
% winfo rooty .t
228
% winfo rootx .t
201
% wm geometry .t
200x200+200+200

The size of the window is reported without the invisible border, so it 
should be possible to ignore the invisible part.

marc_culler (claiming to be Marc Culler) added on 2018-12-13 16:58:36:

OK, I reverted tkUnixWm.c back to the core-8-6-branch version and then took care to make the absolute minimal change needed to fix the problem with the invisible borders. The observed behavior of Gnome3 and the workaround are explained in a comment. The tests unixWM-50.1 - unixWm-50.10 still pass. I believe that the behavior with titlebars, borders and foreigh windows should all be the same as before, whatever that was. A total of 11 contiguous lines of code were added.

Please test check-in [9c4a5faf]. (Thanks!)


marc_culler (claiming to be Marc Culler) added on 2018-12-13 16:53:29:
Right.  I should have said "window managers" where I said "distros".

I am going to pursue a different strategy (d).  I am going to start all over
again with the core-8-6-branch version of tkUnixWm.c.  Now that I understand
the code better I think I may be able to fix this specific problem with a
much smaller change which will not affect any other behaviors.

bll added on 2018-12-13 05:31:07:
You don't need other distros.  You can install XFCE and Mate and other
window managers on your Ubuntu system.

> However, I am taking your word that this is an expected X11 behavior and 
> so should be preserved. Do you think that macOS should do this too? 
> Should it be a documented behavior?

Unfortunately, Tk has some interfaces that are very thin
layers over the X11 api.  Obviously, quite often, these don't 
translate to Windows and Mac OS X very well.

I don't know the correct answer to this question, as Tk was originally 
developed on unix with the thin layers over the X11 api.  In most cases, 
I think the native semantics should be used.  But this causes 
portability issues.  It's a design problem from long ago.

I am just worried about backwards compatibility.

Very possibly I'm worrying too much, as most of the time winfo 
containing is used when the Tk windows are active.  I believe all of 
the uses of it I have are certainly not to determine which toplevel 
I might be in, but which specific widget I am in.

I just tested the latest changes you mentioned.  Doesn't always work.

At this point, choices are:
a) Revert to the original X11 behavior.
b) Use the changes before 8e843c7a
c) Continue with the fixes so that a Tk window will not be reported when
overlaid with some other window.

Damned if I know what to do about title bars and borders.

I'm just right now trying to figure out the risk assessment.
(a) is certainly valid, but may create special case code for macos, 
which is not wanted.  It maintains backwards compatibility, but windows
and macos may work differently.
(b) and (c) creates a logical method for determining which window (though 
title bars and borders are weird) that matches what the documentation
states.  Should create a single method that works across platforms.
-- In general 'winfo containing' is mostly (assumption) used to determine 
which specific widget the coordinates are in.

I suppose (c) is fine, though I have no idea what to do about title bars
and borders.  If it can be done, it would be safest to not report a Tk
window when overlaid.  If this can't be made to work, then back to (b), 
perhaps.

I wonder what gnome-3 reports as the border size.

Sorry, this got long and rambled a bit.

marc_culler (claiming to be Marc Culler) added on 2018-12-13 04:18:23:

(b) The issue is that on some linux distros the "winfo containing" command incorrectly returns an empty string when there is a small window contained in and higher than a larger window, and the point is inside the larger window, outside of the smaller window but close to its border. This is not what the manual says should happen and should not be expected by the tests unixWm-50.1 and unixWm-50.2. The command should return the pathname of the larger window.

(a) As you (bll) have so kindly and carefully documented in this ticket, the problem does indeed exist and occurs on Gnome-3 systems exactly when the point is inside the "invisible border" that Gnome-3 provides in order to make resizing easier. The goal is to fix the problem described in (b) and not break or change anything else.

(c) The latest commit to the bugfix branch, check-in [8e843c7a], fixes (b) and also attempts to ensure that neither of the two things described in your (c) happens. If the point is inside the title bar of a window the command does not return that window's pathname. If the point is covered by a higher window belonging to a different process the command returns an empty string. The second behavior is not something that I could expect from reading the manual, which simply says "If no window in this application contains the point then an empty string is returned." However, I am taking your word that this is an expected X11 behavior and so should be preserved. Do you think that macOS should do this too? Should it be a documented behavior?

More importantly, check-in [8e843c7a] makes Ubuntu 18.04 pass all of the tests that involve the "winfo containing" command, namely unixWm-50.1 -- unixWm-50.10. I do not know what happens on other distros yet.

(d) There is no change to the semantics of the "winfo containing" command. The only change is to return the pathname of the larger window in the situation described above in part (b). If there is any other change it is a bug, and I would appreciate hearing about it.


bll added on 2018-12-12 16:19:48:
a) I think this is trying to fix a problem that does not exist.
b) I would like to see a clear statement of the issue, as I do not
   understand what it is you think is wrong.  winfo containing
   works as it has always has been working on X11.
c) The bug fix branch completely changes how winfo containing works.
   I can now overlay the windows with my terminal, and winfo containing
   now claims that the coordinates are within . or .t.
   winfo containing now also claims that the mouse pointer is part of a 
   window when the coordinates are in the title bar.
d) I do not think a change of this magnitude should be going in.
   This is not a bug fix, but a complete change of the semantics of
   winfo containing.

marc_culler (claiming to be Marc Culler) added on 2018-12-12 04:42:52:

I think this is fixable. In fact, Check-in [365289f5] in the bug-18a4ba19bd branch may be a fix. Please test it. It works correctly for me on Ubuntu 18.04, at least in the basic setting that the tests consider. It should be treated as very tentative, since I have not tested on any other distros and there may be tricky special cases that I missed. But I think it is close to being correct.

There are two points. (1) It is easy to recognize the invisible window. It shows up as a wmPtr with NULL winPtr. Obviously a window with no winPtr will also have no name and cannot possibly be the answer to wm containing. (2) I think the strategy in the current code is wrong. Basically, if they see any wmPtr that smells bad they return NULL. What they should do instead is to keep searching in case there is a nice toplevel further down in the stack which contains the the point. That is how my implementation works.

You have to be a bit careful about testing points in the title bar. The window may not be where you think it is:

% wm geometry . 400x400+100+100
% wm geometry .
400x400+100+100
% winfo y .
130

In my case I think the extra 30 pixels come from the Unity menu bar. Anyway, in my tests Check-in [365289f5] gives the right answer for points in the title bar.


bll added on 2018-12-12 01:09:21:
I suspect that since the borders and invisible borders are not
"owned" by Tk, they will always return NULL. 

Note that winfo containing on the title bar also returns NULL.
winfo containing 210 210 ; # on MX Linux, no window is returned.

I doubt if anything can be done about this, as the borders are 
apparently not part of Tk's window, but belong to the window 
manager.

marc_culler (claiming to be Marc Culler) added on 2018-12-11 17:10:56:

The X11 API call seems to be XTranslateCoordinates.

The man page for XTranslateCoordinates says:

If the coordinates are contained in a mapped child of dest_w, that child is
returned to child_return. Otherwise, child_return is set to None.
Here is my guess. The invisible window, which is 10 pixels bigger in each dimension, is just below the highest window. But it is not mapped. So XTranslateCoordinates returns NULL for the child_return pointer when the point is outside the highest window but inside the invisible window.


bll added on 2018-12-11 14:53:42:
This appears to be gnome-3's invisible window border.

If you move the mouse around, you will notice that there is an invisible
window border in which the cursor changes to the resize-window cursor.

This is done so that the windows can be resized easier, given modern window's
very thin borders and especially with issues grabbing borders on hi-dpi 
displays.

I wish windows 10 and Xfce had this.  It is so difficult to resize windows
nowadays.

bll added on 2018-12-11 14:31:49:
Ubuntu 18.04/Gnome3, ng.
Ubuntu 16.04/Mate, ok.
Ubuntu 16.04/Unity, ng.
Ubuntu 16.04/xfce, ok.
Ubuntu 16.04/Cinnamon, ng.

Don't know how to tell whether gnome3 or unity is running.
As unity is mostly gnome3, there's not a lot of difference.

This appears to be a problem in gnome3 and variants.
I guess we need to know the X11 api call so we can check in launchpad and see if
this is a known problem or not.

bll added on 2018-12-11 14:03:41:
Ubuntu 18.04/Unity, confirmed.
Ubuntu 16.04/Mate, ok.
Ubuntu 16.04/Unity, ng.
Ubuntu 16.04/xfce, ok.

Appears to be an issue with unity.
Going to download an install cinnamon, as that is also based on gnome-3.

bll added on 2018-12-11 13:41:15:
MX Linux 17.1, xfce:
I guess I will hook up the hard drive and try the 18.04 VM.

bll-tecra:bll$ rlwrap ../linux/64/tcl/bin/tclsh
% package require Tk
8.6.9
% toplevel .t -bg red
.t
% wm geometry . 400x400+100+100
% wm geometry .t 200x200+200+200
% focus . ; update
% winfo containing 195 300
.
% focus .t ; update
% winfo containing 195 300
.
%

marc_culler (claiming to be Marc Culler) added on 2018-12-11 13:28:15:

The behavior of bind is not related to this problem. I don't see any issue with events being received by the wrong window, or being missed. This problem is only about the command "wminfo containing".

I am not seeing any change in behavior if I change the focus. In the example below (on Ubuntu 18.04) the point 195 300 is in the 10 pixel wide dead zone around the small window .t. For points in that zone "winfo containing" reports that no window contains the point, even though the entire zone is contained in the big window. This behavior is expected by the tests, but I think it is wrong.

@bll I think you are reporting a different issue, that I am trying to separate from this one. Namely that when "winfo containing" is used in a script the results are different than when the command is entered into the wish shell. I am guessing that that is a timing issue, but I don't know. In any case it seems simpler to first make sure we are getting correct behavior in the shell, before worrying about things that might be related to timing.

% toplevel .t -bg red
.t
% wm geometry . 400x400+100+100
% wm geometry .t 200x200+200+200
% focus . ; update
% winfo containing 195 300 # returns no window - should be .
% focus .t ; update
% winfo containing 195 300 # returns no window - should be .
%


bll added on 2018-12-10 23:26:54:
I think the window focus has to be set.
In the code below, the 'bind's work properly.
I mucked with the focus, so the comments are not valid any longer.
I suspect C is on the window border (for my execution), so it doesn't register.

package require Tk
toplevel .t -width 200 -height 200 -bg red
wm geometry . 400x400+100+100
wm geometry .t 200x200+200+200
update
raise .t .
update
focus .;update
puts "A:[winfo containing 150 300] # correct: inside . but not inside .t"
focus .;update
puts "B:[winfo containing 190 300] # wrong: inside . but no window reported"
focus .t;update
puts "C:[winfo containing 200 300] # correct: the left edge of .t is inside .t"
focus .t;update
puts "D:[winfo containing 399 300] # correct: this is the last point in .t"
focus .t;update
puts "E:[winfo containing 400 300] # wrong: on the right edge of .t and inside . but no window reported"
focus .;update
puts "F:[winfo containing 409 300] # wrong: inside . but no window reported"
focus .;update
puts "G:[winfo containing 410 300] # correct: 10 pixels to the right of .t we are back in ."

proc z { x y }  {
   puts "z: [winfo containing $x $y]"
}

bind . <ButtonRelease-1> [list z %X %Y]
bind .t <ButtonRelease-1> [list z %X %Y]


A:. # correct: inside . but not inside .t
B:. # wrong: inside . but no window reported
C: # correct: the left edge of .t is inside .t
D:.t # correct: this is the last point in .t
E:.t # wrong: on the right edge of .t and inside . but no window reported
F:. # wrong: inside . but no window reported
G:. # correct: 10 pixels to the right of .t we are back in .