+void
+attach(Client *c)
+{
+ Client *first = getnext(clients);
+
+ if(!first) {
+ if(clients) {
+ for(first = clients; first->next; first = first->next);
+ first->next = c;
+ c->prev = first;
+ }
+ else
+ clients = c;
+ }
+ else if(first == clients) {
+ c->next = clients;
+ clients->prev = c;
+ clients = c;
+ }
+ else {
+ first->prev->next = c;
+ c->prev = first->prev;
+ first->prev = c;
+ c->next = first;
+ }
+}
+
+void
+detach(Client *c)
+{
+ if(c->prev)
+ c->prev->next = c->next;
+ if(c->next)
+ c->next->prev = c->prev;
+ if(c == clients)
+ clients = c->next;
+ c->next = c->prev = NULL;
+}
+