summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--include/output.h3
-rw-r--r--sway/container.c21
-rw-r--r--sway/output.c26
3 files changed, 33 insertions, 17 deletions
diff --git a/include/output.h b/include/output.h
index 1307ead8..12bc478f 100644
--- a/include/output.h
+++ b/include/output.h
@@ -16,4 +16,7 @@ void get_absolute_position(swayc_t *container, struct wlc_point *point);
16// given wlc_point. 16// given wlc_point.
17void get_absolute_center_position(swayc_t *container, struct wlc_point *point); 17void get_absolute_center_position(swayc_t *container, struct wlc_point *point);
18 18
19int sort_workspace_cmp_qsort(const void *a, const void *b);
20void sort_workspaces(swayc_t *output);
21
19#endif 22#endif
diff --git a/sway/container.c b/sway/container.c
index b49b32ee..20b7905b 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -13,6 +13,7 @@
13#include "input_state.h" 13#include "input_state.h"
14#include "log.h" 14#include "log.h"
15#include "ipc-server.h" 15#include "ipc-server.h"
16#include "output.h"
16 17
17#define ASSERT_NONNULL(PTR) \ 18#define ASSERT_NONNULL(PTR) \
18 sway_assert (PTR, #PTR "must be non-null") 19 sway_assert (PTR, #PTR "must be non-null")
@@ -180,24 +181,9 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
180 workspace->visible = false; 181 workspace->visible = false;
181 workspace->floating = create_list(); 182 workspace->floating = create_list();
182 183
183 if (isdigit(workspace->name[0])) { 184 add_child(output, workspace);
184 // find position for numbered workspace 185 sort_workspaces(output);
185 // order: ascending numbers, insert before same number
186 // numbers before unnumbered
187 int num = strtol(workspace->name, NULL, 10);
188 int i;
189 for (i = 0; i < output->children->length; ++i) {
190 char *name = ((swayc_t *)output->children->items[i])->name;
191 if (!isdigit(name[0]) || num <= strtol(name, NULL, 10)) {
192 break;
193 }
194 }
195 insert_child(output, workspace, i);
196 186
197 } else {
198 // append new unnumbered to the end
199 add_child(output, workspace);
200 }
201 return workspace; 187 return workspace;
202} 188}
203 189
@@ -353,6 +339,7 @@ swayc_t *destroy_output(swayc_t *output) {
353 remove_child(child); 339 remove_child(child);
354 add_child(root_container.children->items[p], child); 340 add_child(root_container.children->items[p], child);
355 } 341 }
342 sort_workspaces(root_container.children->items[p]);
356 update_visibility(root_container.children->items[p]); 343 update_visibility(root_container.children->items[p]);
357 arrange_windows(root_container.children->items[p], -1, -1); 344 arrange_windows(root_container.children->items[p], -1, -1);
358 } 345 }
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}