* See LICENSE file for license details.
*/
#include "dwm.h"
+#include <stdio.h>
+
+/* static */
+
+static Client *
+minclient()
+{
+ Client *c, *min;
+
+ for(min = c = clients; c; c = c->next)
+ if(c->weight < min->weight)
+ min = c;
+ return min;
+}
+
+
+static void
+reorder()
+{
+ Client *c, *newclients, *tail;
+
+ newclients = tail = NULL;
+ while((c = minclient())) {
+ detach(c);
+ if(tail) {
+ c->prev = tail;
+ tail->next = c;
+ tail = c;
+ }
+ else
+ tail = newclients = c;
+ }
+ clients = newclients;
+}
/* 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);
}
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);
}