diff --git a/.claude/skills/orca-wxwidgets/references/mouse-keyboard-focus.md b/.claude/skills/orca-wxwidgets/references/mouse-keyboard-focus.md index 48646134d8..679d69cb30 100644 --- a/.claude/skills/orca-wxwidgets/references/mouse-keyboard-focus.md +++ b/.claude/skills/orca-wxwidgets/references/mouse-keyboard-focus.md @@ -867,6 +867,8 @@ append_shortcut_item(export_menu, Shortcut::ExportSlicedFile, true, _L("Export p itself; never keep a raw pointer (`interface/wx/tipwin.h:20-110`). - `wxRichToolTip` is not a window: each `ShowFor()` creates a new one, and the native MSW version only applies to text controls (`interface/wx/richtooltip.h:70-192`). +- On Wayland, a GTK tooltip of a widget inside a shown popup maps as a grabbing `xdg_popup` and takes the + keyboard focus from the toplevel, which reports a deactivation → `references/popups-menus.md` §9. | Static [source] | MSW | GTK | macOS | |---|---|---|---| diff --git a/.claude/skills/orca-wxwidgets/references/platforms.md b/.claude/skills/orca-wxwidgets/references/platforms.md index ef386efa49..882a7dc59c 100644 --- a/.claude/skills/orca-wxwidgets/references/platforms.md +++ b/.claude/skills/orca-wxwidgets/references/platforms.md @@ -636,7 +636,7 @@ headers. Rows marked [source] or "protocol" come from the implementation or from | `wxBitmap(const wxCursor&)` | creates an invalid bitmap | `interface/wx/bitmap.h:393-395` | — | | OpenGL | only EGL; `PreferGLX()` has no effect. Without EGL in the build, wxGTK's `wxGLCanvas` shows a fatal message and refuses to work [source: `src/gtk/glcanvas.cpp` `IsAvailable`]. The EGL surface is a subsurface over the canvas, ready only after map and a frame callback [source: `src/unix/glegl.cpp`] | `interface/wx/glcanvas.h:1094-1095` | `CLI::run` forces X11 when wx lacks EGL; overlays are drawn in GL/ImGui, never as wx children over the canvas → `references/webview-gl-aui-media.md` | | AUI | the doc note "live resize is always used … for wxOSX and wxGTK3 when using Wayland" is obsolete: "As of wxWidgets 3.3.0 this function always returns false", and `wxAUI_MGR_LIVE_RESIZE` is in the default flags. Floating panes need global positions | `interface/wx/aui/framemanager.h:336-345` | `Plater::priv::priv` clears `wxAUI_MGR_ALLOW_FLOATING`; `sanitize_window_layout_for_wayland` strips floating state from the saved layout → `references/webview-gl-aui-media.md` §wxAuiManager | -| Popups | a GTK popup is an `xdg_popup` only for COMBO/DROPDOWN/POPUP_MENU hints, so wx creates popups with `GDK_WINDOW_TYPE_HINT_COMBO` [source]. A chained popup's parent must be the mapped popup, and mapping it with a grab deactivates the toplevel (Orca's comments in `DropDown::mouseMove`, `DropDown::ShouldDismissOnTopWindowDeactivate`) | `src/gtk/popupwin.cpp:110-114` | `DropDown` transient-for chain, `ShouldDismissOnTopWindowDeactivate` → `references/popups-menus.md` | +| Popups | a GTK popup is an `xdg_popup` only for COMBO/DROPDOWN/POPUP_MENU hints, so wx creates popups with `GDK_WINDOW_TYPE_HINT_COMBO` [source]. A chained popup's parent must be the mapped popup, and mapping it with a grab deactivates the toplevel (Orca's comments in `DropDown::mouseMove`, `DropDown::ShouldDismissOnTopWindowDeactivate`). A GTK tooltip of a widget in a shown popup maps as that popup's grabbing child and deactivates the toplevel the same way | `src/gtk/popupwin.cpp:110-114` | `DropDown` transient-for chain, `ShouldDismissOnTopWindowDeactivate`, the tooltip check in `PopupWindow::topWindowActiavate` → `references/popups-menus.md` | | Fractional scale | arrives as an integer GDK scale | `docs/doxygen/overviews/high_dpi.md:348-351` | → `references/dpi-bitmaps-fonts.md` | | Window decorations | some desktop environments draw a title bar on undecorated windows anyway | — | [Undecorated windows](#wayland-undecorated-top-level-windows-splash) | | `wxWebViewChromium` | X11 only | `interface/wx/webview_chromium.h:133-146` | not built (`wxUSE_WEBVIEW_CHROMIUM` OFF) | diff --git a/.claude/skills/orca-wxwidgets/references/popups-menus.md b/.claude/skills/orca-wxwidgets/references/popups-menus.md index b0538a9da5..d165ceff0a 100644 --- a/.claude/skills/orca-wxwidgets/references/popups-menus.md +++ b/.claude/skills/orca-wxwidgets/references/popups-menus.md @@ -77,6 +77,10 @@ Contents: [Rules](#rules) · [1. Choosing the window kind](#1-choosing-the-windo it maps. `PopupWindow::Show` does it for every Orca popup; a popup outside `PopupWindow` opened from a widget with a GTK tooltip must do it itself. Only a popup that cannot map while a GTK tooltip is visible, such as one opened from the GL canvas (whose tooltips are ImGui), needs nothing. (§9) +30. On Wayland, a hook that dismisses a popup when its toplevel deactivates ignores the deactivation while a GTK + tooltip of a widget in that popup, or in a popup opened from it, is on screen: the tooltip has taken the + keyboard while the user is still on the popup. `PopupWindow::topWindowActiavate` does it for every Orca popup; + a popup outside `PopupWindow` with such a hook must do it itself. (§9) ## 1. Choosing the window kind @@ -394,6 +398,10 @@ compensates for (§6). on older GTK and GTK2. On hide: `gdk_seat_ungrab` + `gtk_grab_remove` (`popupcmn.cpp:335-403`). `gdk_seat_ungrab` releases the *seat's* grab, whichever popup took it, so hiding a sub-popup also drops the parent popup's pointer grab. +- The window is mapped before the grab is taken (`wxPopupWindow::Show` at `popupcmn.cpp:370`, the grab from + 375). Under Wayland the popup itself therefore maps as an `xdg_popup` without an explicit grab, while GDK + records the grab seat on its window, and a popup mapped later as its transient child (a sub-dropdown, a GTK + tooltip of a widget inside it) inherits that seat and maps with `xdg_popup.grab` (§9). - An outside press arrives at the grab widget. `gtk_popup_button_press` sends `wxEVT_KILL_FOCUS` to the popup and **consumes the click** (`return TRUE`, `src/gtk/popupwin.cpp:28-58`). Presses older than the popup's creation time are ignored (33-34). @@ -458,7 +466,7 @@ What it adds per platform: | Port | Behaviour | |---|---| -| GTK | `Create` binds `wxEVT_ACTIVATE` on `GetTopParent(parent)`. `topWindowActiavate` calls `event.Skip()`, then `DismissAndNotify()` if the toplevel deactivated, the popup is shown and `ShouldDismissOnTopWindowDeactivate()` returns true. This supplies the app/toplevel deactivation dismissal that stock wxGTK lacks. Under Wayland, `Show(true)` on a hidden popup first hides every visible GTK tooltip window (§9). | +| GTK | `Create` binds `wxEVT_ACTIVATE` on `GetTopParent(parent)`. `topWindowActiavate` calls `event.Skip()`, then `DismissAndNotify()` if the toplevel deactivated, the popup is shown, `ShouldDismissOnTopWindowDeactivate()` returns true and, under Wayland, no GTK tooltip of the popup's own is on screen (§9). This supplies the app/toplevel deactivation dismissal that stock wxGTK lacks. Under Wayland, `Show(true)` on a hidden popup first hides every visible GTK tooltip window (§9). | | MSW | Nothing automatic. `BindUnfocusEvent()` binds the toplevel's `wxEVT_ACTIVATE`/`wxEVT_ICONIZE`/`wxEVT_SHOW` to `Dismiss()` (no `OnDismiss`). It is for default-style popups: they are desktop children that Windows does not hide with the frame, and stock wx closes them on deactivation or minimizing only if a focus message reaches a wx window (§4, §5). `topWindowActivate` does **not** `Skip()`, so while the popup lives it swallows the frame's `wxEVT_ACTIVATE`, and with it `wxTopLevelWindowMSW::OnActivate`'s focus save and restore (`src/msw/toplevel.cpp:1326-1360`). | | macOS | Only with `wxPU_CONTAINS_CONTROLS`: `OnMouseEvent2`, bound on the popup for `LEFT_DOWN/UP/DCLICK`, `MOTION` and `MOUSEWHEEL`, hit-tests the children (static `HitTest`) and re-dispatches the event to the deepest child under the cursor with `ProcessEventLocally`. On `MOTION` it synthesizes `ENTER`/`LEAVE` for the hovered target. This compensates for the capture rerouting in §5. | @@ -761,6 +769,53 @@ fights the grab and focus model (§10). Two more [source] facts: ``` Cite: `PopupWindow::Show` (#16595). +- **Rule:** On Wayland, don't dismiss a shown popup on a toplevel deactivation while a GTK tooltip of one of its + widgets is on screen. + **Why:** GTK makes a tooltip transient for the toplevel of the widget it describes (`gtktooltip.c:974`), which + for a widget inside a popup, or the popup itself (`DropDown` sets its item tooltips on itself), is the popup's + own `GtkWindow`. The popup's window holds the seat grab (§5), and `find_grab_input_seat` walks the transient + parents to it (`gdkwindow-wayland.c:3142-3147`), so GDK maps the tooltip with an explicit `xdg_popup.grab` + (3100); the walk passes through every popup in a chain, so a tooltip in a popup opened from inside another + popup grabs too. The compositor gives the keyboard to the topmost grabbing popup: KWin sends `wl_keyboard.leave` + for the main window and `enter` for the tooltip (observed with `WAYLAND_DEBUG=client`). wxGTK turns the + toplevel's focus-out into `wxEVT_ACTIVATE(false)` (`src/gtk/toplevel.cpp:192-205`), so a deactivation hook closes + the popup as the tooltip appears, and GDK warns "Tried to unmap the parent of a popup" + (`gdkwindow-wayland.c:3429`) because the tooltip is still mapped as its child. The focus returns to the toplevel + when the tooltip hides. Ask GDK whether the tooltip is mapped (`gdk_window_is_visible`): when the compositor + dismisses a tooltip, `xdg_popup_done` hides only its `GdkWindow` (`gdkwindow-wayland.c:2289`, + `gdkwindow.c:5684-5690`), and `gtk_widget_get_visible` stays TRUE until GTK hides the tooltip itself. Alt+Tab with + a tooltip showing still closes the popup (observed): the Alt press reaches the app, which hides the tooltip after + handling the key (`gtkmain.c:1949-1961`). X11 tooltips never take the focus, so the check is gated on + `is_running_on_wayland()`. (Line numbers are GTK 3.24.52.) + **Limit:** wxGTK sends `wxEVT_ACTIVATE(false)` only while it holds an active frame and then clears it + (`g_activeFrame`, `src/gtk/toplevel.cpp:196-202`), so a deactivation ignored this way is never repeated. If the + app loses the focus while the tooltip holds it, without Orca seeing a key or the pointer leave first (another + app's window taking the focus, a gesture), the popup stays open until the user returns, and the first click + closes it (observed with a dialog from another app). Closing that gap means waiting for the compositor to + reactivate the toplevel, which takes a timer or a blocking round trip. + ```cpp + // Wrong: every toplevel deactivation dismisses, including the one the popup's own tooltip causes + if (!event.GetActive() && IsShown() && ShouldDismissOnTopWindowDeactivate()) + DismissAndNotify(); + // Right (wxGTK): Wayland only, skip it while a tooltip of this popup or of a popup opened from it is mapped + static bool own_tooltip_mapped(GtkWindow *popup) + { + bool mapped = false; + for_each_tooltip_window([popup, &mapped](GtkWindow *win) { // GDK_WINDOW_TYPE_HINT_TOOLTIP toplevels + GdkWindow *gdk_win = gtk_widget_get_window(GTK_WIDGET(win)); + if (!gdk_win || !gdk_window_is_visible(gdk_win)) + return; + for (GtkWindow *w = gtk_window_get_transient_for(win); w && !mapped; w = gtk_window_get_transient_for(w)) + mapped = w == popup; + }); + return mapped; + } + if (!event.GetActive() && IsShown() && ShouldDismissOnTopWindowDeactivate() && + !(Slic3r::GUI::is_running_on_wayland() && own_tooltip_mapped(GTK_WINDOW(m_widget)))) + DismissAndNotify(); + ``` + Cite: `PopupWindow::topWindowActiavate` (#16800). + ## 10. Frameless dialog instead of a popup A transient popup cannot guarantee keyboard focus. On MSW it gets focus only with the flag, on macOS it is a diff --git a/src/slic3r/GUI/Widgets/PopupWindow.cpp b/src/slic3r/GUI/Widgets/PopupWindow.cpp index 6d9e55ccab..a8273b5ce6 100644 --- a/src/slic3r/GUI/Widgets/PopupWindow.cpp +++ b/src/slic3r/GUI/Widgets/PopupWindow.cpp @@ -90,6 +90,15 @@ void PopupWindow::OnMouseEvent2(wxMouseEvent &evt) #endif #ifdef __WXGTK__ +template static void for_each_tooltip_window(Fn fn) +{ + GList *toplevels = gtk_window_list_toplevels(); + for (GList *l = toplevels; l; l = l->next) + if (gtk_window_get_type_hint(GTK_WINDOW(l->data)) == GDK_WINDOW_TYPE_HINT_TOOLTIP) + fn(GTK_WINDOW(l->data)); + g_list_free(toplevels); +} + bool PopupWindow::Show(bool show) { // On Wayland a shown GTK tooltip is itself an xdg_popup, and GDK maps a new popup only as a child of @@ -98,22 +107,39 @@ bool PopupWindow::Show(bool show) // never appear. GtkMenu hides the tooltip first for the same reason, through a private call; hiding the // tooltip window is the public equivalent, and GtkTooltip then treats it as closed and shows it again // on a later hover. - if (show && !IsShown() && Slic3r::GUI::is_running_on_wayland()) { - GList *toplevels = gtk_window_list_toplevels(); - for (GList *l = toplevels; l; l = l->next) { - GtkWidget *win = GTK_WIDGET(l->data); - if (gtk_window_get_type_hint(GTK_WINDOW(win)) == GDK_WINDOW_TYPE_HINT_TOOLTIP && gtk_widget_get_visible(win)) - gtk_widget_hide(win); - } - g_list_free(toplevels); - } + if (show && !IsShown() && Slic3r::GUI::is_running_on_wayland()) + for_each_tooltip_window([](GtkWindow *win) { gtk_widget_hide(GTK_WIDGET(win)); }); return wxPopupTransientWindow::Show(show); } +// Whether a tooltip of a widget in this popup, or in a popup opened from it, is on screen. Such a tooltip is +// transient for the window of the popup holding the widget, and that popup is transient for the one it opened from. +static bool own_tooltip_mapped(GtkWindow *popup) +{ + bool mapped = false; + for_each_tooltip_window([popup, &mapped](GtkWindow *win) { + // The compositor can dismiss a tooltip without GTK hiding the widget, so ask GDK whether it is mapped. + GdkWindow *gdk_win = gtk_widget_get_window(GTK_WIDGET(win)); + if (!gdk_win || !gdk_window_is_visible(gdk_win)) + return; + for (GtkWindow *w = gtk_window_get_transient_for(win); w && !mapped; w = gtk_window_get_transient_for(w)) + mapped = w == popup; + }); + return mapped; +} + +// On Wayland, a GTK tooltip of a widget in a shown popup takes the keyboard focus from the toplevel, which then +// reports a deactivation while the user is still on the popup: GTK makes the tooltip transient for the popup's +// window, which holds the seat grab, so GDK maps the tooltip as an xdg_popup with a grab of its own, and the +// compositor gives the keyboard to the topmost grabbing popup. The toplevel is activated again when the tooltip +// hides, so that deactivation is ignored. wxGTK reports no second deactivation until the next activation, so if +// the app loses the focus while such a tooltip holds it (another app's window taking the focus, a gesture), the +// popup stays open until the user returns. X11 tooltips never take the focus. void PopupWindow::topWindowActiavate(wxActivateEvent &event) { event.Skip(); - if (!event.GetActive() && IsShown() && ShouldDismissOnTopWindowDeactivate()) + if (!event.GetActive() && IsShown() && ShouldDismissOnTopWindowDeactivate() && + !(Slic3r::GUI::is_running_on_wayland() && own_tooltip_mapped(GTK_WINDOW(m_widget)))) DismissAndNotify(); } #endif