aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/seatop_down.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/input/seatop_down.c')
-rw-r--r--sway/input/seatop_down.c106
1 files changed, 102 insertions, 4 deletions
diff --git a/sway/input/seatop_down.c b/sway/input/seatop_down.c
index 3f880ccf..6447134e 100644
--- a/sway/input/seatop_down.c
+++ b/sway/input/seatop_down.c
@@ -2,12 +2,20 @@
2#include <float.h> 2#include <float.h>
3#include <wlr/types/wlr_cursor.h> 3#include <wlr/types/wlr_cursor.h>
4#include <wlr/types/wlr_tablet_v2.h> 4#include <wlr/types/wlr_tablet_v2.h>
5#include <wlr/types/wlr_touch.h>
5#include "sway/input/cursor.h" 6#include "sway/input/cursor.h"
6#include "sway/input/seat.h" 7#include "sway/input/seat.h"
7#include "sway/tree/view.h" 8#include "sway/tree/view.h"
8#include "sway/desktop/transaction.h" 9#include "sway/desktop/transaction.h"
9#include "log.h" 10#include "log.h"
10 11
12struct seatop_touch_point_event {
13 double ref_lx, ref_ly; // touch's x/y at start of op
14 double ref_con_lx, ref_con_ly; // container's x/y at start of op
15 int32_t touch_id;
16 struct wl_list link;
17};
18
11struct seatop_down_event { 19struct seatop_down_event {
12 struct sway_container *con; 20 struct sway_container *con;
13 struct sway_seat *seat; 21 struct sway_seat *seat;
@@ -15,8 +23,87 @@ struct seatop_down_event {
15 struct wlr_surface *surface; 23 struct wlr_surface *surface;
16 double ref_lx, ref_ly; // cursor's x/y at start of op 24 double ref_lx, ref_ly; // cursor's x/y at start of op
17 double ref_con_lx, ref_con_ly; // container's x/y at start of op 25 double ref_con_lx, ref_con_ly; // container's x/y at start of op
26 struct wl_list point_events; // seatop_touch_point_event::link
18}; 27};
19 28
29static void handle_touch_motion(struct sway_seat *seat,
30 struct wlr_touch_motion_event *event, double lx, double ly) {
31 struct seatop_down_event *e = seat->seatop_data;
32
33 struct seatop_touch_point_event *point_event;
34 bool found = false;
35 wl_list_for_each(point_event, &e->point_events, link) {
36 if (point_event->touch_id == event->touch_id) {
37 found = true;
38 break;
39 }
40 }
41 if (!found) {
42 return; // Probably not a point_event from this seatop_down
43 }
44
45 double moved_x = lx - point_event->ref_lx;
46 double moved_y = ly - point_event->ref_ly;
47 double sx = point_event->ref_con_lx + moved_x;
48 double sy = point_event->ref_con_ly + moved_y;
49
50 wlr_seat_touch_notify_motion(seat->wlr_seat, event->time_msec,
51 event->touch_id, sx, sy);
52}
53
54static void handle_touch_up(struct sway_seat *seat,
55 struct wlr_touch_up_event *event) {
56 struct seatop_down_event *e = seat->seatop_data;
57 struct seatop_touch_point_event *point_event, *tmp;
58
59 wl_list_for_each_safe(point_event, tmp, &e->point_events, link) {
60 if (point_event->touch_id == event->touch_id) {
61 wl_list_remove(&point_event->link);
62 free(point_event);
63 break;
64 }
65 }
66
67 if (wl_list_empty(&e->point_events)) {
68 seatop_begin_default(seat);
69 }
70
71 wlr_seat_touch_notify_up(seat->wlr_seat, event->time_msec, event->touch_id);
72}
73
74static void handle_touch_down(struct sway_seat *seat,
75 struct wlr_touch_down_event *event, double lx, double ly) {
76 struct seatop_down_event *e = seat->seatop_data;
77 double sx, sy;
78 struct wlr_surface *surface = NULL;
79 struct sway_node *focused_node = node_at_coords(seat, seat->touch_x,
80 seat->touch_y, &surface, &sx, &sy);
81
82 if (!surface || surface != e->surface) { // Must start from the initial surface
83 return;
84 }
85
86 struct seatop_touch_point_event *point_event =
87 calloc(1, sizeof(struct seatop_touch_point_event));
88 if (!sway_assert(point_event, "Unable to allocate point_event")) {
89 return;
90 }
91 point_event->touch_id = event->touch_id;
92 point_event->ref_lx = lx;
93 point_event->ref_ly = ly;
94 point_event->ref_con_lx = sx;
95 point_event->ref_con_ly = sy;
96
97 wl_list_insert(&e->point_events, &point_event->link);
98
99 wlr_seat_touch_notify_down(seat->wlr_seat, surface, event->time_msec,
100 event->touch_id, sx, sy);
101
102 if (focused_node) {
103 seat_set_focus(seat, focused_node);
104 }
105}
106
20static void handle_pointer_axis(struct sway_seat *seat, 107static void handle_pointer_axis(struct sway_seat *seat,
21 struct wlr_pointer_axis_event *event) { 108 struct wlr_pointer_axis_event *event) {
22 struct sway_input_device *input_device = 109 struct sway_input_device *input_device =
@@ -99,14 +186,17 @@ static const struct sway_seatop_impl seatop_impl = {
99 .pointer_axis = handle_pointer_axis, 186 .pointer_axis = handle_pointer_axis,
100 .tablet_tool_tip = handle_tablet_tool_tip, 187 .tablet_tool_tip = handle_tablet_tool_tip,
101 .tablet_tool_motion = handle_tablet_tool_motion, 188 .tablet_tool_motion = handle_tablet_tool_motion,
189 .touch_motion = handle_touch_motion,
190 .touch_up = handle_touch_up,
191 .touch_down = handle_touch_down,
102 .unref = handle_unref, 192 .unref = handle_unref,
103 .end = handle_end, 193 .end = handle_end,
104 .allow_set_cursor = true, 194 .allow_set_cursor = true,
105}; 195};
106 196
107void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, 197void seatop_begin_down(struct sway_seat *seat, struct sway_container *con,
108 uint32_t time_msec, double sx, double sy) { 198 double sx, double sy) {
109 seatop_begin_down_on_surface(seat, con->view->surface, time_msec, sx, sy); 199 seatop_begin_down_on_surface(seat, con->view->surface, sx, sy);
110 struct seatop_down_event *e = seat->seatop_data; 200 struct seatop_down_event *e = seat->seatop_data;
111 e->con = con; 201 e->con = con;
112 202
@@ -114,13 +204,20 @@ void seatop_begin_down(struct sway_seat *seat, struct sway_container *con,
114 transaction_commit_dirty(); 204 transaction_commit_dirty();
115} 205}
116 206
207void seatop_begin_touch_down(struct sway_seat *seat,
208 struct wlr_surface *surface, struct wlr_touch_down_event *event,
209 double sx, double sy, double lx, double ly) {
210 seatop_begin_down_on_surface(seat, surface, sx, sy);
211 handle_touch_down(seat, event, lx, ly);
212}
213
117void seatop_begin_down_on_surface(struct sway_seat *seat, 214void seatop_begin_down_on_surface(struct sway_seat *seat,
118 struct wlr_surface *surface, uint32_t time_msec, double sx, double sy) { 215 struct wlr_surface *surface, double sx, double sy) {
119 seatop_end(seat); 216 seatop_end(seat);
120 217
121 struct seatop_down_event *e = 218 struct seatop_down_event *e =
122 calloc(1, sizeof(struct seatop_down_event)); 219 calloc(1, sizeof(struct seatop_down_event));
123 if (!e) { 220 if (!sway_assert(e, "Unable to allocate e")) {
124 return; 221 return;
125 } 222 }
126 e->con = NULL; 223 e->con = NULL;
@@ -132,6 +229,7 @@ void seatop_begin_down_on_surface(struct sway_seat *seat,
132 e->ref_ly = seat->cursor->cursor->y; 229 e->ref_ly = seat->cursor->cursor->y;
133 e->ref_con_lx = sx; 230 e->ref_con_lx = sx;
134 e->ref_con_ly = sy; 231 e->ref_con_ly = sy;
232 wl_list_init(&e->point_events);
135 233
136 seat->seatop_impl = &seatop_impl; 234 seat->seatop_impl = &seatop_impl;
137 seat->seatop_data = e; 235 seat->seatop_data = e;