diff options
| author | Anselm R. Garbe <arg@suckless.org> | 2007-02-19 13:00:29 +0100 |
|---|---|---|
| committer | Anselm R. Garbe <arg@suckless.org> | 2007-02-19 13:00:29 +0100 |
| commit | 5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63 (patch) | |
| tree | 2025c7842831bd512df4816717e5e47160f99f7c | |
| parent | simplified configurerequest to a bare minimum, removed wrong ban() calls (diff) | |
| download | dwm-5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63.tar.gz dwm-5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63.zip | |
introduced tile.c, some refactoring of functions
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | config.arg.h | 2 | ||||
| -rw-r--r-- | config.default.h | 2 | ||||
| -rw-r--r-- | dwm.h | 13 | ||||
| -rw-r--r-- | main.c | 2 | ||||
| -rw-r--r-- | tag.c | 2 | ||||
| -rw-r--r-- | tile.c | 132 | ||||
| -rw-r--r-- | view.c | 136 |
8 files changed, 150 insertions, 141 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | include config.mk | 4 | include config.mk |
| 5 | 5 | ||
| 6 | SRC = client.c draw.c event.c main.c tag.c util.c view.c | 6 | SRC = client.c draw.c event.c main.c tile.c tag.c util.c view.c |
| 7 | OBJ = ${SRC:.c=.o} | 7 | OBJ = ${SRC:.c=.o} |
| 8 | 8 | ||
| 9 | all: options dwm | 9 | all: options dwm |
diff --git a/config.arg.h b/config.arg.h index 2b94fd6..fae30d0 100644 --- a/config.arg.h +++ b/config.arg.h | |||
| @@ -5,11 +5,11 @@ | |||
| 5 | #define TAGS \ | 5 | #define TAGS \ |
| 6 | const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; | 6 | const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; |
| 7 | 7 | ||
| 8 | #define BORDERPX 1 | ||
| 9 | #define DEFMODE dotile /* dofloat */ | 8 | #define DEFMODE dotile /* dofloat */ |
| 10 | #define FLOATSYMBOL "><>" | 9 | #define FLOATSYMBOL "><>" |
| 11 | #define TILESYMBOL "[]=" | 10 | #define TILESYMBOL "[]=" |
| 12 | 11 | ||
| 12 | #define BORDERPX 1 | ||
| 13 | #define FONT "-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*" | 13 | #define FONT "-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*" |
| 14 | #define NORMBORDERCOLOR "#333" | 14 | #define NORMBORDERCOLOR "#333" |
| 15 | #define NORMBGCOLOR "#222" | 15 | #define NORMBGCOLOR "#222" |
diff --git a/config.default.h b/config.default.h index b8654bd..c1274a1 100644 --- a/config.default.h +++ b/config.default.h | |||
| @@ -5,11 +5,11 @@ | |||
| 5 | #define TAGS \ | 5 | #define TAGS \ |
| 6 | const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; | 6 | const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; |
| 7 | 7 | ||
| 8 | #define BORDERPX 1 | ||
| 9 | #define DEFMODE dotile /* dofloat */ | 8 | #define DEFMODE dotile /* dofloat */ |
| 10 | #define FLOATSYMBOL "><>" | 9 | #define FLOATSYMBOL "><>" |
| 11 | #define TILESYMBOL "[]=" | 10 | #define TILESYMBOL "[]=" |
| 12 | 11 | ||
| 12 | #define BORDERPX 1 | ||
| 13 | #define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*" | 13 | #define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*" |
| 14 | #define NORMBORDERCOLOR "#dddddd" | 14 | #define NORMBORDERCOLOR "#dddddd" |
| 15 | #define NORMBGCOLOR "#eeeeee" | 15 | #define NORMBGCOLOR "#eeeeee" |
| @@ -127,11 +127,17 @@ extern void sendevent(Window w, Atom a, long value); /* send synthetic event to | |||
| 127 | extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ | 127 | extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ |
| 128 | 128 | ||
| 129 | /* tag.c */ | 129 | /* tag.c */ |
| 130 | extern void initrregs(void); /* initialize regexps of rules defined in config.h */ | 130 | extern void compileregexps(void); /* initialize regexps of rules defined in config.h */ |
| 131 | extern void settags(Client *c, Client *trans); /* sets tags of c */ | 131 | extern void settags(Client *c, Client *trans); /* sets tags of c */ |
| 132 | extern void tag(Arg *arg); /* tags c with arg's index */ | 132 | extern void tag(Arg *arg); /* tags c with arg's index */ |
| 133 | extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ | 133 | extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ |
| 134 | 134 | ||
| 135 | /* tile.c */ | ||
| 136 | extern void dotile(void); /* arranges all windows tiled */ | ||
| 137 | extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */ | ||
| 138 | extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */ | ||
| 139 | extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ | ||
| 140 | |||
| 135 | /* util.c */ | 141 | /* util.c */ |
| 136 | extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ | 142 | extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ |
| 137 | extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ | 143 | extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ |
| @@ -140,15 +146,12 @@ extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */ | |||
| 140 | /* view.c */ | 146 | /* view.c */ |
| 141 | extern void detach(Client *c); /* detaches c from global client list */ | 147 | extern void detach(Client *c); /* detaches c from global client list */ |
| 142 | extern void dofloat(void); /* arranges all windows floating */ | 148 | extern void dofloat(void); /* arranges all windows floating */ |
| 143 | extern void dotile(void); /* arranges all windows tiled */ | ||
| 144 | extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ | 149 | extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ |
| 145 | extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ | 150 | extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ |
| 146 | extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */ | ||
| 147 | extern Bool isvisible(Client *c); /* returns True if client is visible */ | 151 | extern Bool isvisible(Client *c); /* returns True if client is visible */ |
| 148 | extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */ | 152 | extern Client *nextmanaged(Client *c); /* returns managed successor of c */ |
| 149 | extern void restack(void); /* restores z layers of all clients */ | 153 | extern void restack(void); /* restores z layers of all clients */ |
| 150 | extern void togglefloat(Arg *arg); /* toggles focusesd client between floating/non-floating state */ | 154 | extern void togglefloat(Arg *arg); /* toggles focusesd client between floating/non-floating state */ |
| 151 | extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */ | 155 | extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */ |
| 152 | extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ | 156 | extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ |
| 153 | extern void view(Arg *arg); /* views the tag with arg's index */ | 157 | extern void view(Arg *arg); /* views the tag with arg's index */ |
| 154 | extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ | ||
| @@ -117,7 +117,7 @@ setup(void) { | |||
| 117 | wa.cursor = cursor[CurNormal]; | 117 | wa.cursor = cursor[CurNormal]; |
| 118 | XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); | 118 | XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
| 119 | grabkeys(); | 119 | grabkeys(); |
| 120 | initrregs(); | 120 | compileregexps(); |
| 121 | for(ntags = 0; tags[ntags]; ntags++); | 121 | for(ntags = 0; tags[ntags]; ntags++); |
| 122 | seltag = emallocz(sizeof(Bool) * ntags); | 122 | seltag = emallocz(sizeof(Bool) * ntags); |
| 123 | seltag[0] = True; | 123 | seltag[0] = True; |
| @@ -32,7 +32,7 @@ static unsigned int len = 0; | |||
| 32 | /* extern */ | 32 | /* extern */ |
| 33 | 33 | ||
| 34 | void | 34 | void |
| 35 | initrregs(void) { | 35 | compileregexps(void) { |
| 36 | unsigned int i; | 36 | unsigned int i; |
| 37 | regex_t *reg; | 37 | regex_t *reg; |
| 38 | 38 | ||
| @@ -0,0 +1,132 @@ | |||
| 1 | /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com> | ||
| 2 | * See LICENSE file for license details. | ||
| 3 | */ | ||
| 4 | #include "dwm.h" | ||
| 5 | |||
| 6 | /* static */ | ||
| 7 | |||
| 8 | static void | ||
| 9 | togglemax(Client *c) { | ||
| 10 | XEvent ev; | ||
| 11 | |||
| 12 | if(c->isfixed) | ||
| 13 | return; | ||
| 14 | |||
| 15 | if((c->ismax = !c->ismax)) { | ||
| 16 | c->rx = c->x; | ||
| 17 | c->ry = c->y; | ||
| 18 | c->rw = c->w; | ||
| 19 | c->rh = c->h; | ||
| 20 | resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True); | ||
| 21 | } | ||
| 22 | else | ||
| 23 | resize(c, c->rx, c->ry, c->rw, c->rh, True); | ||
| 24 | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | ||
| 25 | } | ||
| 26 | |||
| 27 | /* extern */ | ||
| 28 | |||
| 29 | void | ||
| 30 | dotile(void) { | ||
| 31 | unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; | ||
| 32 | Client *c; | ||
| 33 | |||
| 34 | for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) | ||
| 35 | n++; | ||
| 36 | /* window geoms */ | ||
| 37 | mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); | ||
| 38 | mw = (n > nmaster) ? (waw * master) / 1000 : waw; | ||
| 39 | th = (n > nmaster) ? wah / (n - nmaster) : 0; | ||
| 40 | tw = waw - mw; | ||
| 41 | |||
| 42 | for(i = 0, c = clients; c; c = c->next) | ||
| 43 | if(isvisible(c)) { | ||
| 44 | if(c->isbanned) | ||
| 45 | XMoveWindow(dpy, c->win, c->x, c->y); | ||
| 46 | c->isbanned = False; | ||
| 47 | if(c->isfloat) | ||
| 48 | continue; | ||
| 49 | c->ismax = False; | ||
| 50 | nx = wax; | ||
| 51 | ny = way; | ||
| 52 | if(i < nmaster) { | ||
| 53 | ny += i * mh; | ||
| 54 | nw = mw - 2 * BORDERPX; | ||
| 55 | nh = mh - 2 * BORDERPX; | ||
| 56 | } | ||
| 57 | else { /* tile window */ | ||
| 58 | nx += mw; | ||
| 59 | nw = tw - 2 * BORDERPX; | ||
| 60 | if(th > 2 * BORDERPX) { | ||
| 61 | ny += (i - nmaster) * th; | ||
| 62 | nh = th - 2 * BORDERPX; | ||
| 63 | } | ||
| 64 | else /* fallback if th <= 2 * BORDERPX */ | ||
| 65 | nh = wah - 2 * BORDERPX; | ||
| 66 | } | ||
| 67 | resize(c, nx, ny, nw, nh, False); | ||
| 68 | i++; | ||
| 69 | } | ||
| 70 | else { | ||
| 71 | c->isbanned = True; | ||
| 72 | XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); | ||
| 73 | } | ||
| 74 | if(!sel || !isvisible(sel)) { | ||
| 75 | for(c = stack; c && !isvisible(c); c = c->snext); | ||
| 76 | focus(c); | ||
| 77 | } | ||
| 78 | restack(); | ||
| 79 | } | ||
| 80 | |||
| 81 | void | ||
| 82 | incnmaster(Arg *arg) { | ||
| 83 | if((arrange == dofloat) || (nmaster + arg->i < 1) | ||
| 84 | || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) | ||
| 85 | return; | ||
| 86 | nmaster += arg->i; | ||
| 87 | if(sel) | ||
| 88 | arrange(); | ||
| 89 | else | ||
| 90 | drawstatus(); | ||
| 91 | } | ||
| 92 | |||
| 93 | void | ||
| 94 | resizemaster(Arg *arg) { | ||
| 95 | if(arrange != dotile) | ||
| 96 | return; | ||
| 97 | if(arg->i == 0) | ||
| 98 | master = MASTER; | ||
| 99 | else { | ||
| 100 | if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX | ||
| 101 | || waw * (master + arg->i) / 1000 <= 2 * BORDERPX) | ||
| 102 | return; | ||
| 103 | master += arg->i; | ||
| 104 | } | ||
| 105 | arrange(); | ||
| 106 | } | ||
| 107 | |||
| 108 | void | ||
| 109 | zoom(Arg *arg) { | ||
| 110 | unsigned int n; | ||
| 111 | Client *c; | ||
| 112 | |||
| 113 | if(!sel) | ||
| 114 | return; | ||
| 115 | if(sel->isfloat || (arrange == dofloat)) { | ||
| 116 | togglemax(sel); | ||
| 117 | return; | ||
| 118 | } | ||
| 119 | for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) | ||
| 120 | n++; | ||
| 121 | |||
| 122 | if((c = sel) == nextmanaged(clients)) | ||
| 123 | if(!(c = nextmanaged(c->next))) | ||
| 124 | return; | ||
| 125 | detach(c); | ||
| 126 | if(clients) | ||
| 127 | clients->prev = c; | ||
| 128 | c->next = clients; | ||
| 129 | clients = c; | ||
| 130 | focus(c); | ||
| 131 | arrange(); | ||
| 132 | } | ||
| @@ -2,34 +2,6 @@ | |||
| 2 | * See LICENSE file for license details. | 2 | * See LICENSE file for license details. |
| 3 | */ | 3 | */ |
| 4 | #include "dwm.h" | 4 | #include "dwm.h" |
| 5 | #include <stdio.h> | ||
| 6 | |||
| 7 | /* static */ | ||
| 8 | |||
| 9 | static Client * | ||
| 10 | nexttiled(Client *c) { | ||
| 11 | for(; c && (c->isfloat || !isvisible(c)); c = c->next); | ||
| 12 | return c; | ||
| 13 | } | ||
| 14 | |||
| 15 | static void | ||
| 16 | togglemax(Client *c) { | ||
| 17 | XEvent ev; | ||
| 18 | |||
| 19 | if(c->isfixed) | ||
| 20 | return; | ||
| 21 | |||
| 22 | if((c->ismax = !c->ismax)) { | ||
| 23 | c->rx = c->x; | ||
| 24 | c->ry = c->y; | ||
| 25 | c->rw = c->w; | ||
| 26 | c->rh = c->h; | ||
| 27 | resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True); | ||
| 28 | } | ||
| 29 | else | ||
| 30 | resize(c, c->rx, c->ry, c->rw, c->rh, True); | ||
| 31 | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | ||
| 32 | } | ||
| 33 | 5 | ||
| 34 | /* extern */ | 6 | /* extern */ |
| 35 | 7 | ||
| @@ -70,58 +42,6 @@ dofloat(void) { | |||
| 70 | } | 42 | } |
| 71 | 43 | ||
| 72 | void | 44 | void |
| 73 | dotile(void) { | ||
| 74 | unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; | ||
| 75 | Client *c; | ||
| 76 | |||
| 77 | for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) | ||
| 78 | n++; | ||
| 79 | /* window geoms */ | ||
| 80 | mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); | ||
| 81 | mw = (n > nmaster) ? (waw * master) / 1000 : waw; | ||
| 82 | th = (n > nmaster) ? wah / (n - nmaster) : 0; | ||
| 83 | tw = waw - mw; | ||
| 84 | |||
| 85 | for(i = 0, c = clients; c; c = c->next) | ||
| 86 | if(isvisible(c)) { | ||
| 87 | if(c->isbanned) | ||
| 88 | XMoveWindow(dpy, c->win, c->x, c->y); | ||
| 89 | c->isbanned = False; | ||
| 90 | if(c->isfloat) | ||
| 91 | continue; | ||
| 92 | c->ismax = False; | ||
| 93 | nx = wax; | ||
| 94 | ny = way; | ||
| 95 | if(i < nmaster) { | ||
| 96 | ny += i * mh; | ||
| 97 | nw = mw - 2 * BORDERPX; | ||
| 98 | nh = mh - 2 * BORDERPX; | ||
| 99 | } | ||
| 100 | else { /* tile window */ | ||
| 101 | nx += mw; | ||
| 102 | nw = tw - 2 * BORDERPX; | ||
| 103 | if(th > 2 * BORDERPX) { | ||
| 104 | ny += (i - nmaster) * th; | ||
| 105 | nh = th - 2 * BORDERPX; | ||
| 106 | } | ||
| 107 | else /* fallback if th <= 2 * BORDERPX */ | ||
| 108 | nh = wah - 2 * BORDERPX; | ||
| 109 | } | ||
| 110 | resize(c, nx, ny, nw, nh, False); | ||
| 111 | i++; | ||
| 112 | } | ||
| 113 | else { | ||
| 114 | c->isbanned = True; | ||
| 115 | XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); | ||
| 116 | } | ||
| 117 | if(!sel || !isvisible(sel)) { | ||
| 118 | for(c = stack; c && !isvisible(c); c = c->snext); | ||
| 119 | focus(c); | ||
| 120 | } | ||
| 121 | restack(); | ||
| 122 | } | ||
| 123 | |||
| 124 | void | ||
| 125 | focusnext(Arg *arg) { | 45 | focusnext(Arg *arg) { |
| 126 | Client *c; | 46 | Client *c; |
| 127 | 47 | ||
| @@ -153,18 +73,6 @@ focusprev(Arg *arg) { | |||
| 153 | } | 73 | } |
| 154 | } | 74 | } |
| 155 | 75 | ||
| 156 | void | ||
| 157 | incnmaster(Arg *arg) { | ||
| 158 | if((arrange == dofloat) || (nmaster + arg->i < 1) | ||
| 159 | || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) | ||
| 160 | return; | ||
| 161 | nmaster += arg->i; | ||
| 162 | if(sel) | ||
| 163 | arrange(); | ||
| 164 | else | ||
| 165 | drawstatus(); | ||
| 166 | } | ||
| 167 | |||
| 168 | Bool | 76 | Bool |
| 169 | isvisible(Client *c) { | 77 | isvisible(Client *c) { |
| 170 | unsigned int i; | 78 | unsigned int i; |
| @@ -175,19 +83,10 @@ isvisible(Client *c) { | |||
| 175 | return False; | 83 | return False; |
| 176 | } | 84 | } |
| 177 | 85 | ||
| 178 | void | 86 | Client * |
| 179 | resizemaster(Arg *arg) { | 87 | nextmanaged(Client *c) { |
| 180 | if(arrange != dotile) | 88 | for(; c && (c->isfloat || !isvisible(c)); c = c->next); |
| 181 | return; | 89 | return c; |
| 182 | if(arg->i == 0) | ||
| 183 | master = MASTER; | ||
| 184 | else { | ||
| 185 | if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX | ||
| 186 | || waw * (master + arg->i) / 1000 <= 2 * BORDERPX) | ||
| 187 | return; | ||
| 188 | master += arg->i; | ||
| 189 | } | ||
| 190 | arrange(); | ||
| 191 | } | 90 | } |
| 192 | 91 | ||
| 193 | void | 92 | void |
| @@ -203,7 +102,7 @@ restack(void) { | |||
| 203 | if(arrange != dofloat) { | 102 | if(arrange != dofloat) { |
| 204 | if(!sel->isfloat) | 103 | if(!sel->isfloat) |
| 205 | XLowerWindow(dpy, sel->win); | 104 | XLowerWindow(dpy, sel->win); |
| 206 | for(c = nexttiled(clients); c; c = nexttiled(c->next)) { | 105 | for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) { |
| 207 | if(c == sel) | 106 | if(c == sel) |
| 208 | continue; | 107 | continue; |
| 209 | XLowerWindow(dpy, c->win); | 108 | XLowerWindow(dpy, c->win); |
| @@ -252,28 +151,3 @@ view(Arg *arg) { | |||
| 252 | arrange(); | 151 | arrange(); |
| 253 | } | 152 | } |
| 254 | 153 | ||
| 255 | void | ||
| 256 | zoom(Arg *arg) { | ||
| 257 | unsigned int n; | ||
| 258 | Client *c; | ||
| 259 | |||
| 260 | if(!sel) | ||
| 261 | return; | ||
| 262 | if(sel->isfloat || (arrange == dofloat)) { | ||
| 263 | togglemax(sel); | ||
| 264 | return; | ||
| 265 | } | ||
| 266 | for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) | ||
| 267 | n++; | ||
| 268 | |||
| 269 | if((c = sel) == nexttiled(clients)) | ||
| 270 | if(!(c = nexttiled(c->next))) | ||
| 271 | return; | ||
| 272 | detach(c); | ||
| 273 | if(clients) | ||
| 274 | clients->prev = c; | ||
| 275 | c->next = clients; | ||
| 276 | clients = c; | ||
| 277 | focus(c); | ||
| 278 | arrange(); | ||
| 279 | } | ||
