dwm

my fork of dwm
Index Commits Files Refs README LICENSE
commit 77044e876511f51c34bde379d89e2de754707ee6
parent 2feb3afe784cbd9d900bd70aad91431a4b25f2ab
Author: Anselm R. Garbe <garbeam@gmail.com>
Date:   Mon, 13 Aug 2007 19:13:54 +0200

made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Diffstat:
Mclient.c | 9+++++----
Mconfig.mk | 4++--
Mdraw.c | 2+-
Mdwm.h | 11++++-------
Mevent.c | 10+++++-----
Mlayout.c | 47+++++++++++++++++++++++++++++++++++++----------
Mtag.c | 8++++----
Mtile.c | 13++++---------
8 files changed, 62 insertions(+), 42 deletions(-)
diff --git a/client.c b/client.c
@@ -230,13 +230,14 @@ manage(Window w, XWindowAttributes *wa) {
     setclientstate(c, IconicState);
     c->isbanned = True;
     focus(c);
-    lt->arrange();
+    arrange();
 }
 
 void
 resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
     double dx, dy, max, min, ratio;
     XWindowChanges wc; 
+
     if(sizehints) {
         if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0) {
             dx = (double)(w - c->basew);
@@ -297,12 +298,12 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
 
 void
 togglefloating(const char *arg) {
-    if(!sel || lt->arrange == floating)
+    if(!sel || isfloating())
         return;
     sel->isfloating = !sel->isfloating;
     if(sel->isfloating)
         resize(sel, sel->x, sel->y, sel->w, sel->h, True);
-    lt->arrange();
+    arrange();
 }
 
 void
@@ -334,7 +335,7 @@ unmanage(Client *c) {
     XSync(dpy, False);
     XSetErrorHandler(xerror);
     XUngrabServer(dpy);
-    lt->arrange();
+    arrange();
 }
 
 void
diff --git a/config.mk b/config.mk
@@ -20,8 +20,8 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
 # flags
 CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
 LDFLAGS = -s ${LIBS}
-CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
-LDFLAGS = -g ${LIBS}
+#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
+#LDFLAGS = -g ${LIBS}
 
 # Solaris
 #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
diff --git a/draw.c b/draw.c
@@ -66,7 +66,7 @@ drawstatus(void) {
         dc.x += dc.w;
     }
     dc.w = blw;
-    drawtext(lt->symbol, dc.norm);
+    drawtext(getsymbol(), dc.norm);
     x = dc.x + dc.w;
     dc.w = textw(stext);
     dc.x = sw - dc.w;
diff --git a/dwm.h b/dwm.h
@@ -74,11 +74,6 @@ typedef struct {
     } font;
 } DC; /* draw context */
 
-typedef struct {
-    const char *symbol;
-    void (*arrange)(void);
-} Layout;
-
 extern const char *tags[];            /* all tags */
 extern char stext[256];                /* status text */
 extern int screen, sx, sy, sw, sh;        /* screen geometry */
@@ -92,7 +87,6 @@ extern Client *clients, *sel, *stack;		/* global client list and stack */
 extern Cursor cursor[CurLast];
 extern DC dc;                    /* global draw context */
 extern Display *dpy;
-extern Layout *lt;
 extern Window root, barwin;
 
 /* client.c */
@@ -120,8 +114,11 @@ unsigned int textw(const char *text);	/* return the width of text in px*/
 void grabkeys(void);            /* grab all keys defined in config.h */
 
 /* layout.c */
-void floating(void);            /* arranges all windows floating, fallback layout  */
+void arrange(void);            /* arranges all windows depending on the layout in use */
 void focusclient(const char *arg);    /* focuses next(1)/previous(-1) visible client */
+const char *getsymbol(void);        /* returns True  symbol of enabled layout */
+Bool isfloating(void);            /* returns True if floating layout is enabled */
+Bool isarrange(void (*func)());        /* returns True if func is the layout function in use */
 void initlayouts(void);            /* initialize layout array */
 Client *nexttiled(Client *c);        /* returns tiled successor of c */
 void restack(void);            /* restores z layers of all clients */
