mirror of
https://github.com/dylanaraps/sowm.git
synced 2025-05-19 09:30:24 -07:00
sowm: swap to circular doubly linked list
This commit is contained in:
parent
0fa485eb7b
commit
7fe47aefc1
55
sowm.c
55
sowm.c
@ -66,7 +66,7 @@ static void (*events[LASTEvent])(XEvent *e) = {
|
|||||||
|
|
||||||
#include "config.h"
|
#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 win_focus(W) XSetInputFocus(d, W, RevertToParent, CurrentTime)
|
||||||
#define ws_save(W) ws_list[W] = list
|
#define ws_save(W) ws_list[W] = list
|
||||||
#define ws_sel(W) list = ws_list[ws = W]
|
#define ws_sel(W) list = ws_list[ws = W]
|
||||||
@ -130,53 +130,40 @@ void button_release() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void win_add(Window w) {
|
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);
|
exit(1);
|
||||||
|
|
||||||
if (!list) {
|
c->w = w;
|
||||||
c->next = c->prev = 0;
|
|
||||||
c->w = w;
|
if (list) {
|
||||||
list = c;
|
list->prev->next = c;
|
||||||
|
c->prev = list->prev;
|
||||||
|
list->prev = c;
|
||||||
|
c->next = list;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for (t=list;t->next;t=t->next);
|
list = c;
|
||||||
|
list->prev = list->next = list;
|
||||||
c->next = 0;
|
|
||||||
c->prev = t;
|
|
||||||
c->w = w;
|
|
||||||
t->next = c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ws_save(ws);
|
ws_save(ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
void win_del(Window w) {
|
void win_del(Window w) {
|
||||||
for win if (c->w == w) {
|
client *x = 0;
|
||||||
if (!c->prev && !c->next) {
|
|
||||||
free(list);
|
|
||||||
list = 0;
|
|
||||||
ws_save(ws);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!c->prev) {
|
for win if (c->w == w) x = c;
|
||||||
list = c->next;
|
|
||||||
c->next->prev = 0;
|
|
||||||
|
|
||||||
} else if (!c->next) {
|
if (!list || !x) return;
|
||||||
c->prev->next = 0;
|
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;
|
||||||
|
|
||||||
} else {
|
free(x);
|
||||||
c->prev->next = c->next;
|
ws_save(ws);
|
||||||
c->next->prev = c->prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(c);
|
|
||||||
ws_save(ws);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void win_kill() {
|
void win_kill() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user