diff options
author | 2018-04-02 10:57:45 -0400 | |
---|---|---|
committer | 2018-04-02 10:57:45 -0400 | |
commit | 61fabede14bb3a8fe9ee5a249352cd405fd1b9bf (patch) | |
tree | de0cc1378f2edba5cc194c8dcebe4d5fdaeda647 /sway/tree | |
parent | Add sway_view_impl (diff) | |
download | sway-61fabede14bb3a8fe9ee5a249352cd405fd1b9bf.tar.gz sway-61fabede14bb3a8fe9ee5a249352cd405fd1b9bf.tar.zst sway-61fabede14bb3a8fe9ee5a249352cd405fd1b9bf.zip |
Address review comments
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/layout.c | 8 | ||||
-rw-r--r-- | sway/tree/output.c | 1 | ||||
-rw-r--r-- | sway/tree/view.c | 137 |
3 files changed, 85 insertions, 61 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index ce0682dc..3fec02a1 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -261,7 +261,7 @@ void arrange_windows(struct sway_container *container, | |||
261 | { | 261 | { |
262 | container->width = width; | 262 | container->width = width; |
263 | container->height = height; | 263 | container->height = height; |
264 | view_set_size(container->sway_view, | 264 | view_configure(container->sway_view, container->x, container->y, |
265 | container->width, container->height); | 265 | container->width, container->height); |
266 | wlr_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f", | 266 | wlr_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f", |
267 | container->width, container->height, | 267 | container->width, container->height, |
@@ -322,7 +322,8 @@ static void apply_horiz_layout(struct sway_container *container, | |||
322 | wlr_log(L_DEBUG, | 322 | wlr_log(L_DEBUG, |
323 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 323 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
324 | child, child->type, width, scale); | 324 | child, child->type, width, scale); |
325 | view_set_position(child->sway_view, child_x, y); | 325 | view_configure(child->sway_view, child_x, y, child->width, |
326 | child->height); | ||
326 | 327 | ||
327 | if (i == end - 1) { | 328 | if (i == end - 1) { |
328 | double remaining_width = x + width - child_x; | 329 | double remaining_width = x + width - child_x; |
@@ -373,7 +374,8 @@ void apply_vert_layout(struct sway_container *container, | |||
373 | wlr_log(L_DEBUG, | 374 | wlr_log(L_DEBUG, |
374 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 375 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
375 | child, child->type, height, scale); | 376 | child, child->type, height, scale); |
376 | view_set_position(child->sway_view, x, child_y); | 377 | view_configure(child->sway_view, x, child_y, child->width, |
378 | child->height); | ||
377 | 379 | ||
378 | if (i == end - 1) { | 380 | if (i == end - 1) { |
379 | double remaining_height = y + height - child_y; | 381 | double remaining_height = y + height - child_y; |
diff --git a/sway/tree/output.c b/sway/tree/output.c index 7248fd00..80a36ac7 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c | |||
@@ -29,6 +29,7 @@ struct sway_container *container_output_destroy(struct sway_container *output) { | |||
29 | wl_list_remove(&output->sway_output->destroy.link); | 29 | wl_list_remove(&output->sway_output->destroy.link); |
30 | wl_list_remove(&output->sway_output->mode.link); | 30 | wl_list_remove(&output->sway_output->mode.link); |
31 | wl_list_remove(&output->sway_output->transform.link); | 31 | wl_list_remove(&output->sway_output->transform.link); |
32 | wl_list_remove(&output->sway_output->scale.link); | ||
32 | 33 | ||
33 | wl_list_remove(&output->sway_output->damage_destroy.link); | 34 | wl_list_remove(&output->sway_output->damage_destroy.link); |
34 | wl_list_remove(&output->sway_output->damage_frame.link); | 35 | wl_list_remove(&output->sway_output->damage_frame.link); |
diff --git a/sway/tree/view.c b/sway/tree/view.c index d7a52e19..73e3d445 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -62,55 +62,10 @@ const char *view_get_instance(struct sway_view *view) { | |||
62 | return NULL; | 62 | return NULL; |
63 | } | 63 | } |
64 | 64 | ||
65 | static void view_update_outputs(struct sway_view *view, | 65 | void view_configure(struct sway_view *view, double ox, double oy, int width, |
66 | const struct wlr_box *before) { | 66 | int height) { |
67 | struct wlr_output_layout *output_layout = | 67 | if (view->impl->configure) { |
68 | root_container.sway_root->output_layout; | 68 | view->impl->configure(view, ox, oy, width, height); |
69 | struct wlr_box box = { | ||
70 | .x = view->swayc->x, | ||
71 | .y = view->swayc->y, | ||
72 | .width = view->width, | ||
73 | .height = view->height, | ||
74 | }; | ||
75 | struct wlr_output_layout_output *layout_output; | ||
76 | wl_list_for_each(layout_output, &output_layout->outputs, link) { | ||
77 | bool intersected = before != NULL && wlr_output_layout_intersects( | ||
78 | output_layout, layout_output->output, before); | ||
79 | bool intersects = wlr_output_layout_intersects(output_layout, | ||
80 | layout_output->output, &box); | ||
81 | if (intersected && !intersects) { | ||
82 | wlr_surface_send_leave(view->surface, layout_output->output); | ||
83 | } | ||
84 | if (!intersected && intersects) { | ||
85 | wlr_surface_send_enter(view->surface, layout_output->output); | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | |||
90 | void view_set_size(struct sway_view *view, int width, int height) { | ||
91 | if (view->impl->set_size) { | ||
92 | struct wlr_box box = { | ||
93 | .x = view->swayc->x, | ||
94 | .y = view->swayc->y, | ||
95 | .width = view->width, | ||
96 | .height = view->height, | ||
97 | }; | ||
98 | view->impl->set_size(view, width, height); | ||
99 | view_update_outputs(view, &box); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | // TODO make view coordinates in layout coordinates | ||
104 | void view_set_position(struct sway_view *view, double ox, double oy) { | ||
105 | if (view->impl->set_position) { | ||
106 | struct wlr_box box = { | ||
107 | .x = view->swayc->x, | ||
108 | .y = view->swayc->y, | ||
109 | .width = view->width, | ||
110 | .height = view->height, | ||
111 | }; | ||
112 | view->impl->set_position(view, ox, oy); | ||
113 | view_update_outputs(view, &box); | ||
114 | } | 69 | } |
115 | } | 70 | } |
116 | 71 | ||
@@ -136,6 +91,56 @@ struct sway_container *container_view_destroy(struct sway_container *view) { | |||
136 | return parent; | 91 | return parent; |
137 | } | 92 | } |
138 | 93 | ||
94 | void view_damage_whole(struct sway_view *view) { | ||
95 | for (int i = 0; i < root_container.children->length; ++i) { | ||
96 | struct sway_container *cont = root_container.children->items[i]; | ||
97 | if (cont->type == C_OUTPUT) { | ||
98 | output_damage_whole_view(cont->sway_output, view); | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | |||
103 | void view_damage_from(struct sway_view *view) { | ||
104 | // TODO | ||
105 | view_damage_whole(view); | ||
106 | } | ||
107 | |||
108 | static void view_get_layout_box(struct sway_view *view, struct wlr_box *box) { | ||
109 | struct sway_container *cont = container_parent(view->swayc, C_OUTPUT); | ||
110 | |||
111 | struct wlr_output_layout *output_layout = | ||
112 | root_container.sway_root->output_layout; | ||
113 | struct wlr_box *output_box = wlr_output_layout_get_box(output_layout, | ||
114 | cont->sway_output->wlr_output); | ||
115 | |||
116 | box->x = output_box->x + view->swayc->x; | ||
117 | box->y = output_box->y + view->swayc->y; | ||
118 | box->width = view->width; | ||
119 | box->height = view->height; | ||
120 | } | ||
121 | |||
122 | static void view_update_outputs(struct sway_view *view, | ||
123 | const struct wlr_box *before) { | ||
124 | struct wlr_box box; | ||
125 | view_get_layout_box(view, &box); | ||
126 | |||
127 | struct wlr_output_layout *output_layout = | ||
128 | root_container.sway_root->output_layout; | ||
129 | struct wlr_output_layout_output *layout_output; | ||
130 | wl_list_for_each(layout_output, &output_layout->outputs, link) { | ||
131 | bool intersected = before != NULL && wlr_output_layout_intersects( | ||
132 | output_layout, layout_output->output, before); | ||
133 | bool intersects = wlr_output_layout_intersects(output_layout, | ||
134 | layout_output->output, &box); | ||
135 | if (intersected && !intersects) { | ||
136 | wlr_surface_send_leave(view->surface, layout_output->output); | ||
137 | } | ||
138 | if (!intersected && intersects) { | ||
139 | wlr_surface_send_enter(view->surface, layout_output->output); | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | |||
139 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | 144 | void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { |
140 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { | 145 | if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { |
141 | return; | 146 | return; |
@@ -153,6 +158,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
153 | sway_input_manager_set_focus(input_manager, cont); | 158 | sway_input_manager_set_focus(input_manager, cont); |
154 | 159 | ||
155 | view_damage_whole(view); | 160 | view_damage_whole(view); |
161 | view_update_outputs(view, NULL); | ||
156 | } | 162 | } |
157 | 163 | ||
158 | void view_map_unmanaged(struct sway_view *view, | 164 | void view_map_unmanaged(struct sway_view *view, |
@@ -168,6 +174,8 @@ void view_map_unmanaged(struct sway_view *view, | |||
168 | &view->unmanaged_view_link); | 174 | &view->unmanaged_view_link); |
169 | 175 | ||
170 | view_damage_whole(view); | 176 | view_damage_whole(view); |
177 | // TODO: make this work for unmanaged views | ||
178 | //view_update_outputs(view, NULL); | ||
171 | } | 179 | } |
172 | 180 | ||
173 | void view_unmap(struct sway_view *view) { | 181 | void view_unmap(struct sway_view *view) { |
@@ -186,17 +194,30 @@ void view_unmap(struct sway_view *view) { | |||
186 | view->surface = NULL; | 194 | view->surface = NULL; |
187 | } | 195 | } |
188 | 196 | ||
189 | void view_damage_whole(struct sway_view *view) { | 197 | void view_update_position(struct sway_view *view, double ox, double oy) { |
190 | struct sway_container *cont = NULL; | 198 | if (view->swayc->x == ox && view->swayc->y == oy) { |
191 | for (int i = 0; i < root_container.children->length; ++i) { | 199 | return; |
192 | cont = root_container.children->items[i]; | ||
193 | if (cont->type == C_OUTPUT) { | ||
194 | output_damage_whole_view(cont->sway_output, view); | ||
195 | } | ||
196 | } | 200 | } |
201 | |||
202 | struct wlr_box box; | ||
203 | view_get_layout_box(view, &box); | ||
204 | view_damage_whole(view); | ||
205 | view->swayc->x = ox; | ||
206 | view->swayc->y = oy; | ||
207 | view_update_outputs(view, &box); | ||
208 | view_damage_whole(view); | ||
197 | } | 209 | } |
198 | 210 | ||
199 | void view_damage_from(struct sway_view *view) { | 211 | void view_update_size(struct sway_view *view, int width, int height) { |
200 | // TODO | 212 | if (view->width == width && view->height == height) { |
213 | return; | ||
214 | } | ||
215 | |||
216 | struct wlr_box box; | ||
217 | view_get_layout_box(view, &box); | ||
218 | view_damage_whole(view); | ||
219 | view->width = width; | ||
220 | view->height = height; | ||
221 | view_update_outputs(view, &box); | ||
201 | view_damage_whole(view); | 222 | view_damage_whole(view); |
202 | } | 223 | } |