Skip to content

Commit 4666d17

Browse files
Stacy Harperbl4ckb0ne
Stacy Harper
authored andcommitted
Implement seatop_touch
Atm we got issue with the touch position sent to the clients. While holding contact, leaving the initial container will continue to send motion event to the client but with the new local position from the new container. This seatop goal is to send the position of the touch event, relatively to the initial container layout position.
1 parent 7d2e4a5 commit 4666d17

File tree

6 files changed

+187
-48
lines changed

6 files changed

+187
-48
lines changed

include/sway/input/cursor.h

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ void cursor_unhide(struct sway_cursor *cursor);
108108
int cursor_get_timeout(struct sway_cursor *cursor);
109109
void cursor_notify_key_press(struct sway_cursor *cursor);
110110

111+
void pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
112+
struct wlr_input_device *device, double dx, double dy,
113+
double dx_unaccel, double dy_unaccel);
114+
111115
void dispatch_cursor_button(struct sway_cursor *cursor,
112116
struct wlr_input_device *device, uint32_t time_msec, uint32_t button,
113117
enum wlr_button_state state);

include/sway/input/seat.h

+21-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <wlr/types/wlr_keyboard_shortcuts_inhibit_v1.h>
55
#include <wlr/types/wlr_layer_shell_v1.h>
66
#include <wlr/types/wlr_seat.h>
7+
#include <wlr/types/wlr_touch.h>
78
#include <wlr/util/edges.h>
89
#include "sway/config.h"
910
#include "sway/input/input-manager.h"
@@ -36,6 +37,12 @@ struct sway_seatop_impl {
3637
void (*swipe_end)(struct sway_seat *seat,
3738
struct wlr_pointer_swipe_end_event *event);
3839
void (*rebase)(struct sway_seat *seat, uint32_t time_msec);
40+
void (*touch_motion)(struct sway_seat *seat,
41+
struct wlr_touch_motion_event *event, double lx, double ly);
42+
void (*touch_up)(struct sway_seat *seat,
43+
struct wlr_touch_up_event *event);
44+
void (*touch_down)(struct sway_seat *seat,
45+
struct wlr_touch_down_event *event, double lx, double ly);
3946
void (*tablet_tool_motion)(struct sway_seat *seat,
4047
struct sway_tablet_tool *tool, uint32_t time_msec);
4148
void (*tablet_tool_tip)(struct sway_seat *seat, struct sway_tablet_tool *tool,
@@ -256,10 +263,13 @@ enum wlr_edges find_resize_edge(struct sway_container *cont,
256263
void seatop_begin_default(struct sway_seat *seat);
257264

258265
void seatop_begin_down(struct sway_seat *seat, struct sway_container *con,
259-
uint32_t time_msec, double sx, double sy);
266+
double sx, double sy);
260267

261268
void seatop_begin_down_on_surface(struct sway_seat *seat,
262-
struct wlr_surface *surface, uint32_t time_msec, double sx, double sy);
269+
struct wlr_surface *surface, double sx, double sy);
270+
271+
void seatop_begin_touch_down(struct sway_seat *seat, struct wlr_surface *surface,
272+
struct wlr_touch_down_event *event, double sx, double sy, double lx, double ly);
263273

264274
void seatop_begin_move_floating(struct sway_seat *seat,
265275
struct sway_container *con);
@@ -319,6 +329,15 @@ void seatop_swipe_update(struct sway_seat *seat,
319329
void seatop_swipe_end(struct sway_seat *seat,
320330
struct wlr_pointer_swipe_end_event *event);
321331

332+
void seatop_touch_motion(struct sway_seat *seat,
333+
struct wlr_touch_motion_event *event, double lx, double ly);
334+
335+
void seatop_touch_up(struct sway_seat *seat,
336+
struct wlr_touch_up_event *event);
337+
338+
void seatop_touch_down(struct sway_seat *seat,
339+
struct wlr_touch_down_event *event, double lx, double ly);
340+
322341
void seatop_rebase(struct sway_seat *seat, uint32_t time_msec);
323342

324343
/**

sway/input/cursor.c

+6-39
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ void cursor_unhide(struct sway_cursor *cursor) {
364364
wl_event_source_timer_update(cursor->hide_source, cursor_get_timeout(cursor));
365365
}
366366

367-
static void pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
367+
void pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
368368
struct wlr_input_device *device, double dx, double dy,
369369
double dx_unaccel, double dy_unaccel) {
370370
wlr_relative_pointer_manager_v1_send_relative_motion(
@@ -479,51 +479,24 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
479479
cursor_hide(cursor);
480480

481481
struct sway_seat *seat = cursor->seat;
482-
struct wlr_seat *wlr_seat = seat->wlr_seat;
483-
struct wlr_surface *surface = NULL;
484482

485483
double lx, ly;
486484
wlr_cursor_absolute_to_layout_coords(cursor->cursor, &event->touch->base,
487485
event->x, event->y, &lx, &ly);
488-
double sx, sy;
489-
struct sway_node *focused_node = node_at_coords(seat, lx, ly, &surface, &sx, &sy);
490486

491487
seat->touch_id = event->touch_id;
492488
seat->touch_x = lx;
493489
seat->touch_y = ly;
494490

495-
if (surface && wlr_surface_accepts_touch(wlr_seat, surface)) {
496-
if (seat_is_input_allowed(seat, surface)) {
497-
wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec,
498-
event->touch_id, sx, sy);
499-
500-
if (focused_node) {
501-
seat_set_focus(seat, focused_node);
502-
}
503-
}
504-
} else if (!cursor->simulating_pointer_from_touch &&
505-
(!surface || seat_is_input_allowed(seat, surface))) {
506-
// Fallback to cursor simulation.
507-
// The pointer_touch_id state is needed, so drags are not aborted when over
508-
// a surface supporting touch and multi touch events don't interfere.
509-
cursor->simulating_pointer_from_touch = true;
510-
cursor->pointer_touch_id = seat->touch_id;
511-
double dx, dy;
512-
dx = lx - cursor->cursor->x;
513-
dy = ly - cursor->cursor->y;
514-
pointer_motion(cursor, event->time_msec, &event->touch->base, dx, dy,
515-
dx, dy);
516-
dispatch_cursor_button(cursor, &event->touch->base, event->time_msec,
517-
BTN_LEFT, WLR_BUTTON_PRESSED);
518-
}
491+
seatop_touch_down(seat, event, lx, ly);
519492
}
520493

521494
static void handle_touch_up(struct wl_listener *listener, void *data) {
522495
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up);
523496
struct wlr_touch_up_event *event = data;
524497
cursor_handle_activity_from_device(cursor, &event->touch->base);
525498

526-
struct wlr_seat *wlr_seat = cursor->seat->wlr_seat;
499+
struct sway_seat *seat = cursor->seat;
527500

528501
if (cursor->simulating_pointer_from_touch) {
529502
if (cursor->pointer_touch_id == cursor->seat->touch_id) {
@@ -532,7 +505,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) {
532505
event->time_msec, BTN_LEFT, WLR_BUTTON_RELEASED);
533506
}
534507
} else {
535-
wlr_seat_touch_notify_up(wlr_seat, event->time_msec, event->touch_id);
508+
seatop_touch_up(seat, event);
536509
}
537510
}
538511

@@ -543,19 +516,14 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
543516
cursor_handle_activity_from_device(cursor, &event->touch->base);
544517

545518
struct sway_seat *seat = cursor->seat;
546-
struct wlr_seat *wlr_seat = seat->wlr_seat;
547-
struct wlr_surface *surface = NULL;
548519

549520
double lx, ly;
550521
wlr_cursor_absolute_to_layout_coords(cursor->cursor, &event->touch->base,
551522
event->x, event->y, &lx, &ly);
552-
double sx, sy;
553-
node_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy);
554523

555524
if (seat->touch_id == event->touch_id) {
556525
seat->touch_x = lx;
557526
seat->touch_y = ly;
558-
559527
struct sway_drag_icon *drag_icon;
560528
wl_list_for_each(drag_icon, &root->drag_icons, link) {
561529
if (drag_icon->seat == seat) {
@@ -572,9 +540,8 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
572540
pointer_motion(cursor, event->time_msec, &event->touch->base,
573541
dx, dy, dx, dy);
574542
}
575-
} else if (surface) {
576-
wlr_seat_touch_notify_motion(wlr_seat, event->time_msec,
577-
event->touch_id, sx, sy);
543+
} else {
544+
seatop_touch_motion(seat, event, lx, ly);
578545
}
579546
}
580547

sway/input/seat.c

+20
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,26 @@ void seatop_pointer_axis(struct sway_seat *seat,
16181618
}
16191619
}
16201620

1621+
void seatop_touch_motion(struct sway_seat *seat, struct wlr_touch_motion_event *event,
1622+
double lx, double ly) {
1623+
if (seat->seatop_impl->touch_motion) {
1624+
seat->seatop_impl->touch_motion(seat, event, lx, ly);
1625+
}
1626+
}
1627+
1628+
void seatop_touch_up(struct sway_seat *seat, struct wlr_touch_up_event *event) {
1629+
if (seat->seatop_impl->touch_up) {
1630+
seat->seatop_impl->touch_up(seat, event);
1631+
}
1632+
}
1633+
1634+
void seatop_touch_down(struct sway_seat *seat, struct wlr_touch_down_event *event,
1635+
double lx, double ly) {
1636+
if (seat->seatop_impl->touch_down) {
1637+
seat->seatop_impl->touch_down(seat, event, lx, ly);
1638+
}
1639+
}
1640+
16211641
void seatop_tablet_tool_tip(struct sway_seat *seat,
16221642
struct sway_tablet_tool *tool, uint32_t time_msec,
16231643
enum wlr_tablet_tool_tip_state state) {

sway/input/seatop_default.c

+34-3
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static void handle_tablet_tool_tip(struct sway_seat *seat,
261261

262262
// Handle tapping on a container surface
263263
seat_set_focus_container(seat, cont);
264-
seatop_begin_down(seat, node->sway_container, time_msec, sx, sy);
264+
seatop_begin_down(seat, node->sway_container, sx, sy);
265265
}
266266
#if HAVE_XWAYLAND
267267
// Handle tapping on an xwayland unmanaged view
@@ -374,7 +374,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
374374
transaction_commit_dirty();
375375
}
376376
if (state == WLR_BUTTON_PRESSED) {
377-
seatop_begin_down_on_surface(seat, surface, time_msec, sx, sy);
377+
seatop_begin_down_on_surface(seat, surface, sx, sy);
378378
}
379379
seat_pointer_notify_button(seat, time_msec, button, state);
380380
return;
@@ -499,7 +499,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
499499

500500
// Handle mousedown on a container surface
501501
if (surface && cont && state == WLR_BUTTON_PRESSED) {
502-
seatop_begin_down(seat, cont, time_msec, sx, sy);
502+
seatop_begin_down(seat, cont, sx, sy);
503503
seat_pointer_notify_button(seat, time_msec, button, WLR_BUTTON_PRESSED);
504504
return;
505505
}
@@ -649,6 +649,36 @@ static void handle_tablet_tool_motion(struct sway_seat *seat,
649649
e->previous_node = node;
650650
}
651651

652+
static void handle_touch_down(struct sway_seat *seat,
653+
struct wlr_touch_down_event *event, double lx, double ly) {
654+
struct wlr_surface *surface = NULL;
655+
struct wlr_seat *wlr_seat = seat->wlr_seat;
656+
struct sway_cursor *cursor = seat->cursor;
657+
double sx, sy;
658+
node_at_coords(seat, seat->touch_x, seat->touch_y, &surface, &sx, &sy);
659+
660+
if (surface && wlr_surface_accepts_touch(wlr_seat, surface)) {
661+
if (seat_is_input_allowed(seat, surface)) {
662+
cursor->simulating_pointer_from_touch = false;
663+
seatop_begin_touch_down(seat, surface, event, sx, sy, lx, ly);
664+
}
665+
} else if (!cursor->simulating_pointer_from_touch &&
666+
(!surface || seat_is_input_allowed(seat, surface))) {
667+
// Fallback to cursor simulation.
668+
// The pointer_touch_id state is needed, so drags are not aborted when over
669+
// a surface supporting touch and multi touch events don't interfere.
670+
cursor->simulating_pointer_from_touch = true;
671+
cursor->pointer_touch_id = seat->touch_id;
672+
double dx, dy;
673+
dx = seat->touch_x - cursor->cursor->x;
674+
dy = seat->touch_y - cursor->cursor->y;
675+
pointer_motion(cursor, event->time_msec, &event->touch->base, dx, dy,
676+
dx, dy);
677+
dispatch_cursor_button(cursor, &event->touch->base, event->time_msec,
678+
BTN_LEFT, WLR_BUTTON_PRESSED);
679+
}
680+
}
681+
652682
/*----------------------------------------\
653683
* Functions used by handle_pointer_axis /
654684
*--------------------------------------*/
@@ -1096,6 +1126,7 @@ static const struct sway_seatop_impl seatop_impl = {
10961126
.swipe_begin = handle_swipe_begin,
10971127
.swipe_update = handle_swipe_update,
10981128
.swipe_end = handle_swipe_end,
1129+
.touch_down = handle_touch_down,
10991130
.rebase = handle_rebase,
11001131
.allow_set_cursor = true,
11011132
};

0 commit comments

Comments
 (0)