diff options
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r-- | sway/tree/view.c | 111 |
1 files changed, 53 insertions, 58 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c index c9c82405..658a94e8 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -25,6 +25,7 @@ void view_init(struct sway_view *view, enum sway_view_type type, | |||
25 | view->impl = impl; | 25 | view->impl = impl; |
26 | view->executed_criteria = create_list(); | 26 | view->executed_criteria = create_list(); |
27 | view->marks = create_list(); | 27 | view->marks = create_list(); |
28 | view->instructions = create_list(); | ||
28 | wl_signal_init(&view->events.unmap); | 29 | wl_signal_init(&view->events.unmap); |
29 | } | 30 | } |
30 | 31 | ||
@@ -37,6 +38,11 @@ void view_destroy(struct sway_view *view) { | |||
37 | view_unmap(view); | 38 | view_unmap(view); |
38 | } | 39 | } |
39 | 40 | ||
41 | if (!sway_assert(view->instructions->length == 0, | ||
42 | "Tried to destroy view with pending instructions")) { | ||
43 | return; | ||
44 | } | ||
45 | |||
40 | list_free(view->executed_criteria); | 46 | list_free(view->executed_criteria); |
41 | 47 | ||
42 | for (int i = 0; i < view->marks->length; ++i) { | 48 | for (int i = 0; i < view->marks->length; ++i) { |
@@ -44,6 +50,8 @@ void view_destroy(struct sway_view *view) { | |||
44 | } | 50 | } |
45 | list_free(view->marks); | 51 | list_free(view->marks); |
46 | 52 | ||
53 | list_free(view->instructions); | ||
54 | |||
47 | wlr_texture_destroy(view->marks_focused); | 55 | wlr_texture_destroy(view->marks_focused); |
48 | wlr_texture_destroy(view->marks_focused_inactive); | 56 | wlr_texture_destroy(view->marks_focused_inactive); |
49 | wlr_texture_destroy(view->marks_unfocused); | 57 | wlr_texture_destroy(view->marks_unfocused); |
@@ -119,29 +127,30 @@ const char *view_get_shell(struct sway_view *view) { | |||
119 | return "unknown"; | 127 | return "unknown"; |
120 | } | 128 | } |
121 | 129 | ||
122 | void view_configure(struct sway_view *view, double lx, double ly, int width, | 130 | uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, |
123 | int height) { | 131 | int height) { |
124 | if (view->impl->configure) { | 132 | if (view->impl->configure) { |
125 | view->impl->configure(view, lx, ly, width, height); | 133 | return view->impl->configure(view, lx, ly, width, height); |
126 | } | 134 | } |
135 | return 0; | ||
127 | } | 136 | } |
128 | 137 | ||
129 | static void view_autoconfigure_floating(struct sway_view *view) { | 138 | void view_init_floating(struct sway_view *view) { |
130 | struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); | 139 | struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); |
131 | int max_width = ws->width * 0.6666; | 140 | int max_width = ws->width * 0.6666; |
132 | int max_height = ws->height * 0.6666; | 141 | int max_height = ws->height * 0.6666; |
133 | int width = | 142 | view->width = |
134 | view->natural_width > max_width ? max_width : view->natural_width; | 143 | view->natural_width > max_width ? max_width : view->natural_width; |
135 | int height = | 144 | view->height = |
136 | view->natural_height > max_height ? max_height : view->natural_height; | 145 | view->natural_height > max_height ? max_height : view->natural_height; |
137 | int lx = ws->x + (ws->width - width) / 2; | 146 | view->x = ws->x + (ws->width - view->width) / 2; |
138 | int ly = ws->y + (ws->height - height) / 2; | 147 | view->y = ws->y + (ws->height - view->height) / 2; |
139 | 148 | ||
140 | // If the view's border is B_NONE then these properties are ignored. | 149 | // If the view's border is B_NONE then these properties are ignored. |
141 | view->border_top = view->border_bottom = true; | 150 | view->border_top = view->border_bottom = true; |
142 | view->border_left = view->border_right = true; | 151 | view->border_left = view->border_right = true; |
143 | 152 | ||
144 | view_configure(view, lx, ly, width, height); | 153 | container_set_geometry_from_floating_view(view->swayc); |
145 | } | 154 | } |
146 | 155 | ||
147 | void view_autoconfigure(struct sway_view *view) { | 156 | void view_autoconfigure(struct sway_view *view) { |
@@ -153,12 +162,14 @@ void view_autoconfigure(struct sway_view *view) { | |||
153 | struct sway_container *output = container_parent(view->swayc, C_OUTPUT); | 162 | struct sway_container *output = container_parent(view->swayc, C_OUTPUT); |
154 | 163 | ||
155 | if (view->is_fullscreen) { | 164 | if (view->is_fullscreen) { |
156 | view_configure(view, output->x, output->y, output->width, output->height); | 165 | view->x = output->x; |
166 | view->y = output->y; | ||
167 | view->width = output->width; | ||
168 | view->height = output->height; | ||
157 | return; | 169 | return; |
158 | } | 170 | } |
159 | 171 | ||
160 | if (container_is_floating(view->swayc)) { | 172 | if (container_is_floating(view->swayc)) { |
161 | view_autoconfigure_floating(view); | ||
162 | return; | 173 | return; |
163 | } | 174 | } |
164 | 175 | ||
@@ -178,20 +189,22 @@ void view_autoconfigure(struct sway_view *view) { | |||
178 | } | 189 | } |
179 | } | 190 | } |
180 | 191 | ||
192 | struct sway_container *con = view->swayc; | ||
193 | |||
181 | view->border_top = view->border_bottom = true; | 194 | view->border_top = view->border_bottom = true; |
182 | view->border_left = view->border_right = true; | 195 | view->border_left = view->border_right = true; |
183 | if (config->hide_edge_borders == E_BOTH | 196 | if (config->hide_edge_borders == E_BOTH |
184 | || config->hide_edge_borders == E_VERTICAL | 197 | || config->hide_edge_borders == E_VERTICAL |
185 | || (config->hide_edge_borders == E_SMART && !other_views)) { | 198 | || (config->hide_edge_borders == E_SMART && !other_views)) { |
186 | view->border_left = view->swayc->x != ws->x; | 199 | view->border_left = con->x != ws->x; |
187 | int right_x = view->swayc->x + view->swayc->width; | 200 | int right_x = con->x + con->width; |
188 | view->border_right = right_x != ws->x + ws->width; | 201 | view->border_right = right_x != ws->x + ws->width; |
189 | } | 202 | } |
190 | if (config->hide_edge_borders == E_BOTH | 203 | if (config->hide_edge_borders == E_BOTH |
191 | || config->hide_edge_borders == E_HORIZONTAL | 204 | || config->hide_edge_borders == E_HORIZONTAL |
192 | || (config->hide_edge_borders == E_SMART && !other_views)) { | 205 | || (config->hide_edge_borders == E_SMART && !other_views)) { |
193 | view->border_top = view->swayc->y != ws->y; | 206 | view->border_top = con->y != ws->y; |
194 | int bottom_y = view->swayc->y + view->swayc->height; | 207 | int bottom_y = con->y + con->height; |
195 | view->border_bottom = bottom_y != ws->y + ws->height; | 208 | view->border_bottom = bottom_y != ws->y + ws->height; |
196 | } | 209 | } |
197 | 210 | ||
@@ -202,45 +215,44 @@ void view_autoconfigure(struct sway_view *view) { | |||
202 | // In a tabbed or stacked container, the swayc's y is the top of the title | 215 | // In a tabbed or stacked container, the swayc's y is the top of the title |
203 | // area. We have to offset the surface y by the height of the title bar, and | 216 | // area. We have to offset the surface y by the height of the title bar, and |
204 | // disable any top border because we'll always have the title bar. | 217 | // disable any top border because we'll always have the title bar. |
205 | if (view->swayc->parent->layout == L_TABBED) { | 218 | if (con->parent->layout == L_TABBED) { |
206 | y_offset = container_titlebar_height(); | 219 | y_offset = container_titlebar_height(); |
207 | view->border_top = false; | 220 | view->border_top = false; |
208 | } else if (view->swayc->parent->layout == L_STACKED) { | 221 | } else if (con->parent->layout == L_STACKED) { |
209 | y_offset = container_titlebar_height() | 222 | y_offset = container_titlebar_height() * con->parent->children->length; |
210 | * view->swayc->parent->children->length; | ||
211 | view->border_top = false; | 223 | view->border_top = false; |
212 | } | 224 | } |
213 | 225 | ||
214 | switch (view->border) { | 226 | switch (view->border) { |
215 | case B_NONE: | 227 | case B_NONE: |
216 | x = view->swayc->x; | 228 | x = con->x; |
217 | y = view->swayc->y + y_offset; | 229 | y = con->y + y_offset; |
218 | width = view->swayc->width; | 230 | width = con->width; |
219 | height = view->swayc->height - y_offset; | 231 | height = con->height - y_offset; |
220 | break; | 232 | break; |
221 | case B_PIXEL: | 233 | case B_PIXEL: |
222 | x = view->swayc->x + view->border_thickness * view->border_left; | 234 | x = con->x + view->border_thickness * view->border_left; |
223 | y = view->swayc->y + view->border_thickness * view->border_top + y_offset; | 235 | y = con->y + view->border_thickness * view->border_top + y_offset; |
224 | width = view->swayc->width | 236 | width = con->width |
225 | - view->border_thickness * view->border_left | 237 | - view->border_thickness * view->border_left |
226 | - view->border_thickness * view->border_right; | 238 | - view->border_thickness * view->border_right; |
227 | height = view->swayc->height - y_offset | 239 | height = con->height - y_offset |
228 | - view->border_thickness * view->border_top | 240 | - view->border_thickness * view->border_top |
229 | - view->border_thickness * view->border_bottom; | 241 | - view->border_thickness * view->border_bottom; |
230 | break; | 242 | break; |
231 | case B_NORMAL: | 243 | case B_NORMAL: |
232 | // Height is: 1px border + 3px pad + title height + 3px pad + 1px border | 244 | // Height is: 1px border + 3px pad + title height + 3px pad + 1px border |
233 | x = view->swayc->x + view->border_thickness * view->border_left; | 245 | x = con->x + view->border_thickness * view->border_left; |
234 | width = view->swayc->width | 246 | width = con->width |
235 | - view->border_thickness * view->border_left | 247 | - view->border_thickness * view->border_left |
236 | - view->border_thickness * view->border_right; | 248 | - view->border_thickness * view->border_right; |
237 | if (y_offset) { | 249 | if (y_offset) { |
238 | y = view->swayc->y + y_offset; | 250 | y = con->y + y_offset; |
239 | height = view->swayc->height - y_offset | 251 | height = con->height - y_offset |
240 | - view->border_thickness * view->border_bottom; | 252 | - view->border_thickness * view->border_bottom; |
241 | } else { | 253 | } else { |
242 | y = view->swayc->y + container_titlebar_height(); | 254 | y = con->y + container_titlebar_height(); |
243 | height = view->swayc->height - container_titlebar_height() | 255 | height = con->height - container_titlebar_height() |
244 | - view->border_thickness * view->border_bottom; | 256 | - view->border_thickness * view->border_bottom; |
245 | } | 257 | } |
246 | break; | 258 | break; |
@@ -248,7 +260,8 @@ void view_autoconfigure(struct sway_view *view) { | |||
248 | 260 | ||
249 | view->x = x; | 261 | view->x = x; |
250 | view->y = y; | 262 | view->y = y; |
251 | view_configure(view, x, y, width, height); | 263 | view->width = width; |
264 | view->height = height; | ||
252 | } | 265 | } |
253 | 266 | ||
254 | void view_set_activated(struct sway_view *view, bool activated) { | 267 | void view_set_activated(struct sway_view *view, bool activated) { |
@@ -257,8 +270,7 @@ void view_set_activated(struct sway_view *view, bool activated) { | |||
257 | } | 270 | } |
258 | } | 271 | } |
259 | 272 | ||
260 | // Set fullscreen, but without IPC events or arranging windows. | 273 | void view_set_fullscreen(struct sway_view *view, bool fullscreen) { |
261 | void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { | ||
262 | if (view->is_fullscreen == fullscreen) { | 274 | if (view->is_fullscreen == fullscreen) { |
263 | return; | 275 | return; |
264 | } | 276 | } |
@@ -304,27 +316,17 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { | |||
304 | } else { | 316 | } else { |
305 | workspace->sway_workspace->fullscreen = NULL; | 317 | workspace->sway_workspace->fullscreen = NULL; |
306 | if (container_is_floating(view->swayc)) { | 318 | if (container_is_floating(view->swayc)) { |
307 | view_configure(view, view->saved_x, view->saved_y, | 319 | view->x = view->saved_x; |
308 | view->saved_width, view->saved_height); | 320 | view->y = view->saved_y; |
321 | view->width = view->saved_width; | ||
322 | view->height = view->saved_height; | ||
323 | container_set_geometry_from_floating_view(view->swayc); | ||
309 | } else { | 324 | } else { |
310 | view->swayc->width = view->swayc->saved_width; | 325 | view->swayc->width = view->swayc->saved_width; |
311 | view->swayc->height = view->swayc->saved_height; | 326 | view->swayc->height = view->swayc->saved_height; |
312 | view_autoconfigure(view); | ||
313 | } | 327 | } |
314 | } | 328 | } |
315 | } | ||
316 | 329 | ||
317 | void view_set_fullscreen(struct sway_view *view, bool fullscreen) { | ||
318 | if (view->is_fullscreen == fullscreen) { | ||
319 | return; | ||
320 | } | ||
321 | |||
322 | view_set_fullscreen_raw(view, fullscreen); | ||
323 | |||
324 | struct sway_container *workspace = | ||
325 | container_parent(view->swayc, C_WORKSPACE); | ||
326 | arrange_workspace(workspace); | ||
327 | output_damage_whole(workspace->parent->sway_output); | ||
328 | ipc_event_window(view->swayc, "fullscreen_mode"); | 330 | ipc_event_window(view->swayc, "fullscreen_mode"); |
329 | } | 331 | } |
330 | 332 | ||
@@ -507,8 +509,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
507 | 509 | ||
508 | if (view->impl->wants_floating && view->impl->wants_floating(view)) { | 510 | if (view->impl->wants_floating && view->impl->wants_floating(view)) { |
509 | container_set_floating(view->swayc, true); | 511 | container_set_floating(view->swayc, true); |
510 | } else { | ||
511 | arrange_children_of(cont->parent); | ||
512 | } | 512 | } |
513 | 513 | ||
514 | input_manager_set_focus(input_manager, cont); | 514 | input_manager_set_focus(input_manager, cont); |
@@ -520,7 +520,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
520 | container_notify_subtree_changed(view->swayc->parent); | 520 | container_notify_subtree_changed(view->swayc->parent); |
521 | view_execute_criteria(view); | 521 | view_execute_criteria(view); |
522 | 522 | ||
523 | container_damage_whole(cont); | ||
524 | view_handle_container_reparent(&view->container_reparent, NULL); | 523 | view_handle_container_reparent(&view->container_reparent, NULL); |
525 | } | 524 | } |
526 | 525 | ||
@@ -551,11 +550,7 @@ void view_unmap(struct sway_view *view) { | |||
551 | view->title_format = NULL; | 550 | view->title_format = NULL; |
552 | } | 551 | } |
553 | 552 | ||
554 | if (parent->type == C_OUTPUT) { | 553 | arrange_and_commit(parent); |
555 | arrange_output(parent); | ||
556 | } else { | ||
557 | arrange_children_of(parent); | ||
558 | } | ||
559 | } | 554 | } |
560 | 555 | ||
561 | void view_update_position(struct sway_view *view, double lx, double ly) { | 556 | void view_update_position(struct sway_view *view, double lx, double ly) { |