diff options
author | Tudor Brindus <me@tbrindus.ca> | 2020-06-14 16:38:48 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-06-18 22:35:01 +0200 |
commit | 82c439c4f116b36d7d171bcc923b50ead59b4ab2 (patch) | |
tree | 3d503dfc3c3baa43ce1febef80d7a2259683b25d /sway/input | |
parent | 21b77f376df9e92be3c1d594e72cbbef03755f66 (diff) |
input/cursor: send idle events based off device type, not input type
Previously, a tablet or touch device could report activity as a pointer
device if it went through pointer emulation. This commit refactors idle
sources to be consistently reported based on the type of the device that
generated an input event, and now how that input event is being
processed.
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/cursor.c | 65 | ||||
-rw-r--r-- | sway/input/seat.c | 4 |
2 files changed, 44 insertions, 25 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index d6c50acc..f4ac74b4 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -253,11 +253,32 @@ int cursor_get_timeout(struct sway_cursor *cursor) { return timeout; } +static enum sway_input_idle_source idle_source_from_device( + struct wlr_input_device *device) { + switch (device->type) { + case WLR_INPUT_DEVICE_KEYBOARD: + return IDLE_SOURCE_KEYBOARD; + case WLR_INPUT_DEVICE_POINTER: + return IDLE_SOURCE_POINTER; + case WLR_INPUT_DEVICE_TOUCH: + return IDLE_SOURCE_TOUCH; + case WLR_INPUT_DEVICE_TABLET_TOOL: + return IDLE_SOURCE_TABLET_TOOL; + case WLR_INPUT_DEVICE_TABLET_PAD: + return IDLE_SOURCE_TABLET_PAD; + case WLR_INPUT_DEVICE_SWITCH: + return IDLE_SOURCE_SWITCH; + } + + assert(false); +} + void cursor_handle_activity(struct sway_cursor *cursor, - enum sway_input_idle_source idle_source) { + struct wlr_input_device *device) { wl_event_source_timer_update( cursor->hide_source, cursor_get_timeout(cursor)); + enum sway_input_idle_source idle_source = idle_source_from_device(device); seat_idle_notify_activity(cursor->seat, idle_source); if (cursor->hidden && idle_source != IDLE_SOURCE_TOUCH) { cursor_unhide(cursor); @@ -283,10 +304,6 @@ void cursor_unhide(struct sway_cursor *cursor) { static void pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, struct wlr_input_device *device, double dx, double dy, double dx_unaccel, double dy_unaccel) { - if (device->type == WLR_INPUT_DEVICE_POINTER) { - cursor_handle_activity(cursor, IDLE_SOURCE_POINTER); - } - wlr_relative_pointer_manager_v1_send_relative_motion( server.relative_pointer_manager, cursor->seat->wlr_seat, (uint64_t)time_msec * 1000, @@ -322,6 +339,7 @@ static void handle_pointer_motion_relative( struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, motion); struct wlr_event_pointer_motion *e = data; + cursor_handle_activity(cursor, e->device); pointer_motion(cursor, e->time_msec, e->device, e->delta_x, e->delta_y, e->unaccel_dx, e->unaccel_dy); @@ -333,6 +351,7 @@ static void handle_pointer_motion_absolute( struct sway_cursor *cursor = wl_container_of(listener, cursor, motion_absolute); struct wlr_event_pointer_motion_absolute *event = data; + cursor_handle_activity(cursor, event->device); double lx, ly; wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, @@ -358,6 +377,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, static void handle_pointer_button(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, button); struct wlr_event_pointer_button *event = data; + cursor_handle_activity(cursor, event->device); if (event->state == WLR_BUTTON_PRESSED) { cursor->pressed_button_count++; @@ -369,7 +389,6 @@ static void handle_pointer_button(struct wl_listener *listener, void *data) { } } - cursor_handle_activity(cursor, IDLE_SOURCE_POINTER); dispatch_cursor_button(cursor, event->device, event->time_msec, event->button, event->state); transaction_commit_dirty(); @@ -383,20 +402,21 @@ void dispatch_cursor_axis(struct sway_cursor *cursor, static void handle_pointer_axis(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, axis); struct wlr_event_pointer_axis *event = data; - cursor_handle_activity(cursor, IDLE_SOURCE_POINTER); + cursor_handle_activity(cursor, event->device); dispatch_cursor_axis(cursor, event); transaction_commit_dirty(); } static void handle_pointer_frame(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, frame); - cursor_handle_activity(cursor, IDLE_SOURCE_POINTER); wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat); } static void handle_touch_down(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down); struct wlr_event_touch_down *event = data; + cursor_handle_activity(cursor, event->device); + cursor_hide(cursor); struct sway_seat *seat = cursor->seat; struct wlr_seat *wlr_seat = seat->wlr_seat; @@ -414,8 +434,6 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { if (surface && wlr_surface_accepts_touch(wlr_seat, surface)) { if (seat_is_input_allowed(seat, surface)) { - cursor_hide(cursor); - cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH); wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec, event->touch_id, sx, sy); @@ -444,19 +462,19 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { static void handle_touch_up(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up); struct wlr_event_touch_up *event = data; + cursor_handle_activity(cursor, event->device); + struct wlr_seat *wlr_seat = cursor->seat->wlr_seat; if (cursor->simulating_pointer_from_touch) { if (cursor->pointer_touch_id == cursor->seat->touch_id) { cursor->simulating_pointer_from_touch = false; - cursor_handle_activity(cursor, IDLE_SOURCE_POINTER); dispatch_cursor_button(cursor, event->device, event->time_msec, BTN_LEFT, WLR_BUTTON_RELEASED); wlr_seat_pointer_notify_frame(wlr_seat); transaction_commit_dirty(); } } else { - cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH); wlr_seat_touch_notify_up(wlr_seat, event->time_msec, event->touch_id); } } @@ -465,6 +483,7 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_motion); struct wlr_event_touch_motion *event = data; + cursor_handle_activity(cursor, event->device); struct sway_seat *seat = cursor->seat; struct wlr_seat *wlr_seat = seat->wlr_seat; @@ -497,7 +516,6 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { transaction_commit_dirty(); } } else if (surface) { - cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH); wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, event->touch_id, sx, sy); } @@ -535,7 +553,6 @@ static void handle_tablet_tool_position(struct sway_cursor *cursor, bool change_x, bool change_y, double x, double y, double dx, double dy, int32_t time_msec) { - cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL); if (!change_x && !change_y) { return; @@ -587,10 +604,10 @@ static void handle_tablet_tool_position(struct sway_cursor *cursor, static void handle_tool_axis(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); - cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL); struct wlr_event_tablet_tool_axis *event = data; - struct sway_tablet_tool *sway_tool = event->tool->data; + cursor_handle_activity(cursor, event->device); + struct sway_tablet_tool *sway_tool = event->tool->data; if (!sway_tool) { sway_log(SWAY_DEBUG, "tool axis before proximity"); return; @@ -643,12 +660,14 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { static void handle_tool_tip(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip); - cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL); struct wlr_event_tablet_tool_tip *event = data; + cursor_handle_activity(cursor, event->device); + struct sway_tablet_tool *sway_tool = event->tool->data; struct wlr_tablet_v2_tablet *tablet_v2 = sway_tool->tablet->tablet_v2; struct sway_seat *seat = cursor->seat; + double sx, sy; struct wlr_surface *surface = NULL; node_at_coords(seat, cursor->cursor->x, cursor->cursor->y, @@ -692,9 +711,10 @@ static struct sway_tablet *get_tablet_for_device(struct sway_cursor *cursor, } static void handle_tool_proximity(struct wl_listener *listener, void *data) { - struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_proximity); - cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL); + struct sway_cursor *cursor = + wl_container_of(listener, cursor, tool_proximity); struct wlr_event_tablet_tool_proximity *event = data; + cursor_handle_activity(cursor, event->device); struct wlr_tablet_tool *tool = event->tool; if (!tool->data) { @@ -723,10 +743,9 @@ static void handle_tool_proximity(struct wl_listener *listener, void *data) { static void handle_tool_button(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button); - struct sway_seat *seat = cursor->seat; - cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL); - struct wlr_event_tablet_tool_button *event = data; + cursor_handle_activity(cursor, event->device); + struct sway_tablet_tool *sway_tool = event->tool->data; if (!sway_tool) { sway_log(SWAY_DEBUG, "tool button before proximity"); @@ -737,7 +756,7 @@ static void handle_tool_button(struct wl_listener *listener, void *data) { double sx, sy; struct wlr_surface *surface = NULL; - node_at_coords(seat, cursor->cursor->x, cursor->cursor->y, + node_at_coords(cursor->seat, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); if (!surface || !wlr_surface_accepts_tablet_v2(tablet_v2, surface)) { diff --git a/sway/input/seat.c b/sway/input/seat.c index 73a8deac..1be8d552 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1380,9 +1380,9 @@ void seat_apply_config(struct sway_seat *seat, wl_list_for_each(seat_device, &seat->devices, link) { seat_configure_device(seat, seat_device->input_device); + cursor_handle_activity(seat->cursor, + seat_device->input_device->wlr_device); } - - cursor_handle_activity(seat->cursor, IDLE_SOURCE_POINTER); } struct seat_config *seat_get_config(struct sway_seat *seat) { |