]> git.mdlowis.com Git - proto/labwc.git/commitdiff
input: close xdg-popups on touch down
authorJens Peters <jp7677@gmail.com>
Fri, 1 Nov 2024 08:11:33 +0000 (09:11 +0100)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Sun, 10 Nov 2024 08:08:38 +0000 (17:08 +0900)
Taken over and now shared from the tablet implementation.

include/labwc.h
src/input/tablet.c
src/input/touch.c
src/seat.c

index dc41c74e09f04ab58ad124a832657ae36635fa4e..730c083a91c1f06374777e8e86710c12b0bc1a24 100644 (file)
@@ -486,6 +486,8 @@ void seat_finish(struct server *server);
 void seat_reconfigure(struct server *server);
 void seat_focus_surface(struct seat *seat, struct wlr_surface *surface);
 
+void seat_pointer_end_grab(struct seat *seat, struct wlr_surface *surface);
+
 /**
  * seat_focus_lock_surface() - ONLY to be called from session-lock.c to
  * focus lock screen surfaces. Use seat_focus_surface() otherwise.
index ac94228b859ffc5468d3311ad0ecc7be6c62f439..08e52e2f1574d9bf349b73374958dd1f6e8f09ef 100644 (file)
@@ -458,29 +458,6 @@ 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_tablet_tool_tip(struct wl_listener *listener, void *data)
 {
@@ -519,7 +496,7 @@ handle_tablet_tool_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);
+                               seat_pointer_end_grab(tool->seat, surface);
                                wlr_tablet_v2_tablet_tool_notify_down(tool->tool_v2);
                                wlr_tablet_tool_v2_start_implicit_grab(tool->tool_v2);
                        }
@@ -603,7 +580,7 @@ handle_tablet_tool_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);
+                               seat_pointer_end_grab(tool->seat, surface);
                        }
                        wlr_tablet_v2_tablet_tool_notify_button(tool->tool_v2,
                                stylus_button,
index d36d98858809f8cc22a27cbd7d18bb4110a18ac7..e09bb6ae7585892069b14a7a5c0fd6188690f1ec 100644 (file)
@@ -126,6 +126,7 @@ handle_touch_down(struct wl_listener *listener, void *data)
        int touch_point_count = wl_list_length(&seat->touch_points);
 
        if (touch_point->surface) {
+               seat_pointer_end_grab(seat, touch_point->surface);
                /* Clear focus to not interfere with touch input */
                wlr_seat_pointer_notify_clear_focus(seat->seat);
 
index 3aa2e234503cb9292ab6d8a4cb8319c966241cb0..bc51c898be0b0e83abd773c34a312260346e409d 100644 (file)
@@ -596,6 +596,28 @@ configure_keyboard(struct seat *seat, struct input *input)
        keyboard_configure(seat, kb, keyboard->is_virtual);
 }
 
+void
+seat_pointer_end_grab(struct seat *seat, struct wlr_surface *surface)
+{
+       if (!surface || !wlr_seat_pointer_has_grab(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/touch
+                * 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(seat->seat);
+       }
+}
+
 /* This is called on SIGHUP (generally in response to labwc --reconfigure */
 void
 seat_reconfigure(struct server *server)