diff --git a/include/input/cursor.h b/include/input/cursor.h index 4e62183d..b52d9218 100644 --- a/include/input/cursor.h +++ b/include/input/cursor.h @@ -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) diff --git a/include/labwc.h b/include/labwc.h index 730c083a..7d02f7ae 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -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 { diff --git a/src/input/cursor.c b/src/input/cursor.c index 0d2ebca2..5f76c908 100644 --- a/src/input/cursor.c +++ b/src/input/cursor.c @@ -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); diff --git a/src/input/tablet.c b/src/input/tablet.c index 08e52e2f..acf1f01e 100644 --- a/src/input/tablet.c +++ b/src/input/tablet.c @@ -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); diff --git a/src/input/touch.c b/src/input/touch.c index e09bb6ae..a8a9b9e1 100644 --- a/src/input/touch.c +++ b/src/input/touch.c @@ -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 */ diff --git a/src/seat.c b/src/seat.c index bc51c898..92603a1f 100644 --- a/src/seat.c +++ b/src/seat.c @@ -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");