aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/border.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-31 20:28:36 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-10-31 23:56:20 +1000
commit528c7495bb09e18a8b63e1c741b90f65ff5541c6 (patch)
treeb1dddeefb15f2511b33f7bed52d0df3b4110d8f8 /sway/commands/border.c
parentMerge pull request #3031 from atomnuker/master (diff)
downloadsway-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/commands/border.c')
-rw-r--r--sway/commands/border.c60
1 files changed, 32 insertions, 28 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.
15static void set_border(struct sway_view *view, 15static 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
29static void border_toggle(struct sway_view *view) { 33static 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}