mirror of
https://github.com/swaywm/sway.git
synced 2024-11-14 06:24:20 +01:00
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.
This commit is contained in:
parent
21b77f376d
commit
82c439c4f1
@ -91,7 +91,7 @@ void cursor_rebase_all(void);
|
|||||||
void cursor_update_image(struct sway_cursor *cursor, struct sway_node *node);
|
void cursor_update_image(struct sway_cursor *cursor, struct sway_node *node);
|
||||||
|
|
||||||
void cursor_handle_activity(struct sway_cursor *cursor,
|
void cursor_handle_activity(struct sway_cursor *cursor,
|
||||||
enum sway_input_idle_source idle_source);
|
struct wlr_input_device *device);
|
||||||
void cursor_unhide(struct sway_cursor *cursor);
|
void cursor_unhide(struct sway_cursor *cursor);
|
||||||
int cursor_get_timeout(struct sway_cursor *cursor);
|
int cursor_get_timeout(struct sway_cursor *cursor);
|
||||||
|
|
||||||
|
@ -253,11 +253,32 @@ int cursor_get_timeout(struct sway_cursor *cursor) {
|
|||||||
return timeout;
|
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,
|
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(
|
wl_event_source_timer_update(
|
||||||
cursor->hide_source, cursor_get_timeout(cursor));
|
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);
|
seat_idle_notify_activity(cursor->seat, idle_source);
|
||||||
if (cursor->hidden && idle_source != IDLE_SOURCE_TOUCH) {
|
if (cursor->hidden && idle_source != IDLE_SOURCE_TOUCH) {
|
||||||
cursor_unhide(cursor);
|
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,
|
static void pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
|
||||||
struct wlr_input_device *device, double dx, double dy,
|
struct wlr_input_device *device, double dx, double dy,
|
||||||
double dx_unaccel, double dy_unaccel) {
|
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(
|
wlr_relative_pointer_manager_v1_send_relative_motion(
|
||||||
server.relative_pointer_manager,
|
server.relative_pointer_manager,
|
||||||
cursor->seat->wlr_seat, (uint64_t)time_msec * 1000,
|
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 wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, motion);
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, motion);
|
||||||
struct wlr_event_pointer_motion *e = data;
|
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,
|
pointer_motion(cursor, e->time_msec, e->device, e->delta_x, e->delta_y,
|
||||||
e->unaccel_dx, e->unaccel_dy);
|
e->unaccel_dx, e->unaccel_dy);
|
||||||
@ -333,6 +351,7 @@ static void handle_pointer_motion_absolute(
|
|||||||
struct sway_cursor *cursor =
|
struct sway_cursor *cursor =
|
||||||
wl_container_of(listener, cursor, motion_absolute);
|
wl_container_of(listener, cursor, motion_absolute);
|
||||||
struct wlr_event_pointer_motion_absolute *event = data;
|
struct wlr_event_pointer_motion_absolute *event = data;
|
||||||
|
cursor_handle_activity(cursor, event->device);
|
||||||
|
|
||||||
double lx, ly;
|
double lx, ly;
|
||||||
wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device,
|
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) {
|
static void handle_pointer_button(struct wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
|
||||||
struct wlr_event_pointer_button *event = data;
|
struct wlr_event_pointer_button *event = data;
|
||||||
|
cursor_handle_activity(cursor, event->device);
|
||||||
|
|
||||||
if (event->state == WLR_BUTTON_PRESSED) {
|
if (event->state == WLR_BUTTON_PRESSED) {
|
||||||
cursor->pressed_button_count++;
|
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,
|
dispatch_cursor_button(cursor, event->device,
|
||||||
event->time_msec, event->button, event->state);
|
event->time_msec, event->button, event->state);
|
||||||
transaction_commit_dirty();
|
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) {
|
static void handle_pointer_axis(struct wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, axis);
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, axis);
|
||||||
struct wlr_event_pointer_axis *event = data;
|
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);
|
dispatch_cursor_axis(cursor, event);
|
||||||
transaction_commit_dirty();
|
transaction_commit_dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_pointer_frame(struct wl_listener *listener, void *data) {
|
static void handle_pointer_frame(struct wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, frame);
|
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);
|
wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_touch_down(struct wl_listener *listener, void *data) {
|
static void handle_touch_down(struct wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down);
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down);
|
||||||
struct wlr_event_touch_down *event = data;
|
struct wlr_event_touch_down *event = data;
|
||||||
|
cursor_handle_activity(cursor, event->device);
|
||||||
|
cursor_hide(cursor);
|
||||||
|
|
||||||
struct sway_seat *seat = cursor->seat;
|
struct sway_seat *seat = cursor->seat;
|
||||||
struct wlr_seat *wlr_seat = seat->wlr_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 (surface && wlr_surface_accepts_touch(wlr_seat, surface)) {
|
||||||
if (seat_is_input_allowed(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,
|
wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec,
|
||||||
event->touch_id, sx, sy);
|
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) {
|
static void handle_touch_up(struct wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up);
|
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up);
|
||||||
struct wlr_event_touch_up *event = data;
|
struct wlr_event_touch_up *event = data;
|
||||||
|
cursor_handle_activity(cursor, event->device);
|
||||||
|
|
||||||
struct wlr_seat *wlr_seat = cursor->seat->wlr_seat;
|
struct wlr_seat *wlr_seat = cursor->seat->wlr_seat;
|
||||||
|
|
||||||
if (cursor->simulating_pointer_from_touch) {
|
if (cursor->simulating_pointer_from_touch) {
|
||||||
if (cursor->pointer_touch_id == cursor->seat->touch_id) {
|
if (cursor->pointer_touch_id == cursor->seat->touch_id) {
|
||||||
cursor->simulating_pointer_from_touch = false;
|
cursor->simulating_pointer_from_touch = false;
|
||||||
cursor_handle_activity(cursor, IDLE_SOURCE_POINTER);
|
|
||||||
dispatch_cursor_button(cursor, event->device, event->time_msec,
|
dispatch_cursor_button(cursor, event->device, event->time_msec,
|
||||||
BTN_LEFT, WLR_BUTTON_RELEASED);
|
BTN_LEFT, WLR_BUTTON_RELEASED);
|
||||||
wlr_seat_pointer_notify_frame(wlr_seat);
|
wlr_seat_pointer_notify_frame(wlr_seat);
|
||||||
transaction_commit_dirty();
|
transaction_commit_dirty();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH);
|
|
||||||
wlr_seat_touch_notify_up(wlr_seat, event->time_msec, event->touch_id);
|
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 =
|
struct sway_cursor *cursor =
|
||||||
wl_container_of(listener, cursor, touch_motion);
|
wl_container_of(listener, cursor, touch_motion);
|
||||||
struct wlr_event_touch_motion *event = data;
|
struct wlr_event_touch_motion *event = data;
|
||||||
|
cursor_handle_activity(cursor, event->device);
|
||||||
|
|
||||||
struct sway_seat *seat = cursor->seat;
|
struct sway_seat *seat = cursor->seat;
|
||||||
struct wlr_seat *wlr_seat = seat->wlr_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();
|
transaction_commit_dirty();
|
||||||
}
|
}
|
||||||
} else if (surface) {
|
} else if (surface) {
|
||||||
cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH);
|
|
||||||
wlr_seat_touch_notify_motion(wlr_seat, event->time_msec,
|
wlr_seat_touch_notify_motion(wlr_seat, event->time_msec,
|
||||||
event->touch_id, sx, sy);
|
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,
|
bool change_x, bool change_y,
|
||||||
double x, double y, double dx, double dy,
|
double x, double y, double dx, double dy,
|
||||||
int32_t time_msec) {
|
int32_t time_msec) {
|
||||||
cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL);
|
|
||||||
|
|
||||||
if (!change_x && !change_y) {
|
if (!change_x && !change_y) {
|
||||||
return;
|
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) {
|
static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis);
|
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 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) {
|
if (!sway_tool) {
|
||||||
sway_log(SWAY_DEBUG, "tool axis before proximity");
|
sway_log(SWAY_DEBUG, "tool axis before proximity");
|
||||||
return;
|
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) {
|
static void handle_tool_tip(struct wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip);
|
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;
|
struct wlr_event_tablet_tool_tip *event = data;
|
||||||
|
cursor_handle_activity(cursor, event->device);
|
||||||
|
|
||||||
struct sway_tablet_tool *sway_tool = event->tool->data;
|
struct sway_tablet_tool *sway_tool = event->tool->data;
|
||||||
struct wlr_tablet_v2_tablet *tablet_v2 = sway_tool->tablet->tablet_v2;
|
struct wlr_tablet_v2_tablet *tablet_v2 = sway_tool->tablet->tablet_v2;
|
||||||
struct sway_seat *seat = cursor->seat;
|
struct sway_seat *seat = cursor->seat;
|
||||||
|
|
||||||
|
|
||||||
double sx, sy;
|
double sx, sy;
|
||||||
struct wlr_surface *surface = NULL;
|
struct wlr_surface *surface = NULL;
|
||||||
node_at_coords(seat, cursor->cursor->x, cursor->cursor->y,
|
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) {
|
static void handle_tool_proximity(struct wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_proximity);
|
struct sway_cursor *cursor =
|
||||||
cursor_handle_activity(cursor, IDLE_SOURCE_TABLET_TOOL);
|
wl_container_of(listener, cursor, tool_proximity);
|
||||||
struct wlr_event_tablet_tool_proximity *event = data;
|
struct wlr_event_tablet_tool_proximity *event = data;
|
||||||
|
cursor_handle_activity(cursor, event->device);
|
||||||
|
|
||||||
struct wlr_tablet_tool *tool = event->tool;
|
struct wlr_tablet_tool *tool = event->tool;
|
||||||
if (!tool->data) {
|
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) {
|
static void handle_tool_button(struct wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button);
|
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;
|
struct wlr_event_tablet_tool_button *event = data;
|
||||||
|
cursor_handle_activity(cursor, event->device);
|
||||||
|
|
||||||
struct sway_tablet_tool *sway_tool = event->tool->data;
|
struct sway_tablet_tool *sway_tool = event->tool->data;
|
||||||
if (!sway_tool) {
|
if (!sway_tool) {
|
||||||
sway_log(SWAY_DEBUG, "tool button before proximity");
|
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;
|
double sx, sy;
|
||||||
struct wlr_surface *surface = NULL;
|
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);
|
&surface, &sx, &sy);
|
||||||
|
|
||||||
if (!surface || !wlr_surface_accepts_tablet_v2(tablet_v2, surface)) {
|
if (!surface || !wlr_surface_accepts_tablet_v2(tablet_v2, surface)) {
|
||||||
|
@ -1380,9 +1380,9 @@ void seat_apply_config(struct sway_seat *seat,
|
|||||||
|
|
||||||
wl_list_for_each(seat_device, &seat->devices, link) {
|
wl_list_for_each(seat_device, &seat->devices, link) {
|
||||||
seat_configure_device(seat, seat_device->input_device);
|
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) {
|
struct seat_config *seat_get_config(struct sway_seat *seat) {
|
||||||
|
Loading…
Reference in New Issue
Block a user