aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Alexander Orzechowski <alex@ozal.ski>2023-11-21 19:55:47 -0500
committerLibravatar Kirill Primak <vyivel@eclair.cafe>2024-01-18 18:36:54 +0300
commitc640c3015f3a7ea2987bd7854d13ff282f90804f (patch)
treed292934709dcd71bdb244546b1684e690e0511f4 /sway
parentrenderer: Render scene_graph (diff)
downloadsway-c640c3015f3a7ea2987bd7854d13ff282f90804f.tar.gz
sway-c640c3015f3a7ea2987bd7854d13ff282f90804f.tar.zst
sway-c640c3015f3a7ea2987bd7854d13ff282f90804f.zip
scene_graph: Port seat drag icons
Diffstat (limited to 'sway')
-rw-r--r--sway/desktop/output.c16
-rw-r--r--sway/desktop/render.c10
-rw-r--r--sway/input/cursor.c10
-rw-r--r--sway/input/seat.c98
-rw-r--r--sway/input/seatop_default.c15
-rw-r--r--sway/tree/root.c2
6 files changed, 40 insertions, 111 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 11de25fb..321e2a72 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -259,22 +259,6 @@ void output_unmanaged_for_each_surface(struct sway_output *output,
259} 259}
260#endif 260#endif
261 261
262void output_drag_icons_for_each_surface(struct sway_output *output,
263 struct wl_list *drag_icons, sway_surface_iterator_func_t iterator,
264 void *user_data) {
265 struct sway_drag_icon *drag_icon;
266 wl_list_for_each(drag_icon, drag_icons, link) {
267 double ox = drag_icon->x - output->lx;
268 double oy = drag_icon->y - output->ly;
269
270 if (drag_icon->wlr_drag_icon->surface->mapped) {
271 output_surface_for_each_surface(output,
272 drag_icon->wlr_drag_icon->surface, ox, oy,
273 iterator, user_data);
274 }
275 }
276}
277
278static int scale_length(int length, int offset, float scale) { 262static int scale_length(int length, int offset, float scale) {
279 return roundf((offset + length) * scale) - roundf(offset * scale); 263 return roundf((offset + length) * scale) - roundf(offset * scale);
280} 264}
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index 168c941b..735dddb8 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -184,15 +184,6 @@ static void render_unmanaged(struct render_context *ctx, struct wl_list *unmanag
184} 184}
185#endif 185#endif
186 186
187static void render_drag_icons(struct render_context *ctx, struct wl_list *drag_icons) {
188 struct render_data data = {
189 .alpha = 1.0f,
190 .ctx = ctx,
191 };
192 output_drag_icons_for_each_surface(ctx->output, drag_icons,
193 render_surface_iterator, &data);
194}
195
196// _box.x and .y are expected to be layout-local 187// _box.x and .y are expected to be layout-local
197// _box.width and .height are expected to be output-buffer-local 188// _box.width and .height are expected to be output-buffer-local
198void render_rect(struct render_context *ctx, const struct wlr_box *_box, 189void render_rect(struct render_context *ctx, const struct wlr_box *_box,
@@ -1131,7 +1122,6 @@ render_overlay:
1131 &output->shell_layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); 1122 &output->shell_layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
1132 render_layer_popups(ctx, 1123 render_layer_popups(ctx,
1133 &output->shell_layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); 1124 &output->shell_layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
1134 render_drag_icons(ctx, &root->drag_icons);
1135 1125
1136renderer_end: 1126renderer_end:
1137 pixman_region32_fini(&transformed_damage); 1127 pixman_region32_fini(&transformed_damage);
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 73aef4b0..e8604193 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -19,12 +19,12 @@
19#include "log.h" 19#include "log.h"
20#include "util.h" 20#include "util.h"
21#include "sway/commands.h" 21#include "sway/commands.h"
22#include "sway/desktop.h"
23#include "sway/input/cursor.h" 22#include "sway/input/cursor.h"
24#include "sway/input/keyboard.h" 23#include "sway/input/keyboard.h"
25#include "sway/input/tablet.h" 24#include "sway/input/tablet.h"
26#include "sway/layers.h" 25#include "sway/layers.h"
27#include "sway/output.h" 26#include "sway/output.h"
27#include "sway/scene_descriptor.h"
28#include "sway/tree/container.h" 28#include "sway/tree/container.h"
29#include "sway/tree/root.h" 29#include "sway/tree/root.h"
30#include "sway/tree/view.h" 30#include "sway/tree/view.h"
@@ -543,12 +543,8 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
543 if (seat->touch_id == event->touch_id) { 543 if (seat->touch_id == event->touch_id) {
544 seat->touch_x = lx; 544 seat->touch_x = lx;
545 seat->touch_y = ly; 545 seat->touch_y = ly;
546 struct sway_drag_icon *drag_icon; 546
547 wl_list_for_each(drag_icon, &root->drag_icons, link) { 547 drag_icons_update_position(seat);
548 if (drag_icon->seat == seat) {
549 drag_icon_update_position(drag_icon);
550 }
551 }
552 } 548 }
553 549
554 if (cursor->simulating_pointer_from_touch) { 550 if (cursor->simulating_pointer_from_touch) {
diff --git a/sway/input/seat.c b/sway/input/seat.c
index cb8ac6a4..d2cd1ba4 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -18,7 +18,7 @@
18#include "list.h" 18#include "list.h"
19#include "log.h" 19#include "log.h"
20#include "sway/config.h" 20#include "sway/config.h"
21#include "sway/desktop.h" 21#include "sway/scene_descriptor.h"
22#include "sway/input/cursor.h" 22#include "sway/input/cursor.h"
23#include "sway/input/input-manager.h" 23#include "sway/input/input-manager.h"
24#include "sway/input/keyboard.h" 24#include "sway/input/keyboard.h"
@@ -92,6 +92,7 @@ void seat_destroy(struct sway_seat *seat) {
92 for (int i = 0; i < seat->deferred_bindings->length; i++) { 92 for (int i = 0; i < seat->deferred_bindings->length; i++) {
93 free_sway_binding(seat->deferred_bindings->items[i]); 93 free_sway_binding(seat->deferred_bindings->items[i]);
94 } 94 }
95 wlr_scene_node_destroy(&seat->scene_tree->node);
95 list_free(seat->deferred_bindings); 96 list_free(seat->deferred_bindings);
96 free(seat->prev_workspace_name); 97 free(seat->prev_workspace_name);
97 free(seat); 98 free(seat);
@@ -353,25 +354,15 @@ static void handle_new_node(struct wl_listener *listener, void *data) {
353 seat_node_from_node(seat, node); 354 seat_node_from_node(seat, node);
354} 355}
355 356
356static void drag_icon_damage_whole(struct sway_drag_icon *icon) { 357static void drag_icon_update_position(struct sway_seat *seat, struct wlr_scene_node *node) {
357 if (!icon->wlr_drag_icon->surface->mapped) { 358 struct wlr_drag_icon *wlr_icon = scene_descriptor_try_get(node, SWAY_SCENE_DESC_DRAG_ICON);
358 return;
359 }
360 desktop_damage_surface(icon->wlr_drag_icon->surface, icon->x, icon->y, true);
361}
362
363void drag_icon_update_position(struct sway_drag_icon *icon) {
364 drag_icon_damage_whole(icon);
365
366 struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon;
367 struct sway_seat *seat = icon->seat;
368 struct wlr_cursor *cursor = seat->cursor->cursor; 359 struct wlr_cursor *cursor = seat->cursor->cursor;
360
369 switch (wlr_icon->drag->grab_type) { 361 switch (wlr_icon->drag->grab_type) {
370 case WLR_DRAG_GRAB_KEYBOARD: 362 case WLR_DRAG_GRAB_KEYBOARD:
371 return; 363 return;
372 case WLR_DRAG_GRAB_KEYBOARD_POINTER: 364 case WLR_DRAG_GRAB_KEYBOARD_POINTER:
373 icon->x = cursor->x + icon->dx; 365 wlr_scene_node_set_position(node, cursor->x, cursor->y);
374 icon->y = cursor->y + icon->dy;
375 break; 366 break;
376 case WLR_DRAG_GRAB_KEYBOARD_TOUCH:; 367 case WLR_DRAG_GRAB_KEYBOARD_TOUCH:;
377 struct wlr_touch_point *point = 368 struct wlr_touch_point *point =
@@ -379,42 +370,15 @@ void drag_icon_update_position(struct sway_drag_icon *icon) {
379 if (point == NULL) { 370 if (point == NULL) {
380 return; 371 return;
381 } 372 }
382 icon->x = seat->touch_x + icon->dx; 373 wlr_scene_node_set_position(node, seat->touch_x, seat->touch_y);
383 icon->y = seat->touch_y + icon->dy;
384 } 374 }
385
386 drag_icon_damage_whole(icon);
387}
388
389static void drag_icon_handle_surface_commit(struct wl_listener *listener,
390 void *data) {
391 struct sway_drag_icon *icon =
392 wl_container_of(listener, icon, surface_commit);
393 struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon;
394 icon->dx += wlr_icon->surface->current.dx;
395 icon->dy += wlr_icon->surface->current.dy;
396 drag_icon_update_position(icon);
397}
398
399static void drag_icon_handle_map(struct wl_listener *listener, void *data) {
400 struct sway_drag_icon *icon = wl_container_of(listener, icon, map);
401 drag_icon_damage_whole(icon);
402}
403
404static void drag_icon_handle_unmap(struct wl_listener *listener, void *data) {
405 struct sway_drag_icon *icon = wl_container_of(listener, icon, unmap);
406 drag_icon_damage_whole(icon);
407} 375}
408 376
409static void drag_icon_handle_destroy(struct wl_listener *listener, void *data) { 377void drag_icons_update_position(struct sway_seat *seat) {
410 struct sway_drag_icon *icon = wl_container_of(listener, icon, destroy); 378 struct wlr_scene_node *node;
411 icon->wlr_drag_icon->data = NULL; 379 wl_list_for_each(node, &seat->drag_icons->children, link) {
412 wl_list_remove(&icon->link); 380 drag_icon_update_position(seat, node);
413 wl_list_remove(&icon->surface_commit.link); 381 }
414 wl_list_remove(&icon->unmap.link);
415 wl_list_remove(&icon->map.link);
416 wl_list_remove(&icon->destroy.link);
417 free(icon);
418} 382}
419 383
420static void drag_handle_destroy(struct wl_listener *listener, void *data) { 384static void drag_handle_destroy(struct wl_listener *listener, void *data) {
@@ -486,27 +450,20 @@ static void handle_start_drag(struct wl_listener *listener, void *data) {
486 450
487 struct wlr_drag_icon *wlr_drag_icon = wlr_drag->icon; 451 struct wlr_drag_icon *wlr_drag_icon = wlr_drag->icon;
488 if (wlr_drag_icon != NULL) { 452 if (wlr_drag_icon != NULL) {
489 struct sway_drag_icon *icon = calloc(1, sizeof(struct sway_drag_icon)); 453 struct wlr_scene_tree *tree = wlr_scene_drag_icon_create(seat->drag_icons, wlr_drag_icon);
490 if (icon == NULL) { 454 if (!tree) {
491 sway_log(SWAY_ERROR, "Allocation failed"); 455 sway_log(SWAY_ERROR, "Failed to allocate a drag icon scene tree");
492 return; 456 return;
493 } 457 }
494 icon->seat = seat;
495 icon->wlr_drag_icon = wlr_drag_icon;
496 wlr_drag_icon->data = icon;
497
498 icon->surface_commit.notify = drag_icon_handle_surface_commit;
499 wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit);
500 icon->unmap.notify = drag_icon_handle_unmap;
501 wl_signal_add(&wlr_drag_icon->surface->events.unmap, &icon->unmap);
502 icon->map.notify = drag_icon_handle_map;
503 wl_signal_add(&wlr_drag_icon->surface->events.map, &icon->map);
504 icon->destroy.notify = drag_icon_handle_destroy;
505 wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy);
506 458
507 wl_list_insert(&root->drag_icons, &icon->link); 459 if (!scene_descriptor_assign(&tree->node, SWAY_SCENE_DESC_DRAG_ICON,
460 wlr_drag_icon)) {
461 sway_log(SWAY_ERROR, "Failed to allocate a drag icon scene descriptor");
462 wlr_scene_node_destroy(&tree->node);
463 return;
464 }
508 465
509 drag_icon_update_position(icon); 466 drag_icon_update_position(seat, &tree->node);
510 } 467 }
511 seatop_begin_default(seat); 468 seatop_begin_default(seat);
512} 469}
@@ -553,8 +510,18 @@ struct sway_seat *seat_create(const char *seat_name) {
553 return NULL; 510 return NULL;
554 } 511 }
555 512
513 bool failed = false;
514 seat->scene_tree = alloc_scene_tree(root->layers.seat, &failed);
515 seat->drag_icons = alloc_scene_tree(seat->scene_tree, &failed);
516 if (failed) {
517 wlr_scene_node_destroy(&seat->scene_tree->node);
518 free(seat);
519 return NULL;
520 }
521
556 seat->wlr_seat = wlr_seat_create(server.wl_display, seat_name); 522 seat->wlr_seat = wlr_seat_create(server.wl_display, seat_name);
557 if (!sway_assert(seat->wlr_seat, "could not allocate seat")) { 523 if (!sway_assert(seat->wlr_seat, "could not allocate seat")) {
524 wlr_scene_node_destroy(&seat->scene_tree->node);
558 free(seat); 525 free(seat);
559 return NULL; 526 return NULL;
560 } 527 }
@@ -562,6 +529,7 @@ struct sway_seat *seat_create(const char *seat_name) {
562 529
563 seat->cursor = sway_cursor_create(seat); 530 seat->cursor = sway_cursor_create(seat);
564 if (!seat->cursor) { 531 if (!seat->cursor) {
532 wlr_scene_node_destroy(&seat->scene_tree->node);
565 wlr_seat_destroy(seat->wlr_seat); 533 wlr_seat_destroy(seat->wlr_seat);
566 free(seat); 534 free(seat);
567 return NULL; 535 return NULL;
diff --git a/sway/input/seatop_default.c b/sway/input/seatop_default.c
index 1dce6dae..62261c77 100644
--- a/sway/input/seatop_default.c
+++ b/sway/input/seatop_default.c
@@ -12,6 +12,7 @@
12#include "sway/input/tablet.h" 12#include "sway/input/tablet.h"
13#include "sway/layers.h" 13#include "sway/layers.h"
14#include "sway/output.h" 14#include "sway/output.h"
15#include "sway/scene_descriptor.h"
15#include "sway/tree/view.h" 16#include "sway/tree/view.h"
16#include "sway/tree/workspace.h" 17#include "sway/tree/workspace.h"
17#include "log.h" 18#include "log.h"
@@ -620,12 +621,7 @@ static void handle_pointer_motion(struct sway_seat *seat, uint32_t time_msec) {
620 wlr_seat_pointer_notify_clear_focus(seat->wlr_seat); 621 wlr_seat_pointer_notify_clear_focus(seat->wlr_seat);
621 } 622 }
622 623
623 struct sway_drag_icon *drag_icon; 624 drag_icons_update_position(seat);
624 wl_list_for_each(drag_icon, &root->drag_icons, link) {
625 if (drag_icon->seat == seat) {
626 drag_icon_update_position(drag_icon);
627 }
628 }
629 625
630 e->previous_node = node; 626 e->previous_node = node;
631} 627}
@@ -655,12 +651,7 @@ static void handle_tablet_tool_motion(struct sway_seat *seat,
655 wlr_tablet_v2_tablet_tool_notify_proximity_out(tool->tablet_v2_tool); 651 wlr_tablet_v2_tablet_tool_notify_proximity_out(tool->tablet_v2_tool);
656 } 652 }
657 653
658 struct sway_drag_icon *drag_icon; 654 drag_icons_update_position(seat);
659 wl_list_for_each(drag_icon, &root->drag_icons, link) {
660 if (drag_icon->seat == seat) {
661 drag_icon_update_position(drag_icon);
662 }
663 }
664 655
665 e->previous_node = node; 656 e->previous_node = node;
666} 657}
diff --git a/sway/tree/root.c b/sway/tree/root.c
index 75fb63f1..38fcdb7c 100644
--- a/sway/tree/root.c
+++ b/sway/tree/root.c
@@ -49,6 +49,7 @@ struct sway_root *root_create(struct wl_display *wl_display) {
49 root->layers.floating = alloc_scene_tree(&root_scene->tree, &failed); 49 root->layers.floating = alloc_scene_tree(&root_scene->tree, &failed);
50 root->layers.fullscreen = alloc_scene_tree(&root_scene->tree, &failed); 50 root->layers.fullscreen = alloc_scene_tree(&root_scene->tree, &failed);
51 root->layers.fullscreen_global = alloc_scene_tree(&root_scene->tree, &failed); 51 root->layers.fullscreen_global = alloc_scene_tree(&root_scene->tree, &failed);
52 root->layers.seat = alloc_scene_tree(&root_scene->tree, &failed);
52 53
53 if (failed) { 54 if (failed) {
54 wlr_scene_node_destroy(&root_scene->tree.node); 55 wlr_scene_node_destroy(&root_scene->tree.node);
@@ -63,7 +64,6 @@ struct sway_root *root_create(struct wl_display *wl_display) {
63#if HAVE_XWAYLAND 64#if HAVE_XWAYLAND
64 wl_list_init(&root->xwayland_unmanaged); 65 wl_list_init(&root->xwayland_unmanaged);
65#endif 66#endif
66 wl_list_init(&root->drag_icons);
67 wl_signal_init(&root->events.new_node); 67 wl_signal_init(&root->events.new_node);
68 root->outputs = create_list(); 68 root->outputs = create_list();
69 root->non_desktop_outputs = create_list(); 69 root->non_desktop_outputs = create_list();