From 2c91bfe0d3be767fc965185fffdbcf2c4530e73e Mon Sep 17 00:00:00 2001 From: SoftFever Date: Fri, 23 Oct 2026 22:11:05 +0800 Subject: [PATCH] Open dropdowns on the first click on Wayland when a tooltip is showing --- .../orca-wxwidgets/references/platforms.md | 7 +++- .../orca-wxwidgets/references/popups-menus.md | 41 ++++++++++++++++++- src/slic3r/GUI/Widgets/PopupWindow.cpp | 25 +++++++++++ src/slic3r/GUI/Widgets/PopupWindow.hpp | 3 ++ 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/.claude/skills/orca-wxwidgets/references/platforms.md b/.claude/skills/orca-wxwidgets/references/platforms.md index 673f58357f..ef386efa49 100644 --- a/.claude/skills/orca-wxwidgets/references/platforms.md +++ b/.claude/skills/orca-wxwidgets/references/platforms.md @@ -372,7 +372,9 @@ form a chain of parents. Window icons come from the `.desktop` file. The full li `references/mouse-keyboard-focus.md`; - GL blending must keep destination alpha at 1 (d8369e5f75); - GL post-init must retry until the surface is committed (d2c24fdabb) → - `references/webview-gl-aui-media.md`. + `references/webview-gl-aui-media.md`; +- a shown GTK tooltip is the topmost `xdg_popup`, so it must be hidden before a popup maps + (`PopupWindow::Show`) → `references/popups-menus.md` §9. ### XWayland (GTK3 X11 backend inside a Wayland session) @@ -409,7 +411,8 @@ start there when looking for prior art. The sites below are exemplars, cited by (`focus_left_popup(...)`) instead of hit-testing `wxGetMousePosition()`. - `PopupWindow::Create`: on GTK it binds the top-level `wxEVT_ACTIVATE` to `topWindowActiavate` → `DismissAndNotify()`, gated by the virtual `ShouldDismissOnTopWindowDeactivate()`, which `DropDown` - overrides for Wayland popup chains. On `__WXOSX__` with `wxPU_CONTAINS_CONTROLS`, + overrides for Wayland popup chains. `PopupWindow::Show` (GTK) hides visible GTK tooltips before mapping + on Wayland. On `__WXOSX__` with `wxPU_CONTAINS_CONTROLS`, `PopupWindow::OnMouseEvent2` hit-tests children, re-dispatches mouse events and synthesises enter/leave. - `SidePopup::Popup` (`Widgets/SideMenuPopup.cpp`): on `__APPLE__` the menu is anchored flush against diff --git a/.claude/skills/orca-wxwidgets/references/popups-menus.md b/.claude/skills/orca-wxwidgets/references/popups-menus.md index 1ad6a09271..b0538a9da5 100644 --- a/.claude/skills/orca-wxwidgets/references/popups-menus.md +++ b/.claude/skills/orca-wxwidgets/references/popups-menus.md @@ -73,6 +73,10 @@ Contents: [Rules](#rules) · [1. Choosing the window kind](#1-choosing-the-windo 27. Build `MenuFactory` menus once. Pass `parent` to `append_menu_item` only for items that persist. (§16) 28. macOS: bind `wxID_EXIT` on `OSXGetAppleMenu()` to `Close()`, only insert into the Apple menu, and always `Skip()` a frame's `wxEVT_ACTIVATE`. (§15) +29. On Wayland, a popup that can open while a GTK tooltip is shown hides every visible tooltip window before + 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) ## 1. Choosing the window kind @@ -439,6 +443,9 @@ class PopupWindow : public wxPopupTransientWindow { public: PopupWindow(wxWindow* parent, int style = wxBORDER_NONE); bool Create(wxWindow* parent, int flags = wxBORDER_NONE); +#ifdef __WXGTK__ + bool Show(bool show = true) override; // hides GTK tooltips first on Wayland (§9) +#endif #ifdef __WXMSW__ void BindUnfocusEvent(); // opt-in #endif @@ -451,7 +458,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. | +| 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). | | 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. | @@ -721,6 +728,38 @@ fights the grab and focus model (§10). Two more [source] facts: `DropDown::Popup`, applied when `!mainDropDown && m_widget`). - **Rule:** Don't open a grabbing popup on hover on Linux if the opener must stay clickable. Cite: `MainFrame` slice-button hover handlers (`#ifndef __linux__`). +- **Rule:** On Wayland, hide every visible GTK tooltip window right before mapping a popup that can open + while one is shown. + **Why:** A GTK3 tooltip is a `GTK_WINDOW_POPUP` with the `tooltip` type hint, placed with + `gdk_window_move_to_rect` (`gtktooltip.c:974-983`), so GDK Wayland maps it as an `xdg_popup` of the + hovered widget's toplevel (`should_map_as_popup`, `gdkwindow-wayland.c:3198-3199`). GDK refuses to map a + popup whose parent is not the last popup it mapped, warning "Tried to map a popup with a non-top most + parent" (`gdkwindow-wayland.c:3040-3046`), and the window stays invisible while wx believes it is shown. + GTK hides the tooltip on a button or key press, but only after the event has been propagated to the + widgets (`gtkmain.c:1949-1961`, `_gtk_tooltip_handle_event`). A dropdown opened from the click is therefore + mapped while the opener's tooltip is still up, and the click that opens it after the tooltip delay does + nothing. The same holds for a sub-dropdown opened on hover while the main dropdown shows an item tooltip. + GTK hides the current tooltip the same way before mapping its own menus (`gtk_menu_popup_internal`, + `gtkmenu.c:1837`), but through the private `_gtk_tooltip_hide_in_display` (`gtktooltip.c:1297`); apps have + no public call, so hide the window: `gtk_widget_hide` unmaps the `xdg_popup` at once, and GtkTooltip treats + the tooltip as no longer visible (`GTK_TOOLTIP_VISIBLE`, `gtktooltip.c:135`). Its own hide on the press + then returns early, before it times out browse mode (`gtk_tooltip_hide_tooltip`, `gtktooltip.c:1078`, + 1092), so the next tooltip shows after the 60 ms browse delay instead of 500 ms. A tooltip GTK tries to + show while a popup is open fails to map with the same warning and stays hidden, unless its widget is in + the topmost popup (a dropdown's own item tooltip maps as that popup's child); that happens with or without + this step and is harmless. X11 has no popup stacking rule, so the step is gated on + `is_running_on_wayland()`. (Line numbers are GTK 3.24.52.) + ```cpp + // Wrong: map the popup with the opener's tooltip still on top + drop.Popup(&drop); + // Right (wxGTK, Wayland): PopupWindow::Show does this before every map + 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 && gtk_widget_get_visible(GTK_WIDGET(l->data))) + gtk_widget_hide(GTK_WIDGET(l->data)); + g_list_free(toplevels); + ``` + Cite: `PopupWindow::Show` (#16595). ## 10. Frameless dialog instead of a popup diff --git a/src/slic3r/GUI/Widgets/PopupWindow.cpp b/src/slic3r/GUI/Widgets/PopupWindow.cpp index 371ece392b..6d9e55ccab 100644 --- a/src/slic3r/GUI/Widgets/PopupWindow.cpp +++ b/src/slic3r/GUI/Widgets/PopupWindow.cpp @@ -2,6 +2,11 @@ #include #include +#ifdef __WXGTK__ +#include +#include "slic3r/GUI/LinuxDisplayBackend.hpp" +#endif + static wxWindow *GetTopParent(wxWindow *pWindow) { wxWindow *pWin = pWindow; @@ -85,6 +90,26 @@ void PopupWindow::OnMouseEvent2(wxMouseEvent &evt) #endif #ifdef __WXGTK__ +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 + // the topmost one ("Tried to map a popup with a non-top most parent"). GTK hides the tooltip on a + // click or key press only after the widgets have handled it, so a popup opened from that click would + // 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); + } + return wxPopupTransientWindow::Show(show); +} + void PopupWindow::topWindowActiavate(wxActivateEvent &event) { event.Skip(); diff --git a/src/slic3r/GUI/Widgets/PopupWindow.hpp b/src/slic3r/GUI/Widgets/PopupWindow.hpp index 45afea8213..a95a04e214 100644 --- a/src/slic3r/GUI/Widgets/PopupWindow.hpp +++ b/src/slic3r/GUI/Widgets/PopupWindow.hpp @@ -14,6 +14,9 @@ public: PopupWindow(wxWindow *parent, int style = wxBORDER_NONE) { Create(parent, style); } bool Create(wxWindow *parent, int flags = wxBORDER_NONE); +#ifdef __WXGTK__ + bool Show(bool show = true) override; +#endif #ifdef __WXMSW__ void BindUnfocusEvent(); #endif