diff options
| -rw-r--r-- | client.c | 9 | ||||
| -rw-r--r-- | config.mk | 4 | ||||
| -rw-r--r-- | draw.c | 2 | ||||
| -rw-r--r-- | dwm.h | 11 | ||||
| -rw-r--r-- | event.c | 10 | ||||
| -rw-r--r-- | layout.c | 47 | ||||
| -rw-r--r-- | tag.c | 8 | ||||
| -rw-r--r-- | tile.c | 13 |
8 files changed, 62 insertions, 42 deletions
| @@ -230,13 +230,14 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 230 | setclientstate(c, IconicState); | 230 | setclientstate(c, IconicState); |
| 231 | c->isbanned = True; | 231 | c->isbanned = True; |
| 232 | focus(c); | 232 | focus(c); |
| 233 | lt->arrange(); | 233 | arrange(); |
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | void | 236 | void |
| 237 | resize(Client *c, int x, int y, int w, int h, Bool sizehints) { | 237 | resize(Client *c, int x, int y, int w, int h, Bool sizehints) { |
| 238 | double dx, dy, max, min, ratio; | 238 | double dx, dy, max, min, ratio; |
| 239 | XWindowChanges wc; | 239 | XWindowChanges wc; |
| 240 | |||
| 240 | if(sizehints) { | 241 | if(sizehints) { |
| 241 | if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0) { | 242 | if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0) { |
| 242 | dx = (double)(w - c->basew); | 243 | dx = (double)(w - c->basew); |
| @@ -297,12 +298,12 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { | |||
| 297 | 298 | ||
| 298 | void | 299 | void |
| 299 | togglefloating(const char *arg) { | 300 | togglefloating(const char *arg) { |
| 300 | if(!sel || lt->arrange == floating) | 301 | if(!sel || isfloating()) |
| 301 | return; | 302 | return; |
| 302 | sel->isfloating = !sel->isfloating; | 303 | sel->isfloating = !sel->isfloating; |
| 303 | if(sel->isfloating) | 304 | if(sel->isfloating) |
| 304 | resize(sel, sel->x, sel->y, sel->w, sel->h, True); | 305 | resize(sel, sel->x, sel->y, sel->w, sel->h, True); |
| 305 | lt->arrange(); | 306 | arrange(); |
| 306 | } | 307 | } |
| 307 | 308 | ||
| 308 | void | 309 | void |
| @@ -334,7 +335,7 @@ unmanage(Client *c) { | |||
| 334 | XSync(dpy, False); | 335 | XSync(dpy, False); |
| 335 | XSetErrorHandler(xerror); | 336 | XSetErrorHandler(xerror); |
| 336 | XUngrabServer(dpy); | 337 | XUngrabServer(dpy); |
| 337 | lt->arrange(); | 338 | arrange(); |
| 338 | } | 339 | } |
| 339 | 340 | ||
| 340 | void | 341 | void |
| @@ -20,8 +20,8 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 | |||
| 20 | # flags | 20 | # flags |
| 21 | CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" | 21 | CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" |
| 22 | LDFLAGS = -s ${LIBS} | 22 | LDFLAGS = -s ${LIBS} |
| 23 | CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" | 23 | #CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" |
| 24 | LDFLAGS = -g ${LIBS} | 24 | #LDFLAGS = -g ${LIBS} |
| 25 | 25 | ||
| 26 | # Solaris | 26 | # Solaris |
| 27 | #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" | 27 | #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" |
| @@ -66,7 +66,7 @@ drawstatus(void) { | |||
| 66 | dc.x += dc.w; | 66 | dc.x += dc.w; |
| 67 | } | 67 | } |
| 68 | dc.w = blw; | 68 | dc.w = blw; |
| 69 | drawtext(lt->symbol, dc.norm); | 69 | drawtext(getsymbol(), dc.norm); |
| 70 | x = dc.x + dc.w; | 70 | x = dc.x + dc.w; |
| 71 | dc.w = textw(stext); | 71 | dc.w = textw(stext); |
| 72 | dc.x = sw - dc.w; | 72 | dc.x = sw - dc.w; |
| @@ -74,11 +74,6 @@ typedef struct { | |||
| 74 | } font; | 74 | } font; |
| 75 | } DC; /* draw context */ | 75 | } DC; /* draw context */ |
| 76 | 76 | ||
| 77 | typedef struct { | ||
| 78 | const char *symbol; | ||
| 79 | void (*arrange)(void); | ||
| 80 | } Layout; | ||
| 81 | |||
| 82 | extern const char *tags[]; /* all tags */ | 77 | extern const char *tags[]; /* all tags */ |
| 83 | extern char stext[256]; /* status text */ | 78 | extern char stext[256]; /* status text */ |
| 84 | extern int screen, sx, sy, sw, sh; /* screen geometry */ | 79 | extern int screen, sx, sy, sw, sh; /* screen geometry */ |
| @@ -92,7 +87,6 @@ extern Client *clients, *sel, *stack; /* global client list and stack */ | |||
| 92 | extern Cursor cursor[CurLast]; | 87 | extern Cursor cursor[CurLast]; |
| 93 | extern DC dc; /* global draw context */ | 88 | extern DC dc; /* global draw context */ |
| 94 | extern Display *dpy; | 89 | extern Display *dpy; |
| 95 | extern Layout *lt; | ||
| 96 | extern Window root, barwin; | 90 | extern Window root, barwin; |
| 97 | 91 | ||
| 98 | /* client.c */ | 92 | /* client.c */ |
| @@ -120,8 +114,11 @@ unsigned int textw(const char *text); /* return the width of text in px*/ | |||
| 120 | void grabkeys(void); /* grab all keys defined in config.h */ | 114 | void grabkeys(void); /* grab all keys defined in config.h */ |
| 121 | 115 | ||
| 122 | /* layout.c */ | 116 | /* layout.c */ |
| 123 | void floating(void); /* arranges all windows floating, fallback layout */ | 117 | void arrange(void); /* arranges all windows depending on the layout in use */ |
| 124 | void focusclient(const char *arg); /* focuses next(1)/previous(-1) visible client */ | 118 | void focusclient(const char *arg); /* focuses next(1)/previous(-1) visible client */ |
| 119 | const char *getsymbol(void); /* returns True symbol of enabled layout */ | ||
| 120 | Bool isfloating(void); /* returns True if floating layout is enabled */ | ||
| 121 | Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */ | ||
| 125 | void initlayouts(void); /* initialize layout array */ | 122 | void initlayouts(void); /* initialize layout array */ |
| 126 | Client *nexttiled(Client *c); /* returns tiled successor of c */ | 123 | Client *nexttiled(Client *c); /* returns tiled successor of c */ |
| 127 | void restack(void); /* restores z layers of all clients */ | 124 | void restack(void); /* restores z layers of all clients */ |
| @@ -145,14 +145,14 @@ buttonpress(XEvent *e) { | |||
| 145 | focus(c); | 145 | focus(c); |
| 146 | if(CLEANMASK(ev->state) != MODKEY) | 146 | if(CLEANMASK(ev->state) != MODKEY) |
| 147 | return; | 147 | return; |
| 148 | if(ev->button == Button1 && (lt->arrange == floating || c->isfloating)) { | 148 | if(ev->button == Button1 && (isfloating() || c->isfloating)) { |
| 149 | restack(); | 149 | restack(); |
| 150 | movemouse(c); | 150 | movemouse(c); |
| 151 | } | 151 | } |
| 152 | else if(ev->button == Button2) | 152 | else if(ev->button == Button2) |
| 153 | zoom(NULL); | 153 | zoom(NULL); |
| 154 | else if(ev->button == Button3 | 154 | else if(ev->button == Button3 |
| 155 | && (lt->arrange == floating || c->isfloating) && !c->isfixed) | 155 | && (isfloating() || c->isfloating) && !c->isfixed) |
| 156 | { | 156 | { |
| 157 | restack(); | 157 | restack(); |
| 158 | resizemouse(c); | 158 | resizemouse(c); |
| @@ -170,7 +170,7 @@ configurerequest(XEvent *e) { | |||
| 170 | c->ismax = False; | 170 | c->ismax = False; |
| 171 | if(ev->value_mask & CWBorderWidth) | 171 | if(ev->value_mask & CWBorderWidth) |
| 172 | c->border = ev->border_width; | 172 | c->border = ev->border_width; |
| 173 | if(c->isfixed || c->isfloating || (lt->arrange == floating)) { | 173 | if(c->isfixed || c->isfloating || isfloating()) { |
| 174 | if(ev->value_mask & CWX) | 174 | if(ev->value_mask & CWX) |
| 175 | c->x = ev->x; | 175 | c->x = ev->x; |
| 176 | if(ev->value_mask & CWY) | 176 | if(ev->value_mask & CWY) |
| @@ -216,7 +216,7 @@ configurenotify(XEvent *e) { | |||
| 216 | dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); | 216 | dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); |
| 217 | XResizeWindow(dpy, barwin, sw, bh); | 217 | XResizeWindow(dpy, barwin, sw, bh); |
| 218 | updatebarpos(); | 218 | updatebarpos(); |
| 219 | lt->arrange(); | 219 | arrange(); |
| 220 | } | 220 | } |
| 221 | } | 221 | } |
| 222 | 222 | ||
| @@ -317,7 +317,7 @@ propertynotify(XEvent *e) { | |||
| 317 | case XA_WM_TRANSIENT_FOR: | 317 | case XA_WM_TRANSIENT_FOR: |
| 318 | XGetTransientForHint(dpy, c->win, &trans); | 318 | XGetTransientForHint(dpy, c->win, &trans); |
| 319 | if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL))) | 319 | if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL))) |
| 320 | lt->arrange(); | 320 | arrange(); |
| 321 | break; | 321 | break; |
| 322 | case XA_WM_NORMAL_HINTS: | 322 | case XA_WM_NORMAL_HINTS: |
| 323 | updatesizehints(c); | 323 | updatesizehints(c); |
| @@ -2,11 +2,25 @@ | |||
| 2 | #include "dwm.h" | 2 | #include "dwm.h" |
| 3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
| 4 | 4 | ||
| 5 | typedef struct { | ||
| 6 | const char *symbol; | ||
| 7 | void (*arrange)(void); | ||
| 8 | } Layout; | ||
| 9 | |||
| 5 | unsigned int blw = 0; | 10 | unsigned int blw = 0; |
| 6 | Layout *lt = NULL; | 11 | static Layout *lt = NULL; |
| 7 | 12 | ||
| 8 | /* static */ | 13 | /* static */ |
| 9 | 14 | ||
| 15 | static void | ||
| 16 | floating(void) { | ||
| 17 | Client *c; | ||
| 18 | |||
| 19 | for(c = clients; c; c = c->next) | ||
| 20 | if(isvisible(c)) | ||
| 21 | resize(c, c->x, c->y, c->w, c->h, True); | ||
| 22 | } | ||
| 23 | |||
| 10 | static unsigned int nlayouts = 0; | 24 | static unsigned int nlayouts = 0; |
| 11 | 25 | ||
| 12 | LAYOUTS | 26 | LAYOUTS |
| @@ -14,19 +28,15 @@ LAYOUTS | |||
| 14 | /* extern */ | 28 | /* extern */ |
| 15 | 29 | ||
| 16 | void | 30 | void |
| 17 | floating(void) { | 31 | arrange(void) { |
| 18 | Client *c; | 32 | Client *c; |
| 19 | 33 | ||
| 20 | if(lt->arrange != floating) | ||
| 21 | return; | ||
| 22 | |||
| 23 | for(c = clients; c; c = c->next) | 34 | for(c = clients; c; c = c->next) |
| 24 | if(isvisible(c)) { | 35 | if(isvisible(c)) |
| 25 | unban(c); | 36 | unban(c); |
| 26 | resize(c, c->x, c->y, c->w, c->h, True); | ||
| 27 | } | ||
| 28 | else | 37 | else |
| 29 | ban(c); | 38 | ban(c); |
| 39 | lt->arrange(); | ||
| 30 | focus(NULL); | 40 | focus(NULL); |
| 31 | restack(); | 41 | restack(); |
| 32 | } | 42 | } |
| @@ -55,6 +65,23 @@ focusclient(const char *arg) { | |||
| 55 | } | 65 | } |
| 56 | } | 66 | } |
| 57 | 67 | ||
| 68 | const char * | ||
| 69 | getsymbol(void) | ||
| 70 | { | ||
| 71 | return lt->symbol; | ||
| 72 | } | ||
| 73 | |||
| 74 | Bool | ||
| 75 | isfloating(void) { | ||
| 76 | return lt->arrange == floating; | ||
| 77 | } | ||
| 78 | |||
| 79 | Bool | ||
| 80 | isarrange(void (*func)()) | ||
| 81 | { | ||
| 82 | return func == lt->arrange; | ||
| 83 | } | ||
| 84 | |||
| 58 | void | 85 | void |
| 59 | initlayouts(void) { | 86 | initlayouts(void) { |
| 60 | unsigned int i, w; | 87 | unsigned int i, w; |
| @@ -119,7 +146,7 @@ setlayout(const char *arg) { | |||
| 119 | lt = &layout[i]; | 146 | lt = &layout[i]; |
| 120 | } | 147 | } |
| 121 | if(sel) | 148 | if(sel) |
| 122 | lt->arrange(); | 149 | arrange(); |
| 123 | else | 150 | else |
| 124 | drawstatus(); | 151 | drawstatus(); |
| 125 | } | 152 | } |
| @@ -131,7 +158,7 @@ togglebar(const char *arg) { | |||
| 131 | else | 158 | else |
| 132 | bpos = BarOff; | 159 | bpos = BarOff; |
| 133 | updatebarpos(); | 160 | updatebarpos(); |
| 134 | lt->arrange(); | 161 | arrange(); |
| 135 | } | 162 | } |
| 136 | 163 | ||
| 137 | void | 164 | void |
| @@ -110,7 +110,7 @@ tag(const char *arg) { | |||
| 110 | i = arg ? atoi(arg) : 0; | 110 | i = arg ? atoi(arg) : 0; |
| 111 | if(i >= 0 && i < ntags) | 111 | if(i >= 0 && i < ntags) |
| 112 | sel->tags[i] = True; | 112 | sel->tags[i] = True; |
| 113 | lt->arrange(); | 113 | arrange(); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | void | 116 | void |
| @@ -124,7 +124,7 @@ toggletag(const char *arg) { | |||
| 124 | for(j = 0; j < ntags && !sel->tags[j]; j++); | 124 | for(j = 0; j < ntags && !sel->tags[j]; j++); |
| 125 | if(j == ntags) | 125 | if(j == ntags) |
| 126 | sel->tags[i] = True; | 126 | sel->tags[i] = True; |
| 127 | lt->arrange(); | 127 | arrange(); |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | void | 130 | void |
| @@ -136,7 +136,7 @@ toggleview(const char *arg) { | |||
| 136 | for(j = 0; j < ntags && !seltag[j]; j++); | 136 | for(j = 0; j < ntags && !seltag[j]; j++); |
| 137 | if(j == ntags) | 137 | if(j == ntags) |
| 138 | seltag[i] = True; /* cannot toggle last view */ | 138 | seltag[i] = True; /* cannot toggle last view */ |
| 139 | lt->arrange(); | 139 | arrange(); |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | void | 142 | void |
| @@ -148,5 +148,5 @@ view(const char *arg) { | |||
| 148 | i = arg ? atoi(arg) : 0; | 148 | i = arg ? atoi(arg) : 0; |
| 149 | if(i >= 0 && i < ntags) | 149 | if(i >= 0 && i < ntags) |
| 150 | seltag[i] = True; | 150 | seltag[i] = True; |
| 151 | lt->arrange(); | 151 | arrange(); |
| 152 | } | 152 | } |
| @@ -12,7 +12,7 @@ void | |||
| 12 | addtomwfact(const char *arg) { | 12 | addtomwfact(const char *arg) { |
| 13 | double delta; | 13 | double delta; |
| 14 | 14 | ||
| 15 | if(lt->arrange != tile) | 15 | if(isarrange(tile)) |
| 16 | return; | 16 | return; |
| 17 | 17 | ||
| 18 | /* arg handling, manipulate mwfact */ | 18 | /* arg handling, manipulate mwfact */ |
| @@ -20,7 +20,7 @@ addtomwfact(const char *arg) { | |||
| 20 | if(delta + mwfact > 0.1 && delta + mwfact < 0.9) | 20 | if(delta + mwfact > 0.1 && delta + mwfact < 0.9) |
| 21 | mwfact += delta; | 21 | mwfact += delta; |
| 22 | } | 22 | } |
| 23 | lt->arrange(); | 23 | arrange(); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | void | 26 | void |
| @@ -41,7 +41,6 @@ tile(void) { | |||
| 41 | ny = way; | 41 | ny = way; |
| 42 | for(i = 0, c = clients; c; c = c->next) | 42 | for(i = 0, c = clients; c; c = c->next) |
| 43 | if(isvisible(c)) { | 43 | if(isvisible(c)) { |
| 44 | unban(c); | ||
| 45 | if(c->isfloating) | 44 | if(c->isfloating) |
| 46 | continue; | 45 | continue; |
| 47 | c->ismax = False; | 46 | c->ismax = False; |
| @@ -65,17 +64,13 @@ tile(void) { | |||
| 65 | ny += nh + 2 * c->border; | 64 | ny += nh + 2 * c->border; |
| 66 | i++; | 65 | i++; |
| 67 | } | 66 | } |
| 68 | else | ||
| 69 | ban(c); | ||
| 70 | focus(NULL); | ||
| 71 | restack(); | ||
| 72 | } | 67 | } |
| 73 | 68 | ||
| 74 | void | 69 | void |
| 75 | zoom(const char *arg) { | 70 | zoom(const char *arg) { |
| 76 | Client *c; | 71 | Client *c; |
| 77 | 72 | ||
| 78 | if(!sel || lt->arrange == floating || sel->isfloating) | 73 | if(!sel || !isarrange(tile) || sel->isfloating) |
| 79 | return; | 74 | return; |
| 80 | if((c = sel) == nexttiled(clients)) | 75 | if((c = sel) == nexttiled(clients)) |
| 81 | if(!(c = nexttiled(c->next))) | 76 | if(!(c = nexttiled(c->next))) |
| @@ -83,5 +78,5 @@ zoom(const char *arg) { | |||
| 83 | detach(c); | 78 | detach(c); |
| 84 | attach(c); | 79 | attach(c); |
| 85 | focus(c); | 80 | focus(c); |
| 86 | lt->arrange(); | 81 | arrange(); |
| 87 | } | 82 | } |
