[dwm] 3 bugs fixed and code review for the (D)WMII patch

From: QUINTIN Guillaume <coincoin169g_AT_gmail.com>
Date: Mon, 28 Jul 2008 22:17:39 +0200

Hello all,

I didn't use my new layout enough, I just fixed 3 bugs and review my
code. I have attached a diff file, excuse me for having attached the
whole dwm.c file in my last post, I was in a hurry. Well tell me what
you think about it, in particular Anselm.

Kind regards
QUINTIN Guillaume

--- dwm.org.c 2008-07-13 23:25:02.000000000 +0200
+++ dwm.c 2008-07-28 22:08:27.000000000 +0200
@@ -17,7 +17,7 @@
  * set the override_redirect flag. Clients are organized in a global
  * doubly-linked client list, the focus history is remembered through a global
  * stack list. Each client contains a bit array to indicate the tags of a
- * client.
+i* client.
  *
  * Keys and tagging rules are organized as arrays and defined in config.h.
  *
@@ -93,6 +93,7 @@
         Client *next;
         Client *snext;
         Window win;
+ int dwmii,desiredw,desiredh;
 };
 
 typedef struct {
@@ -202,6 +203,16 @@
 static int xerrordummy(Display *dpy, XErrorEvent *ee);
 static int xerrorstart(Display *dpy, XErrorEvent *ee);
 static void zoom(const Arg *arg);
+static void dwmiiup(const Arg *);
+static void dwmiidown(const Arg *);
+static void dwmiiright(const Arg *);
+static void dwmiileft(const Arg *);
+static void dwmiiuniformcol(void);
+static void dwmiiinsertafter(Client *,Client *,int,int);
+static void dwmiitoggle(const Arg *);
+static void dwmiiresize(Client *);
+static void dwmiicostumcol(void);
+static int dwmiidim(int,int,int,int);
 
 /* variables */
 static char stext[256];
@@ -237,6 +248,7 @@
 static DC dc = {0};
 static Layout *lt = NULL;
 static Window root, barwin;
+static int dwmiiresizing = 0;
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
@@ -296,6 +308,17 @@
 
 void
 attach(Client *c) {
+ Client* firstclients = nexttiled(clients);
+ if ( !c->isfloating )
+ {
+ c->dwmii = 1;
+ if ( firstclients )
+ {
+ firstclients->dwmii = 0;
+ c->desiredw = firstclients->desiredw;
+ firstclients->desiredw = 0;
+ }
+ }
         c->next = clients;
         clients = c;
 }
@@ -467,7 +490,12 @@
 void
 detach(Client *c) {
         Client *i;
-
+ i = nexttiled(c->next);
+ if ( i && !i->dwmii )
+ {
+ i->dwmii = c->dwmii;
+ i->desiredw = c->desiredw;
+ }
         if (c != clients) {
                 for(i = clients; i->next != c; i = i->next);
                 i->next = c->next;
@@ -1145,6 +1173,7 @@
         None, cursor[CurResize], CurrentTime) != GrabSuccess)
                 return;
         XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
+ if ( (lt->arrange == dwmiicostumcol) && !sel->isfloating ) { dwmiiresizing = 1; }
         for(;;) {
                 XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask , &ev);
                 switch(ev.type) {
@@ -1153,6 +1182,7 @@
                                         c->w + c->bw - 1, c->h + c->bw - 1);
                         XUngrabPointer(dpy, CurrentTime);
                         while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+ if ( dwmiiresizing ) { dwmiiresizing = 0; sel->isfloating = False; dwmiiresize(c); }
                         return;
                 case ConfigureRequest:
                 case Expose:
@@ -1724,3 +1754,159 @@
         XCloseDisplay(dpy);
         return 0;
 }
