From c6c3a8e7586c0fe14fba2fcd3fc856765169250e Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Fri, 27 May 2016 17:37:56 -0500 Subject: Implement sort_workspaces() function for outputs. This seems to have resolved issue #669 for me. --- sway/output.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'sway/output.c') 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 @@ #include +#include +#include #include "output.h" #include "log.h" @@ -177,3 +179,27 @@ 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; + } else { + retval = strcmp(a->name, b->name); + } + + return retval; +} + +void sort_workspaces(swayc_t *output) { + list_qsort(output->children, sort_workspace_cmp_qsort); +} -- cgit v1.2.3 From 7df38ce9dade4708fb658bab88eb5eb4824d3556 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Sat, 28 May 2016 08:35:58 -0500 Subject: remove alphabetic sorting from sort_workspaces also add a couple missing spaces to container.c (unrelated) --- sway/commands.c | 4 ++-- sway/output.c | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'sway/output.c') diff --git a/sway/commands.c b/sway/commands.c index fbdb5fb8..487b6a8e 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -2328,7 +2328,7 @@ static struct cmd_results *cmd_workspace(int argc, char **argv) { if (!(ws=workspace_by_number(argv[1]))) { ws = workspace_create(argv[1]); } - }else if (strcasecmp(argv[0], "next") == 0) { + } else if (strcasecmp(argv[0], "next") == 0) { ws = workspace_next(); } else if (strcasecmp(argv[0], "prev") == 0) { ws = workspace_prev(); @@ -2343,7 +2343,7 @@ static struct cmd_results *cmd_workspace(int argc, char **argv) { } } } else { - if (!(ws= workspace_by_name(argv[0]))) { + if (!(ws = workspace_by_name(argv[0]))) { ws = workspace_create(argv[0]); } } diff --git a/sway/output.c b/sway/output.c index 046dee8c..53b24232 100644 --- a/sway/output.c +++ b/sway/output.c @@ -193,8 +193,6 @@ int sort_workspace_cmp_qsort(const void *_a, const void *_b) { retval = -1; } else if (isdigit(b->name[0])) { retval = 1; - } else { - retval = strcmp(a->name, b->name); } return retval; -- cgit v1.2.3