aboutsummaryrefslogtreecommitdiff
path: root/sway/output.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2016-05-28 11:08:57 -0400
committerDrew DeVault <sir@cmpwn.com>2016-05-28 11:08:57 -0400
commita0315dc849aacd6e20cf57cb0cbb9ea1d91dce79 (patch)
treed43477a8ead345a7ca3d2f40c4335ec44352ec65 /sway/output.c
parent907283d23094d406ffafca77c75569b2d9de9aaa (diff)
parent7df38ce9dade4708fb658bab88eb5eb4824d3556 (diff)
Merge pull request #675 from zandrmartin/add-workspace-sorting
Implement sort_workspaces() function for outputs.
Diffstat (limited to 'sway/output.c')
-rw-r--r--sway/output.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/sway/output.c b/sway/output.c
index cf8ed9a5..53b24232 100644
--- a/sway/output.c
+++ b/sway/output.c
@@ -1,4 +1,6 @@
#include <strings.h>
+#include <ctype.h>
+#include <stdlib.h>
#include "output.h"
#include "log.h"
@@ -177,3 +179,25 @@ void get_absolute_center_position(swayc_t *container, struct wlc_point *point) {
point->x += container->width/2;
point->y += container->height/2;
}
+
+int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
+ swayc_t *a = *(void **)_a;
+ swayc_t *b = *(void **)_b;
+ int retval = 0;
+
+ if (isdigit(a->name[0]) && isdigit(b->name[0])) {
+ int a_num = strtol(a->name, NULL, 10);
+ int b_num = strtol(b->name, NULL, 10);
+ retval = (a_num < b_num) ? -1 : (a_num > b_num);
+ } else if (isdigit(a->name[0])) {
+ retval = -1;
+ } else if (isdigit(b->name[0])) {
+ retval = 1;
+ }
+
+ return retval;
+}
+
+void sort_workspaces(swayc_t *output) {
+ list_qsort(output->children, sort_workspace_cmp_qsort);
+}