diff options
author | Alexander Orzechowski <alex@ozal.ski> | 2023-11-21 19:55:47 -0500 |
---|---|---|
committer | Kirill Primak <vyivel@eclair.cafe> | 2024-01-18 18:36:54 +0300 |
commit | c640c3015f3a7ea2987bd7854d13ff282f90804f (patch) | |
tree | d292934709dcd71bdb244546b1684e690e0511f4 /sway/input/seat.c | |
parent | renderer: Render scene_graph (diff) | |
download | sway-c640c3015f3a7ea2987bd7854d13ff282f90804f.tar.gz sway-c640c3015f3a7ea2987bd7854d13ff282f90804f.tar.zst sway-c640c3015f3a7ea2987bd7854d13ff282f90804f.zip |
scene_graph: Port seat drag icons
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r-- | sway/input/seat.c | 98 |
1 files changed, 33 insertions, 65 deletions
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 | ||
356 | static void drag_icon_damage_whole(struct sway_drag_icon *icon) { | 357 | static 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 | |||
363 | void 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 | |||
389 | static 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 | |||
399 | static 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 | |||
404 | static 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 | ||
409 | static void drag_icon_handle_destroy(struct wl_listener *listener, void *data) { | 377 | void 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 | ||
420 | static void drag_handle_destroy(struct wl_listener *listener, void *data) { | 384 | static 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; |