aboutsummaryrefslogtreecommitdiffstats
path: root/sway/output.c
diff options
context:
space:
mode:
authorLibravatar Zandr Martin <zandrmartin+git@gmail.com>2016-05-27 17:37:56 -0500
committerLibravatar Zandr Martin <zandrmartin+git@gmail.com>2016-05-27 17:37:56 -0500
commitc6c3a8e7586c0fe14fba2fcd3fc856765169250e (patch)
tree46446abe682a7a163c9f28da77e75e5c7360621a /sway/output.c
parentMerge pull request #673 from zandrmartin/swaylock-no-unlock-indicator (diff)
downloadsway-c6c3a8e7586c0fe14fba2fcd3fc856765169250e.tar.gz
sway-c6c3a8e7586c0fe14fba2fcd3fc856765169250e.tar.zst
sway-c6c3a8e7586c0fe14fba2fcd3fc856765169250e.zip
Implement sort_workspaces() function for outputs.
This seems to have resolved issue #669 for me.
Diffstat (limited to 'sway/output.c')
-rw-r--r--sway/output.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/sway/output.c b/sway/output.c
index cf8ed9a5..046dee8c 100644
--- a/sway/output.c
+++ b/sway/output.c
@@ -1,4 +1,6 @@
1#include <strings.h> 1#include <strings.h>
2#include <ctype.h>
3#include <stdlib.h>
2#include "output.h" 4#include "output.h"
3#include "log.h" 5#include "log.h"
4 6
@@ -177,3 +179,27 @@ void get_absolute_center_position(swayc_t *container, struct wlc_point *point) {
177 point->x += container->width/2; 179 point->x += container->width/2;
178 point->y += container->height/2; 180 point->y += container->height/2;
179} 181}
182
183int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
184 swayc_t *a = *(void **)_a;
185 swayc_t *b = *(void **)_b;
186 int retval = 0;
187
188 if (isdigit(a->name[0]) && isdigit(b->name[0])) {
189 int a_num = strtol(a->name, NULL, 10);
190 int b_num = strtol(b->name, NULL, 10);
191 retval = (a_num < b_num) ? -1 : (a_num > b_num);
192 } else if (isdigit(a->name[0])) {
193 retval = -1;
194 } else if (isdigit(b->name[0])) {
195 retval = 1;
196 } else {
197 retval = strcmp(a->name, b->name);
198 }
199
200 return retval;
201}
202
203void sort_workspaces(swayc_t *output) {
204 list_qsort(output->children, sort_workspace_cmp_qsort);
205}