diff --git a/event.c b/event.c
@@ -145,14 +145,14 @@ buttonpress(XEvent *e) {
         focus(c);
         if(CLEANMASK(ev->state) != MODKEY)
             return;
-        if(ev->button == Button1 && (lt->arrange == floating || c->isfloating)) {
+        if(ev->button == Button1 && (isfloating() || c->isfloating)) {
             restack();
             movemouse(c);
         }
         else if(ev->button == Button2)
             zoom(NULL);
         else if(ev->button == Button3
-        && (lt->arrange == floating || c->isfloating) && !c->isfixed)
+        && (isfloating() || c->isfloating) && !c->isfixed)
         {
             restack();
             resizemouse(c);
@@ -170,7 +170,7 @@ configurerequest(XEvent *e) {
         c->ismax = False;
         if(ev->value_mask & CWBorderWidth)
             c->border = ev->border_width;
-        if(c->isfixed || c->isfloating || (lt->arrange == floating)) {
+        if(c->isfixed || c->isfloating || isfloating()) {
             if(ev->value_mask & CWX)
                 c->x = ev->x;
             if(ev->value_mask & CWY)
@@ -216,7 +216,7 @@ configurenotify(XEvent *e) {
         dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
         XResizeWindow(dpy, barwin, sw, bh);
         updatebarpos();
-        lt->arrange();
+        arrange();
     }
 }
 
@@ -317,7 +317,7 @@ propertynotify(XEvent *e) {
             case XA_WM_TRANSIENT_FOR:
                 XGetTransientForHint(dpy, c->win, &trans);
                 if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
-                    lt->arrange();
+                    arrange();
                 break;
             case XA_WM_NORMAL_HINTS:
                 updatesizehints(c);
diff --git a/layout.c b/layout.c
@@ -2,11 +2,25 @@
 #include "dwm.h"
 #include <stdlib.h>
 
+typedef struct {
+    const char *symbol;
+    void (*arrange)(void);
+} Layout;
+
 unsigned int blw = 0;
-Layout *lt = NULL;
+static Layout *lt = NULL;
 
 /* static */
 
+static void
+floating(void) {
+    Client *c;
+
+    for(c = clients; c; c = c->next)
+        if(isvisible(c))
+            resize(c, c->x, c->y, c->w, c->h, True);
+}
+
 static unsigned int nlayouts = 0;
 
 LAYOUTS
@@ -14,19 +28,15 @@ LAYOUTS
 /* extern */
 
 void
-floating(void) {
+arrange(void) {
     Client *c;
 
-    if(lt->arrange != floating)
-        return;
-
     for(c = clients; c; c = c->next)
-        if(isvisible(c)) {
+        if(isvisible(c))
             unban(c);
-            resize(c, c->x, c->y, c->w, c->h, True);
-        }
         else
             ban(c);
+    lt->arrange();
     focus(NULL);
     restack();
 }
@@ -55,6 +65,23 @@ focusclient(const char *arg) {
     }
 }
 
+const char *
+getsymbol(void)
+{
+    return lt->symbol;
+}
+
+Bool
+isfloating(void) {
+    return lt->arrange == floating;
+}
+
+Bool
+isarrange(void (*func)())
+{
+    return func == lt->arrange;
+}
+
 void
 initlayouts(void) {
     unsigned int i, w;
@@ -119,7 +146,7 @@ setlayout(const char *arg) {
         lt = &layout[i];
     }
     if(sel)
-        lt->arrange();
+        arrange();
     else
         drawstatus();
 }
@@ -131,7 +158,7 @@ togglebar(const char *arg) {
     else
         bpos = BarOff;
     updatebarpos();
-    lt->arrange();
+    arrange();
 }
 
 void
diff --git a/tag.c b/tag.c
@@ -110,7 +110,7 @@ tag(const char *arg) {
     i = arg ? atoi(arg) : 0;
     if(i >= 0 && i < ntags)
         sel->tags[i] = True;
-    lt->arrange();
+    arrange();
 }
 
 void
@@ -124,7 +124,7 @@ toggletag(const char *arg) {
     for(j = 0; j < ntags && !sel->tags[j]; j++);
     if(j == ntags)
         sel->tags[i] = True;
-    lt->arrange();
+    arrange();
 }
 
 void
@@ -136,7 +136,7 @@ toggleview(const char *arg) {
     for(j = 0; j < ntags && !seltag[j]; j++);
     if(j == ntags)
         seltag[i] = True; /* cannot toggle last view */
-    lt->arrange();
+    arrange();
 }
 
 void
@@ -148,5 +148,5 @@ view(const char *arg) {
     i = arg ? atoi(arg) : 0;
     if(i >= 0 && i < ntags)
         seltag[i] = True;
-    lt->arrange();
+    arrange();
 }
diff --git a/tile.c b/tile.c
@@ -12,7 +12,7 @@ void
 addtomwfact(const char *arg) {
     double delta;
 
-    if(lt->arrange != tile)
+    if(isarrange(tile))
         return;
 
     /* arg handling, manipulate mwfact */
@@ -20,7 +20,7 @@ addtomwfact(const char *arg) {
         if(delta + mwfact > 0.1 && delta + mwfact < 0.9)
             mwfact += delta;
     }
-    lt->arrange();
+    arrange();
 }
 
 void
@@ -41,7 +41,6 @@ tile(void) {
     ny = way;
     for(i = 0, c = clients; c; c = c->next)
         if(isvisible(c)) {
-            unban(c);
             if(c->isfloating)
                 continue;
             c->ismax = False;
@@ -65,17 +64,13 @@ tile(void) {
                 ny += nh + 2 * c->border;
             i++;
         }
-        else
-            ban(c);
-    focus(NULL);
-    restack();
 }
 
 void
 zoom(const char *arg) {
     Client *c;
 
-    if(!sel || lt->arrange == floating || sel->isfloating)
+    if(!sel || !isarrange(tile) || sel->isfloating)
         return;
     if((c = sel) == nexttiled(clients))
         if(!(c = nexttiled(c->next)))
@@ -83,5 +78,5 @@ zoom(const char *arg) {
     detach(c);
     attach(c);
     focus(c);
-    lt->arrange();
+    arrange();
 }