Hi all,
This is the DWMII layout for DWM 5.1. It is a layout in the dwm way this
time ! The only modification is within the Client struct and holds in 11
chars : "int dwmii;\n". This modification prevents from having a more
complex algorithm and more lines of code. The last release of my layout
for dwm 5.0.1 contained bugs that I found later. Now, I think it's bug
free and I review the code for cleaning ! I also added the row layout
because I missed it. Feel free to try it and send me all your comments.
Kind regards,
QUINTIN Guillaume.
--- dwm.org.c 2008-07-30 12:48:52.000000000 +0200
+++ dwm.c 2008-07-30 12:56:10.000000000 +0200
@@ -91,6 +91,7 @@
Client *next;
Client *snext;
Window win;
+ int dwmii;
};
typedef struct {
@@ -201,6 +202,12 @@
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
+static void dwmiitoggle(const Arg *);
+static void dwmiiinsertafter(Client *,Client *,int);
+static void dwmiikeypressed(const Arg *);
+static void dwmiinoinfiniteloop(void);
+static void dwmiilayoutcol(void);
+static void dwmiilayoutrow(void);
/* variables */
static char stext[256];
@@ -1742,3 +1749,127 @@
XCloseDisplay(dpy);
return 0;
}
+
+void dwmiitoggle(const Arg *arg)
+{
+ if ( !lt[sellt]->arrange || (sel && sel->isfloating) ) { return; }
+ Client *firstclients = nexttiled(clients);
+ if ( sel == firstclients ) { return ; }
+ if ( sel->dwmii ) { sel->dwmii = 0; return; }
+ sel->dwmii = 1;
+ arrange();
+}
+
+void dwmiiinsertafter(Client *c,Client *after,int dwmii)
+{
+ if ( !c || !after ) { return; }
+ detach(c);
+ c->dwmii = dwmii;
+ c->next = after->next;
+ after->next = c;
+}
+
+void dwmiikeypressed(const Arg *arg)
+{
+ if ( !lt[sellt]->arrange || (sel && sel->isfloating) ) { return; }
+ Client* firstclients = nexttiled(clients);
+ if ( ( (arg->i == XK_Up) && (lt[sellt]->arrange == dwmiilayoutcol) ) || ( (arg->i == XK_Left) && (lt[sellt]->arrange == dwmiilayoutrow) ) )
+ {
+ if ( sel->dwmii ) { return; }
+ Client *t = firstclients,*s = 0;
+ for( ; t != sel ; s = t,t = nexttiled(t->next) );
+ sel->dwmii = s->dwmii;
+ dwmiiinsertafter(s,sel,0);
+ }
+ if ( ( (arg->i == XK_Right) && (lt[sellt]->arrange == dwmiilayoutcol) ) || ( (arg->i == XK_Down) && (lt[sellt]->arrange == dwmiilayoutrow) ) )
+ {
+ Client *t = nexttiled(sel->next),*s = 0;
+ if ( !t ) { sel->dwmii = 1; arrange(); return; }
+ int i = 2;
+ for( ; t && ((i -= ( t->dwmii ? 1 : 0 )) > 0) ; s = t,t = nexttiled(t->next) );
+ if ( sel->dwmii ) { t = nexttiled(sel->next); if ( t ) { t->dwmii = 1; } }
+ dwmiiinsertafter(sel,s,( i == 2 ? 1 : 0 ));
+ }
+ if ( ( (arg->i == XK_Down) && (lt[sellt]->arrange == dwmiilayoutcol) ) || ( (arg->i == XK_Right) && (lt[sellt]->arrange == dwmiilayoutrow) ) )
+ {
+ Client *t = nexttiled(sel->next);
+ if ( !t || t->dwmii ) { return; }
+ t->dwmii = sel->dwmii;
+ dwmiiinsertafter(sel,t,0);
+ }
+ if ( ( (arg->i == XK_Left) && (lt[sellt]->arrange == dwmiilayoutcol) ) || ( (arg->i == XK_Up) && (lt[sellt]->arrange == dwmiilayoutrow) ) )
+ {
+ if ( sel == firstclients ) { return; }
+ Client *t = firstclients,*s = 0,*u = 0;
+ for( ; t != sel ; s = t,t = nexttiled(t->next),u = ( t->dwmii ? s : u) );
+ if ( !u ) { return; }
+ if ( sel->dwmii ) { t = nexttiled(sel->next); if ( t ) { t->dwmii = 1; } }
+ dwmiiinsertafter(sel,u,0);
+ }
+ arrange();
+}
+
+void dwmiinoinfiniteloop(void)
+{
+ Client* firstclients = nexttiled(clients),*t = firstclients;
+ for( ; t && !t->dwmii ; t = nexttiled(t->next) );
+ firstclients->dwmii = 1;
+ if ( t && (t != firstclients) ) { t->dwmii = 0; }
+}
+
+void dwmiilayoutcol(void)
+{
+ Client *firstclients = nexttiled(clients);
+ if ( !firstclients || (lt[sellt]->arrange != dwmiilayoutcol) ) { return; }
+ dwmiinoinfiniteloop();
+ Client *t = nexttiled(firstclients->next);
+ int n = 1;
+ for( ; t ; n += ( t->dwmii ? 1 : 0 ),t = nexttiled(t->next) );
+ int x = wx,dw = ww / n;
+ for ( t = firstclients ; t ; )
+ {
+ if ( t->dwmii )
+ {
+ n = 1;
+ Client *s = nexttiled(t->next);
+ for( ; s && !s->dwmii ; n++,s = nexttiled(s->next) );
+ int dh = wh / n,y = wy + dh;
+ resize(t,x,wy,dw - 2 * t->bw,dh - 2 * t->bw,resizehints);
+ for( t = nexttiled(t->next) ; t && !t->dwmii ; t = nexttiled(t->next) )
+ {
+ resize(t,x,y,dw - 2 * t->bw,dh - 2 * t->bw,resizehints);
+ y += dh;
+ }
+ x += dw;
+ }
+ }
+}
+
+void dwmiilayoutrow(void)
+{
+ Client *firstclients = nexttiled(clients);
+ if ( !firstclients || (lt[sellt]->arrange != dwmiilayoutrow) ) { return; }
+ dwmiinoinfiniteloop();
+ Client *t = nexttiled(firstclients->next);
+ int n = 1;
+ for( ; t ; n += ( t->dwmii ? 1 : 0 ),t = nexttiled(t->next) );
+ int y = wy,dh = wh / n;
+ for ( t = firstclients ; t ; )
+ {
+ if ( t->dwmii )
+ {
+ n = 1;
+ Client *s = nexttiled(t->next);
+ for( ; s && !s->dwmii ; n++,s = nexttiled(s->next) );
+ int dw = ww / n,x = wx + dw;
+ resize(t,wx,y,dw - 2 * t->bw,dh - 2 * t->bw,resizehints);
+ for( t = nexttiled(t->next) ; t && !t->dwmii ; t = nexttiled(t->next) )
+ {
+ resize(t,x,y,dw - 2 * t->bw,dh - 2 * t->bw,resizehints);
+ x += dw;
+ }
+ y += dh;
+ }
+ }
+}
+
This archive was generated by hypermail 2.2.0 : Wed Jul 30 2008 - 11:24:04 UTC