Tk Source Code

View Ticket
Login
Ticket UUID: 470331
Title: Displaced Menus do not stay open.
Type: Bug Version: obsolete: 8.5.4, 8.6.18, 9.0.5, 9.1b1
Submitter: randolf Created on: 2001-10-11 18:15:43
Subsystem: 12. Unix Menus Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-09-30 20:25:49
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-09-30 20:25:49
Description:
When
a) a menubutton is near the lower edge of the screen
b) the user tries to open the menu with a simple click
   (and immediately releases the mouse button)
c) the menu is too long to be displayed in full
length     on the remaining screen space and is
displaced:

the menu will immediately disappear again, selecting
an entry that is under the mouse pointer after
displacement. The user has no chance to select, nor
does he even see what he selected. Anything including
some really evil things like deleting files etc. can
happen.

Expected behaviour:
The menu should simply stay open as it is doing
when it does not need to be displaced.

Note: On Windows this works as expected!
No test has been performed on the Mac.
Xaw(3D) does it wrong too, Motif/GTK do it right
but displace in a different way.

Sample Script:
Run it. Place the window on the lower edge of your
screen. Do a single click on "File". The application
quits unexpectedly...

-snip-
# Create a menubar 
# 
menu .mb -type menubar 
. config -menu .mb 
.mb add cascade -label File -underline 0 -menu .mb.file 
menu .mb.file -tearoff 0 
.mb.file add command -label Exit -command exit 
.mb.file add command -label Exit -command exit 
.mb.file add command -label Exit -command exit 
.mb.file add command -label Exit -command exit 
.mb.file add command -label Exit -command exit 
.mb.file add command -label Exit -command exit 
.mb.file add command -label Exit -command exit 
.mb.file add command -label Exit -command exit 
.mb.file add command -label Exit -command exit 
.mb.file add command -label Exit -command exit 
.mb.file add command -label Exit -command exit 

frame .f -width 200 -height 100 
pack .f -side top -fill both -expand 1 
update 
-snap-
User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-09-30 20:24:16:

Serhiy, many thanks! The fix is now in main, core-9-0-branch, and core-8-6-branch; see commits [0f866663], [5c47ae3e], and [3aacabb1].


serhiy.storchaka added on 2026-09-30 08:44:23:

Still present in 8.6 and 9.x on X11. The same problem is reported in [680660], [1596662] and [f9d316a5e0]. If a menu does not fit below its menubar entry or menubutton, it is moved up over the entry. The release of the click which posted it then invokes the entry under the pointer. The same happens with tk_popup near the bottom or right edge of the screen.

I implemented a fix in two parts, similar to other toolkits:

  1. A menu is posted above the menubar entry or menubutton if it does not fit below it but fits above it. A menubutton menu which fits neither below nor above is posted beside the pointer. tk_popup posts the menu to the left of and/or above the point if it does not fit to the right of or below it.
  2. If the menu is still under the pointer (for example, it is larger than the screen, or it is an option menu), the release of the click which posted it is ignored while the pointer has not moved, and the entry under the pointer is not highlighted. A menu larger than the screen should rather be limited to the screen and scrolled, as in other toolkits; see [4e7fbe8b4a].

The new demo "Popup (context) menus" shows this with tk_popup and menus of different sizes. Menus posted from a menubar or a menubutton behave similarly, but it is easiest to see with popup menus.


tmh added on 2008-08-19 09:44:03:
Logged In: YES 
user_id=92123
Originator: NO

The included script behaves the same with Tk 8.5.4 and Tk 8.6 on my test system.
I'm not convinced that this is a bug however, though I agree it is annoying.

When the posted menu is too near the bottom of the screen.  Selecting the Menu causes one of the menu items to appear under the cursor.  Simply releasing the mouse button causes that menu item to be executed.  If one moves the mouse pointer off of the menu list item.  The button can be released without invoking anything and in fact the menu paints.  Correcting this would require changing the 'X' location of the menu as well as adjusting the Y to fit the menu on the screen.