diff options
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r-- | sway/tree/layout.c | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 617350d9..5abdbc32 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -1,5 +1,4 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <assert.h> | ||
3 | #include <ctype.h> | 2 | #include <ctype.h> |
4 | #include <math.h> | 3 | #include <math.h> |
5 | #include <stdbool.h> | 4 | #include <stdbool.h> |
@@ -52,6 +51,19 @@ static void output_layout_handle_change(struct wl_listener *listener, | |||
52 | arrange_windows(&root_container, -1, -1); | 51 | arrange_windows(&root_container, -1, -1); |
53 | } | 52 | } |
54 | 53 | ||
54 | struct sway_container *container_set_layout(struct sway_container *container, | ||
55 | enum sway_container_layout layout) { | ||
56 | if (container->type == C_WORKSPACE) { | ||
57 | container->workspace_layout = layout; | ||
58 | if (layout == L_HORIZ || layout == L_VERT) { | ||
59 | container->layout = layout; | ||
60 | } | ||
61 | } else { | ||
62 | container->layout = layout; | ||
63 | } | ||
64 | return container; | ||
65 | } | ||
66 | |||
55 | void layout_init(void) { | 67 | void layout_init(void) { |
56 | root_container.id = 0; // normally assigned in new_swayc() | 68 | root_container.id = 0; // normally assigned in new_swayc() |
57 | root_container.type = C_ROOT; | 69 | root_container.type = C_ROOT; |
@@ -107,32 +119,6 @@ void container_add_child(struct sway_container *parent, | |||
107 | child->parent = parent; | 119 | child->parent = parent; |
108 | } | 120 | } |
109 | 121 | ||
110 | struct sway_container *container_reap_empty(struct sway_container *container) { | ||
111 | if (container == NULL) { | ||
112 | return NULL; | ||
113 | } | ||
114 | wlr_log(L_DEBUG, "Reaping %p %s '%s'", container, | ||
115 | container_type_to_str(container->type), container->name); | ||
116 | while (container->type != C_ROOT && container->type != C_OUTPUT | ||
117 | && container->children->length == 0) { | ||
118 | if (container->type == C_WORKSPACE) { | ||
119 | if (!workspace_is_visible(container)) { | ||
120 | struct sway_container *parent = container->parent; | ||
121 | container_workspace_destroy(container); | ||
122 | return parent; | ||
123 | } | ||
124 | return container; | ||
125 | } else if (container->type == C_CONTAINER) { | ||
126 | struct sway_container *parent = container->parent; | ||
127 | container_destroy(container); | ||
128 | container = parent; | ||
129 | } else { | ||
130 | container = container->parent; | ||
131 | } | ||
132 | } | ||
133 | return container; | ||
134 | } | ||
135 | |||
136 | struct sway_container *container_remove_child(struct sway_container *child) { | 122 | struct sway_container *container_remove_child(struct sway_container *child) { |
137 | struct sway_container *parent = child->parent; | 123 | struct sway_container *parent = child->parent; |
138 | for (int i = 0; i < parent->children->length; ++i) { | 124 | for (int i = 0; i < parent->children->length; ++i) { |
@@ -167,7 +153,7 @@ void container_move_to(struct sway_container *container, | |||
167 | if (old_parent->children->length == 0) { | 153 | if (old_parent->children->length == 0) { |
168 | char *ws_name = workspace_next_name(old_parent->name); | 154 | char *ws_name = workspace_next_name(old_parent->name); |
169 | struct sway_container *ws = | 155 | struct sway_container *ws = |
170 | container_workspace_create(old_parent, ws_name); | 156 | workspace_create(old_parent, ws_name); |
171 | free(ws_name); | 157 | free(ws_name); |
172 | seat_set_focus(seat, ws); | 158 | seat_set_focus(seat, ws); |
173 | } | 159 | } |
@@ -186,12 +172,22 @@ void container_move(struct sway_container *container, | |||
186 | } | 172 | } |
187 | 173 | ||
188 | enum sway_container_layout container_get_default_layout( | 174 | enum sway_container_layout container_get_default_layout( |
189 | struct sway_container *output) { | 175 | struct sway_container *con) { |
176 | if (con->type != C_OUTPUT) { | ||
177 | con = container_parent(con, C_OUTPUT); | ||
178 | } | ||
179 | |||
180 | if (!sway_assert(con != NULL, | ||
181 | "container_get_default_layout must be called on an attached" | ||
182 | " container below the root container")) { | ||
183 | return 0; | ||
184 | } | ||
185 | |||
190 | if (config->default_layout != L_NONE) { | 186 | if (config->default_layout != L_NONE) { |
191 | return config->default_layout; | 187 | return config->default_layout; |
192 | } else if (config->default_orientation != L_NONE) { | 188 | } else if (config->default_orientation != L_NONE) { |
193 | return config->default_orientation; | 189 | return config->default_orientation; |
194 | } else if (output->width >= output->height) { | 190 | } else if (con->width >= con->height) { |
195 | return L_HORIZ; | 191 | return L_HORIZ; |
196 | } else { | 192 | } else { |
197 | return L_VERT; | 193 | return L_VERT; |