aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Plakolb <s.plakolb@gmail.com>2021-08-24 16:53:03 +0200
committerLibravatar Tudor Brindus <vulcainus@gmail.com>2021-09-02 13:13:40 -0400
commit4baf845a3ab90ac4ae8832e9e022c8638080e743 (patch)
tree452ed400b8b772f3cb27ed6b8b868fb0804aba62
parentinput: Use seatop_down on layer surface click (diff)
downloadsway-4baf845a3ab90ac4ae8832e9e022c8638080e743.tar.gz
sway-4baf845a3ab90ac4ae8832e9e022c8638080e743.tar.zst
sway-4baf845a3ab90ac4ae8832e9e022c8638080e743.zip
seatop_down: End if surface is destroyed or other seatop starts
If the surface the pointer started to interact with is destroyed we also want the seatop_down to end. In case a drag is initiated we receive a call to handle_end.
-rw-r--r--include/sway/input/seat.h2
-rw-r--r--sway/input/seatop_default.c2
-rw-r--r--sway/input/seatop_down.c40
3 files changed, 25 insertions, 19 deletions
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index 78dbda6f..77c2278d 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -241,7 +241,7 @@ void seatop_begin_default(struct sway_seat *seat);
241void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, 241void seatop_begin_down(struct sway_seat *seat, struct sway_container *con,
242 uint32_t time_msec, double sx, double sy); 242 uint32_t time_msec, double sx, double sy);
243 243
244void seatop_begin_down_on_layer_surface(struct sway_seat *seat, 244void seatop_begin_down_on_surface(struct sway_seat *seat,
245 struct wlr_surface *surface, uint32_t time_msec, double sx, double sy); 245 struct wlr_surface *surface, uint32_t time_msec, double sx, double sy);
246 246
247void seatop_begin_move_floating(struct sway_seat *seat, 247void seatop_begin_move_floating(struct sway_seat *seat,
diff --git a/sway/input/seatop_default.c b/sway/input/seatop_default.c
index 7a3745d2..4320a3b4 100644
--- a/sway/input/seatop_default.c
+++ b/sway/input/seatop_default.c
@@ -374,7 +374,7 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
374 transaction_commit_dirty(); 374 transaction_commit_dirty();
375 } 375 }
376 if (state == WLR_BUTTON_PRESSED) { 376 if (state == WLR_BUTTON_PRESSED) {
377 seatop_begin_down_on_layer_surface(seat, surface, time_msec, sx, sy); 377 seatop_begin_down_on_surface(seat, surface, time_msec, sx, sy);
378 } 378 }
379 seat_pointer_notify_button(seat, time_msec, button, state); 379 seat_pointer_notify_button(seat, time_msec, button, state);
380 return; 380 return;
diff --git a/sway/input/seatop_down.c b/sway/input/seatop_down.c
index cc54b90b..ecc34fea 100644
--- a/sway/input/seatop_down.c
+++ b/sway/input/seatop_down.c
@@ -10,8 +10,10 @@
10 10
11struct seatop_down_event { 11struct seatop_down_event {
12 struct sway_container *con; 12 struct sway_container *con;
13 struct sway_seat *seat;
14 struct wl_listener surface_destroy;
13 struct wlr_surface *surface; 15 struct wlr_surface *surface;
14 double ref_lx, ref_ly; // cursor's x/y at start of op 16 double ref_lx, ref_ly; // cursor's x/y at start of op
15 double ref_con_lx, ref_con_ly; // container's x/y at start of op 17 double ref_con_lx, ref_con_ly; // container's x/y at start of op
16}; 18};
17 19
@@ -71,6 +73,14 @@ static void handle_tablet_tool_motion(struct sway_seat *seat,
71 } 73 }
72} 74}
73 75
76static void handle_destroy(struct wl_listener *listener, void *data) {
77 struct seatop_down_event *e =
78 wl_container_of(listener, e, surface_destroy);
79 if (e) {
80 seatop_begin_default(e->seat);
81 }
82}
83
74static void handle_unref(struct sway_seat *seat, struct sway_container *con) { 84static void handle_unref(struct sway_seat *seat, struct sway_container *con) {
75 struct seatop_down_event *e = seat->seatop_data; 85 struct seatop_down_event *e = seat->seatop_data;
76 if (e->con == con) { 86 if (e->con == con) {
@@ -78,6 +88,11 @@ static void handle_unref(struct sway_seat *seat, struct sway_container *con) {
78 } 88 }
79} 89}
80 90
91static void handle_end(struct sway_seat *seat) {
92 struct seatop_down_event *e = seat->seatop_data;
93 wl_list_remove(&e->surface_destroy.link);
94}
95
81static const struct sway_seatop_impl seatop_impl = { 96static const struct sway_seatop_impl seatop_impl = {
82 .button = handle_button, 97 .button = handle_button,
83 .pointer_motion = handle_pointer_motion, 98 .pointer_motion = handle_pointer_motion,
@@ -85,33 +100,21 @@ static const struct sway_seatop_impl seatop_impl = {
85 .tablet_tool_tip = handle_tablet_tool_tip, 100 .tablet_tool_tip = handle_tablet_tool_tip,
86 .tablet_tool_motion = handle_tablet_tool_motion, 101 .tablet_tool_motion = handle_tablet_tool_motion,
87 .unref = handle_unref, 102 .unref = handle_unref,
103 .end = handle_end,
88 .allow_set_cursor = true, 104 .allow_set_cursor = true,
89}; 105};
90 106
91void seatop_begin_down(struct sway_seat *seat, struct sway_container *con, 107void seatop_begin_down(struct sway_seat *seat, struct sway_container *con,
92 uint32_t time_msec, double sx, double sy) { 108 uint32_t time_msec, double sx, double sy) {
93 seatop_end(seat); 109 seatop_begin_down_on_surface(seat, con->view->surface, time_msec, sx, sy);
94 110 struct seatop_down_event *e = seat->seatop_data;
95 struct seatop_down_event *e =
96 calloc(1, sizeof(struct seatop_down_event));
97 if (!e) {
98 return;
99 }
100 e->con = con; 111 e->con = con;
101 e->surface = con->view->surface;
102 e->ref_lx = seat->cursor->cursor->x;
103 e->ref_ly = seat->cursor->cursor->y;
104 e->ref_con_lx = sx;
105 e->ref_con_ly = sy;
106
107 seat->seatop_impl = &seatop_impl;
108 seat->seatop_data = e;
109 112
110 container_raise_floating(con); 113 container_raise_floating(con);
111 transaction_commit_dirty(); 114 transaction_commit_dirty();
112} 115}
113 116
114void seatop_begin_down_on_layer_surface(struct sway_seat *seat, 117void seatop_begin_down_on_surface(struct sway_seat *seat,
115 struct wlr_surface *surface, uint32_t time_msec, double sx, double sy) { 118 struct wlr_surface *surface, uint32_t time_msec, double sx, double sy) {
116 seatop_end(seat); 119 seatop_end(seat);
117 120
@@ -121,7 +124,10 @@ void seatop_begin_down_on_layer_surface(struct sway_seat *seat,
121 return; 124 return;
122 } 125 }
123 e->con = NULL; 126 e->con = NULL;
127 e->seat = seat;
124 e->surface = surface; 128 e->surface = surface;
129 wl_signal_add(&e->surface->events.destroy, &e->surface_destroy);
130 e->surface_destroy.notify = handle_destroy;
125 e->ref_lx = seat->cursor->cursor->x; 131 e->ref_lx = seat->cursor->cursor->x;
126 e->ref_ly = seat->cursor->cursor->y; 132 e->ref_ly = seat->cursor->cursor->y;
127 e->ref_con_lx = sx; 133 e->ref_con_lx = sx;