]> git.mdlowis.com Git - proto/labwc.git/commitdiff
input: hide cursor when using touch input
authorJens Peters <jp7677@gmail.com>
Sat, 2 Nov 2024 14:59:33 +0000 (15:59 +0100)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Sun, 10 Nov 2024 08:08:38 +0000 (17:08 +0900)
Hide the cursor on touch input and keep the cursur invisible
until pointer or tablet input.

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

index 4e62183d7c353e17f0dcffa21538212c1cb62e2c..b52d92188dd636c586d4290920a37cdfec6a6b9c 100644 (file)
@@ -72,6 +72,8 @@ struct cursor_context get_cursor_context(struct server *server);
  */
 void cursor_set(struct seat *seat, enum lab_cursors cursor);
 
+void cursor_set_visible(struct seat *seat, bool visible);
+
 /**
  * cursor_get_resize_edges - calculate resize edge based on cursor position
  * @cursor - the current cursor (usually server->seat.cursor)
index 730c083a91c1f06374777e8e86710c12b0bc1a24..7d02f7ae68d3443f1dd69239b3756db0815f0529 100644 (file)
@@ -108,6 +108,7 @@ struct seat {
         * (in that case the client is expected to set its own cursor image).
         */
        enum lab_cursors server_cursor;
+       bool cursor_visible;
        struct wlr_cursor *cursor;
        struct wlr_xcursor_manager *xcursor_manager;
        struct {
index 0d2ebca20dc455de113383ef4b7a69a048f87926..5f76c908ea2ee0de51cef92fbc5a464693e9b135 100644 (file)
@@ -145,6 +145,14 @@ request_cursor_notify(struct wl_listener *listener, void *data)
                return;
        }
 
+       /*
+        * Omit cursor notifications when the current cursor is
+        * invisible, e.g. on touch input.
+        */
+       if (!seat->cursor_visible) {
+               return;
+       }
+
        /*
         * Omit cursor notifications from a pointer when a tablet
         * tool (stylus/pen) is in proximity. We expect to get cursor
@@ -196,6 +204,14 @@ request_set_shape_notify(struct wl_listener *listener, void *data)
                return;
        }
 
+       /*
+        * Omit set shape when the current cursor is
+        * invisible, e.g. on touch input.
+        */
+       if (!seat->cursor_visible) {
+               return;
+       }
+
        /*
         * This can be sent by any client, so we check to make sure this one
         * actually has pointer focus first.
@@ -347,15 +363,34 @@ cursor_set(struct seat *seat, enum lab_cursors cursor)
                return;
        }
 
-       wlr_cursor_set_xcursor(seat->cursor, seat->xcursor_manager,
-               cursor_names[cursor]);
+       if (seat->cursor_visible) {
+               wlr_cursor_set_xcursor(seat->cursor, seat->xcursor_manager,
+                       cursor_names[cursor]);
+       }
        seat->server_cursor = cursor;
 }
 
+void
+cursor_set_visible(struct seat *seat, bool visible)
+{
+       if (seat->cursor_visible == visible) {
+               return;
+       }
+
+       seat->cursor_visible = visible;
+       cursor_update_image(seat);
+}
+
 void
 cursor_update_image(struct seat *seat)
 {
        enum lab_cursors cursor = seat->server_cursor;
+
+       if (!seat->cursor_visible) {
+               wlr_cursor_unset_image(seat->cursor);
+               return;
+       }
+
        if (cursor == LAB_CURSOR_CLIENT) {
                /*
                 * When we loose the output cursor while over a client
@@ -817,6 +852,7 @@ cursor_motion(struct wl_listener *listener, void *data)
        struct server *server = seat->server;
        struct wlr_pointer_motion_event *event = data;
        idle_manager_notify_activity(seat->seat);
+       cursor_set_visible(seat, /* visible */ true);
 
        wlr_relative_pointer_manager_v1_send_relative_motion(
                server->relative_pointer_manager,
@@ -843,6 +879,7 @@ cursor_motion_absolute(struct wl_listener *listener, void *data)
                listener, seat, cursor_motion_absolute);
        struct wlr_pointer_motion_absolute_event *event = data;
        idle_manager_notify_activity(seat->seat);
