| Ticket UUID: | b6f0d688027b7ef729d6df9c69ce2334e77c9279 | |||
| Title: | New command [winfo container] | |||
| Type: | Patch | Version: | 8.6.12 | |
| Submitter: | erikleunissen | Created on: | 2021-12-09 21:33:14 | |
| Subsystem: | 62. Geometry Functions | Assigned To: | fvogel | |
| Priority: | 5 Medium | Severity: | Important | |
| Status: | Closed | Last Modified: | 2022-01-16 17:56:20 | |
| Resolution: | Rejected | Closed By: | fvogel | |
| Closed on: | 2022-01-16 17:56:20 | |||
| Description: |
This Patch/RFE suggests a new sub command "container" to be added to the Tk command "winfo" A. Rationale
B. Implementation The Implementation is provided with: 1. Source code: see the attached patch file "winfo_container.patch". This patch was created against Tk checkin [bb04c242]. Note that this checkin currently isn't merged yet into the main development branches. However, it is the checkin that has the most recent change to TkGetContainer (in tkInt.h) that we need for this new command. 2. Tests: the attached file exercise.tcl holds four tests. Note that the test winfo_container-2 doesn't PASS yet. This is to makes clear that either TkGetContainer is incorrect in case of unmanaged windows, or I am mistaken about what the container window for an unmanaged window SHOULD be. Since I'm unsure and don't know how to fix TkGetContainer right now, I let this be. 3. Documentation: the following text can readily be added to the manual page for the winfo command. Two variants are provided to accommodate the dual terminology: master and/or container, as desired. winfo master window Returns the path name of window's master. If window is a toplevel window or if it isn't currently managed by any geometry manager, an empty string is returned. winfo container window Returns the path name of window's container (containing) window. If window is a toplevel window or if it isn't currently managed by any geometry manager, an empty string is returned. Regards, Erik Leunissen. | |||
| User Comments: |
fvogel added on 2022-01-16 17:56:20:
Thank you for this feedback. I see we are now both aligned regarding this topic. As a result I have closed branch bug-b6f0d68802 and branch rfe-b6f0d68802. Regarding the name of the macro, after lots of thinking I'd say it's adapted to its specific purpose. Moreover the code documents what maintainerPtr exactly is. I don't think a name change is needed. I'm closing the present ticket. erikleunissen added on 2022-01-09 17:30:41: Thanks for pointing out the main roads/purposes again. Regarding: > I think the fix I have proposed does the job of fixing that bug. I agree. You made clear that the purpose of the TkGetContainer macro is not to return the container window in all cases (which is what I presumed). So I understand that, right now, there is no issue that shows when using the C API (TkGetContainer isn't part of the public API, so for internal use only), or script level code. The macro not always doing what its name suggests, is a reason to consider a rename. But who am I to insist on that, if the maintainers themselves can live with this name? While Tk doesn't appear to have a user-visible issue (at the public C or script level), I believe that this ticket touched on several aspects that indicate a problem lurching under the hood. The obvious witnesses are: - the fact that (we both?) got side-tracked from the purpose - the initial intended rename from maintainerPtr to containerptr, which needed to be reverted for reasons of confusion - the amount of analysis needed to conclude that, right now, there is no user-visible issue (b.t.w. my respect for performing this analysis!). As long as there is nobody who attempts to make aspects in the area of container windows public (like I did), these problems won't surface. At the same time, it's also not a state that facilitates maintenance or enhancements. Bottom line: - I don't mind about maintainerPtr - (all things considered) I won't pursue [winfo container], i.e. branch rfe-b6f0d68802. I appreciate very much your analysis of the situation, and your having travelled along my path of logic for a while. Erik. fvogel added on 2022-01-09 10:11:21: I had understood you, but thanks anyway for the clarification. At this point, I believe we have lost sight to the real goal. The goal is to have [b1d115fa60] fixed. This latter ticket demonstrates a real bug, and I think the fix I have proposed does the job of fixing that bug. Then, you stated on 2021-12-10 16:52:28 in that ticket that you believe the fix is incorrect, which shows when a Tk window (not a toplevel) is created but not packed, gridded or placed, i.o.w. "its geometry isn't managed". While this is technically correct by reading the code, do we have a real world (not conceptual) testcase demonstrating that this is an issue? Or is this only a conceptual idea more or less based on the name of the macro? If the latter, I wouldn't do anything more, except at most perhaps change the macro name to something better or less confusing if you wish. Remember what we're trying to achieve, which is to fix [b1d115fa60]. Another note: Analyzing the code, I have understood why Marc did set maintainerPtr only when the ancestor is not the parent: it's because limiting to this case serves the exact need for which this pointer was introduced, which is to detect (and prevent) geometry management loops (see [07ff41445a7d5f83]). There is no such possibility of a loop when the container is the parent. Tk_MaintainGeometry sets maintainerPtr and is called to handle content whose container is not the parent. Handling content whose container is the parent is done in the code at many places, each of which being specific of the considered geometry manager. And there are many, as already mentioned. In all those places, maintainerPtr is not set. Setting maintainerPtr everywhere in the cases container!=parent for each geometry manager looks like a useless work prone to errors. So, bottom line: I think the fix I have proposed for [b1d115fa60] is fine (except perhaps regarding the TkGetContainer macro name that could be changed if you insist), and I would simply abandon both branch bug-b6f0d68802 and branch rfe-b6f0d68802. Unless you wish to undertake the work of setting maintainerPtr everywhere needed? erikleunissen added on 2022-01-07 15:17:05: B.t.w. I wrote at 2022-01-05 12:28:28: "I did not plan/expect for others to partake in the implementation (except for guiding me through the Fossil workflow)." That might easily be misunderstood. I meant: "I didn't expect that the implementation of [winfo container] would require a lot of effort from maintainers/TCT members." erikleunissen added on 2022-01-05 14:05:43: Hmm, my first hunch was right after all: % package require Tk 8.6.12 % pack [frame .f] % winfo ismapped .f 1 % wm withdraw . % winfo ismapped .f 0 % pack content . .f erikleunissen added on 2022-01-05 13:33:17: Rethinking my comment: > If I understand the intention of using Tk_Ismapped() correctly: > this doesn't seem right to me. Not being mapped is not the same > as not being under control of a geometry manager > (as in test winfo-container-3). Actually I'm not sure, maybe they are the same thing. If so, then it would be an OK replacement. erikleunissen added on 2022-01-05 12:28:28: Regarding: 1. > Well... Resolving the failing tests in branch rfe-b6f0d68802 is needed if we > want to have a working [winfo container] command. True, but that also holds for test winfo-container-3, for which the fix is in the bug-fix branch. 2. > I start to think that it would be so much easier to let everything as is > except to refine the TkGetContainer macro, and just forget about adding > a [winfo container] new command. Hmm, this matter is difficult. My considerations, and checking whether I see thing correctly: A. The extra tests that are failing now, do they indicate that something is wrong at the C level (i.e. regardless providing a [winfo container] at the script level)? - If the answer is "yes": I'm reluctant to forgetting entirely about [winfo container]. Not because of [winfo container] per se though. I'd say, resolve the issues first anyway, and maybe [winfo container] will still be feasible later. - If the answer is "no": I proposed [winfo container] also because it wasn't so difficult for me to provide an implementation. But I didn't foresee the complications that we're facing now, and I don't oversee the effort that it takes to resolve them because I never used geometry managers other than pack, grid and place. I did not plan/expect for others to partake in the implementation (except for guiding me through the Fossil workflow). I can imagine that having [winfo container] doesn't justify the extra effort to resolve the complications that have now surfaced. That's disappointing, but I don't indend to pursue [winfo container] against the odds as they appear now. So, I don't object against letting [winfo container] go. B. Regarding the bugfix branch in its current state: - unless the unforeseen complications also affect this aspect, I'd disfavour to let exist what I indicated as a conceptual bug: i.e. the fact that maintainerPtr is not set when the container is the parent. Can't we apply the fix for that? - w.r.t: > #define TkGetContainer(tkwin) (Tk_IsMapped((TkWindow > *)tkwin) ? NULL : \\ (Tk_TopWinHierarchy((TkWindow *)tkwin) ? NULL : > \\ (((TkWindow *)tkwin)->maintainerPtr != NULL ? \\ ((TkWindow > *)tkwin)->maintainerPtr : ((TkWindow *)tkwin)->parentPtr))) If I understand the intention of using Tk_Ismapped() correctly: this doesn't seem right to me. Not being mapped is not the same as not being under control of a geometry manager (as in test winfo-container-3). fvogel added on 2022-01-04 20:13:15: Well... Resolving the failing tests in branch rfe-b6f0d68802 is needed if we want to have a working [winfo container] command. Actually, this command may be needed (the rationale in the corresponding TIP should explain why) butcurrently it is (was) just a way to test the TkGetContainer macro. It was determined in [b1d115fa60] in your comment dated 2021-12-10 16:52:28 that the current TkGetContainer macro and the proposed new version of that macro does not address the case of unmapped windows, for which it should return NULL. Now, at the end of the day, seeing that what Marc feared (the multiplicity of locations where the containerPtr should be set) is happening, I start to think that it would be so much easier to let everything as is except to refine the TkGetContainer macro, and just forget about adding a [winfo container] new command. Refinement of the macro could be:
#define TkGetContainer(tkwin) (Tk_IsMapped((TkWindow *)tkwin) ? NULL : \
(Tk_TopWinHierarchy((TkWindow *)tkwin) ? NULL : \
(((TkWindow *)tkwin)->maintainerPtr != NULL ? \
((TkWindow *)tkwin)->maintainerPtr : ((TkWindow *)tkwin)->parentPtr)))
erikleunissen added on 2022-01-04 11:37:18: Am I right that resolving these additional failing tests should be part of the workflow of the bug-fix branch that belongs to this ticket (and not of the RFE branch)? fvogel added on 2022-01-03 20:19:39:
> @Marc: Ttk (ttkManager), [text] (textWind), [panedwindow], tkCanvWind all > call Tk_MaintainGeometry() already. Isn't this enough? Marc you must be right. Apparently it's not enough! I have added a few tests in [8acc651c4c], they almost all fail. fvogel added on 2022-01-03 19:53:33: > About renaming: this crossed my mind too. Now done in [c4e8e44e]. Second thoughts. containerPtr is already a name (of type MaintainContainer) used throughout the pack, place and grid geometry managers and in tkGeomtry.c. I think the above renaming adds to the confusion. As a consequence I have reverted this commit. erikleunissen added on 2022-01-02 16:25:05: Regarding the rfe part/branch of this ticket, using the numbered aspects of part A in the post by François at 2022-01-01 19:20:13: A1. TIP I am prepared to write a draft text for a TIP, but I am not really interested in managing a TIP process or taking control of pursuing it. Actually, that's an understatement. My process management capabilities are near non-existent; I tend to drown in them. I'll look at the structure of a TIP and come up with a draft text later. A3: master/slave and container/content terminology I don't oversee the systematics regarding these terminology variants over the entire Tk code base (and I have a vague recollection of inconsistencies). Therefore, I provide a [winfo] API and documentation texts supporting both, and let maintainers/TCT members decide/choose. A5: replace [twait] Yes I already expected that. I tend to use [twait] when I don't see immediately which combinations of vwait/after/update are really appropriate. It's just an easy, overly safe, first method meant to be replaced by something more directed later. fvogel added on 2022-01-02 15:44:34: @Erik: About renaming: this crossed my mind too. Now done in [c4e8e44e]. @Marc: Ttk (ttkManager), [text] (textWind), [panedwindow], tkCanvWind all call Tk_MaintainGeometry() already. Isn't this enough? marc_culler (claiming to be Marc Culler) added on 2022-01-02 15:39:10: Why is that not needed in all of the other geometry managers? There are lots of them. Ttk is the one that I would worry most about, but there are also things like paned windows. erikleunissen added on 2022-01-02 15:21:42: Yes, I recognize bug-fix and rfe distinction in the ticket as I filed it. Thanks for separating them explicitly into targetted branches for the technical follow up. Regarding branch [bug-b6f0d68802] *: we could merge it right now, and that's very fine with me. But now we're at it: what about renaming "maintainterPtr" to "containerPtr" throughout? * attempt to use link not working, can't wait for that, sorry I already thought that containerPtr is much clearer than maintainerPtr when I filed this ticket, but I didn't oversee the area or motives for using that term. If I see it correctly, Marc now also uses the term containerPtr (for maintainerPtr) in this ticket. Therefore, I believe it's wise, and the right time, to consider a rename after all. (I'll post more comment about the rfe part/branch of this ticket later) fvogel added on 2022-01-02 13:27:59: Thank you for your feedback. I think we already have what we need. Apart from the the three places in the pack, grid and place code, maintainerPtr is set in Tk_MaintainGeometry() and 'unset' in Tk_UnmaintainGeometry(). I think this is all the places it needs to be. So I think branch bug-b6f0d68802 can be merged. marc_culler (claiming to be Marc Culler) added on 2022-01-01 22:27:09: If the question is: "should the containterPtr be equal to the parentPtr when the parent is the container?" then my answer is "Yes". I don't remember why I didn't do that when I added the containerPtr. I think I may have been worried about finding all of the places where we would need to set the containerPtr. I get nervous about making changes to the generic code. fvogel added on 2022-01-01 19:20:13: Thank you for this contribution. Here are a few thoughts to chew on. Basically: The present ticket mixes two different things: A. a proposal for a new command, and B. a bugfix (perhaps just a change) about the (internal) semantics of maintainerPtr. The former can only go in an RFE branch off trunk. The latter may go in a bugfix branch off core-8-6-branch. A. [winfo container] new subcommand A.1. Adding such a subcommand to [winfo] needs a small TIP. You already have sketched it, but we'll need to have a proper TIP that can go through the voting process. A.2. Since this is a new command, it can only go to trunk, not in 8.6. This is now in branch r=rfe-b6f0d68802, off trunk. A.3. I don't think there is any interest in having 'master' supported. 'container' is enough. We already hunted down all occurences of master/slave in the code, why would we want to take a step back now? A.4. I have added a quick test of [winfo container] for embedded windows, in the case of an embedded window in a text widget. A.5. In the test file, I have committed your proc twait, but I think update should work just as fine. B. Change in the semantics of with maintainerPtr B.1. What you write makes sense to me I think. I have committed the change in branch bug-b6f0d68802, off core-8-6-branch. I would like to get Marc Culler's opinion about this, since he was the one who added the maintainerPtr in the TkWindow struct (the need was to detect geometry management loops). Marc, could you please provide your feedback on this? erikleunissen added on 2021-12-12 15:10:08: exercise.tcl: removed unneeded pack options and improved 1 test description winfo_container.patch: fixed precedence of cast erikleunissen added on 2021-12-10 22:54:30: I believe that the origin of the problem that test winfo_container-2 didn't pass lies in the misconception explained by the following code comment (definition of struct TkWindow in tkInt.h, line 876):
struct TkWindow *maintainerPtr;
/* The geometry container for this window. The
* value is NULL if the window has no container or
* if its container is its parent. */
This is a conceptual bug, that mixes up two very different semantics. Also note that there is not a single place in the Tk code where a condition is tested for maintainerPtr being NULL except in TkGetContainer; that is in checkin [bb04c242]. Therefore, I believe that when a Tk widget is packed, gridded or placed, we ought set maintainerPtr also if the container window and the parent window are the same (instead of leaving it to be NULL). Also the definition for TkGetContainer needs to be corrected (in the way that I originally indicated in [b1d115fa60]), which simplifies it a lot. The new patch does this (patch updated again). Applying the patch makes all tests for [winfo container] in exercise.tcl PASS. As a check, I ran the Tk test suite under Linux (under x11.KDE.KWin.non-aurorae) to see that the patch doesn't raise new test failures. (In fact the Tk test suite shows 1 failure less with the patch, but that's probably insignificant) erikleunissen added on 2021-12-10 16:09:28: I made a few improvements: Code: - the code now accepts [winfo master] as well as [winfo container]. - used winPtr->pathName as a shortcut to the name of container window. The patch file has been refreshed. Tests: have been made more simple and straight-forward (file exercise.tcl has been refreshed). | |||
Attachments:
- winfo_container.patch [download] added by erikleunissen on 2021-12-12 15:07:27. [details]
- exercise.tcl [download] added by erikleunissen on 2021-12-12 15:07:16. [details]
