wmww / gtk-layer-shell

A library to create panels and other desktop components for Wayland using the Layer Shell protocol
GNU General Public License v3.0
319 stars 16 forks source link

Menus spawned from layer shell windows leave a focus "dead zone" on the window #160

Closed spl237 closed 1 year ago

spl237 commented 1 year ago

This trivial example shows the problem.

#include <gtk/gtk.h>
#include <gtk-layer-shell.h>

int main (int argc, char *argv[])
{
    gtk_init (&argc, &argv);
    GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_layer_init_for_window (GTK_WINDOW (win));  // this line causes the bug to occur

    GtkWidget *btn = gtk_menu_button_new ();
    GtkWidget *men = gtk_menu_new ();
    GtkWidget *item = gtk_menu_item_new_with_label ("Item");
    gtk_menu_shell_append (GTK_MENU_SHELL (men), item);
    gtk_container_add (GTK_CONTAINER (win), btn);
    gtk_button_set_label (GTK_BUTTON (btn), "Test");
    gtk_menu_button_set_popup (GTK_MENU_BUTTON (btn), men);
    gtk_widget_show_all (win);
    gtk_widget_show_all (men);
    gtk_main ();
    return 0;
}

Build with gcc test.c `pkg-config --cflags --libs gtk+-3.0 gtk-layer-shell-0`

If this code is built without the call to gtk_layer_init_for_window, it works as expected - clicking the menu button opens the menu; clicking the menu button again closes it as it removes focus from the menu.

However, if the code is built with the call to gtk_layer_init_for_window, it fails. Clicking the menu button opens the menu, and clicking almost anywhere else on the screen closes it by removing focus, but clicking the button anywhere other than the very lower edge does not close the menu. By observation in more sophisticated cases, this is because there is a focus "dead zone" the same size and shape of the menu which starts at the top left of the underlying window, and this overlaps the menu button, rendering it non-functional. The very bottom edge of the button is outside the dead zone, so clicking here will move focus and close the window.

Tested using wayfire 0.7.5 and gtk-layer-shell 0.8.0 from Debian bookworm.

spl237 commented 1 year ago

Also repeated in sway 1.7-6 from Debian bookworm, so not Wayfire-specific.

Note that the problem goes away if the mouse is moved outside the dead zone and then brought back in again before clicking. But unless the mouse is moved out, clicking the button never closes the menu.

Tamaranch commented 1 year ago

See also #141.

spl237 commented 1 year ago

One addition to the above - the "dead zone" is a lot more obvious if you increase the length of the label in the menu button - change it to "Test label with some longer text" and rebuild. If you then click the button to open the menu, it is very obvious that you can close the menu by clicking the right hand end of the button, but not the left hand end, and that the point on the button at which the menu starts/stops closing when clicked is aligned with the end of the menu.

spl237 commented 1 year ago

Also repeated on KDE Plasma - identical behaviour - so not a wlroots issue.

spl237 commented 1 year ago

Raised as an issue on GTK repo as well - not sure whether this is in GTK itself or in layer-shell - https://gitlab.gnome.org/GNOME/gtk/-/issues/5780

wmww commented 1 year ago

Please don't open issues relating to GTK Layer Shell on GTK. Unless you can reproduce it without GTK Layer Shell involved, it's safe to assume it's not an upstream GTK bug.

spl237 commented 1 year ago

This morning I was able to reproduce it on Mutter, which doesn't support layer shell. But I still needed the call to layer_init_for_window to trigger it, which then produced a warning that the compositor didn't support layer shell and would fall back to xdg_shell instead.

I'm not sure whether that indicates that it can be reproduced without layer shell or not? Perhaps you could please clarify?

wmww commented 1 year ago

"reproduced without layer shell" means you see the bug without #including, linking against or calling anything to do with layer shell. If GTK Layer Shell needs to be involved in any way then it's safe to assume it's GTK Layer Shell that's causing the problem (it is interesting to know that layer shell doesn't need to be working in order to cause the problem, this will be helpful information in fixing it).

spl237 commented 1 year ago

OK, many thanks - in that case I will leave it to you. If I can do any further investigation or testing, please let me know.

One additional data point from today's testing - the "dead zone" is aligned with the top left corner of the underlying window, not the menu button which opens the menu. And it is definitely the same size as the menu.

wmww commented 1 year ago

Can you close the upstream GTK bug please? thanks

spl237 commented 1 year ago

Yes, sure - done.

spl237 commented 1 year ago

Confirm this fixes the problem I was seeing - many thanks!