]> git.mdlowis.com Git - proto/labwc.git/commitdiff
input: close xdg-popups on tablet tip or button press
authorJens Peters <jp7677@gmail.com>
Fri, 24 May 2024 14:18:24 +0000 (16:18 +0200)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Mon, 27 May 2024 20:40:50 +0000 (22:40 +0200)
src/input/tablet.c

index 21e1b05e8b9e219c4c7a6ea5877be8847ecea940..417e609f67f85523d2d572d229f41f3e831adc02 100644 (file)
@@ -316,6 +316,29 @@ to_stylus_button(uint32_t button)
        }
 }
 
+static void
+seat_pointer_end_grab(struct drawing_tablet_tool *tool,
+               struct wlr_surface *surface)
+{
+       if (!surface || !wlr_seat_pointer_has_grab(tool->seat->seat)) {
+               return;
+       }
+
+       struct wlr_xdg_surface *xdg_surface =
+               wlr_xdg_surface_try_from_wlr_surface(surface);
+       if (!xdg_surface || xdg_surface->role != WLR_XDG_SURFACE_ROLE_POPUP) {
+               /*
+                * If we have an active popup grab (an open popup) and we are
+                * not on the popup itself, end that grab to close the popup.
+                * Contrary to pointer button notifications, a tablet button
+                * notification sometimes doesn't end grabs automatically on
+                * button notifications in another client (observed in GTK4),
+                * so end the grab manually.
+                */
+               wlr_seat_pointer_end_grab(tool->seat->seat);
+       }
+}
+
 static void
 handle_tip(struct wl_listener *listener, void *data)
 {
@@ -340,6 +363,7 @@ handle_tip(struct wl_listener *listener, void *data)
                        bool notify = cursor_process_button_press(tool->seat, BTN_LEFT,
                                ev->time_msec);
                        if (notify) {
+                               seat_pointer_end_grab(tool, surface);
                                wlr_tablet_v2_tablet_tool_notify_down(tool->tool_v2);
                                wlr_tablet_tool_v2_start_implicit_grab(tool->tool_v2);
                        }
@@ -408,6 +432,9 @@ handle_button(struct wl_listener *listener, void *data)
 
                uint32_t stylus_button = to_stylus_button(button);
                if (stylus_button && stylus_button != BTN_TOOL_PEN) {
+                       if (ev->state == WLR_BUTTON_PRESSED) {
+                               seat_pointer_end_grab(tool, surface);
+                       }
                        wlr_tablet_v2_tablet_tool_notify_button(tool->tool_v2,
                                stylus_button,
                                ev->state == WLR_BUTTON_PRESSED