aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/output.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-18 21:54:09 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-18 22:02:03 +1000
commit16c663ed49e3950388901f220066e4da69956dfb (patch)
treebf71a43528328a786be1a4de02781e6e83aea406 /sway/tree/output.c
parentMerge pull request #2480 from RyanDwyer/fix-mod-resize (diff)
downloadsway-16c663ed49e3950388901f220066e4da69956dfb.tar.gz
sway-16c663ed49e3950388901f220066e4da69956dfb.tar.zst
sway-16c663ed49e3950388901f220066e4da69956dfb.zip
Rename container_sort_workspaces and container_wrap_children
This commit renames container_sort_workspaces to output_sort_workspaces and moves it to output.c. This also renames container_wrap_children to workspace_wrap_children and moves it to workspace.c. This function is only called with workspaces.
Diffstat (limited to 'sway/tree/output.c')
-rw-r--r--sway/tree/output.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/sway/tree/output.c b/sway/tree/output.c
index 31e3bf9b..ab955359 100644
--- a/sway/tree/output.c
+++ b/sway/tree/output.c
@@ -1,4 +1,5 @@
1#define _POSIX_C_SOURCE 200809L 1#define _POSIX_C_SOURCE 200809L
2#include <ctype.h>
2#include <string.h> 3#include <string.h>
3#include <strings.h> 4#include <strings.h>
4#include "sway/ipc-server.h" 5#include "sway/ipc-server.h"
@@ -28,7 +29,7 @@ static void restore_workspaces(struct sway_container *output) {
28 } 29 }
29 } 30 }
30 31
31 container_sort_workspaces(output); 32 output_sort_workspaces(output);
32} 33}
33 34
34struct sway_container *output_create( 35struct sway_container *output_create(
@@ -102,3 +103,23 @@ struct sway_container *output_create(
102 return output; 103 return output;
103} 104}
104 105
106static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
107 struct sway_container *a = *(void **)_a;
108 struct sway_container *b = *(void **)_b;
109
110 if (isdigit(a->name[0]) && isdigit(b->name[0])) {
111 int a_num = strtol(a->name, NULL, 10);
112 int b_num = strtol(b->name, NULL, 10);
113 return (a_num < b_num) ? -1 : (a_num > b_num);
114 } else if (isdigit(a->name[0])) {
115 return -1;
116 } else if (isdigit(b->name[0])) {
117 return 1;
118 }
119 return 0;
120}
121
122void output_sort_workspaces(struct sway_container *output) {
123 list_stable_sort(output->children, sort_workspace_cmp_qsort);
124}
125