aboutsummaryrefslogtreecommitdiff
path: root/sway/tree/output.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-08-18 10:29:46 -0400
committerGitHub <noreply@github.com>2018-08-18 10:29:46 -0400
commit744724b3cb28c2ee9d265dcbf78b1cbf2b2e3fef (patch)
tree7a5ebeae1d5e15f047f09698978fa84f61756faa /sway/tree/output.c
parentd4a32800d5eb938a769d7802b23f4a0f43cadaef (diff)
parentd6cd79c342495738fc23fbfbf19a01e73cdc42dc (diff)
Merge pull request #2473 from RyanDwyer/iterators-per-type
Implement iterators per container type
Diffstat (limited to 'sway/tree/output.c')
-rw-r--r--sway/tree/output.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/sway/tree/output.c b/sway/tree/output.c
index ab955359..6da63064 100644
--- a/sway/tree/output.c
+++ b/sway/tree/output.c
@@ -103,6 +103,57 @@ struct sway_container *output_create(
return output;
}
+void output_for_each_workspace(struct sway_container *output,
+ void (*f)(struct sway_container *con, void *data), void *data) {
+ if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
+ return;
+ }
+ for (int i = 0; i < output->children->length; ++i) {
+ struct sway_container *workspace = output->children->items[i];
+ f(workspace, data);
+ }
+}
+
+void output_for_each_container(struct sway_container *output,
+ void (*f)(struct sway_container *con, void *data), void *data) {
+ if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
+ return;
+ }
+ for (int i = 0; i < output->children->length; ++i) {
+ struct sway_container *workspace = output->children->items[i];
+ workspace_for_each_container(workspace, f, data);
+ }
+}
+
+struct sway_container *output_find_workspace(struct sway_container *output,
+ bool (*test)(struct sway_container *con, void *data), void *data) {
+ if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
+ return NULL;
+ }
+ for (int i = 0; i < output->children->length; ++i) {
+ struct sway_container *workspace = output->children->items[i];
+ if (test(workspace, data)) {
+ return workspace;
+ }
+ }
+ return NULL;
+}
+
+struct sway_container *output_find_container(struct sway_container *output,
+ bool (*test)(struct sway_container *con, void *data), void *data) {
+ if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
+ return NULL;
+ }
+ struct sway_container *result = NULL;
+ for (int i = 0; i < output->children->length; ++i) {
+ struct sway_container *workspace = output->children->items[i];
+ if ((result = workspace_find_container(workspace, test, data))) {
+ return result;
+ }
+ }
+ return NULL;
+}
+
static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
struct sway_container *a = *(void **)_a;
struct sway_container *b = *(void **)_b;
@@ -122,4 +173,3 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
void output_sort_workspaces(struct sway_container *output) {
list_stable_sort(output->children, sort_workspace_cmp_qsort);
}
-