diff options
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | client.c | 73 | ||||
| -rw-r--r-- | dwm.h | 10 | ||||
| -rw-r--r-- | screen.c (renamed from view.c) | 51 |
4 files changed, 67 insertions, 69 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 manage.c util.c | 6 | SRC = client.c draw.c event.c main.c screen.c util.c |
| 7 | OBJ = ${SRC:.c=.o} | 7 | OBJ = ${SRC:.c=.o} |
| 8 | 8 | ||
| 9 | all: options dwm | 9 | all: options dwm |
| @@ -10,6 +10,19 @@ | |||
| 10 | /* static */ | 10 | /* static */ |
| 11 | 11 | ||
| 12 | static void | 12 | static void |
| 13 | attachstack(Client *c) { | ||
| 14 | c->snext = stack; | ||
| 15 | stack = c; | ||
| 16 | } | ||
| 17 | |||
| 18 | static void | ||
| 19 | detachstack(Client *c) { | ||
| 20 | Client **tc; | ||
| 21 | for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext); | ||
| 22 | *tc = c->snext; | ||
| 23 | } | ||
| 24 | |||
| 25 | static void | ||
| 13 | grabbuttons(Client *c, Bool focused) { | 26 | grabbuttons(Client *c, Bool focused) { |
| 14 | XUngrabButton(dpy, AnyButton, AnyModifier, c->win); | 27 | XUngrabButton(dpy, AnyButton, AnyModifier, c->win); |
| 15 | 28 | ||
| @@ -68,6 +81,24 @@ setclientstate(Client *c, long state) { | |||
| 68 | PropModeReplace, (unsigned char *)data, 2); | 81 | PropModeReplace, (unsigned char *)data, 2); |
| 69 | } | 82 | } |
| 70 | 83 | ||
| 84 | static void | ||
| 85 | togglemax(Client *c) { | ||
| 86 | XEvent ev; | ||
| 87 | |||
| 88 | if(c->isfixed) | ||
| 89 | return; | ||
| 90 | if((c->ismax = !c->ismax)) { | ||
| 91 | c->rx = c->x; | ||
| 92 | c->ry = c->y; | ||
| 93 | c->rw = c->w; | ||
| 94 | c->rh = c->h; | ||
| 95 | resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True); | ||
| 96 | } | ||
| 97 | else | ||
| 98 | resize(c, c->rx, c->ry, c->rw, c->rh, True); | ||
| 99 | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | ||
| 100 | } | ||
| 101 | |||
| 71 | static int | 102 | static int |
| 72 | xerrordummy(Display *dsply, XErrorEvent *ee) { | 103 | xerrordummy(Display *dsply, XErrorEvent *ee) { |
| 73 | return 0; | 104 | return 0; |
| @@ -84,12 +115,6 @@ attach(Client *c) { | |||
| 84 | } | 115 | } |
| 85 | 116 | ||
| 86 | void | 117 | void |
| 87 | attachstack(Client *c) { | ||
| 88 | c->snext = stack; | ||
| 89 | stack = c; | ||
| 90 | } | ||
| 91 | |||
| 92 | void | ||
| 93 | configure(Client *c) { | 118 | configure(Client *c) { |
| 94 | XConfigureEvent ce; | 119 | XConfigureEvent ce; |
| 95 | 120 | ||
| @@ -119,13 +144,6 @@ detach(Client *c) { | |||
| 119 | } | 144 | } |
| 120 | 145 | ||
| 121 | void | 146 | void |
| 122 | detachstack(Client *c) { | ||
| 123 | Client **tc; | ||
| 124 | for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext); | ||
| 125 | *tc = c->snext; | ||
| 126 | } | ||
| 127 | |||
| 128 | void | ||
| 129 | focus(Client *c) { | 147 | focus(Client *c) { |
| 130 | if(c && !isvisible(c)) | 148 | if(c && !isvisible(c)) |
| 131 | return; | 149 | return; |
| @@ -256,6 +274,12 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 256 | arrange(); | 274 | arrange(); |
| 257 | } | 275 | } |
| 258 | 276 | ||
| 277 | Client * | ||
| 278 | nexttiled(Client *c) { | ||
| 279 | for(; c && (c->isfloat || !isvisible(c)); c = c->next); | ||
| 280 | return c; | ||
| 281 | } | ||
| 282 | |||
| 259 | void | 283 | void |
| 260 | resize(Client *c, int x, int y, int w, int h, Bool sizehints) { | 284 | resize(Client *c, int x, int y, int w, int h, Bool sizehints) { |
| 261 | float actual, dx, dy, max, min; | 285 | float actual, dx, dy, max, min; |
| @@ -416,3 +440,26 @@ unmanage(Client *c) { | |||
| 416 | XUngrabServer(dpy); | 440 | XUngrabServer(dpy); |
| 417 | arrange(); | 441 | arrange(); |
| 418 | } | 442 | } |
| 443 | |||
| 444 | void | ||
| 445 | zoom(Arg *arg) { | ||
| 446 | unsigned int n; | ||
| 447 | Client *c; | ||
| 448 | |||
| 449 | if(!sel) | ||
| 450 | return; | ||
| 451 | if(sel->isfloat || (arrange == dofloat)) { | ||
| 452 | togglemax(sel); | ||
| 453 | return; | ||
| 454 | } | ||
| 455 | for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) | ||
| 456 | n++; | ||
| 457 | |||
| 458 | if((c = sel) == nexttiled(clients)) | ||
| 459 | if(!(c = nexttiled(c->next))) | ||
| 460 | return; | ||
| 461 | detach(c); | ||
| 462 | attach(c); | ||
| 463 | focus(c); | ||
| 464 | arrange(); | ||
| 465 | } | ||
| @@ -99,22 +99,20 @@ extern Display *dpy; | |||
| 99 | extern Window root, barwin; | 99 | extern Window root, barwin; |
| 100 | 100 | ||
| 101 | /* client.c */ | 101 | /* client.c */ |
| 102 | extern void attach(Client *c); /* attaches c to global client list */ | ||
| 103 | extern void attachstack(Client *c); /* attaches client to stack */ | ||
| 104 | extern void configure(Client *c); /* send synthetic configure event */ | 102 | extern void configure(Client *c); /* send synthetic configure event */ |
| 105 | extern void detach(Client *c); /* detaches c from global client list */ | ||
| 106 | extern void detachstack(Client *c); /* detaches client from stack */ | ||
| 107 | extern void focus(Client *c); /* focus c, c may be NULL */ | 103 | extern void focus(Client *c); /* focus c, c may be NULL */ |
| 108 | extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ | 104 | extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ |
| 109 | extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ | 105 | extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ |
| 110 | extern Client *getclient(Window w); /* return client of w */ | 106 | extern Client *getclient(Window w); /* return client of w */ |
| 111 | extern void killclient(Arg *arg); /* kill c nicely */ | 107 | extern void killclient(Arg *arg); /* kill c nicely */ |
| 112 | extern void manage(Window w, XWindowAttributes *wa); /* manage new client */ | 108 | extern void manage(Window w, XWindowAttributes *wa); /* manage new client */ |
| 109 | Client *nexttiled(Client *c); /* returns tiled successor of c */ | ||
| 113 | extern void resize(Client *c, int x, int y, | 110 | extern void resize(Client *c, int x, int y, |
| 114 | int w, int h, Bool sizehints); /* resize c*/ | 111 | int w, int h, Bool sizehints); /* resize c*/ |
| 115 | extern void updatesizehints(Client *c); /* update the size hint variables of c */ | 112 | extern void updatesizehints(Client *c); /* update the size hint variables of c */ |
| 116 | extern void updatetitle(Client *c); /* update the name of c */ | 113 | extern void updatetitle(Client *c); /* update the name of c */ |
| 117 | extern void unmanage(Client *c); /* destroy c */ | 114 | extern void unmanage(Client *c); /* destroy c */ |
| 115 | extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ | ||
| 118 | 116 | ||
| 119 | /* draw.c */ | 117 | /* draw.c */ |
| 120 | extern void drawstatus(void); /* draw the bar */ | 118 | extern void drawstatus(void); /* draw the bar */ |
| @@ -131,7 +129,7 @@ extern void quit(Arg *arg); /* quit dwm nicely */ | |||
| 131 | extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ | 129 | extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ |
| 132 | extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ | 130 | extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ |
| 133 | 131 | ||
| 134 | /* manage.c */ | 132 | /* screen.c */ |
| 135 | extern void compileregexps(void); /* initialize regexps of rules defined in config.h */ | 133 | extern void compileregexps(void); /* initialize regexps of rules defined in config.h */ |
| 136 | extern void dofloat(void); /* arranges all windows floating */ | 134 | extern void dofloat(void); /* arranges all windows floating */ |
| 137 | extern void dotile(void); /* arranges all windows tiled */ | 135 | extern void dotile(void); /* arranges all windows tiled */ |
| @@ -146,9 +144,9 @@ extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/do | |||
| 146 | extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ | 144 | extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ |
| 147 | extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ | 145 | extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ |
| 148 | extern void view(Arg *arg); /* views the tag with arg's index */ | 146 | extern void view(Arg *arg); /* views the tag with arg's index */ |
| 149 | extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ | ||
| 150 | 147 | ||
| 151 | /* util.c */ | 148 | /* util.c */ |
| 152 | extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ | 149 | extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ |
| 153 | extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ | 150 | extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ |
| 154 | extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */ | 151 | extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */ |
| 152 | |||
| @@ -32,30 +32,6 @@ RULES | |||
| 32 | static Regexps *regexps = NULL; | 32 | static Regexps *regexps = NULL; |
| 33 | static unsigned int len = 0; | 33 | static unsigned int len = 0; |
| 34 | 34 | ||
| 35 | static Client * | ||
| 36 | nextmanaged(Client *c) { | ||
| 37 | for(; c && (c->isfloat || !isvisible(c)); c = c->next); | ||
| 38 | return c; | ||
| 39 | } | ||
| 40 | |||
| 41 | static void | ||
| 42 | togglemax(Client *c) { | ||
| 43 | XEvent ev; | ||
| 44 | |||
| 45 | if(c->isfixed) | ||
| 46 | return; | ||
| 47 | if((c->ismax = !c->ismax)) { | ||
| 48 | c->rx = c->x; | ||
| 49 | c->ry = c->y; | ||
| 50 | c->rw = c->w; | ||
| 51 | c->rh = c->h; | ||
| 52 | resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True); | ||
| 53 | } | ||
| 54 | else | ||
| 55 | resize(c, c->rx, c->ry, c->rw, c->rh, True); | ||
| 56 | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | ||
| 57 | } | ||
| 58 | |||
| 59 | /* extern */ | 35 | /* extern */ |
| 60 | 36 | ||
| 61 | void | 37 | void |
| @@ -112,7 +88,7 @@ dotile(void) { | |||
| 112 | unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; | 88 | unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; |
| 113 | Client *c; | 89 | Client *c; |
| 114 | 90 | ||
| 115 | for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) | 91 | for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) |
| 116 | n++; | 92 | n++; |
| 117 | /* window geoms */ | 93 | /* window geoms */ |
| 118 | mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); | 94 | mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); |
| @@ -209,7 +185,7 @@ restack(void) { | |||
| 209 | if(arrange != dofloat) { | 185 | if(arrange != dofloat) { |
| 210 | if(!sel->isfloat) | 186 | if(!sel->isfloat) |
| 211 | XLowerWindow(dpy, sel->win); | 187 | XLowerWindow(dpy, sel->win); |
| 212 | for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) { | 188 | for(c = nexttiled(clients); c; c = nexttiled(c->next)) { |
| 213 | if(c == sel) | 189 | if(c == sel) |
| 214 | continue; | 190 | continue; |
| 215 | XLowerWindow(dpy, c->win); | 191 | XLowerWindow(dpy, c->win); |
| @@ -319,26 +295,3 @@ view(Arg *arg) { | |||
| 319 | seltag[arg->i] = True; | 295 | seltag[arg->i] = True; |
| 320 | arrange(); | 296 | arrange(); |
| 321 | } | 297 | } |
| 322 | |||
| 323 | void | ||
| 324 | zoom(Arg *arg) { | ||
| 325 | unsigned int n; | ||
| 326 | Client *c; | ||
| 327 | |||
| 328 | if(!sel) | ||
| 329 | return; | ||
| 330 | if(sel->isfloat || (arrange == dofloat)) { | ||
| 331 | togglemax(sel); | ||
| 332 | return; | ||
| 333 | } | ||
| 334 | for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) | ||
| 335 | n++; | ||
| 336 | |||
| 337 | if((c = sel) == nextmanaged(clients)) | ||
| 338 | if(!(c = nextmanaged(c->next))) | ||
| 339 | return; | ||
| 340 | detach(c); | ||
| 341 | attach(c); | ||
| 342 | focus(c); | ||
| 343 | arrange(); | ||
| 344 | } | ||
