diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-05-26 16:26:10 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-01 23:14:58 +1000 |
commit | e4e912ea91a5a36d9f17c1730ffbf29707984399 (patch) | |
tree | 7efb328eeabe0154294e6ef4fee216590df04c9c /sway/desktop | |
parent | Add L_FLOATING back to debug tree (diff) | |
download | sway-e4e912ea91a5a36d9f17c1730ffbf29707984399.tar.gz sway-e4e912ea91a5a36d9f17c1730ffbf29707984399.tar.zst sway-e4e912ea91a5a36d9f17c1730ffbf29707984399.zip |
Store swayc coordinates as layout-local
Diffstat (limited to 'sway/desktop')
-rw-r--r-- | sway/desktop/output.c | 83 | ||||
-rw-r--r-- | sway/desktop/xdg_shell.c | 4 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 4 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 28 |
4 files changed, 30 insertions, 89 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index fb80fd87..8600d049 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -65,6 +65,13 @@ struct root_geometry { | |||
65 | float rotation; | 65 | float rotation; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | struct render_data { | ||
69 | struct root_geometry root_geo; | ||
70 | struct sway_output *output; | ||
71 | pixman_region32_t *damage; | ||
72 | float alpha; | ||
73 | }; | ||
74 | |||
68 | static bool get_surface_box(struct root_geometry *geo, | 75 | static bool get_surface_box(struct root_geometry *geo, |
69 | struct sway_output *output, struct wlr_surface *surface, int sx, int sy, | 76 | struct sway_output *output, struct wlr_surface *surface, int sx, int sy, |
70 | struct wlr_box *surface_box) { | 77 | struct wlr_box *surface_box) { |
@@ -116,8 +123,9 @@ static void surface_for_each_surface(struct wlr_surface *surface, | |||
116 | static void output_view_for_each_surface(struct sway_view *view, | 123 | static void output_view_for_each_surface(struct sway_view *view, |
117 | struct root_geometry *geo, wlr_surface_iterator_func_t iterator, | 124 | struct root_geometry *geo, wlr_surface_iterator_func_t iterator, |
118 | void *user_data) { | 125 | void *user_data) { |
119 | geo->x = view->x; | 126 | struct render_data *data = user_data; |
120 | geo->y = view->y; | 127 | geo->x = view->x - data->output->wlr_output->lx; |
128 | geo->y = view->y - data->output->wlr_output->ly; | ||
121 | geo->width = view->surface->current->width; | 129 | geo->width = view->surface->current->width; |
122 | geo->height = view->surface->current->height; | 130 | geo->height = view->surface->current->height; |
123 | geo->rotation = 0; // TODO | 131 | geo->rotation = 0; // TODO |
@@ -160,13 +168,6 @@ static void scale_box(struct wlr_box *box, float scale) { | |||
160 | box->height *= scale; | 168 | box->height *= scale; |
161 | } | 169 | } |
162 | 170 | ||
163 | struct render_data { | ||
164 | struct root_geometry root_geo; | ||
165 | struct sway_output *output; | ||
166 | pixman_region32_t *damage; | ||
167 | float alpha; | ||
168 | }; | ||
169 | |||
170 | static void scissor_output(struct wlr_output *wlr_output, | 171 | static void scissor_output(struct wlr_output *wlr_output, |
171 | pixman_box32_t *rect) { | 172 | pixman_box32_t *rect) { |
172 | struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); | 173 | struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); |
@@ -275,7 +276,10 @@ static void render_rect(struct wlr_output *wlr_output, | |||
275 | struct wlr_renderer *renderer = | 276 | struct wlr_renderer *renderer = |
276 | wlr_backend_get_renderer(wlr_output->backend); | 277 | wlr_backend_get_renderer(wlr_output->backend); |
277 | 278 | ||
278 | struct wlr_box box = *_box; | 279 | struct wlr_box box; |
280 | memcpy(&box, _box, sizeof(struct wlr_box)); | ||
281 | box.x -= wlr_output->lx * wlr_output->scale; | ||
282 | box.y -= wlr_output->ly * wlr_output->scale; | ||
279 | 283 | ||
280 | pixman_region32_t damage; | 284 | pixman_region32_t damage; |
281 | pixman_region32_init(&damage); | 285 | pixman_region32_init(&damage); |
@@ -450,8 +454,10 @@ static void render_titlebar(struct sway_output *output, | |||
450 | wlr_texture_get_size(marks_texture, | 454 | wlr_texture_get_size(marks_texture, |
451 | &texture_box.width, &texture_box.height); | 455 | &texture_box.width, &texture_box.height); |
452 | texture_box.x = | 456 | texture_box.x = |
453 | (x + width - TITLEBAR_H_PADDING) * output_scale - texture_box.width; | 457 | (x - output->wlr_output->lx + width - TITLEBAR_H_PADDING) |
454 | texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale; | 458 | * output_scale - texture_box.width; |
459 | texture_box.y = (y - output->wlr_output->ly + TITLEBAR_V_PADDING) | ||
460 | * output_scale; | ||
455 | 461 | ||
456 | float matrix[9]; | 462 | float matrix[9]; |
457 | wlr_matrix_project_box(matrix, &texture_box, | 463 | wlr_matrix_project_box(matrix, &texture_box, |
@@ -472,8 +478,10 @@ static void render_titlebar(struct sway_output *output, | |||
472 | struct wlr_box texture_box; | 478 | struct wlr_box texture_box; |
473 | wlr_texture_get_size(title_texture, | 479 | wlr_texture_get_size(title_texture, |
474 | &texture_box.width, &texture_box.height); | 480 | &texture_box.width, &texture_box.height); |
475 | texture_box.x = (x + TITLEBAR_H_PADDING) * output_scale; | 481 | texture_box.x = (x - output->wlr_output->lx + TITLEBAR_H_PADDING) |
476 | texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale; | 482 | * output_scale; |
483 | texture_box.y = (y - output->wlr_output->ly + TITLEBAR_V_PADDING) | ||
484 | * output_scale; | ||
477 | 485 | ||
478 | float matrix[9]; | 486 | float matrix[9]; |
479 | wlr_matrix_project_box(matrix, &texture_box, | 487 | wlr_matrix_project_box(matrix, &texture_box, |
@@ -771,28 +779,8 @@ static bool floater_intersects_output(struct sway_container *floater, | |||
771 | output->sway_output->wlr_output, &box); | 779 | output->sway_output->wlr_output, &box); |
772 | } | 780 | } |
773 | 781 | ||
774 | static void container_translate(struct sway_container *con, int x, int y) { | ||
775 | con->x += x; | ||
776 | con->y += y; | ||
777 | if (con->type == C_VIEW) { | ||
778 | con->sway_view->x += x; | ||
779 | con->sway_view->y += y; | ||
780 | } else { | ||
781 | for (int i = 0; i < con->children->length; ++i) { | ||
782 | struct sway_container *child = con->children->items[i]; | ||
783 | container_translate(child, x, y); | ||
784 | } | ||
785 | } | ||
786 | } | ||
787 | |||
788 | static void render_floating_container(struct sway_output *soutput, | 782 | static void render_floating_container(struct sway_output *soutput, |
789 | pixman_region32_t *damage, struct sway_container *con) { | 783 | pixman_region32_t *damage, struct sway_container *con) { |
790 | // We need to translate the floating container's coordinates from layout | ||
791 | // coordinates into output-local coordinates. This needs to happen for all | ||
792 | // children of the floating container too. | ||
793 | struct sway_container *output = container_parent(con, C_OUTPUT); | ||
794 | container_translate(con, -output->x, -output->y); | ||
795 | |||
796 | if (con->type == C_VIEW) { | 784 | if (con->type == C_VIEW) { |
797 | struct sway_view *view = con->sway_view; | 785 | struct sway_view *view = con->sway_view; |
798 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 786 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
@@ -821,8 +809,6 @@ static void render_floating_container(struct sway_output *soutput, | |||
821 | } else { | 809 | } else { |
822 | render_container(soutput, damage, con, false); | 810 | render_container(soutput, damage, con, false); |
823 | } | 811 | } |
824 | // Undo the translation | ||
825 | container_translate(con, output->x, output->y); | ||
826 | } | 812 | } |
827 | 813 | ||
828 | static void render_floating(struct sway_output *soutput, | 814 | static void render_floating(struct sway_output *soutput, |
@@ -1123,15 +1109,7 @@ static void output_damage_view(struct sway_output *output, | |||
1123 | 1109 | ||
1124 | void output_damage_from_view(struct sway_output *output, | 1110 | void output_damage_from_view(struct sway_output *output, |
1125 | struct sway_view *view) { | 1111 | struct sway_view *view) { |
1126 | if (container_self_or_parent_floating(view->swayc)) { | 1112 | output_damage_view(output, view, false); |
1127 | view->x -= output->swayc->x; | ||
1128 | view->y -= output->swayc->y; | ||
1129 | output_damage_view(output, view, false); | ||
1130 | view->x += output->swayc->x; | ||
1131 | view->y += output->swayc->y; | ||
1132 | } else { | ||
1133 | output_damage_view(output, view, false); | ||
1134 | } | ||
1135 | } | 1113 | } |
1136 | 1114 | ||
1137 | static void output_damage_whole_container_iterator(struct sway_container *con, | 1115 | static void output_damage_whole_container_iterator(struct sway_container *con, |
@@ -1148,24 +1126,13 @@ static void output_damage_whole_container_iterator(struct sway_container *con, | |||
1148 | void output_damage_whole_container(struct sway_output *output, | 1126 | void output_damage_whole_container(struct sway_output *output, |
1149 | struct sway_container *con) { | 1127 | struct sway_container *con) { |
1150 | struct wlr_box box = { | 1128 | struct wlr_box box = { |
1151 | .x = con->x, | 1129 | .x = con->x - output->wlr_output->lx, |
1152 | .y = con->y, | 1130 | .y = con->y - output->wlr_output->ly, |
1153 | .width = con->width, | 1131 | .width = con->width, |
1154 | .height = con->height, | 1132 | .height = con->height, |
1155 | }; | 1133 | }; |
1156 | if (container_is_floating(con)) { | ||
1157 | box.x -= output->wlr_output->lx; | ||
1158 | box.y -= output->wlr_output->ly; | ||
1159 | } | ||
1160 | scale_box(&box, output->wlr_output->scale); | 1134 | scale_box(&box, output->wlr_output->scale); |
1161 | wlr_output_damage_add_box(output->damage, &box); | 1135 | wlr_output_damage_add_box(output->damage, &box); |
1162 | |||
1163 | if (con->type == C_VIEW) { | ||
1164 | output_damage_whole_container_iterator(con, output); | ||
1165 | } else { | ||
1166 | container_descendants(con, C_VIEW, | ||
1167 | output_damage_whole_container_iterator, output); | ||
1168 | } | ||
1169 | } | 1136 | } |
1170 | 1137 | ||
1171 | static void damage_handle_destroy(struct wl_listener *listener, void *data) { | 1138 | static void damage_handle_destroy(struct wl_listener *listener, void *data) { |
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 73d9477f..412488b3 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c | |||
@@ -87,7 +87,7 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p | |||
87 | } | 87 | } |
88 | } | 88 | } |
89 | 89 | ||
90 | static void configure(struct sway_view *view, double ox, double oy, int width, | 90 | static void configure(struct sway_view *view, double lx, double ly, int width, |
91 | int height) { | 91 | int height) { |
92 | struct sway_xdg_shell_view *xdg_shell_view = | 92 | struct sway_xdg_shell_view *xdg_shell_view = |
93 | xdg_shell_view_from_view(view); | 93 | xdg_shell_view_from_view(view); |
@@ -98,7 +98,7 @@ static void configure(struct sway_view *view, double ox, double oy, int width, | |||
98 | xdg_shell_view->pending_width = width; | 98 | xdg_shell_view->pending_width = width; |
99 | xdg_shell_view->pending_height = height; | 99 | xdg_shell_view->pending_height = height; |
100 | wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height); | 100 | wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height); |
101 | view_update_position(view, ox, oy); | 101 | view_update_position(view, lx, ly); |
102 | } | 102 | } |
103 | 103 | ||
104 | static void set_activated(struct sway_view *view, bool activated) { | 104 | static void set_activated(struct sway_view *view, bool activated) { |
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 6c98744c..b3653913 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -86,7 +86,7 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p | |||
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | static void configure(struct sway_view *view, double ox, double oy, int width, | 89 | static void configure(struct sway_view *view, double lx, double ly, int width, |
90 | int height) { | 90 | int height) { |
91 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = | 91 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = |
92 | xdg_shell_v6_view_from_view(view); | 92 | xdg_shell_v6_view_from_view(view); |
@@ -97,7 +97,7 @@ static void configure(struct sway_view *view, double ox, double oy, int width, | |||
97 | xdg_shell_v6_view->pending_width = width; | 97 | xdg_shell_v6_view->pending_width = width; |
98 | xdg_shell_v6_view->pending_height = height; | 98 | xdg_shell_v6_view->pending_height = height; |
99 | wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height); | 99 | wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height); |
100 | view_update_position(view, ox, oy); | 100 | view_update_position(view, lx, ly); |
101 | } | 101 | } |
102 | 102 | ||
103 | static void set_activated(struct sway_view *view, bool activated) { | 103 | static void set_activated(struct sway_view *view, bool activated) { |
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 783868bc..fc488162 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -152,9 +152,7 @@ static uint32_t get_int_prop(struct sway_view *view, enum sway_view_prop prop) { | |||
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | // The x and y arguments are output-local for tiled views, and layout | 155 | static void configure(struct sway_view *view, double lx, double ly, int width, |
156 | // coordinates for floating views. | ||
157 | static void configure(struct sway_view *view, double x, double y, int width, | ||
158 | int height) { | 156 | int height) { |
159 | struct sway_xwayland_view *xwayland_view = xwayland_view_from_view(view); | 157 | struct sway_xwayland_view *xwayland_view = xwayland_view_from_view(view); |
160 | if (xwayland_view == NULL) { | 158 | if (xwayland_view == NULL) { |
@@ -162,30 +160,6 @@ static void configure(struct sway_view *view, double x, double y, int width, | |||
162 | } | 160 | } |
163 | struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; | 161 | struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; |
164 | 162 | ||
165 | double lx, ly; | ||
166 | if (container_is_floating(view->swayc)) { | ||
167 | lx = x; | ||
168 | ly = y; | ||
169 | } else { | ||
170 | struct sway_container *output = container_parent(view->swayc, C_OUTPUT); | ||
171 | if (!sway_assert(output, "view must be within tree to set position")) { | ||
172 | return; | ||
173 | } | ||
174 | struct sway_container *root = container_parent(output, C_ROOT); | ||
175 | if (!sway_assert(root, "output must be within tree to set position")) { | ||
176 | return; | ||
177 | } | ||
178 | struct wlr_output_layout *layout = root->sway_root->output_layout; | ||
179 | struct wlr_output_layout_output *loutput = | ||
180 | wlr_output_layout_get(layout, output->sway_output->wlr_output); | ||
181 | if (!sway_assert(loutput, | ||
182 | "output must be within layout to set position")) { | ||
183 | return; | ||
184 | } | ||
185 | lx = x + loutput->x; | ||
186 | ly = y + loutput->y; | ||
187 | } | ||
188 | |||
189 | xwayland_view->pending_width = width; | 163 | xwayland_view->pending_width = width; |
190 | xwayland_view->pending_height = height; | 164 | xwayland_view->pending_height = height; |
191 | wlr_xwayland_surface_configure(xsurface, lx, ly, width, height); | 165 | wlr_xwayland_surface_configure(xsurface, lx, ly, width, height); |