*/
#include "dwm.h"
+/* static */
+
+static void
+reorder()
+{
+ Client *c, *orig, *p;
+
+ orig = clients;
+ clients = NULL;
+
+ while((c = orig)) {
+ orig = orig->next;
+ detach(c);
+
+ for(p = clients; p && p->next && p->weight <= c->weight; p = p->next);
+ c->prev = p;
+ if(p) {
+ if((c->next = p->next))
+ c->next->prev = c;
+ p->next = c;
+ }
+ else
+ clients = c;
+ }
+}
+
/* extern */
void (*arrange)(Arg *) = DEFMODE;
+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;
+}
+
void
dofloat(Arg *arg)
{
for(i = 0; i < ntags && !seltag[i]; i++);
if(i == ntags)
seltag[arg->i] = True; /* cannot toggle last view */
+ reorder();
arrange(NULL);
}
view(Arg *arg)
{
unsigned int i;
+ Client *c;
for(i = 0; i < ntags; i++)
seltag[i] = False;
seltag[arg->i] = True;
+ reorder();
arrange(NULL);
}
void
zoom(Arg *arg)
{
- Client *c;
+ Client *c = sel;
- if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax)
+ if(!c || (arrange != dotile) || c->isfloat || c->ismax)
return;
- if(sel == getnext(clients)) {
- if((c = getnext(sel->next)))
- sel = c;
- else
+ if(c == getnext(clients))
+ if(!(c = getnext(c->next)))
return;
- }
-
- /* pop */
- sel->prev->next = sel->next;
- if(sel->next)
- sel->next->prev = sel->prev;
- sel->prev = NULL;
- clients->prev = sel;
- sel->next = clients;
- clients = sel;
- focus(sel);
+ detach(c);
+ c->next = clients;
+ clients->prev = c;
+ clients = c;
+ focus(c);
arrange(NULL);
}