[hackers] [dwm] 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

From: Anselm R. Garbe <garbeam_AT_gmail.com>
Date: Mon Aug 13 19:14:42 2007

changeset: 946:b938876de936
tag: tip
user: Anselm R. Garbe <garbeam_AT_gmail.com>
date: Mon Aug 13 19:13:54 2007 +0200
summary: 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

diff -r 89ea2acd2646 -r b938876de936 client.c
--- a/client.c Mon Aug 13 18:24:15 2007 +0200
+++ b/client.c Mon Aug 13 19:13:54 2007 +0200
@@ -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, i
 
 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 -r 89ea2acd2646 -r b938876de936 config.mk
--- a/config.mk Mon Aug 13 18:24:15 2007 +0200
+++ b/config.mk Mon Aug 13 19:13:54 2007 +0200
@@ -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 -r 89ea2acd2646 -r b938876de936 draw.c
--- a/draw.c Mon Aug 13 18:24:15 2007 +0200
+++ b/draw.c Mon Aug 13 19:13:54 2007 +0200
@@ -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 -r 89ea2acd2646 -r b938876de936 dwm.h
--- a/dwm.h Mon Aug 13 18:24:15 2007 +0200
+++ b/dwm.h Mon Aug 13 19:13:54 2007 +0200
@@ -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 Cursor cursor[CurLast];
 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 @@ void grabkeys(void); /* grab all keys
 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 -r 89ea2acd2646 -r b938876de936 event.c
--- a/event.c Mon Aug 13 18:24:15 2007 +0200
+++ b/event.c Mon Aug 13 19:13:54 2007 +0200
@@ -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 -r 89ea2acd2646 -r b938876de936 layout.c
--- a/layout.c Mon Aug 13 18:24:15 2007 +0200
+++ b/layout.c Mon Aug 13 19:13:54 2007 +0200
@@ -2,10 +2,24 @@
 #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;
 
@@ -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();
 }
@@ -53,6 +63,23 @@ focusclient(const char *arg) {
                 focus(c);
                 restack();
         }
+}
+
+const char *
+getsymbol(void)
+{
+ return lt->symbol;
+}
+
+Bool
+isfloating(void) {
+ return lt->arrange == floating;
+}
+
+Bool
+isarrange(void (*func)())
+{
+ return func == lt->arrange;
 }
 
 void
@@ -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 -r 89ea2acd2646 -r b938876de936 tag.c
--- a/tag.c Mon Aug 13 18:24:15 2007 +0200
+++ b/tag.c Mon Aug 13 19:13:54 2007 +0200
@@ -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 -r 89ea2acd2646 -r b938876de936 tile.c
--- a/tile.c Mon Aug 13 18:24:15 2007 +0200
+++ b/tile.c Mon Aug 13 19:13:54 2007 +0200
@@ -12,7 +12,7 @@ addtomwfact(const char *arg) {
 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();
 }
Received on Mon Aug 13 2007 - 19:14:42 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:57:51 UTC