From 336dde4bb1d2eb9190e3590f4ed6b76291921419 Mon Sep 17 00:00:00 2001 From: anof-cyber Date: Wed, 21 Oct 2026 19:20:42 +0530 Subject: [PATCH] fix(linux/gui): menus open on Wayland The window now runs as the user, so on a Wayland desktop it is a native Wayland window. Opening a menu moves the keyboard focus to the menu's popup, and the handler that closed menus when the window lost focus (written for the old root window on X11, where a menu grab could outlive a switch to another program) cancelled every menu the moment it opened. The handler is now connected on X11 only. --- Linux/gui/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Linux/gui/main.c b/Linux/gui/main.c index e53d503..a49d362 100644 --- a/Linux/gui/main.c +++ b/Linux/gui/main.c @@ -666,8 +666,14 @@ int main(int argc, char *argv[]) { GtkWidget *menubar = gtk_menu_bar_new(); // An open menu holds a grab. When the user moves to another program (often a native Wayland window this X11 client // never gets pointer events from) the menu would stay on top of it: close it as soon as this window loses focus. - g_signal_connect(window, "notify::is-active", G_CALLBACK(on_active_changed), menubar); - g_signal_connect(window, "focus-out-event", G_CALLBACK(on_focus_out), menubar); + // Only on X11, where a menu holds a grab that can outlive a switch to another program. On Wayland (the window now runs as the user, so + // it is a native Wayland window) opening a menu moves the keyboard focus to the menu's own popup: closing menus when the window + // "loses focus" would close every menu the moment it opens, and the compositor already dismisses popups itself. + GdkDisplay *gdisp = gdk_display_get_default(); + if (gdisp && strcmp(G_OBJECT_TYPE_NAME(gdisp), "GdkX11Display") == 0) { + g_signal_connect(window, "notify::is-active", G_CALLBACK(on_active_changed), menubar); + g_signal_connect(window, "focus-out-event", G_CALLBACK(on_focus_out), menubar); + } // The same four menus as the Windows app: Proxy, Profile, Settings, Help GtkWidget *proxy_menu = add_submenu(menubar, "Proxy"); enable_item = add_check_item(proxy_menu, "Enable ProxyBridge", true, G_CALLBACK(on_enable_toggled)); // the main on/off switch