diff options
Diffstat (limited to 'sway/tree/output.c')
-rw-r--r-- | sway/tree/output.c | 23 |
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 | ||
34 | struct sway_container *output_create( | 35 | struct sway_container *output_create( |
@@ -102,3 +103,23 @@ struct sway_container *output_create( | |||
102 | return output; | 103 | return output; |
103 | } | 104 | } |
104 | 105 | ||
106 | static 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 | |||
122 | void output_sort_workspaces(struct sway_container *output) { | ||
123 | list_stable_sort(output->children, sort_workspace_cmp_qsort); | ||
124 | } | ||
125 | |||