diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-31 20:28:36 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-31 23:56:20 +1000 |
commit | 528c7495bb09e18a8b63e1c741b90f65ff5541c6 (patch) | |
tree | b1dddeefb15f2511b33f7bed52d0df3b4110d8f8 /sway | |
parent | Merge pull request #3031 from atomnuker/master (diff) | |
download | sway-528c7495bb09e18a8b63e1c741b90f65ff5541c6.tar.gz sway-528c7495bb09e18a8b63e1c741b90f65ff5541c6.tar.zst sway-528c7495bb09e18a8b63e1c741b90f65ff5541c6.zip |
Move view border properties to container struct
This will be needed to implement layout saving and restoring, as we need
to be able to configure borders on a placeholder container which has no
view.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/border.c | 60 | ||||
-rw-r--r-- | sway/desktop/transaction.c | 12 | ||||
-rw-r--r-- | sway/input/cursor.c | 13 | ||||
-rw-r--r-- | sway/tree/container.c | 14 | ||||
-rw-r--r-- | sway/tree/view.c | 61 |
5 files changed, 82 insertions, 78 deletions
diff --git a/sway/commands/border.c b/sway/commands/border.c index 37047812..b6eab550 100644 --- a/sway/commands/border.c +++ b/sway/commands/border.c | |||
@@ -12,37 +12,41 @@ | |||
12 | // in use (we set using_csd instead and render a sway border). | 12 | // in use (we set using_csd instead and render a sway border). |
13 | // - view->saved_border should be the last applied border when switching to CSD. | 13 | // - view->saved_border should be the last applied border when switching to CSD. |
14 | // - view->using_csd should always reflect whether CSD is applied or not. | 14 | // - view->using_csd should always reflect whether CSD is applied or not. |
15 | static void set_border(struct sway_view *view, | 15 | static void set_border(struct sway_container *con, |
16 | enum sway_container_border new_border) { | 16 | enum sway_container_border new_border) { |
17 | if (view->using_csd && new_border != B_CSD) { | 17 | if (con->view) { |
18 | view_set_csd_from_server(view, false); | 18 | if (con->view->using_csd && new_border != B_CSD) { |
19 | } else if (!view->using_csd && new_border == B_CSD) { | 19 | view_set_csd_from_server(con->view, false); |
20 | view_set_csd_from_server(view, true); | 20 | } else if (!con->view->using_csd && new_border == B_CSD) { |
21 | view->saved_border = view->border; | 21 | view_set_csd_from_server(con->view, true); |
22 | con->saved_border = con->border; | ||
23 | } | ||
24 | } | ||
25 | if (new_border != B_CSD || container_is_floating(con)) { | ||
26 | con->border = new_border; | ||
22 | } | 27 | } |
23 | if (new_border != B_CSD || container_is_floating(view->container)) { | 28 | if (con->view) { |
24 | view->border = new_border; | 29 | con->view->using_csd = new_border == B_CSD; |
25 | } | 30 | } |
26 | view->using_csd = new_border == B_CSD; | ||
27 | } | 31 | } |
28 | 32 | ||
29 | static void border_toggle(struct sway_view *view) { | 33 | static void border_toggle(struct sway_container *con) { |
30 | if (view->using_csd) { | 34 | if (con->view && con->view->using_csd) { |
31 | set_border(view, B_NONE); | 35 | set_border(con, B_NONE); |
32 | return; | 36 | return; |
33 | } | 37 | } |
34 | switch (view->border) { | 38 | switch (con->border) { |
35 | case B_NONE: | 39 | case B_NONE: |
36 | set_border(view, B_PIXEL); | 40 | set_border(con, B_PIXEL); |
37 | break; | 41 | break; |
38 | case B_PIXEL: | 42 | case B_PIXEL: |
39 | set_border(view, B_NORMAL); | 43 | set_border(con, B_NORMAL); |
40 | break; | 44 | break; |
41 | case B_NORMAL: | 45 | case B_NORMAL: |
42 | if (view->xdg_decoration) { | 46 | if (con->view && con->view->xdg_decoration) { |
43 | set_border(view, B_CSD); | 47 | set_border(con, B_CSD); |
44 | } else { | 48 | } else { |
45 | set_border(view, B_NONE); | 49 | set_border(con, B_NONE); |
46 | } | 50 | } |
47 | break; | 51 | break; |
48 | case B_CSD: | 52 | case B_CSD: |
@@ -66,33 +70,33 @@ struct cmd_results *cmd_border(int argc, char **argv) { | |||
66 | struct sway_view *view = container->view; | 70 | struct sway_view *view = container->view; |
67 | 71 | ||
68 | if (strcmp(argv[0], "none") == 0) { | 72 | if (strcmp(argv[0], "none") == 0) { |
69 | set_border(view, B_NONE); | 73 | set_border(container, B_NONE); |
70 | } else if (strcmp(argv[0], "normal") == 0) { | 74 | } else if (strcmp(argv[0], "normal") == 0) { |
71 | set_border(view, B_NORMAL); | 75 | set_border(container, B_NORMAL); |
72 | } else if (strcmp(argv[0], "pixel") == 0) { | 76 | } else if (strcmp(argv[0], "pixel") == 0) { |
73 | set_border(view, B_PIXEL); | 77 | set_border(container, B_PIXEL); |
74 | } else if (strcmp(argv[0], "csd") == 0) { | 78 | } else if (strcmp(argv[0], "csd") == 0) { |
75 | if (!view->xdg_decoration) { | 79 | if (!view || !view->xdg_decoration) { |
76 | return cmd_results_new(CMD_INVALID, "border", | 80 | return cmd_results_new(CMD_INVALID, "border", |
77 | "This window doesn't support client side decorations"); | 81 | "This window doesn't support client side decorations"); |
78 | } | 82 | } |
79 | set_border(view, B_CSD); | 83 | set_border(container, B_CSD); |
80 | } else if (strcmp(argv[0], "toggle") == 0) { | 84 | } else if (strcmp(argv[0], "toggle") == 0) { |
81 | border_toggle(view); | 85 | border_toggle(container); |
82 | } else { | 86 | } else { |
83 | return cmd_results_new(CMD_INVALID, "border", | 87 | return cmd_results_new(CMD_INVALID, "border", |
84 | "Expected 'border <none|normal|pixel|csd|toggle>' " | 88 | "Expected 'border <none|normal|pixel|csd|toggle>' " |
85 | "or 'border pixel <px>'"); | 89 | "or 'border pixel <px>'"); |
86 | } | 90 | } |
87 | if (argc == 2) { | 91 | if (argc == 2) { |
88 | view->border_thickness = atoi(argv[1]); | 92 | container->border_thickness = atoi(argv[1]); |
89 | } | 93 | } |
90 | 94 | ||
91 | if (container_is_floating(view->container)) { | 95 | if (container_is_floating(container)) { |
92 | container_set_geometry_from_floating_view(view->container); | 96 | container_set_geometry_from_floating_view(container); |
93 | } | 97 | } |
94 | 98 | ||
95 | arrange_container(view->container); | 99 | arrange_container(container); |
96 | 100 | ||
97 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 101 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
98 | } | 102 | } |
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index c3efb210..44156d41 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c | |||
@@ -137,6 +137,12 @@ static void copy_container_state(struct sway_container *container, | |||
137 | state->is_fullscreen = container->is_fullscreen; | 137 | state->is_fullscreen = container->is_fullscreen; |
138 | state->parent = container->parent; | 138 | state->parent = container->parent; |
139 | state->workspace = container->workspace; | 139 | state->workspace = container->workspace; |
140 | state->border = container->border; | ||
141 | state->border_thickness = container->border_thickness; | ||
142 | state->border_top = container->border_top; | ||
143 | state->border_left = container->border_left; | ||
144 | state->border_right = container->border_right; | ||
145 | state->border_bottom = container->border_bottom; | ||
140 | 146 | ||
141 | if (container->view) { | 147 | if (container->view) { |
142 | struct sway_view *view = container->view; | 148 | struct sway_view *view = container->view; |
@@ -144,12 +150,6 @@ static void copy_container_state(struct sway_container *container, | |||
144 | state->view_y = view->y; | 150 | state->view_y = view->y; |
145 | state->view_width = view->width; | 151 | state->view_width = view->width; |
146 | state->view_height = view->height; | 152 | state->view_height = view->height; |
147 | state->border = view->border; | ||
148 | state->border_thickness = view->border_thickness; | ||
149 | state->border_top = view->border_top; | ||
150 | state->border_left = view->border_left; | ||
151 | state->border_right = view->border_right; | ||
152 | state->border_bottom = view->border_bottom; | ||
153 | } else { | 153 | } else { |
154 | state->children = create_list(); | 154 | state->children = create_list(); |
155 | list_cat(state->children, container->children); | 155 | list_cat(state->children, container->children); |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 7ede48bf..c539df40 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -187,23 +187,22 @@ static enum wlr_edges find_edge(struct sway_container *cont, | |||
187 | if (!cont->view) { | 187 | if (!cont->view) { |
188 | return WLR_EDGE_NONE; | 188 | return WLR_EDGE_NONE; |
189 | } | 189 | } |
190 | struct sway_view *view = cont->view; | 190 | if (cont->border == B_NONE || !cont->border_thickness || |
191 | if (view->border == B_NONE || !view->border_thickness || | 191 | cont->border == B_CSD) { |
192 | view->border == B_CSD) { | ||
193 | return WLR_EDGE_NONE; | 192 | return WLR_EDGE_NONE; |
194 | } | 193 | } |
195 | 194 | ||
196 | enum wlr_edges edge = 0; | 195 | enum wlr_edges edge = 0; |
197 | if (cursor->cursor->x < cont->x + view->border_thickness) { | 196 | if (cursor->cursor->x < cont->x + cont->border_thickness) { |
198 | edge |= WLR_EDGE_LEFT; | 197 | edge |= WLR_EDGE_LEFT; |
199 | } | 198 | } |
200 | if (cursor->cursor->y < cont->y + view->border_thickness) { | 199 | if (cursor->cursor->y < cont->y + cont->border_thickness) { |
201 | edge |= WLR_EDGE_TOP; | 200 | edge |= WLR_EDGE_TOP; |
202 | } | 201 | } |
203 | if (cursor->cursor->x >= cont->x + cont->width - view->border_thickness) { | 202 | if (cursor->cursor->x >= cont->x + cont->width - cont->border_thickness) { |
204 | edge |= WLR_EDGE_RIGHT; | 203 | edge |= WLR_EDGE_RIGHT; |
205 | } | 204 | } |
206 | if (cursor->cursor->y >= cont->y + cont->height - view->border_thickness) { | 205 | if (cursor->cursor->y >= cont->y + cont->height - cont->border_thickness) { |
207 | edge |= WLR_EDGE_BOTTOM; | 206 | edge |= WLR_EDGE_BOTTOM; |
208 | } | 207 | } |
209 | 208 | ||
diff --git a/sway/tree/container.c b/sway/tree/container.c index 8ab6ebf8..322f2f67 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -639,8 +639,8 @@ void container_init_floating(struct sway_container *con) { | |||
639 | view->y = ws->y + (ws->height - view->height) / 2; | 639 | view->y = ws->y + (ws->height - view->height) / 2; |
640 | 640 | ||
641 | // If the view's border is B_NONE then these properties are ignored. | 641 | // If the view's border is B_NONE then these properties are ignored. |
642 | view->border_top = view->border_bottom = true; | 642 | con->border_top = con->border_bottom = true; |
643 | view->border_left = view->border_right = true; | 643 | con->border_left = con->border_right = true; |
644 | 644 | ||
645 | container_set_geometry_from_floating_view(con); | 645 | container_set_geometry_from_floating_view(con); |
646 | } | 646 | } |
@@ -662,7 +662,7 @@ void container_set_floating(struct sway_container *container, bool enable) { | |||
662 | if (container->view) { | 662 | if (container->view) { |
663 | view_set_tiled(container->view, false); | 663 | view_set_tiled(container->view, false); |
664 | if (container->view->using_csd) { | 664 | if (container->view->using_csd) { |
665 | container->view->border = B_CSD; | 665 | container->border = B_CSD; |
666 | } | 666 | } |
667 | } | 667 | } |
668 | if (old_parent) { | 668 | if (old_parent) { |
@@ -688,7 +688,7 @@ void container_set_floating(struct sway_container *container, bool enable) { | |||
688 | if (container->view) { | 688 | if (container->view) { |
689 | view_set_tiled(container->view, true); | 689 | view_set_tiled(container->view, true); |
690 | if (container->view->using_csd) { | 690 | if (container->view->using_csd) { |
691 | container->view->border = container->view->saved_border; | 691 | container->border = container->saved_border; |
692 | } | 692 | } |
693 | } | 693 | } |
694 | container->is_sticky = false; | 694 | container->is_sticky = false; |
@@ -710,9 +710,9 @@ void container_set_geometry_from_floating_view(struct sway_container *con) { | |||
710 | size_t border_width = 0; | 710 | size_t border_width = 0; |
711 | size_t top = 0; | 711 | size_t top = 0; |
712 | 712 | ||
713 | if (view->border != B_CSD) { | 713 | if (con->border != B_CSD) { |
714 | border_width = view->border_thickness * (view->border != B_NONE); | 714 | border_width = con->border_thickness * (con->border != B_NONE); |
715 | top = view->border == B_NORMAL ? | 715 | top = con->border == B_NORMAL ? |
716 | container_titlebar_height() : border_width; | 716 | container_titlebar_height() : border_width; |
717 | } | 717 | } |
718 | 718 | ||
diff --git a/sway/tree/view.c b/sway/tree/view.c index 4bc9e0f3..9a89b8ea 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -225,21 +225,21 @@ void view_autoconfigure(struct sway_view *view) { | |||
225 | bool no_gaps = config->hide_edge_borders != E_SMART_NO_GAPS | 225 | bool no_gaps = config->hide_edge_borders != E_SMART_NO_GAPS |
226 | || !gaps_to_edge(view); | 226 | || !gaps_to_edge(view); |
227 | 227 | ||
228 | view->border_top = view->border_bottom = true; | 228 | con->border_top = con->border_bottom = true; |
229 | view->border_left = view->border_right = true; | 229 | con->border_left = con->border_right = true; |
230 | if (config->hide_edge_borders == E_BOTH | 230 | if (config->hide_edge_borders == E_BOTH |
231 | || config->hide_edge_borders == E_VERTICAL | 231 | || config->hide_edge_borders == E_VERTICAL |
232 | || (smart && !other_views && no_gaps)) { | 232 | || (smart && !other_views && no_gaps)) { |
233 | view->border_left = con->x - con->current_gaps != ws->x; | 233 | con->border_left = con->x - con->current_gaps != ws->x; |
234 | int right_x = con->x + con->width + con->current_gaps; | 234 | int right_x = con->x + con->width + con->current_gaps; |
235 | view->border_right = right_x != ws->x + ws->width; | 235 | con->border_right = right_x != ws->x + ws->width; |
236 | } | 236 | } |
237 | if (config->hide_edge_borders == E_BOTH | 237 | if (config->hide_edge_borders == E_BOTH |
238 | || config->hide_edge_borders == E_HORIZONTAL | 238 | || config->hide_edge_borders == E_HORIZONTAL |
239 | || (smart && !other_views && no_gaps)) { | 239 | || (smart && !other_views && no_gaps)) { |
240 | view->border_top = con->y - con->current_gaps != ws->y; | 240 | con->border_top = con->y - con->current_gaps != ws->y; |
241 | int bottom_y = con->y + con->height + con->current_gaps; | 241 | int bottom_y = con->y + con->height + con->current_gaps; |
242 | view->border_bottom = bottom_y != ws->y + ws->height; | 242 | con->border_bottom = bottom_y != ws->y + ws->height; |
243 | } | 243 | } |
244 | 244 | ||
245 | double x, y, width, height; | 245 | double x, y, width, height; |
@@ -252,14 +252,14 @@ void view_autoconfigure(struct sway_view *view) { | |||
252 | enum sway_container_layout layout = container_parent_layout(con); | 252 | enum sway_container_layout layout = container_parent_layout(con); |
253 | if (layout == L_TABBED && !container_is_floating(con)) { | 253 | if (layout == L_TABBED && !container_is_floating(con)) { |
254 | y_offset = container_titlebar_height(); | 254 | y_offset = container_titlebar_height(); |
255 | view->border_top = false; | 255 | con->border_top = false; |
256 | } else if (layout == L_STACKED && !container_is_floating(con)) { | 256 | } else if (layout == L_STACKED && !container_is_floating(con)) { |
257 | list_t *siblings = container_get_siblings(con); | 257 | list_t *siblings = container_get_siblings(con); |
258 | y_offset = container_titlebar_height() * siblings->length; | 258 | y_offset = container_titlebar_height() * siblings->length; |
259 | view->border_top = false; | 259 | con->border_top = false; |
260 | } | 260 | } |
261 | 261 | ||
262 | switch (view->border) { | 262 | switch (con->border) { |
263 | case B_CSD: | 263 | case B_CSD: |
264 | case B_NONE: | 264 | case B_NONE: |
265 | x = con->x; | 265 | x = con->x; |
@@ -268,29 +268,29 @@ void view_autoconfigure(struct sway_view *view) { | |||
268 | height = con->height - y_offset; | 268 | height = con->height - y_offset; |
269 | break; | 269 | break; |
270 | case B_PIXEL: | 270 | case B_PIXEL: |
271 | x = con->x + view->border_thickness * view->border_left; | 271 | x = con->x + con->border_thickness * con->border_left; |
272 | y = con->y + view->border_thickness * view->border_top + y_offset; | 272 | y = con->y + con->border_thickness * con->border_top + y_offset; |
273 | width = con->width | 273 | width = con->width |
274 | - view->border_thickness * view->border_left | 274 | - con->border_thickness * con->border_left |
275 | - view->border_thickness * view->border_right; | 275 | - con->border_thickness * con->border_right; |
276 | height = con->height - y_offset | 276 | height = con->height - y_offset |
277 | - view->border_thickness * view->border_top | 277 | - con->border_thickness * con->border_top |
278 | - view->border_thickness * view->border_bottom; | 278 | - con->border_thickness * con->border_bottom; |
279 | break; | 279 | break; |
280 | case B_NORMAL: | 280 | case B_NORMAL: |
281 | // Height is: 1px border + 3px pad + title height + 3px pad + 1px border | 281 | // Height is: 1px border + 3px pad + title height + 3px pad + 1px border |
282 | x = con->x + view->border_thickness * view->border_left; | 282 | x = con->x + con->border_thickness * con->border_left; |
283 | width = con->width | 283 | width = con->width |
284 | - view->border_thickness * view->border_left | 284 | - con->border_thickness * con->border_left |
285 | - view->border_thickness * view->border_right; | 285 | - con->border_thickness * con->border_right; |
286 | if (y_offset) { | 286 | if (y_offset) { |
287 | y = con->y + y_offset; | 287 | y = con->y + y_offset; |
288 | height = con->height - y_offset | 288 | height = con->height - y_offset |
289 | - view->border_thickness * view->border_bottom; | 289 | - con->border_thickness * con->border_bottom; |
290 | } else { | 290 | } else { |
291 | y = con->y + container_titlebar_height(); | 291 | y = con->y + container_titlebar_height(); |
292 | height = con->height - container_titlebar_height() | 292 | height = con->height - container_titlebar_height() |
293 | - view->border_thickness * view->border_bottom; | 293 | - con->border_thickness * con->border_bottom; |
294 | } | 294 | } |
295 | break; | 295 | break; |
296 | } | 296 | } |
@@ -347,13 +347,14 @@ void view_set_csd_from_server(struct sway_view *view, bool enabled) { | |||
347 | 347 | ||
348 | void view_update_csd_from_client(struct sway_view *view, bool enabled) { | 348 | void view_update_csd_from_client(struct sway_view *view, bool enabled) { |
349 | wlr_log(WLR_DEBUG, "View %p updated CSD to %i", view, enabled); | 349 | wlr_log(WLR_DEBUG, "View %p updated CSD to %i", view, enabled); |
350 | if (enabled && view->border != B_CSD) { | 350 | struct sway_container *con = view->container; |
351 | view->saved_border = view->border; | 351 | if (enabled && con && con->border != B_CSD) { |
352 | if (view->container && container_is_floating(view->container)) { | 352 | con->saved_border = con->border; |
353 | view->border = B_CSD; | 353 | if (container_is_floating(con)) { |
354 | con->border = B_CSD; | ||
354 | } | 355 | } |
355 | } else if (!enabled && view->border == B_CSD) { | 356 | } else if (!enabled && con && con->border == B_CSD) { |
356 | view->border = view->saved_border; | 357 | con->border = con->saved_border; |
357 | } | 358 | } |
358 | view->using_csd = enabled; | 359 | view->using_csd = enabled; |
359 | } | 360 | } |
@@ -584,12 +585,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface, | |||
584 | view->surface_new_subsurface.notify = view_handle_surface_new_subsurface; | 585 | view->surface_new_subsurface.notify = view_handle_surface_new_subsurface; |
585 | 586 | ||
586 | if (view->impl->wants_floating && view->impl->wants_floating(view)) { | 587 | if (view->impl->wants_floating && view->impl->wants_floating(view)) { |
587 | view->border = config->floating_border; | 588 | view->container->border = config->floating_border; |
588 | view->border_thickness = config->floating_border_thickness; | 589 | view->container->border_thickness = config->floating_border_thickness; |
589 | container_set_floating(view->container, true); | 590 | container_set_floating(view->container, true); |
590 | } else { | 591 | } else { |
591 | view->border = config->border; | 592 | view->container->border = config->border; |
592 | view->border_thickness = config->border_thickness; | 593 | view->container->border_thickness = config->border_thickness; |
593 | view_set_tiled(view, true); | 594 | view_set_tiled(view, true); |
594 | } | 595 | } |
595 | 596 | ||