From aeda2e077f6184ecd26dc078c7b5db7f0dc54fd7 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 22 Nov 2017 20:39:27 -0500 Subject: Add workspace to outputs --- sway/tree/layout.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'sway/tree/layout.c') diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 06200bbf..5a70c570 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -1,5 +1,7 @@ #define _POSIX_C_SOURCE 200809L +#include #include +#include #include #include #include "sway/container.h" @@ -33,3 +35,38 @@ void add_child(swayc_t *parent, swayc_t *child) { } */ } + +enum swayc_layouts default_layout(swayc_t *output) { + /* TODO WLR + if (config->default_layout != L_NONE) { + //return config->default_layout; + } else if (config->default_orientation != L_NONE) { + return config->default_orientation; + } else */if (output->width >= output->height) { + return L_HORIZ; + } else { + return L_VERT; + } +} + +static 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_stable_sort(output->children, sort_workspace_cmp_qsort); +} -- cgit v1.2.3-54-g00ecf