+       cursor_set_visible(seat, /* visible */ true);
 
        double lx, ly;
        wlr_cursor_absolute_to_layout_coords(seat->cursor,
@@ -1144,6 +1181,7 @@ cursor_button(struct wl_listener *listener, void *data)
        struct seat *seat = wl_container_of(listener, seat, cursor_button);
        struct wlr_pointer_button_event *event = data;
        idle_manager_notify_activity(seat->seat);
+       cursor_set_visible(seat, /* visible */ true);
 
        bool notify;
        switch (event->state) {
@@ -1324,6 +1362,7 @@ cursor_axis(struct wl_listener *listener, void *data)
 
        struct cursor_context ctx = get_cursor_context(server);
        idle_manager_notify_activity(seat->seat);
+       cursor_set_visible(seat, /* visible */ true);
 
        /* Bindings swallow mouse events if activated */
        bool handled = handle_cursor_axis(server, &ctx, event);
index 08e52e2f1574d9bf349b73374958dd1f6e8f09ef..acf1f01ea637d8451dabd68156317a7a374279b5 100644 (file)
@@ -251,6 +251,7 @@ handle_tablet_tool_proximity(struct wl_listener *listener, void *data)
        }
 
        idle_manager_notify_activity(tablet->seat->seat);
+       cursor_set_visible(tablet->seat, /* visible */ true);
 
        if (ev->state == WLR_TABLET_TOOL_PROXIMITY_IN) {
                tablet->motion_mode =
@@ -313,6 +314,7 @@ handle_tablet_tool_axis(struct wl_listener *listener, void *data)
        }
 
        idle_manager_notify_activity(tablet->seat->seat);
+       cursor_set_visible(tablet->seat, /* visible */ true);
 
        /*
         * Reset relative coordinates. If those axes aren't updated,
@@ -470,6 +472,7 @@ handle_tablet_tool_tip(struct wl_listener *listener, void *data)
        }
 
        idle_manager_notify_activity(tablet->seat->seat);
+       cursor_set_visible(tablet->seat, /* visible */ true);
 
        double x, y, dx, dy;
        struct wlr_surface *surface = tablet_get_coords(tablet, &x, &y, &dx, &dy);
@@ -549,6 +552,7 @@ handle_tablet_tool_button(struct wl_listener *listener, void *data)
        }
 
        idle_manager_notify_activity(tablet->seat->seat);
+       cursor_set_visible(tablet->seat, /* visible */ true);
 
        double x, y, dx, dy;
        struct wlr_surface *surface = tablet_get_coords(tablet, &x, &y, &dx, &dy);
index e09bb6ae7585892069b14a7a5c0fd6188690f1ec..a8a9b9e103561d775ccbbdec808807b9e94d447f 100644 (file)
@@ -125,6 +125,9 @@ handle_touch_down(struct wl_listener *listener, void *data)
        wl_list_insert(&seat->touch_points, &touch_point->link);
        int touch_point_count = wl_list_length(&seat->touch_points);
 
+       /* hide the cursor when starting touch input */
+       cursor_set_visible(seat, /* visible */ false);
+
        if (touch_point->surface) {
                seat_pointer_end_grab(seat, touch_point->surface);
                /* Clear focus to not interfere with touch input */
index bc51c898be0b0e83abd773c34a312260346e409d..92603a1f3694166520541794126e0ea44c33aae2 100644 (file)
@@ -556,6 +556,7 @@ seat_init(struct server *server)
        seat->input_method_relay = input_method_relay_create(seat);
 
        seat->xcursor_manager = NULL;
+       seat->cursor_visible = true;
        seat->cursor = wlr_cursor_create();
        if (!seat->cursor) {
                wlr_log(WLR_ERROR, "unable to create cursor");