From 54c3e8458b728523b91194d36d85ff8b8e26d4a8 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Thu, 17 Dec 2015 01:39:15 +0100 Subject: [PATCH] Sort workspace on bar by num --- swaybar/main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/swaybar/main.c b/swaybar/main.c index 65d2a493..8e39dbe8 100644 --- a/swaybar/main.c +++ b/swaybar/main.c @@ -98,6 +98,19 @@ void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { (color & 0xFF) / 256.0); } +int workspace_cmp(const void *left, const void *right) { + const struct workspace *a = left, *b = right; + if (a->num > b->num) { + return 1; + } + + if (a->num < b->num) { + return -1; + } + + return 0; +} + void ipc_update_workspaces() { if (workspaces) { free_flat_list(workspaces); @@ -138,6 +151,9 @@ void ipc_update_workspaces() { json_object_put(ws_json); } + // sort by num + list_sort(workspaces, workspace_cmp); + json_object_put(results); free(res); }