| Ticket UUID: | e5ccf5425407b90973a5c6c9a915dd284b159c8d | |||
| Title: | Binding to toplevels fails for the root window | |||
| Type: | Bug | Version: | 8.6.10 | |
| Submitter: | erikleunissen | Created on: | 2020-12-14 12:11:20 | |
| Subsystem: | 01. Bindings | Assigned To: | nobody | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Open | Last Modified: | 2021-01-03 18:57:49 | |
| Resolution: | None | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
(Observed under Linux) Binding to toplevels, using the invocation: [bind Toplevel $event $script] dos not affect the root window because its class is not Toplevel. Its class has been set to the name of the invoked program on program launch. I do not understand the reason for this, but it appears intentionally (but undocumented). This class replacement, however, introduces inconsistent behaviour when binding to toplevels: all toplevels respond to such a binding except the root window. The attached script exercise.tcl demonstrates the issue. I don't understand the reason of this class replacement for the root window (and that seems to me crucial. But from the sole, maybe limited, point of view of the inconsistency that it creates when handling toplevels, to me this is "not OK" (a misfeature?). Do we need to accept this inconsistency? If not, I see two different solutions that restore consistency: A. The class replacement on program launch is a misfeature ========================================================== Revert the whole implementation of the widget class replacement for the root window, AND MAYBE for compensation add the program name *as a binding tag* to the root window. B. The class replacement on program launch is based on really good jugdgement ============================================================================= In this case, an additional binding tag "Toplevel" may be added to the root window. Maybe there is an option C. that I don't see. | |||
| User Comments: |
erikleunissen added on 2021-01-03 18:57:49:
Thanks for posting your view. It's clear that our views differ.
W.r.t.
"Yes it has consequences in the bindtags. And again this is fine: Use the specific bindtag item or don't use it. ... "
I consider what you suggest as a (rather extreme) workaround for a bug/misfeature with a conceptual origin. In this case the issue exhibits when you want to bind to the widget class "Toplevel".
The documentation targets two different aspects in isolation:
- the exceptional treatment of the application name/class as a widget class
- the 2nd binding tag representing the widget class.
You can "piece this together" as cjmcdonald posted (the first repsonse to this ticket). However, I don't believe that these two aspects in isolation show the intent/design/purpose w.r.t. the consequence for the binding tags of the root window. I rather consider the issue of this ticket as a conceptual exception having been allowed to propagate one step too far. And then you can document as much as you like, that doesn't justify something that's wrong at a conceptual level. (You may add "Alice in Wonderland" to your documentation, but that doesn't make it useful ;-) ). But the documentation isn't my target. The origin of the issue is elsewhere.
I am going to rest this case if there is no further support for my point of view. No problem! I'm happy that at least the different views are clear.
fvogel added on 2021-01-01 22:36:34: Toplevels created through the 'toplevel' Tcl/Tk command can be created with a specifically given class, or without that option specified at creation time. Result in the bindtags is not the same, and that's just fine: in each case we get what we have requested. Either the bindtags list contains "Toplevel" or it contains a most specific item specified by the programmer. The decision to specify -class or not at toplevel creation time needs to be thought of carefully by the programmer: does he need a specific class of toplevels that he will bind something to later, or are the created toplevels just standard toplevels of class "Toplevel"? That's a design decision, and it depends on the application. And all this stuff is documented (even if documentation is always perfectible). About the root toplevel: The root toplevel gets a specific class at creation time (it gets the name of the application). This is out of the control of the programmer and is documented. Yes it has consequences in the bindtags. And again this is fine: Use the specific bindtag item or don't use it. If the "." root toplevel window is not needed, of the consequences in the bindtags of "." are not desired, then just "wm withdraw" it, forget about it, and use other toplevels (which are children of "." by the way). Many apps do this. Therefore, indeed, I'm not convinced that something needs to be changed. And since I don't see that something needs to be changed, what the change should be is even more obscure. erikleunissen added on 2021-01-01 18:52:07: W.r.t.
"In a nutshell: it's hard for me to tell what is the right way to go."
Yes, I can certainly understand that this is not an easy one.
But I also sense some hesitation in your response. Do you maybe think that the current state of affairs is OK?
fvogel added on 2020-12-31 11:33:47: When creating a toplevel window, it gets three binding tags: the name of the toplevel window, its class name, and all. When the class is not given at window creation time (through the -class option) then the default class is "Toplevel". Therefore: % toplevel .top .top % bindtags .top .top Toplevel all % and: % toplevel .top -class topclass .top % bindtags .top .top topclass all When the root (".") toplevel is created at Tk initialization time, the code that is executed is: toplevel .t -class <appname> where <appname> is the application name (for me on Windows, it is the executable name: tclsh86tg, capitazlized to become Tclsh86tg). As a logical consequence: % bindtags . . <appname> all This is consistent with the documentation, which says (in the bindtags man page): "By default, each window has four binding tags consisting of the name of the window, the window's class name, the name of the window's nearest toplevel ancestor, and all, in that order. Toplevel windows have only three tags by default, since the toplevel name is the same as that of the window.". The first proposed patch adds a "Toplevel" binding tag to the list of bind tags for the root toplevel window. This means the above sentence from the documentation would be violated but perhaps we could change that (in 8.7 then I think). The second proposed patch replaces the second binding tag by "Toplevel". While we perhaps do not see any use of binding to the class name, we cannot exclude it is used somewhere in the wild, especially since the presence of this binding tag is documented. We could perhaps do this in 8.7. In a nutshell: it's hard for me to tell what is the right way to go. erikleunissen added on 2020-12-23 21:11:55: Uhmm ... I wrote: "The results of the test suite did not indicate that, but I don't know whether that feature is included in the tests." But I meant "The results of the test suite did not indicate any breakage of that feature, but I don't know whether it is included in the tests." erikleunissen added on 2020-12-23 21:08:14: Further analysis and another fix ================================ It seems to me that we're talking about three different concepts: a. the application class/name b. the widget class c. the second (default) binding tag for any widget a. and b. are conceptually convoluted for the root window, and [winfo class .] returns the application name set upon launch (capitalized). While I don't like this convolution, it doesn't necessariy need to affect the issue of this ticket. c. The second (default) binding tag is the widget's class name, which becomes the application name through the convolution of a. and b. described above. However, what if we simply ignore the application name for the binding tags of the root window, would that break anything? I cannot imagine why any developer would want to bind events to an application name/class; that doesn't make any sense to me. Therefore, an even simpler fix would be to completely decouple the convoluted feature a/b from the second binding tag: we (re-)assign the widget class "Toplevel" regardless the application name. We currrently have: % [winfo class .] Wish % [bindtags .] . Wish all We would get then: % [winfo class .] Wish % [bindtags .] . Toplevel all I think this would leave the feature of specifying options with a RESOURCE_MANAGER property or .Xdefaults file intact, wouldn't it? The results of the test suite did not indicate that, but I don't know whether that feature is included in the tests. And we get rid of something for which I cannot imagine a use, and it solves the issue of this ticket. I adapted the patch corresponding to this idea, a new one is attached: tk-2.patch. erikleunissen added on 2020-12-22 21:06:12: I've attached a proposed fix presuming case B, that is: the current exceptional handling of the root window w.r.t. the widget class assignment is what we really want. The fix changes the binding tags for the root window as follows (as seen by the result of [bindtags .]):
old: {. Wish all}
new: {. Wish Toplevel all}
I applied the change to tk8.6.10 and ran the test suite in order to see whether this change introduced additional test failures. Problem is that the test suite doesn't even yield identical results when I run it consecutively. From what I saw, I could not attribute extra test failures to this change, but there is some fragility here, and I think it is wise that others check this as well.
Regardless, this change introduces a POSSIBLE INCOMPATIBILITY because some users may rely on the root window having three binding tags, where the binding tag "all" is the third in the list returned by [bindtags .]
oehhar added on 2020-12-15 18:14:26: I know similar issues on Windows. I think, the relevant bug reports are only on sourceforge. If you do: "wish.exe myprogram.tcl scale". You get very subtile errors. Backround is, that the scale widget bindings are applied to the toplevel window, as it gets the class "scale". This is a feature we may not touch, I suppose. Thanks, Harald bll added on 2020-12-14 17:39:28: One reason the class name may be changed is that the Ubuntu Gnome-3
window manager uses the class name for displaying the mouse-over tooltip name.
On their platform, instead of seeing:
Terminal - bll-g7: bll: /home/bll/s/ballroomdj
for a mouse-over display, you see:
Terminal
Instead of:
Tk Source Code: Edit Ticket -- Mozilla Firefox
you would see:
Firefox
This affects all toplevel windows.
I opened a ticket for that issue, but obviously changing that just for
Ubuntu Gnome-3 wouldn't be justified.
https://core.tcl-lang.org/tk/tktview?name=e57dbff619
I suspect Ubuntu Gnome-3 took a hardly ever used field in X11 and made
use of it. Unfortunately, Tk may use it for other purposes.
I would not be surprised if other window managers start doing the same
thing. Seeing "Firefox" is better than seeing the current title of
the current tab in the list of windows or in the mouse-over tooltip.
cjmcdonald added on 2020-12-14 15:35:28: There is some documentation on the feature, but it has to be pieced together. In the PATTERN FORMAT section of the option database manpage https://www.tcl.tk/man/tcl8.6/TkCmd/option.htm#M9 it says "the first word of the pattern is matched against the name and class of the “.” toplevel, which are usually set by options to wish". Then in the APPLICATION NAME AND CLASS section of the wish manpage https://www.tcl.tk/man/tcl8.6/UserCmd/wish.htm#M16 it says "The class of the application, which is used for purposes such as specifying options with a RESOURCE_MANAGER property or .Xdefaults file, is the same as its name except that the first letter is capitalized". | |||
Attachments:
- tk-2.patch [download] added by erikleunissen on 2020-12-23 21:08:36. [details]
- tk.patch [download] added by erikleunissen on 2020-12-22 21:06:42. [details]
- exercise.tcl [download] added by erikleunissen on 2020-12-14 12:11:41. [details]
