Implement pointer simulation if client hasn't bound to touch
This commit is contained in:
parent
7a294b2668
commit
2473cac32c
|
@ -50,6 +50,8 @@ struct sway_cursor {
|
||||||
struct wl_listener touch_down;
|
struct wl_listener touch_down;
|
||||||
struct wl_listener touch_up;
|
struct wl_listener touch_up;
|
||||||
struct wl_listener touch_motion;
|
struct wl_listener touch_motion;
|
||||||
|
bool simulating_pointer_from_touch;
|
||||||
|
int32_t pointer_touch_id;
|
||||||
|
|
||||||
struct wl_listener tool_axis;
|
struct wl_listener tool_axis;
|
||||||
struct wl_listener tool_tip;
|
struct wl_listener tool_tip;
|
||||||
|
|
|
@ -405,7 +405,6 @@ static void handle_pointer_frame(struct wl_listener *listener, void *data) {
|
||||||
|
|
||||||
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);
|
||||||
cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH);
|
|
||||||
struct wlr_event_touch_down *event = data;
|
struct wlr_event_touch_down *event = data;
|
||||||
|
|
||||||
struct sway_seat *seat = cursor->seat;
|
struct sway_seat *seat = cursor->seat;
|
||||||
|
@ -422,35 +421,58 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
|
||||||
seat->touch_x = lx;
|
seat->touch_x = lx;
|
||||||
seat->touch_y = ly;
|
seat->touch_y = ly;
|
||||||
|
|
||||||
if (!surface) {
|
if (surface && wlr_surface_accepts_touch(wlr_seat, surface)) {
|
||||||
return;
|
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);
|
||||||
|
|
||||||
// TODO: fall back to cursor simulation if client has not bound to touch
|
if (focused_node) {
|
||||||
if (seat_is_input_allowed(seat, surface)) {
|
seat_set_focus(seat, focused_node);
|
||||||
cursor_hide(cursor);
|
}
|
||||||
wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec,
|
}
|
||||||
event->touch_id, sx, sy);
|
} else if (!cursor->simulating_pointer_from_touch &&
|
||||||
}
|
(!surface || seat_is_input_allowed(seat, surface))) {
|
||||||
|
// Fallback to cursor simulation.
|
||||||
if (focused_node) {
|
// The pointer_touch_id state is needed, so drags are not aborted when over
|
||||||
seat_set_focus(seat, focused_node);
|
// a surface supporting touch and multi touch events don't interfere.
|
||||||
|
cursor->simulating_pointer_from_touch = true;
|
||||||
|
cursor->pointer_touch_id = seat->touch_id;
|
||||||
|
double dx, dy;
|
||||||
|
dx = lx - cursor->cursor->x;
|
||||||
|
dy = ly - cursor->cursor->y;
|
||||||
|
pointer_motion(cursor, event->time_msec, event->device, dx, dy, dx, dy);
|
||||||
|
dispatch_cursor_button(cursor, event->device, event->time_msec,
|
||||||
|
BTN_LEFT, WLR_BUTTON_PRESSED);
|
||||||
|
wlr_seat_pointer_notify_frame(wlr_seat);
|
||||||
|
transaction_commit_dirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH);
|
|
||||||
struct wlr_event_touch_up *event = data;
|
struct wlr_event_touch_up *event = data;
|
||||||
struct wlr_seat *seat = cursor->seat->wlr_seat;
|
struct wlr_seat *wlr_seat = cursor->seat->wlr_seat;
|
||||||
// TODO: fall back to cursor simulation if client has not bound to touch
|
|
||||||
wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
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);
|
||||||
cursor_handle_activity(cursor, IDLE_SOURCE_TOUCH);
|
|
||||||
struct wlr_event_touch_motion *event = data;
|
struct wlr_event_touch_motion *event = data;
|
||||||
|
|
||||||
struct sway_seat *seat = cursor->seat;
|
struct sway_seat *seat = cursor->seat;
|
||||||
|
@ -475,12 +497,16 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!surface) {
|
if (cursor->simulating_pointer_from_touch) {
|
||||||
return;
|
if (seat->touch_id == cursor->pointer_touch_id) {
|
||||||
}
|
double dx, dy;
|
||||||
|
dx = lx - cursor->cursor->x;
|
||||||
// TODO: fall back to cursor simulation if client has not bound to touch
|
dy = ly - cursor->cursor->y;
|
||||||
if (seat_is_input_allowed(cursor->seat, surface)) {
|
pointer_motion(cursor, event->time_msec, event->device, dx, dy, dx, dy);
|
||||||
|
transaction_commit_dirty();
|
||||||
|
}
|
||||||
|
} 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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue