input: hide cursor when using touch input

Hide the cursor on touch input and keep the cursur invisible
until pointer or tablet input.
This commit is contained in:
Jens Peters 2024-11-02 15:59:33 +01:00 committed by Hiroaki Yamamoto
parent d1cde3c435
commit fc774d0071
6 changed files with 52 additions and 2 deletions

View 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)

View 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 {

View 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;
}
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);

View 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);

View 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 */

View 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");