aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kirill Primak <vyivel@posteo.net>2021-09-07 16:12:21 +0300
committerLibravatar Simon Ser <contact@emersion.fr>2021-09-08 09:36:17 +0200
commite76e13ef854a3f1d291521c6f2c9d6e936bca184 (patch)
treeaec96e56e68ac5f70065461878ea31c09f2f3399
parentbuild: subproject support for wayland-protocols (diff)
downloadsway-e76e13ef854a3f1d291521c6f2c9d6e936bca184.tar.gz
sway-e76e13ef854a3f1d291521c6f2c9d6e936bca184.tar.zst
sway-e76e13ef854a3f1d291521c6f2c9d6e936bca184.zip
view: fix child position calc
Previously, the position was calculated incorrectly for nested subsurfaces.
-rw-r--r--include/sway/tree/view.h2
-rw-r--r--sway/desktop/xdg_shell.c15
-rw-r--r--sway/tree/view.c39
3 files changed, 22 insertions, 34 deletions
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 11ac74c9..5f02d0d6 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -183,7 +183,7 @@ struct sway_xwayland_unmanaged {
183struct sway_view_child; 183struct sway_view_child;
184 184
185struct sway_view_child_impl { 185struct sway_view_child_impl {
186 void (*get_root_coords)(struct sway_view_child *child, int *sx, int *sy); 186 void (*get_view_coords)(struct sway_view_child *child, int *sx, int *sy);
187 void (*destroy)(struct sway_view_child *child); 187 void (*destroy)(struct sway_view_child *child);
188}; 188};
189 189
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index 1f70b193..a97ee8be 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -21,18 +21,15 @@
21 21
22static const struct sway_view_child_impl popup_impl; 22static const struct sway_view_child_impl popup_impl;
23 23
24static void popup_get_root_coords(struct sway_view_child *child, 24static void popup_get_view_coords(struct sway_view_child *child,
25 int *root_sx, int *root_sy) { 25 int *sx, int *sy) {
26 struct sway_xdg_popup *popup = (struct sway_xdg_popup *)child; 26 struct sway_xdg_popup *popup = (struct sway_xdg_popup *)child;
27 struct wlr_xdg_surface *surface = popup->wlr_xdg_surface; 27 struct wlr_xdg_surface *surface = popup->wlr_xdg_surface;
28 28
29 int x_offset = -child->view->geometry.x - surface->geometry.x;
30 int y_offset = -child->view->geometry.y - surface->geometry.y;
31
32 wlr_xdg_popup_get_toplevel_coords(surface->popup, 29 wlr_xdg_popup_get_toplevel_coords(surface->popup,
33 x_offset + surface->popup->geometry.x, 30 surface->popup->geometry.x - surface->geometry.x,
34 y_offset + surface->popup->geometry.y, 31 surface->popup->geometry.y - surface->geometry.y,
35 root_sx, root_sy); 32 sx, sy);
36} 33}
37 34
38static void popup_destroy(struct sway_view_child *child) { 35static void popup_destroy(struct sway_view_child *child) {
@@ -47,7 +44,7 @@ static void popup_destroy(struct sway_view_child *child) {
47} 44}
48 45
49static const struct sway_view_child_impl popup_impl = { 46static const struct sway_view_child_impl popup_impl = {
50 .get_root_coords = popup_get_root_coords, 47 .get_view_coords = popup_get_view_coords,
51 .destroy = popup_destroy, 48 .destroy = popup_destroy,
52}; 49};
53 50
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 1ee00f8d..ccb03088 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -901,30 +901,19 @@ void view_center_surface(struct sway_view *view) {
901 901
902static const struct sway_view_child_impl subsurface_impl; 902static const struct sway_view_child_impl subsurface_impl;
903 903
904static void subsurface_get_root_coords(struct sway_view_child *child, 904static void subsurface_get_view_coords(struct sway_view_child *child,
905 int *root_sx, int *root_sy) { 905 int *sx, int *sy) {
906 struct wlr_surface *surface = child->surface; 906 struct wlr_surface *surface = child->surface;
907 *root_sx = -child->view->geometry.x;
908 *root_sy = -child->view->geometry.y;
909
910 if (child->parent && child->parent->impl && 907 if (child->parent && child->parent->impl &&
911 child->parent->impl->get_root_coords) { 908 child->parent->impl->get_view_coords) {
912 int sx, sy; 909 child->parent->impl->get_view_coords(child->parent, sx, sy);
913 child->parent->impl->get_root_coords(child->parent, &sx, &sy);
914 *root_sx += sx;
915 *root_sy += sy;
916 } else { 910 } else {
917 while (surface && wlr_surface_is_subsurface(surface)) { 911 *sx = *sy = 0;
918 struct wlr_subsurface *subsurface =
919 wlr_subsurface_from_wlr_surface(surface);
920 if (subsurface == NULL) {
921 break;
922 }
923 *root_sx += subsurface->current.x;
924 *root_sy += subsurface->current.y;
925 surface = subsurface->parent;
926 }
927 } 912 }
913 struct wlr_subsurface *subsurface =
914 wlr_subsurface_from_wlr_surface(surface);
915 *sx += subsurface->current.x;
916 *sy += subsurface->current.y;
928} 917}
929 918
930static void subsurface_destroy(struct sway_view_child *child) { 919static void subsurface_destroy(struct sway_view_child *child) {
@@ -938,7 +927,7 @@ static void subsurface_destroy(struct sway_view_child *child) {
938} 927}
939 928
940static const struct sway_view_child_impl subsurface_impl = { 929static const struct sway_view_child_impl subsurface_impl = {
941 .get_root_coords = subsurface_get_root_coords, 930 .get_view_coords = subsurface_get_view_coords,
942 .destroy = subsurface_destroy, 931 .destroy = subsurface_destroy,
943}; 932};
944 933
@@ -1007,10 +996,12 @@ static void view_child_damage(struct sway_view_child *child, bool whole) {
1007 return; 996 return;
1008 } 997 }
1009 int sx, sy; 998 int sx, sy;
1010 child->impl->get_root_coords(child, &sx, &sy); 999 child->impl->get_view_coords(child, &sx, &sy);
1011 desktop_damage_surface(child->surface, 1000 desktop_damage_surface(child->surface,
1012 child->view->container->pending.content_x + sx, 1001 child->view->container->pending.content_x -
1013 child->view->container->pending.content_y + sy, whole); 1002 child->view->geometry.x + sx,
1003 child->view->container->pending.content_y -
1004 child->view->geometry.y + sy, whole);
1014} 1005}
1015 1006
1016static void view_child_handle_surface_commit(struct wl_listener *listener, 1007static void view_child_handle_surface_commit(struct wl_listener *listener,