sowm

An itsy bitsy floating window manager (220~ sloc!).
git clone git://mfeller.io/sowm.git
Log | Files | Refs | README | LICENSE

commit 7fe47aefc193da8dd21a59fd1499be764dc46e82
parent 0fa485eb7b54df67c0bb6713de3436d449d4aba5
Author: Dylan Araps <dylan.araps@gmail.com>
Date:   Sat, 19 Oct 2019 00:16:19 +0300

sowm: swap to circular doubly linked list

Diffstat:
Msowm.c | 61++++++++++++++++++++++++-------------------------------------
1 file changed, 24 insertions(+), 37 deletions(-)

diff --git a/sowm.c b/sowm.c @@ -66,7 +66,7 @@ static void (*events[LASTEvent])(XEvent *e) = { #include "config.h" -#define win (client *c=list;c;c=c->next) +#define win (client *t=0, *c=list; c && t!=list->prev; t=c, c=c->next) #define win_focus(W) XSetInputFocus(d, W, RevertToParent, CurrentTime) #define ws_save(W) ws_list[W] = list #define ws_sel(W) list = ws_list[ws = W] @@ -130,53 +130,40 @@ void button_release() { } void win_add(Window w) { - client *c, *t; + client *c; - if (!(c = (client *)calloc(1, sizeof(client)))) + if (!(c = (client *) calloc(1, sizeof(client)))) exit(1); - if (!list) { - c->next = c->prev = 0; - c->w = w; - list = c; + c->w = w; - } else { - for (t=list;t->next;t=t->next); + if (list) { + list->prev->next = c; + c->prev = list->prev; + list->prev = c; + c->next = list; - c->next = 0; - c->prev = t; - c->w = w; - t->next = c; + } else { + list = c; + list->prev = list->next = list; } ws_save(ws); } void win_del(Window w) { - for win if (c->w == w) { - if (!c->prev && !c->next) { - free(list); - list = 0; - ws_save(ws); - return; - } - - if (!c->prev) { - list = c->next; - c->next->prev = 0; - - } else if (!c->next) { - c->prev->next = 0; - - } else { - c->prev->next = c->next; - c->next->prev = c->prev; - } - - free(c); - ws_save(ws); - return; - } + client *x = 0; + + for win if (c->w == w) x = c; + + if (!list || !x) return; + if (x->prev == x) list = 0; + if (list == x) list = x->next; + if (x->next) x->next->prev = x->prev; + if (x->prev) x->prev->next = x->next; + + free(x); + ws_save(ws); } void win_kill() {