GNOME Bugzilla – Bug 772146
Standalone GtkMenu doesn't disappear when clicking outside of it
Last modified: 2018-04-15 00:23:27 UTC
Created attachment 336474 [details] Test case If I have a standalone GtkMenu, displayed via gtk_menu_popup() (e.g. in GtkStatusIcon's "popup-menu" signal handler), it doesn't go away unless you either select one of its items, or you click inside another GTK window. Clicking e.g. on empty desktop, or on taskbar doesn't make it disappear. This can only be reproduced if no other window belonging to the same application is focused. Attached test case shows the issue. It lets the menu appear when a toplevel window loses focus. If you comment out the g_signal_connect() call and uncomment gtk_menu_popup() call below it, you can test that it works fine if the menu gets popped up while a toplevel window has focus - menu disappears when clicking on an empty desktop. Tried on GTK+ 2.24.30, and I do not see anything in .31 that could have fixed it. I think this might be related to issue solved in old bug report #107320.
If your use-case is *specifically* the popup menu from a tray icon that doesn't go away when user clicks outside of it- that bug is OlderThanFeudalism, and GTK2 had it for as long as i can remember. All applications that do popup menu from a tray icon have a hacky workaround for this (Pidgin, for example). Without digging through bugzilla, from the top of my head, the issue was that to correctly detect the moment when an outside-click is made, the menu window has to do a more-encompassing mouse capture than the one it already does (because normally windows don't get clicks outside of themselves; i'm not sure why keyboard focus wasn't used as a stand-in, maybe popups don't get it initially). I've tried to find a clean app-level workaround for that back in the day (before i started to hack on GTK itself), and failed. Tray icons are deprecated in GTK3 and will be removed in GTK4, AFAIK.
We're moving to gitlab! As part of this move, we are moving bugs to NEEDINFO if they haven't seen activity in more than a year. If this issue is still important to you and still relevant with GTK+ 3.22 or master, please reopen it and we will migrate it to gitlab.
As announced a while ago, we are migrating to gitlab, and bugs that haven't seen activity in the last year or so will be not be migrated, but closed out in bugzilla. If this bug is still relevant to you, you can open a new issue describing the symptoms and how to reproduce it with gtk 3.22.x or master in gitlab: https://gitlab.gnome.org/GNOME/gtk/issues/new