diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-05-28 11:08:57 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-05-28 11:08:57 -0400 |
commit | a0315dc849aacd6e20cf57cb0cbb9ea1d91dce79 (patch) | |
tree | d43477a8ead345a7ca3d2f40c4335ec44352ec65 | |
parent | Merge pull request #673 from zandrmartin/swaylock-no-unlock-indicator (diff) | |
parent | remove alphabetic sorting from sort_workspaces (diff) | |
download | sway-a0315dc849aacd6e20cf57cb0cbb9ea1d91dce79.tar.gz sway-a0315dc849aacd6e20cf57cb0cbb9ea1d91dce79.tar.zst sway-a0315dc849aacd6e20cf57cb0cbb9ea1d91dce79.zip |
Merge pull request #675 from zandrmartin/add-workspace-sorting
Implement sort_workspaces() function for outputs.
-rw-r--r-- | include/output.h | 3 | ||||
-rw-r--r-- | sway/commands.c | 4 | ||||
-rw-r--r-- | sway/container.c | 21 | ||||
-rw-r--r-- | sway/output.c | 24 |
4 files changed, 33 insertions, 19 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. |
17 | void get_absolute_center_position(swayc_t *container, struct wlc_point *point); | 17 | void get_absolute_center_position(swayc_t *container, struct wlc_point *point); |
18 | 18 | ||
19 | int sort_workspace_cmp_qsort(const void *a, const void *b); | ||
20 | void sort_workspaces(swayc_t *output); | ||
21 | |||
19 | #endif | 22 | #endif |
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) { | |||
2328 | if (!(ws=workspace_by_number(argv[1]))) { | 2328 | if (!(ws=workspace_by_number(argv[1]))) { |
2329 | ws = workspace_create(argv[1]); | 2329 | ws = workspace_create(argv[1]); |
2330 | } | 2330 | } |
2331 | }else if (strcasecmp(argv[0], "next") == 0) { | 2331 | } else if (strcasecmp(argv[0], "next") == 0) { |
2332 | ws = workspace_next(); | 2332 | ws = workspace_next(); |
2333 | } else if (strcasecmp(argv[0], "prev") == 0) { | 2333 | } else if (strcasecmp(argv[0], "prev") == 0) { |
2334 | ws = workspace_prev(); | 2334 | ws = workspace_prev(); |
@@ -2343,7 +2343,7 @@ static struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
2343 | } | 2343 | } |
2344 | } | 2344 | } |
2345 | } else { | 2345 | } else { |
2346 | if (!(ws= workspace_by_name(argv[0]))) { | 2346 | if (!(ws = workspace_by_name(argv[0]))) { |
2347 | ws = workspace_create(argv[0]); | 2347 | ws = workspace_create(argv[0]); |
2348 | } | 2348 | } |
2349 | } | 2349 | } |
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..53b24232 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,25 @@ 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 | |||
183 | int 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 | } | ||
197 | |||
198 | return retval; | ||
199 | } | ||
200 | |||
201 | void sort_workspaces(swayc_t *output) { | ||
202 | list_qsort(output->children, sort_workspace_cmp_qsort); | ||
203 | } | ||