+
+void dwmiitoggle(const Arg *arg)
+{
+ if ( ismax || !lt->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,int desiredw)
+{
+ if ( !c || !after ) { return; }
+ detach(c);
+ c->dwmii = dwmii;
+ c->desiredw = desiredw;
+ c->next = after->next;
+ after->next = c;
+}
+
+void dwmiiup(const Arg *arg)
+{
+ if ( ismax || !lt->arrange || (sel && (sel->isfloating || sel->dwmii)) ) { return; }
+ Client *t = nexttiled(clients),*s = 0;
+ for( ; t != sel ; s = t,t = nexttiled(t->next) );
+ sel->dwmii = s->dwmii;
+ sel->desiredw = s->desiredw;
+ dwmiiinsertafter(s,sel,0,0);
+ arrange();
+}
+
+void dwmiiright(const Arg *arg)
+{
+ if ( ismax || !lt->arrange || (sel && sel->isfloating) ) { return; }
+ 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; t->desiredw = sel->desiredw; } }
+ dwmiiinsertafter(sel,s,( i == 2 ? 1 : 0 ),0);
+ arrange();
+}
+
+void dwmiidown(const Arg *arg)
+{
+ if ( ismax || !lt->arrange || (sel && sel->isfloating) ) { return; }
+ Client *t = nexttiled(sel->next);
+ if ( !t || t->dwmii ) { return; }
+ t->dwmii = sel->dwmii;
+ t->desiredw = sel->desiredw;
+ dwmiiinsertafter(sel,t,0,0);
+ arrange();
+}
+
+void dwmiileft(const Arg *arg)
+{
+ if ( ismax || !lt->arrange || (sel && sel->isfloating) ) { return; }
+ Client *firstclients = nexttiled(clients);
+ 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; t->desiredw = sel->desiredw; } }
+ dwmiiinsertafter(sel,u,0,0);
+ arrange();
+}
+
+void dwmiiuniformcol(void)
+{
+ Client *firstclients = nexttiled(clients);
+ if ( !firstclients || (lt->arrange != dwmiiuniformcol) ) { return; }
+ 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;
+ }
+ }
+}
+
+int dwmiidim(int vs,int rs,int ds,int n)
+{
+ if ( vs > rs )
+ {
+ return ( ds ? ds * rs * 75 / vs / 100 : 25 * vs / 100 / n );
+ }
+ else
+ {
+ return ( ds ? ds : (rs - vs) / n );
+ }
+}
+
+void dwmiicostumcol(void)
+{
+ Client *firstclients = nexttiled(clients);
+ if ( !firstclients || (lt->arrange != dwmiicostumcol) ) { return; }
+ Client *t = firstclients;
+ int width = 0,col = 0;
+ for( ; t ; )
+ {
+ int w = t->desiredw;
+ for( t = nexttiled(t->next) ; t && !t->dwmii ; t = nexttiled(t->next) );
+ if ( !w ) { col++; }
+ width += w;
+ }
+ int x = wx;
+ for( t = firstclients ; t ; )
+ {
+ int height = 0,row = 0,w = 0,y = wy,h = 0;
+ height = t->desiredh;
+ row = ( height ? 0 : 1 );
+ Client *s = t;
+ for( s = nexttiled(s->next) ; s && !s->dwmii ; s = nexttiled(s->next) )
+ {
+ height += s->desiredh;
+ row += ( s->desiredh ? 0 : 1 );
+ }
+ w = dwmiidim(width,ww,t->desiredw,col);
+ h = dwmiidim(height,wh,t->desiredh,row);
+ resize(t,x,y,w - 2 * t->bw,h - 2 * t->bw,resizehints);
+ y += h;
+ for( t = nexttiled(t->next) ; t && !t->dwmii ; t = nexttiled(t->next) )
+ {
+ h = dwmiidim(height,wh,t->desiredh,row);
+ resize(t,x,y,w - 2 * t->bw,h - 2 * t->bw,resizehints);
+ y += h;
+ }
+ x += w;
+ }
+}
+
+void dwmiiresize(Client *c)
+{
+ Client *firstclients = nexttiled(clients),*t = firstclients,*s = firstclients;
+ if ( !firstclients ) { return; }
+ for( ; t != c ; s = ( t->dwmii ? t : s ),t = nexttiled(t->next) );
+ s->desiredw = c->w;
+ c->desiredh = c->h;
+ arrange();
+}
+
Received on Mon Jul 28 2008 - 20:17:39 UTC

This archive was generated by hypermail 2.2.0 : Mon Jul 28 2008 - 20:24:04 UTC