diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2019-01-28 19:06:42 +1000 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2019-01-28 10:35:40 +0100 |
commit | 6b8bf10941ec83ac7a6e364b9c34f8c6f74d814a (patch) | |
tree | 61a9e61c64fd1b88a79b06a6f9dafeb84e4f8c35 /sway/tree | |
parent | Add note about required scdoc version to README. (diff) | |
download | sway-6b8bf10941ec83ac7a6e364b9c34f8c6f74d814a.tar.gz sway-6b8bf10941ec83ac7a6e364b9c34f8c6f74d814a.tar.zst sway-6b8bf10941ec83ac7a6e364b9c34f8c6f74d814a.zip |
Introduce container_is_scratchpad_hidden
Just a convenience function that improves readability of the code.
Other things worth noting:
* container_get_siblings and container_sibling_index no longer use the
const keyword
* container_handle_fullscreen_reparent is only ever called after
attaching the container to a workspace, so its con->workspace check has
been changed to an assertion
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/container.c | 15 | ||||
-rw-r--r-- | sway/tree/root.c | 7 | ||||
-rw-r--r-- | sway/tree/view.c | 5 |
3 files changed, 15 insertions, 12 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 1cf5c8e7..e20e44d4 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -1156,11 +1156,11 @@ enum sway_container_layout container_current_parent_layout( | |||
1156 | return con->current.workspace->current.layout; | 1156 | return con->current.workspace->current.layout; |
1157 | } | 1157 | } |
1158 | 1158 | ||
1159 | list_t *container_get_siblings(const struct sway_container *container) { | 1159 | list_t *container_get_siblings(struct sway_container *container) { |
1160 | if (container->parent) { | 1160 | if (container->parent) { |
1161 | return container->parent->children; | 1161 | return container->parent->children; |
1162 | } | 1162 | } |
1163 | if (!container->workspace) { | 1163 | if (container_is_scratchpad_hidden(container)) { |
1164 | return NULL; | 1164 | return NULL; |
1165 | } | 1165 | } |
1166 | if (list_find(container->workspace->tiling, container) != -1) { | 1166 | if (list_find(container->workspace->tiling, container) != -1) { |
@@ -1169,7 +1169,7 @@ list_t *container_get_siblings(const struct sway_container *container) { | |||
1169 | return container->workspace->floating; | 1169 | return container->workspace->floating; |
1170 | } | 1170 | } |
1171 | 1171 | ||
1172 | int container_sibling_index(const struct sway_container *child) { | 1172 | int container_sibling_index(struct sway_container *child) { |
1173 | return list_find(container_get_siblings(child), child); | 1173 | return list_find(container_get_siblings(child), child); |
1174 | } | 1174 | } |
1175 | 1175 | ||
@@ -1181,7 +1181,10 @@ list_t *container_get_current_siblings(struct sway_container *container) { | |||
1181 | } | 1181 | } |
1182 | 1182 | ||
1183 | void container_handle_fullscreen_reparent(struct sway_container *con) { | 1183 | void container_handle_fullscreen_reparent(struct sway_container *con) { |
1184 | if (con->fullscreen_mode != FULLSCREEN_WORKSPACE || !con->workspace || | 1184 | if (!sway_assert(con->workspace, "Expected con to have a workspace")) { |
1185 | return; | ||
1186 | } | ||
1187 | if (con->fullscreen_mode != FULLSCREEN_WORKSPACE || | ||
1185 | con->workspace->fullscreen == con) { | 1188 | con->workspace->fullscreen == con) { |
1186 | return; | 1189 | return; |
1187 | } | 1190 | } |
@@ -1460,3 +1463,7 @@ void container_raise_floating(struct sway_container *con) { | |||
1460 | node_set_dirty(&floater->workspace->node); | 1463 | node_set_dirty(&floater->workspace->node); |
1461 | } | 1464 | } |
1462 | } | 1465 | } |
1466 | |||
1467 | bool container_is_scratchpad_hidden(struct sway_container *con) { | ||
1468 | return con->scratchpad && !con->workspace; | ||
1469 | } | ||
diff --git a/sway/tree/root.c b/sway/tree/root.c index 476e47a3..6e13d6ce 100644 --- a/sway/tree/root.c +++ b/sway/tree/root.c | |||
@@ -310,10 +310,7 @@ void root_for_each_container(void (*f)(struct sway_container *con, void *data), | |||
310 | // Scratchpad | 310 | // Scratchpad |
311 | for (int i = 0; i < root->scratchpad->length; ++i) { | 311 | for (int i = 0; i < root->scratchpad->length; ++i) { |
312 | struct sway_container *container = root->scratchpad->items[i]; | 312 | struct sway_container *container = root->scratchpad->items[i]; |
313 | // If the container has a workspace then it's visible on a workspace | 313 | if (container_is_scratchpad_hidden(container)) { |
314 | // and will have been iterated in the previous for loop. So we only | ||
315 | // iterate the hidden scratchpad containers here. | ||
316 | if (!container->workspace) { | ||
317 | f(container, data); | 314 | f(container, data); |
318 | container_for_each_child(container, f, data); | 315 | container_for_each_child(container, f, data); |
319 | } | 316 | } |
@@ -362,7 +359,7 @@ struct sway_container *root_find_container( | |||
362 | // Scratchpad | 359 | // Scratchpad |
363 | for (int i = 0; i < root->scratchpad->length; ++i) { | 360 | for (int i = 0; i < root->scratchpad->length; ++i) { |
364 | struct sway_container *container = root->scratchpad->items[i]; | 361 | struct sway_container *container = root->scratchpad->items[i]; |
365 | if (!container->workspace) { | 362 | if (container_is_scratchpad_hidden(container)) { |
366 | if (test(container, data)) { | 363 | if (test(container, data)) { |
367 | return container; | 364 | return container; |
368 | } | 365 | } |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 9ccb2a31..612cf96a 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -197,8 +197,7 @@ static bool gaps_to_edge(struct sway_view *view) { | |||
197 | 197 | ||
198 | void view_autoconfigure(struct sway_view *view) { | 198 | void view_autoconfigure(struct sway_view *view) { |
199 | struct sway_container *con = view->container; | 199 | struct sway_container *con = view->container; |
200 | if (!con->workspace) { | 200 | if (container_is_scratchpad_hidden(con)) { |
201 | // Hidden in the scratchpad | ||
202 | return; | 201 | return; |
203 | } | 202 | } |
204 | struct sway_output *output = con->workspace->output; | 203 | struct sway_output *output = con->workspace->output; |
@@ -1054,7 +1053,7 @@ void view_set_urgent(struct sway_view *view, bool enable) { | |||
1054 | 1053 | ||
1055 | ipc_event_window(view->container, "urgent"); | 1054 | ipc_event_window(view->container, "urgent"); |
1056 | 1055 | ||
1057 | if (view->container->workspace) { | 1056 | if (!container_is_scratchpad_hidden(view->container)) { |
1058 | workspace_detect_urgent(view->container->workspace); | 1057 | workspace_detect_urgent(view->container->workspace); |
1059 | } | 1058 | } |
1060 | } | 1059 | } |