aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/root.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/root.c')
-rw-r--r--sway/tree/root.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/sway/tree/root.c b/sway/tree/root.c
index fc908cc1..8d8f42dc 100644
--- a/sway/tree/root.c
+++ b/sway/tree/root.c
@@ -256,3 +256,81 @@ void root_record_workspace_pid(pid_t pid) {
256 &pw->output_destroy); 256 &pw->output_destroy);
257 wl_list_insert(&pid_workspaces, &pw->link); 257 wl_list_insert(&pid_workspaces, &pw->link);
258} 258}
259
260void root_for_each_workspace(void (*f)(struct sway_container *con, void *data),
261 void *data) {
262 for (int i = 0; i < root_container.children->length; ++i) {
263 struct sway_container *output = root_container.children->items[i];
264 output_for_each_workspace(output, f, data);
265 }
266}
267
268void root_for_each_container(void (*f)(struct sway_container *con, void *data),
269 void *data) {
270 for (int i = 0; i < root_container.children->length; ++i) {
271 struct sway_container *output = root_container.children->items[i];
272 output_for_each_container(output, f, data);
273 }
274
275 // Scratchpad
276 for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) {
277 struct sway_container *container =
278 root_container.sway_root->scratchpad->items[i];
279 // If the container has a parent then it's visible on a workspace
280 // and will have been iterated in the previous for loop. So we only
281 // iterate the hidden scratchpad containers here.
282 if (!container->parent) {
283 f(container, data);
284 container_for_each_child(container, f, data);
285 }
286 }
287}
288
289struct sway_container *root_find_output(
290 bool (*test)(struct sway_container *con, void *data), void *data) {
291 for (int i = 0; i < root_container.children->length; ++i) {
292 struct sway_container *output = root_container.children->items[i];
293 if (test(output, data)) {
294 return output;
295 }
296 }
297 return NULL;
298}
299
300struct sway_container *root_find_workspace(
301 bool (*test)(struct sway_container *con, void *data), void *data) {
302 struct sway_container *result = NULL;
303 for (int i = 0; i < root_container.children->length; ++i) {
304 struct sway_container *output = root_container.children->items[i];
305 if ((result = output_find_workspace(output, test, data))) {
306 return result;
307 }
308 }
309 return NULL;
310}
311
312struct sway_container *root_find_container(
313 bool (*test)(struct sway_container *con, void *data), void *data) {
314 struct sway_container *result = NULL;
315 for (int i = 0; i < root_container.children->length; ++i) {
316 struct sway_container *output = root_container.children->items[i];
317 if ((result = output_find_container(output, test, data))) {
318 return result;
319 }
320 }
321
322 // Scratchpad
323 for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) {
324 struct sway_container *container =
325 root_container.sway_root->scratchpad->items[i];
326 if (!container->parent) {
327 if (test(container, data)) {
328 return container;
329 }
330 if ((result = container_find_child(container, test, data))) {
331 return result;
332 }
333 }
334 }
335 return NULL;
336}