aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/tree/view.h3
-rw-r--r--sway/desktop/xdg_shell.c15
-rw-r--r--sway/desktop/xdg_shell_v6.c15
-rw-r--r--sway/tree/view.c56
4 files changed, 80 insertions, 9 deletions
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index eb1e98e1..870ef2e0 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -208,6 +208,7 @@ struct sway_xwayland_unmanaged {
208struct sway_view_child; 208struct sway_view_child;
209 209
210struct sway_view_child_impl { 210struct sway_view_child_impl {
211 void (*get_root_coords)(struct sway_view_child *child, int *sx, int *sy);
211 void (*destroy)(struct sway_view_child *child); 212 void (*destroy)(struct sway_view_child *child);
212}; 213};
213 214
@@ -222,6 +223,8 @@ struct sway_view_child {
222 223
223 struct wl_listener surface_commit; 224 struct wl_listener surface_commit;
224 struct wl_listener surface_new_subsurface; 225 struct wl_listener surface_new_subsurface;
226 struct wl_listener surface_map;
227 struct wl_listener surface_unmap;
225 struct wl_listener surface_destroy; 228 struct wl_listener surface_destroy;
226 struct wl_listener view_unmap; 229 struct wl_listener view_unmap;
227}; 230};
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index 4690a3c5..46582204 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -20,6 +20,17 @@
20 20
21static const struct sway_view_child_impl popup_impl; 21static const struct sway_view_child_impl popup_impl;
22 22
23static void popup_get_root_coords(struct sway_view_child *child,
24 int *root_sx, int *root_sy) {
25 struct sway_xdg_popup *popup = (struct sway_xdg_popup *)child;
26 struct wlr_xdg_surface *surface = popup->wlr_xdg_surface;
27
28 wlr_xdg_popup_get_toplevel_coords(surface->popup,
29 -surface->geometry.x + surface->popup->geometry.x,
30 -surface->geometry.y + surface->popup->geometry.y,
31 root_sx, root_sy);
32}
33
23static void popup_destroy(struct sway_view_child *child) { 34static void popup_destroy(struct sway_view_child *child) {
24 if (!sway_assert(child->impl == &popup_impl, 35 if (!sway_assert(child->impl == &popup_impl,
25 "Expected an xdg_shell popup")) { 36 "Expected an xdg_shell popup")) {
@@ -32,6 +43,7 @@ static void popup_destroy(struct sway_view_child *child) {
32} 43}
33 44
34static const struct sway_view_child_impl popup_impl = { 45static const struct sway_view_child_impl popup_impl = {
46 .get_root_coords = popup_get_root_coords,
35 .destroy = popup_destroy, 47 .destroy = popup_destroy,
36}; 48};
37 49
@@ -85,6 +97,9 @@ static struct sway_xdg_popup *popup_create(
85 wl_signal_add(&xdg_surface->events.destroy, &popup->destroy); 97 wl_signal_add(&xdg_surface->events.destroy, &popup->destroy);
86 popup->destroy.notify = popup_handle_destroy; 98 popup->destroy.notify = popup_handle_destroy;
87 99
100 wl_signal_add(&xdg_surface->events.map, &popup->child.surface_map);
101 wl_signal_add(&xdg_surface->events.unmap, &popup->child.surface_unmap);
102
88 popup_unconstrain(popup); 103 popup_unconstrain(popup);
89 104
90 return popup; 105 return popup;
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index ff950c70..165cc7eb 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -19,6 +19,17 @@
19 19
20static const struct sway_view_child_impl popup_impl; 20static const struct sway_view_child_impl popup_impl;
21 21
22static void popup_get_root_coords(struct sway_view_child *child,
23 int *root_sx, int *root_sy) {
24 struct sway_xdg_popup_v6 *popup = (struct sway_xdg_popup_v6 *)child;
25 struct wlr_xdg_surface_v6 *surface = popup->wlr_xdg_surface_v6;
26
27 wlr_xdg_popup_v6_get_toplevel_coords(surface->popup,
28 -surface->geometry.x + surface->popup->geometry.x,
29 -surface->geometry.y + surface->popup->geometry.y,
30 root_sx, root_sy);
31}
32
22static void popup_destroy(struct sway_view_child *child) { 33static void popup_destroy(struct sway_view_child *child) {
23 if (!sway_assert(child->impl == &popup_impl, 34 if (!sway_assert(child->impl == &popup_impl,
24 "Expected an xdg_shell_v6 popup")) { 35 "Expected an xdg_shell_v6 popup")) {
@@ -31,6 +42,7 @@ static void popup_destroy(struct sway_view_child *child) {
31} 42}
32 43
33static const struct sway_view_child_impl popup_impl = { 44static const struct sway_view_child_impl popup_impl = {
45 .get_root_coords = popup_get_root_coords,
34 .destroy = popup_destroy, 46 .destroy = popup_destroy,
35}; 47};
36 48
@@ -84,6 +96,9 @@ static struct sway_xdg_popup_v6 *popup_create(
84 wl_signal_add(&xdg_surface->events.destroy, &popup->destroy); 96 wl_signal_add(&xdg_surface->events.destroy, &popup->destroy);
85 popup->destroy.notify = popup_handle_destroy; 97 popup->destroy.notify = popup_handle_destroy;
86 98
99 wl_signal_add(&xdg_surface->events.map, &popup->child.surface_map);
100 wl_signal_add(&xdg_surface->events.unmap, &popup->child.surface_unmap);
101
87 popup_unconstrain(popup); 102 popup_unconstrain(popup);
88 103
89 return popup; 104 return popup;
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 97525d6b..1f00452d 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -15,6 +15,7 @@
15#include "log.h" 15#include "log.h"
16#include "sway/criteria.h" 16#include "sway/criteria.h"
17#include "sway/commands.h" 17#include "sway/commands.h"
18#include "sway/desktop.h"
18#include "sway/desktop/transaction.h" 19#include "sway/desktop/transaction.h"
19#include "sway/input/cursor.h" 20#include "sway/input/cursor.h"
20#include "sway/ipc-server.h" 21#include "sway/ipc-server.h"
@@ -639,6 +640,25 @@ void view_update_size(struct sway_view *view, int width, int height) {
639 container_set_geometry_from_floating_view(view->container); 640 container_set_geometry_from_floating_view(view->container);
640} 641}
641 642
643static void subsurface_get_root_coords(struct sway_view_child *child,
644 int *root_sx, int *root_sy) {
645 struct wlr_surface *surface = child->surface;
646 *root_sx = -child->view->geometry.x;
647 *root_sy = -child->view->geometry.y;
648
649 while (surface && wlr_surface_is_subsurface(surface)) {
650 struct wlr_subsurface *subsurface =
651 wlr_subsurface_from_wlr_surface(surface);
652 *root_sx += subsurface->current.x;
653 *root_sy += subsurface->current.y;
654 surface = subsurface->parent;
655 }
656}
657
658static const struct sway_view_child_impl subsurface_impl = {
659 .get_root_coords = subsurface_get_root_coords,
660};
661
642static void view_subsurface_create(struct sway_view *view, 662static void view_subsurface_create(struct sway_view *view,
643 struct wlr_subsurface *subsurface) { 663 struct wlr_subsurface *subsurface) {
644 struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child)); 664 struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child));
@@ -646,15 +666,21 @@ static void view_subsurface_create(struct sway_view *view,
646 wlr_log(WLR_ERROR, "Allocation failed"); 666 wlr_log(WLR_ERROR, "Allocation failed");
647 return; 667 return;
648 } 668 }
649 view_child_init(child, NULL, view, subsurface->surface); 669 view_child_init(child, &subsurface_impl, view, subsurface->surface);
670}
671
672static void view_child_damage(struct sway_view_child *child, bool whole) {
673 int sx, sy;
674 child->impl->get_root_coords(child, &sx, &sy);
675 desktop_damage_surface(child->surface,
676 child->view->x + sx, child->view->y + sy, whole);
650} 677}
651 678
652static void view_child_handle_surface_commit(struct wl_listener *listener, 679static void view_child_handle_surface_commit(struct wl_listener *listener,
653 void *data) { 680 void *data) {
654 struct sway_view_child *child = 681 struct sway_view_child *child =
655 wl_container_of(listener, child, surface_commit); 682 wl_container_of(listener, child, surface_commit);
656 // TODO: only accumulate damage from the child 683 view_child_damage(child, false);
657 view_damage_from(child->view);
658} 684}
659 685
660static void view_child_handle_surface_new_subsurface( 686static void view_child_handle_surface_new_subsurface(
@@ -687,6 +713,20 @@ static void view_init_subsurfaces(struct sway_view *view,
687 } 713 }
688} 714}
689 715
716static void view_child_handle_surface_map(struct wl_listener *listener,
717 void *data) {
718 struct sway_view_child *child =
719 wl_container_of(listener, child, surface_map);
720 view_child_damage(child, true);
721}
722
723static void view_child_handle_surface_unmap(struct wl_listener *listener,
724 void *data) {
725 struct sway_view_child *child =
726 wl_container_of(listener, child, surface_unmap);
727 view_child_damage(child, true);
728}
729
690void view_child_init(struct sway_view_child *child, 730void view_child_init(struct sway_view_child *child,
691 const struct sway_view_child_impl *impl, struct sway_view *view, 731 const struct sway_view_child_impl *impl, struct sway_view *view,
692 struct wlr_surface *surface) { 732 struct wlr_surface *surface) {
@@ -702,6 +742,10 @@ void view_child_init(struct sway_view_child *child,
702 view_child_handle_surface_new_subsurface; 742 view_child_handle_surface_new_subsurface;
703 wl_signal_add(&surface->events.destroy, &child->surface_destroy); 743 wl_signal_add(&surface->events.destroy, &child->surface_destroy);
704 child->surface_destroy.notify = view_child_handle_surface_destroy; 744 child->surface_destroy.notify = view_child_handle_surface_destroy;
745
746 child->surface_map.notify = view_child_handle_surface_map;
747 child->surface_unmap.notify = view_child_handle_surface_unmap;
748
705 wl_signal_add(&view->events.unmap, &child->view_unmap); 749 wl_signal_add(&view->events.unmap, &child->view_unmap);
706 child->view_unmap.notify = view_child_handle_view_unmap; 750 child->view_unmap.notify = view_child_handle_view_unmap;
707 751
@@ -709,15 +753,9 @@ void view_child_init(struct sway_view_child *child,
709 wlr_surface_send_enter(child->surface, output->wlr_output); 753 wlr_surface_send_enter(child->surface, output->wlr_output);
710 754
711 view_init_subsurfaces(child->view, surface); 755 view_init_subsurfaces(child->view, surface);
712
713 // TODO: only damage the whole child
714 container_damage_whole(child->view->container);
715} 756}
716 757
717void view_child_destroy(struct sway_view_child *child) { 758void view_child_destroy(struct sway_view_child *child) {
718 // TODO: only damage the whole child
719 container_damage_whole(child->view->container);
720
721 wl_list_remove(&child->surface_commit.link); 759 wl_list_remove(&child->surface_commit.link);
722 wl_list_remove(&child->surface_destroy.link); 760 wl_list_remove(&child->surface_destroy.link);
723 wl_list_remove(&child->view_unmap.link); 761 wl_list_remove(&child->view_unmap.link);