aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/seat.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r--sway/input/seat.c98
1 files changed, 94 insertions, 4 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 071ef020..1ea36466 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -6,21 +6,22 @@
6#include <wlr/types/wlr_cursor.h> 6#include <wlr/types/wlr_cursor.h>
7#include <wlr/types/wlr_output_layout.h> 7#include <wlr/types/wlr_output_layout.h>
8#include <wlr/types/wlr_xcursor_manager.h> 8#include <wlr/types/wlr_xcursor_manager.h>
9#include "log.h"
9#include "sway/debug.h" 10#include "sway/debug.h"
10#include "sway/tree/container.h" 11#include "sway/desktop.h"
11#include "sway/tree/workspace.h"
12#include "sway/input/seat.h"
13#include "sway/input/cursor.h" 12#include "sway/input/cursor.h"
14#include "sway/input/input-manager.h" 13#include "sway/input/input-manager.h"
15#include "sway/input/keyboard.h" 14#include "sway/input/keyboard.h"
15#include "sway/input/seat.h"
16#include "sway/ipc-server.h" 16#include "sway/ipc-server.h"
17#include "sway/layers.h" 17#include "sway/layers.h"
18#include "sway/output.h" 18#include "sway/output.h"
19#include "sway/tree/arrange.h" 19#include "sway/tree/arrange.h"
20#include "sway/tree/container.h" 20#include "sway/tree/container.h"
21#include "sway/tree/container.h"
21#include "sway/tree/view.h" 22#include "sway/tree/view.h"
22#include "sway/tree/workspace.h" 23#include "sway/tree/workspace.h"
23#include "log.h" 24#include "sway/tree/workspace.h"
24 25
25static void seat_device_destroy(struct sway_seat_device *seat_device) { 26static void seat_device_destroy(struct sway_seat_device *seat_device) {
26 if (!seat_device) { 27 if (!seat_device) {
@@ -40,6 +41,8 @@ void seat_destroy(struct sway_seat *seat) {
40 seat_device_destroy(seat_device); 41 seat_device_destroy(seat_device);
41 } 42 }
42 sway_cursor_destroy(seat->cursor); 43 sway_cursor_destroy(seat->cursor);
44 wl_list_remove(&seat->new_container.link);
45 wl_list_remove(&seat->new_drag_icon.link);
43 wl_list_remove(&seat->link); 46 wl_list_remove(&seat->link);
44 wlr_seat_destroy(seat->wlr_seat); 47 wlr_seat_destroy(seat->wlr_seat);
45} 48}
@@ -234,6 +237,90 @@ static void handle_new_container(struct wl_listener *listener, void *data) {
234 seat_container_from_container(seat, con); 237 seat_container_from_container(seat, con);
235} 238}
236 239
240static void drag_icon_damage_whole(struct sway_drag_icon *icon) {
241 if (!icon->wlr_drag_icon->mapped) {
242 return;
243 }
244 desktop_damage_surface(icon->wlr_drag_icon->surface, icon->x, icon->y, true);
245}
246
247void drag_icon_update_position(struct sway_drag_icon *icon) {
248 drag_icon_damage_whole(icon);
249
250 struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon;
251 struct sway_seat *seat = icon->seat;
252 struct wlr_cursor *cursor = seat->cursor->cursor;
253 if (wlr_icon->is_pointer) {
254 icon->x = cursor->x + wlr_icon->sx;
255 icon->y = cursor->y + wlr_icon->sy;
256 } else {
257 struct wlr_touch_point *point =
258 wlr_seat_touch_get_point(seat->wlr_seat, wlr_icon->touch_id);
259 if (point == NULL) {
260 return;
261 }
262 icon->x = seat->touch_x + wlr_icon->sx;
263 icon->y = seat->touch_y + wlr_icon->sy;
264 }
265
266 drag_icon_damage_whole(icon);
267}
268
269static void drag_icon_handle_surface_commit(struct wl_listener *listener,
270 void *data) {
271 struct sway_drag_icon *icon =
272 wl_container_of(listener, icon, surface_commit);
273 drag_icon_update_position(icon);
274}
275
276static void drag_icon_handle_map(struct wl_listener *listener, void *data) {
277 struct sway_drag_icon *icon = wl_container_of(listener, icon, map);
278 drag_icon_damage_whole(icon);
279}
280
281static void drag_icon_handle_unmap(struct wl_listener *listener, void *data) {
282 struct sway_drag_icon *icon = wl_container_of(listener, icon, unmap);
283 drag_icon_damage_whole(icon);
284}
285
286static void drag_icon_handle_destroy(struct wl_listener *listener,
287 void *data) {
288 struct sway_drag_icon *icon = wl_container_of(listener, icon, destroy);
289 icon->wlr_drag_icon->data = NULL;
290 wl_list_remove(&icon->link);
291 wl_list_remove(&icon->surface_commit.link);
292 wl_list_remove(&icon->unmap.link);
293 wl_list_remove(&icon->destroy.link);
294 free(icon);
295}
296
297static void handle_new_drag_icon(struct wl_listener *listener, void *data) {
298 struct sway_seat *seat = wl_container_of(listener, seat, new_drag_icon);
299 struct wlr_drag_icon *wlr_drag_icon = data;
300
301 struct sway_drag_icon *icon = calloc(1, sizeof(struct sway_drag_icon));
302 if (icon == NULL) {
303 wlr_log(L_ERROR, "Allocation failed");
304 return;
305 }
306 icon->seat = seat;
307 icon->wlr_drag_icon = wlr_drag_icon;
308 wlr_drag_icon->data = icon;
309
310 icon->surface_commit.notify = drag_icon_handle_surface_commit;
311 wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit);
312 icon->unmap.notify = drag_icon_handle_unmap;
313 wl_signal_add(&wlr_drag_icon->events.unmap, &icon->unmap);
314 icon->map.notify = drag_icon_handle_map;
315 wl_signal_add(&wlr_drag_icon->events.map, &icon->map);
316 icon->destroy.notify = drag_icon_handle_destroy;
317 wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy);
318
319 wl_list_insert(&root_container.sway_root->drag_icons, &icon->link);
320
321 drag_icon_update_position(icon);
322}
323
237static void collect_focus_iter(struct sway_container *con, void *data) { 324static void collect_focus_iter(struct sway_container *con, void *data) {
238 struct sway_seat *seat = data; 325 struct sway_seat *seat = data;
239 if (con->type > C_WORKSPACE) { 326 if (con->type > C_WORKSPACE) {
@@ -278,6 +365,9 @@ struct sway_seat *seat_create(struct sway_input_manager *input,
278 &seat->new_container); 365 &seat->new_container);
279 seat->new_container.notify = handle_new_container; 366 seat->new_container.notify = handle_new_container;
280 367
368 wl_signal_add(&seat->wlr_seat->events.new_drag_icon, &seat->new_drag_icon);
369 seat->new_drag_icon.notify = handle_new_drag_icon;
370
281 seat->input = input; 371 seat->input = input;
282 wl_list_init(&seat->devices); 372 wl_list_init(&seat->devices);
283 373