Tk Source Code

View Ticket
Login
Ticket UUID: b358779bd469c95ee8580b75cddd59ffeed2bb46
Title: [place] places at wrong position inside menubars
Type: Bug Version: 8.6
Submitter: erikleunissen Created on: 2020-09-28 09:44:40
Subsystem: 12. Unix Menus Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2020-10-31 17:50:28
Resolution: None Closed By: nobody
    Closed on:
Description:
Under Linux, a menubar is a Tk widget in the widget hierarchy.

When trying to [place] another widget inside the menubar, the widget is placed at a wrong position. I believe that the wrong offset is in the y direction only.

The attached script exercises the behaviour by letting the mouse detect windows, and placing a marker in the centre of the detected widget.
It does so correctly except for the menubar.
User Comments: fvogel added on 2020-10-31 17:50:28:
> Does this mean the observed behaviour is justified, or to be accepted as it is?

I don't think I'll spend time on this. I understand this really as a corner case. However I could analyze patches if someone would propose something.

erikleunissen added on 2020-10-05 10:24:03:
Thanks for the analysis, I understand what you describe.

Does this mean the observed behaviour is justified, or to be accepted as it is?

fvogel added on 2020-10-04 20:18:51:

I have analyzed this a little bit and here is what I have found.

First of all: on Windows you can't place relative to the menu bar of a window using the events you are using. There is no <Enter>/<Leave> events triggered. The menu bar is native.

On Linux, the menu bar is a widget built by Tk. Its name in the test script given is ".#m" (since the menu specificed by the user is ".m").

proc handleEvent basically runs:

    place .marker -in $W -relx 0.5 -rely 0.5
where $W is the menubar.

Digging into the source code, the x and y coordinates are correct in RecomputePlacement until the very end in step 5 of the algorithm, where Tk_MaintainGeometry() is called (with the right x and y).

In Tk_MaintainGeometry(), line 529 calls Tk_MoveResizeWindow, again here the coords are still the right ones.

However, in Tk_MoveResizeWindow, the X function XMoveResizeWindow() is called, again with the right x and y coords.

The problem I see is that (from the man page of XMoveResizeWindow()), the x and y values are interpreted as follows:

Specify the x and y coordinates, which define the new position of the window relative to its parent.

So the x and y values are interpreted in the coordinates system of the parent of ".#m", which is ".", and this is why the placed widget is seen below the menubar instead of on top of it. The implementation detail of the menubar naming makes it the child of "." while being located outside of ".".


bll added on 2020-09-28 16:44:21:
Yes.  Tk's menubar frame is treated as a non-entity so that the coordinates
do not change when the menubar is removed or instantiated.   

If you change the coordinates to 0,0, you will see the new frame always is
placed in the top left corner.

The menubar is supposed to be "native" and there's very little you can do to it.

Tried a placement of -0.3, and the placed frame will not overlap the menubar.

This behavior is not going to change.  You have to use the menu tools to add
to the menu.

Attachments: