GtkMenu has unnecessary scroll handles
Submitted by Sebastian
Link to original bug (#726030)
Description
I would like to describe a bug in GtkMenuItem (or GtkMenu or GtkMenuShell).
The bug only surfaces in a very special edge case. Namely when the following THREE conditions are satisfied:
- The menu is positioned at the bottom of the window AND
- When this window is moved very close to the bottom of the screen AND
- When menu items are added to this menu while the menu is opened
Observed behavior: The result is that the menu will resize but its container. Since the new size will require more space but the menu is at the bottom of the window scroll handles are added to scroll through the menu. A screenshot can be seen at [3].
Expected behavior: The menu should reposition itself towards the top of the screen, this would allow the menu to resize without extending beyond the bottom of the window.
A minimum working example can be found at my Github repository:
https://github.com/lanoxx/gtk-menu-scroll-test
The importent part happens in src/gtk-menu-scroll-test.c:menu_add_entry(), the function is called in a timeout interval of 2 seconds and keeps adding and removing two menu items to the first menu ("File") in the menubar. Move the window very close to the bottom of the screen and open it at a moment when the two menuitems are not attached to the menu. Then notice how the two items are added and the menu will get scroll handles.
I have made the following additional observation: When I only add one menuitem instead of two then the menu resizes correctly but overlays the menubar because the menu extends towards the bottom of the screen. For me this indicates that the bug is located somewhere in the positioning code, possibly in [2].
More details about this bug can be found in [1].
Regards Sebastian
[1] https://bugs.launchpad.net/ubuntu/+source/gnome-panel/+bug/965953 [2] https://git.gnome.org/browse/gtk+/tree/gtk/gtkmenuitem.c#n2081 [3] https://launchpadlibrarian.net/98501423/indicator-expander.png
Version: 3.8.x