mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 08:21:28 +00:00
Merge pull request #675 from zandrmartin/add-workspace-sorting
Implement sort_workspaces() function for outputs.
This commit is contained in:
commit
a0315dc849
|
@ -16,4 +16,7 @@ void get_absolute_position(swayc_t *container, struct wlc_point *point);
|
||||||
// given wlc_point.
|
// given wlc_point.
|
||||||
void get_absolute_center_position(swayc_t *container, struct wlc_point *point);
|
void get_absolute_center_position(swayc_t *container, struct wlc_point *point);
|
||||||
|
|
||||||
|
int sort_workspace_cmp_qsort(const void *a, const void *b);
|
||||||
|
void sort_workspaces(swayc_t *output);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "input_state.h"
|
#include "input_state.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "ipc-server.h"
|
#include "ipc-server.h"
|
||||||
|
#include "output.h"
|
||||||
|
|
||||||
#define ASSERT_NONNULL(PTR) \
|
#define ASSERT_NONNULL(PTR) \
|
||||||
sway_assert (PTR, #PTR "must be non-null")
|
sway_assert (PTR, #PTR "must be non-null")
|
||||||
|
@ -180,24 +181,9 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
|
||||||
workspace->visible = false;
|
workspace->visible = false;
|
||||||
workspace->floating = create_list();
|
workspace->floating = create_list();
|
||||||
|
|
||||||
if (isdigit(workspace->name[0])) {
|
|
||||||
// find position for numbered workspace
|
|
||||||
// order: ascending numbers, insert before same number
|
|
||||||
// numbers before unnumbered
|
|
||||||
int num = strtol(workspace->name, NULL, 10);
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < output->children->length; ++i) {
|
|
||||||
char *name = ((swayc_t *)output->children->items[i])->name;
|
|
||||||
if (!isdigit(name[0]) || num <= strtol(name, NULL, 10)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
insert_child(output, workspace, i);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// append new unnumbered to the end
|
|
||||||
add_child(output, workspace);
|
add_child(output, workspace);
|
||||||
}
|
sort_workspaces(output);
|
||||||
|
|
||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,6 +339,7 @@ swayc_t *destroy_output(swayc_t *output) {
|
||||||
remove_child(child);
|
remove_child(child);
|
||||||
add_child(root_container.children->items[p], child);
|
add_child(root_container.children->items[p], child);
|
||||||
}
|
}
|
||||||
|
sort_workspaces(root_container.children->items[p]);
|
||||||
update_visibility(root_container.children->items[p]);
|
update_visibility(root_container.children->items[p]);
|
||||||
arrange_windows(root_container.children->items[p], -1, -1);
|
arrange_windows(root_container.children->items[p], -1, -1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "log.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->x += container->width/2;
|
||||||
point->y += container->height/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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue