merged tag.c, view.c and tile.c to manage.c
4cdbd523
6 file(s) · +434 −458
| 3 | 3 | ||
| 4 | 4 | include config.mk |
|
| 5 | 5 | ||
| 6 | - | SRC = client.c draw.c event.c main.c tile.c tag.c util.c view.c |
|
| 6 | + | SRC = client.c draw.c event.c main.c manage.c util.c |
|
| 7 | 7 | OBJ = ${SRC:.c=.o} |
|
| 8 | 8 | ||
| 9 | 9 | all: options dwm |
| 101 | 101 | /* client.c */ |
|
| 102 | 102 | extern void configure(Client *c); /* send synthetic configure event */ |
|
| 103 | 103 | extern void focus(Client *c); /* focus c, c may be NULL */ |
|
| 104 | - | extern Bool isprotodel(Client *c); /* returns True if c->win supports wmatom[WMDelete] */ |
|
| 105 | 104 | extern void killclient(Arg *arg); /* kill c nicely */ |
|
| 106 | 105 | extern void manage(Window w, XWindowAttributes *wa); /* manage new client */ |
|
| 107 | 106 | extern void resize(Client *c, int x, int y, |
|
| 125 | 124 | extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ |
|
| 126 | 125 | extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ |
|
| 127 | 126 | ||
| 128 | - | /* tag.c */ |
|
| 129 | - | extern void compileregexps(void); /* initialize regexps of rules defined in config.h */ |
|
| 130 | - | extern void settags(Client *c, Client *trans); /* sets tags of c */ |
|
| 131 | - | extern void tag(Arg *arg); /* tags c with arg's index */ |
|
| 132 | - | extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ |
|
| 133 | - | ||
| 134 | - | /* tile.c */ |
|
| 135 | - | extern void dotile(void); /* arranges all windows tiled */ |
|
| 136 | - | extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */ |
|
| 137 | - | extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */ |
|
| 138 | - | extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ |
|
| 139 | - | ||
| 140 | - | /* util.c */ |
|
| 141 | - | extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ |
|
| 142 | - | extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ |
|
| 143 | - | extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */ |
|
| 144 | - | ||
| 145 | - | /* view.c */ |
|
| 127 | + | /* manage.c */ |
|
| 146 | 128 | extern void attach(Client *c); /* attaches c to global client list */ |
|
| 147 | 129 | extern void attachstack(Client *c); /* attaches client to stack */ |
|
| 148 | - | extern void dofloat(void); /* arranges all windows floating */ |
|
| 130 | + | extern void compileregexps(void); /* initialize regexps of rules defined in config.h */ |
|
| 149 | 131 | extern void detach(Client *c); /* detaches c from global client list */ |
|
| 150 | 132 | extern void detachstack(Client *c); /* detaches client from stack */ |
|
| 133 | + | extern void dofloat(void); /* arranges all windows floating */ |
|
| 134 | + | extern void dotile(void); /* arranges all windows tiled */ |
|
| 151 | 135 | extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ |
|
| 152 | 136 | extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ |
|
| 153 | 137 | extern Client *getclient(Window w); /* return client of w */ |
|
| 138 | + | extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */ |
|
| 154 | 139 | extern Bool isvisible(Client *c); /* returns True if client is visible */ |
|
| 155 | - | extern Client *nextmanaged(Client *c); /* returns managed successor of c */ |
|
| 140 | + | extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */ |
|
| 156 | 141 | extern void restack(void); /* restores z layers of all clients */ |
|
| 142 | + | extern void settags(Client *c, Client *trans); /* sets tags of c */ |
|
| 143 | + | extern void tag(Arg *arg); /* tags c with arg's index */ |
|
| 157 | 144 | extern void togglefloat(Arg *arg); /* toggles focusesd client between floating/non-floating state */ |
|
| 158 | 145 | extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */ |
|
| 146 | + | extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ |
|
| 159 | 147 | extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ |
|
| 160 | 148 | 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 | + | ||
| 151 | + | /* util.c */ |
|
| 152 | + | 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 */ |
|
| 154 | + | extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */ |
|
| 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 | + | #include <regex.h> |
|
| 6 | + | #include <stdio.h> |
|
| 7 | + | #include <stdlib.h> |
|
| 8 | + | #include <string.h> |
|
| 9 | + | #include <sys/types.h> |
|
| 10 | + | #include <X11/Xutil.h> |
|
| 11 | + | ||
| 12 | + | void (*arrange)(void) = DEFMODE; |
|
| 13 | + | unsigned int master = MASTER; |
|
| 14 | + | unsigned int nmaster = NMASTER; |
|
| 15 | + | ||
| 16 | + | /* static */ |
|
| 17 | + | ||
| 18 | + | typedef struct { |
|
| 19 | + | const char *clpattern; |
|
| 20 | + | const char *tpattern; |
|
| 21 | + | Bool isfloat; |
|
| 22 | + | } Rule; |
|
| 23 | + | ||
| 24 | + | typedef struct { |
|
| 25 | + | regex_t *clregex; |
|
| 26 | + | regex_t *tregex; |
|
| 27 | + | } RReg; |
|
| 28 | + | ||
| 29 | + | TAGS |
|
| 30 | + | RULES |
|
| 31 | + | ||
| 32 | + | static RReg *rreg = NULL; |
|
| 33 | + | static unsigned int len = 0; |
|
| 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 */ |
|
| 60 | + | ||
| 61 | + | void |
|
| 62 | + | attach(Client *c) { |
|
| 63 | + | if(clients) |
|
| 64 | + | clients->prev = c; |
|
| 65 | + | c->next = clients; |
|
| 66 | + | clients = c; |
|
| 67 | + | } |
|
| 68 | + | ||
| 69 | + | void |
|
| 70 | + | attachstack(Client *c) { |
|
| 71 | + | c->snext = stack; |
|
| 72 | + | stack = c; |
|
| 73 | + | } |
|
| 74 | + | ||
| 75 | + | void |
|
| 76 | + | compileregexps(void) { |
|
| 77 | + | unsigned int i; |
|
| 78 | + | regex_t *reg; |
|
| 79 | + | ||
| 80 | + | if(rreg) |
|
| 81 | + | return; |
|
| 82 | + | len = sizeof rule / sizeof rule[0]; |
|
| 83 | + | rreg = emallocz(len * sizeof(RReg)); |
|
| 84 | + | for(i = 0; i < len; i++) { |
|
| 85 | + | if(rule[i].clpattern) { |
|
| 86 | + | reg = emallocz(sizeof(regex_t)); |
|
| 87 | + | if(regcomp(reg, rule[i].clpattern, REG_EXTENDED)) |
|
| 88 | + | free(reg); |
|
| 89 | + | else |
|
| 90 | + | rreg[i].clregex = reg; |
|
| 91 | + | } |
|
| 92 | + | if(rule[i].tpattern) { |
|
| 93 | + | reg = emallocz(sizeof(regex_t)); |
|
| 94 | + | if(regcomp(reg, rule[i].tpattern, REG_EXTENDED)) |
|
| 95 | + | free(reg); |
|
| 96 | + | else |
|
| 97 | + | rreg[i].tregex = reg; |
|
| 98 | + | } |
|
| 99 | + | } |
|
| 100 | + | } |
|
| 101 | + | ||
| 102 | + | void |
|
| 103 | + | detach(Client *c) { |
|
| 104 | + | if(c->prev) |
|
| 105 | + | c->prev->next = c->next; |
|
| 106 | + | if(c->next) |
|
| 107 | + | c->next->prev = c->prev; |
|
| 108 | + | if(c == clients) |
|
| 109 | + | clients = c->next; |
|
| 110 | + | c->next = c->prev = NULL; |
|
| 111 | + | } |
|
| 112 | + | ||
| 113 | + | void |
|
| 114 | + | detachstack(Client *c) { |
|
| 115 | + | Client **tc; |
|
| 116 | + | for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext); |
|
| 117 | + | *tc = c->snext; |
|
| 118 | + | } |
|
| 119 | + | ||
| 120 | + | void |
|
| 121 | + | dofloat(void) { |
|
| 122 | + | Client *c; |
|
| 123 | + | ||
| 124 | + | for(c = clients; c; c = c->next) { |
|
| 125 | + | if(isvisible(c)) { |
|
| 126 | + | if(c->isbanned) |
|
| 127 | + | XMoveWindow(dpy, c->win, c->x, c->y); |
|
| 128 | + | c->isbanned = False; |
|
| 129 | + | resize(c, c->x, c->y, c->w, c->h, True); |
|
| 130 | + | } |
|
| 131 | + | else { |
|
| 132 | + | c->isbanned = True; |
|
| 133 | + | XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); |
|
| 134 | + | } |
|
| 135 | + | } |
|
| 136 | + | if(!sel || !isvisible(sel)) { |
|
| 137 | + | for(c = stack; c && !isvisible(c); c = c->snext); |
|
| 138 | + | focus(c); |
|
| 139 | + | } |
|
| 140 | + | restack(); |
|
| 141 | + | } |
|
| 142 | + | void |
|
| 143 | + | dotile(void) { |
|
| 144 | + | unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; |
|
| 145 | + | Client *c; |
|
| 146 | + | ||
| 147 | + | for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) |
|
| 148 | + | n++; |
|
| 149 | + | /* window geoms */ |
|
| 150 | + | mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); |
|
| 151 | + | mw = (n > nmaster) ? (waw * master) / 1000 : waw; |
|
| 152 | + | th = (n > nmaster) ? wah / (n - nmaster) : 0; |
|
| 153 | + | tw = waw - mw; |
|
| 154 | + | ||
| 155 | + | for(i = 0, c = clients; c; c = c->next) |
|
| 156 | + | if(isvisible(c)) { |
|
| 157 | + | if(c->isbanned) |
|
| 158 | + | XMoveWindow(dpy, c->win, c->x, c->y); |
|
| 159 | + | c->isbanned = False; |
|
| 160 | + | if(c->isfloat) |
|
| 161 | + | continue; |
|
| 162 | + | c->ismax = False; |
|
| 163 | + | nx = wax; |
|
| 164 | + | ny = way; |
|
| 165 | + | if(i < nmaster) { |
|
| 166 | + | ny += i * mh; |
|
| 167 | + | nw = mw - 2 * BORDERPX; |
|
| 168 | + | nh = mh - 2 * BORDERPX; |
|
| 169 | + | } |
|
| 170 | + | else { /* tile window */ |
|
| 171 | + | nx += mw; |
|
| 172 | + | nw = tw - 2 * BORDERPX; |
|
| 173 | + | if(th > 2 * BORDERPX) { |
|
| 174 | + | ny += (i - nmaster) * th; |
|
| 175 | + | nh = th - 2 * BORDERPX; |
|
| 176 | + | } |
|
| 177 | + | else /* fallback if th <= 2 * BORDERPX */ |
|
| 178 | + | nh = wah - 2 * BORDERPX; |
|
| 179 | + | } |
|
| 180 | + | resize(c, nx, ny, nw, nh, False); |
|
| 181 | + | i++; |
|
| 182 | + | } |
|
| 183 | + | else { |
|
| 184 | + | c->isbanned = True; |
|
| 185 | + | XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); |
|
| 186 | + | } |
|
| 187 | + | if(!sel || !isvisible(sel)) { |
|
| 188 | + | for(c = stack; c && !isvisible(c); c = c->snext); |
|
| 189 | + | focus(c); |
|
| 190 | + | } |
|
| 191 | + | restack(); |
|
| 192 | + | } |
|
| 193 | + | ||
| 194 | + | void |
|
| 195 | + | focusnext(Arg *arg) { |
|
| 196 | + | Client *c; |
|
| 197 | + | ||
| 198 | + | if(!sel) |
|
| 199 | + | return; |
|
| 200 | + | for(c = sel->next; c && !isvisible(c); c = c->next); |
|
| 201 | + | if(!c) |
|
| 202 | + | for(c = clients; c && !isvisible(c); c = c->next); |
|
| 203 | + | if(c) { |
|
| 204 | + | focus(c); |
|
| 205 | + | restack(); |
|
| 206 | + | } |
|
| 207 | + | } |
|
| 208 | + | ||
| 209 | + | void |
|
| 210 | + | focusprev(Arg *arg) { |
|
| 211 | + | Client *c; |
|
| 212 | + | ||
| 213 | + | if(!sel) |
|
| 214 | + | return; |
|
| 215 | + | for(c = sel->prev; c && !isvisible(c); c = c->prev); |
|
| 216 | + | if(!c) { |
|
| 217 | + | for(c = clients; c && c->next; c = c->next); |
|
| 218 | + | for(; c && !isvisible(c); c = c->prev); |
|
| 219 | + | } |
|
| 220 | + | if(c) { |
|
| 221 | + | focus(c); |
|
| 222 | + | restack(); |
|
| 223 | + | } |
|
| 224 | + | } |
|
| 225 | + | ||
| 226 | + | Client * |
|
| 227 | + | getclient(Window w) { |
|
| 228 | + | Client *c; |
|
| 229 | + | ||
| 230 | + | for(c = clients; c; c = c->next) |
|
| 231 | + | if(c->win == w) |
|
| 232 | + | return c; |
|
| 233 | + | return NULL; |
|
| 234 | + | } |
|
| 235 | + | ||
| 236 | + | void |
|
| 237 | + | incnmaster(Arg *arg) { |
|
| 238 | + | if((arrange == dofloat) || (nmaster + arg->i < 1) |
|
| 239 | + | || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) |
|
| 240 | + | return; |
|
| 241 | + | nmaster += arg->i; |
|
| 242 | + | if(sel) |
|
| 243 | + | arrange(); |
|
| 244 | + | else |
|
| 245 | + | drawstatus(); |
|
| 246 | + | } |
|
| 247 | + | ||
| 248 | + | Bool |
|
| 249 | + | isvisible(Client *c) { |
|
| 250 | + | unsigned int i; |
|
| 251 | + | ||
| 252 | + | for(i = 0; i < ntags; i++) |
|
| 253 | + | if(c->tags[i] && seltag[i]) |
|
| 254 | + | return True; |
|
| 255 | + | return False; |
|
| 256 | + | } |
|
| 257 | + | ||
| 258 | + | void |
|
| 259 | + | resizemaster(Arg *arg) { |
|
| 260 | + | if(arrange != dotile) |
|
| 261 | + | return; |
|
| 262 | + | if(arg->i == 0) |
|
| 263 | + | master = MASTER; |
|
| 264 | + | else { |
|
| 265 | + | if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX |
|
| 266 | + | || waw * (master + arg->i) / 1000 <= 2 * BORDERPX) |
|
| 267 | + | return; |
|
| 268 | + | master += arg->i; |
|
| 269 | + | } |
|
| 270 | + | arrange(); |
|
| 271 | + | } |
|
| 272 | + | ||
| 273 | + | void |
|
| 274 | + | restack(void) { |
|
| 275 | + | Client *c; |
|
| 276 | + | XEvent ev; |
|
| 277 | + | ||
| 278 | + | drawstatus(); |
|
| 279 | + | if(!sel) |
|
| 280 | + | return; |
|
| 281 | + | if(sel->isfloat || arrange == dofloat) |
|
| 282 | + | XRaiseWindow(dpy, sel->win); |
|
| 283 | + | if(arrange != dofloat) { |
|
| 284 | + | if(!sel->isfloat) |
|
| 285 | + | XLowerWindow(dpy, sel->win); |
|
| 286 | + | for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) { |
|
| 287 | + | if(c == sel) |
|
| 288 | + | continue; |
|
| 289 | + | XLowerWindow(dpy, c->win); |
|
| 290 | + | } |
|
| 291 | + | } |
|
| 292 | + | XSync(dpy, False); |
|
| 293 | + | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
|
| 294 | + | } |
|
| 295 | + | ||
| 296 | + | void |
|
| 297 | + | settags(Client *c, Client *trans) { |
|
| 298 | + | char prop[512]; |
|
| 299 | + | unsigned int i, j; |
|
| 300 | + | regmatch_t tmp; |
|
| 301 | + | Bool matched = trans != NULL; |
|
| 302 | + | XClassHint ch = { 0 }; |
|
| 303 | + | ||
| 304 | + | if(matched) |
|
| 305 | + | for(i = 0; i < ntags; i++) |
|
| 306 | + | c->tags[i] = trans->tags[i]; |
|
| 307 | + | else { |
|
| 308 | + | XGetClassHint(dpy, c->win, &ch); |
|
| 309 | + | snprintf(prop, sizeof prop, "%s:%s:%s", |
|
| 310 | + | ch.res_class ? ch.res_class : "", |
|
| 311 | + | ch.res_name ? ch.res_name : "", c->name); |
|
| 312 | + | for(i = 0; i < len; i++) |
|
| 313 | + | if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) { |
|
| 314 | + | c->isfloat = rule[i].isfloat; |
|
| 315 | + | for(j = 0; rreg[i].tregex && j < ntags; j++) { |
|
| 316 | + | if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) { |
|
| 317 | + | matched = True; |
|
| 318 | + | c->tags[j] = True; |
|
| 319 | + | } |
|
| 320 | + | } |
|
| 321 | + | } |
|
| 322 | + | if(ch.res_class) |
|
| 323 | + | XFree(ch.res_class); |
|
| 324 | + | if(ch.res_name) |
|
| 325 | + | XFree(ch.res_name); |
|
| 326 | + | } |
|
| 327 | + | if(!matched) |
|
| 328 | + | for(i = 0; i < ntags; i++) |
|
| 329 | + | c->tags[i] = seltag[i]; |
|
| 330 | + | } |
|
| 331 | + | ||
| 332 | + | void |
|
| 333 | + | tag(Arg *arg) { |
|
| 334 | + | unsigned int i; |
|
| 335 | + | ||
| 336 | + | if(!sel) |
|
| 337 | + | return; |
|
| 338 | + | for(i = 0; i < ntags; i++) |
|
| 339 | + | sel->tags[i] = (arg->i == -1) ? True : False; |
|
| 340 | + | if(arg->i >= 0 && arg->i < ntags) |
|
| 341 | + | sel->tags[arg->i] = True; |
|
| 342 | + | arrange(); |
|
| 343 | + | } |
|
| 344 | + | ||
| 345 | + | void |
|
| 346 | + | togglefloat(Arg *arg) { |
|
| 347 | + | if(!sel || arrange == dofloat) |
|
| 348 | + | return; |
|
| 349 | + | sel->isfloat = !sel->isfloat; |
|
| 350 | + | arrange(); |
|
| 351 | + | } |
|
| 352 | + | ||
| 353 | + | void |
|
| 354 | + | toggletag(Arg *arg) { |
|
| 355 | + | unsigned int i; |
|
| 356 | + | ||
| 357 | + | if(!sel) |
|
| 358 | + | return; |
|
| 359 | + | sel->tags[arg->i] = !sel->tags[arg->i]; |
|
| 360 | + | for(i = 0; i < ntags && !sel->tags[i]; i++); |
|
| 361 | + | if(i == ntags) |
|
| 362 | + | sel->tags[arg->i] = True; |
|
| 363 | + | arrange(); |
|
| 364 | + | } |
|
| 365 | + | ||
| 366 | + | void |
|
| 367 | + | togglemode(Arg *arg) { |
|
| 368 | + | arrange = (arrange == dofloat) ? dotile : dofloat; |
|
| 369 | + | if(sel) |
|
| 370 | + | arrange(); |
|
| 371 | + | else |
|
| 372 | + | drawstatus(); |
|
| 373 | + | } |
|
| 374 | + | ||
| 375 | + | void |
|
| 376 | + | toggleview(Arg *arg) { |
|
| 377 | + | unsigned int i; |
|
| 378 | + | ||
| 379 | + | seltag[arg->i] = !seltag[arg->i]; |
|
| 380 | + | for(i = 0; i < ntags && !seltag[i]; i++); |
|
| 381 | + | if(i == ntags) |
|
| 382 | + | seltag[arg->i] = True; /* cannot toggle last view */ |
|
| 383 | + | arrange(); |
|
| 384 | + | } |
|
| 385 | + | ||
| 386 | + | void |
|
| 387 | + | view(Arg *arg) { |
|
| 388 | + | unsigned int i; |
|
| 389 | + | ||
| 390 | + | for(i = 0; i < ntags; i++) |
|
| 391 | + | seltag[i] = (arg->i == -1) ? True : False; |
|
| 392 | + | if(arg->i >= 0 && arg->i < ntags) |
|
| 393 | + | seltag[arg->i] = True; |
|
| 394 | + | arrange(); |
|
| 395 | + | } |
|
| 396 | + | ||
| 397 | + | void |
|
| 398 | + | zoom(Arg *arg) { |
|
| 399 | + | unsigned int n; |
|
| 400 | + | Client *c; |
|
| 401 | + | ||
| 402 | + | if(!sel) |
|
| 403 | + | return; |
|
| 404 | + | if(sel->isfloat || (arrange == dofloat)) { |
|
| 405 | + | togglemax(sel); |
|
| 406 | + | return; |
|
| 407 | + | } |
|
| 408 | + | for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) |
|
| 409 | + | n++; |
|
| 410 | + | ||
| 411 | + | if((c = sel) == nextmanaged(clients)) |
|
| 412 | + | if(!(c = nextmanaged(c->next))) |
|
| 413 | + | return; |
|
| 414 | + | detach(c); |
|
| 415 | + | attach(c); |
|
| 416 | + | focus(c); |
|
| 417 | + | arrange(); |
|
| 418 | + | } |
| 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 | - | #include <regex.h> |
|
| 6 | - | #include <stdio.h> |
|
| 7 | - | #include <stdlib.h> |
|
| 8 | - | #include <string.h> |
|
| 9 | - | #include <sys/types.h> |
|
| 10 | - | #include <X11/Xutil.h> |
|
| 11 | - | ||
| 12 | - | ||
| 13 | - | typedef struct { |
|
| 14 | - | const char *clpattern; |
|
| 15 | - | const char *tpattern; |
|
| 16 | - | Bool isfloat; |
|
| 17 | - | } Rule; |
|
| 18 | - | ||
| 19 | - | typedef struct { |
|
| 20 | - | regex_t *clregex; |
|
| 21 | - | regex_t *tregex; |
|
| 22 | - | } RReg; |
|
| 23 | - | ||
| 24 | - | /* static */ |
|
| 25 | - | ||
| 26 | - | TAGS |
|
| 27 | - | RULES |
|
| 28 | - | ||
| 29 | - | static RReg *rreg = NULL; |
|
| 30 | - | static unsigned int len = 0; |
|
| 31 | - | ||
| 32 | - | /* extern */ |
|
| 33 | - | ||
| 34 | - | void |
|
| 35 | - | compileregexps(void) { |
|
| 36 | - | unsigned int i; |
|
| 37 | - | regex_t *reg; |
|
| 38 | - | ||
| 39 | - | if(rreg) |
|
| 40 | - | return; |
|
| 41 | - | len = sizeof rule / sizeof rule[0]; |
|
| 42 | - | rreg = emallocz(len * sizeof(RReg)); |
|
| 43 | - | for(i = 0; i < len; i++) { |
|
| 44 | - | if(rule[i].clpattern) { |
|
| 45 | - | reg = emallocz(sizeof(regex_t)); |
|
| 46 | - | if(regcomp(reg, rule[i].clpattern, REG_EXTENDED)) |
|
| 47 | - | free(reg); |
|
| 48 | - | else |
|
| 49 | - | rreg[i].clregex = reg; |
|
| 50 | - | } |
|
| 51 | - | if(rule[i].tpattern) { |
|
| 52 | - | reg = emallocz(sizeof(regex_t)); |
|
| 53 | - | if(regcomp(reg, rule[i].tpattern, REG_EXTENDED)) |
|
| 54 | - | free(reg); |
|
| 55 | - | else |
|
| 56 | - | rreg[i].tregex = reg; |
|
| 57 | - | } |
|
| 58 | - | } |
|
| 59 | - | } |
|
| 60 | - | ||
| 61 | - | void |
|
| 62 | - | settags(Client *c, Client *trans) { |
|
| 63 | - | char prop[512]; |
|
| 64 | - | unsigned int i, j; |
|
| 65 | - | regmatch_t tmp; |
|
| 66 | - | Bool matched = trans != NULL; |
|
| 67 | - | XClassHint ch = { 0 }; |
|
| 68 | - | ||
| 69 | - | if(matched) |
|
| 70 | - | for(i = 0; i < ntags; i++) |
|
| 71 | - | c->tags[i] = trans->tags[i]; |
|
| 72 | - | else { |
|
| 73 | - | XGetClassHint(dpy, c->win, &ch); |
|
| 74 | - | snprintf(prop, sizeof prop, "%s:%s:%s", |
|
| 75 | - | ch.res_class ? ch.res_class : "", |
|
| 76 | - | ch.res_name ? ch.res_name : "", c->name); |
|
| 77 | - | for(i = 0; i < len; i++) |
|
| 78 | - | if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) { |
|
| 79 | - | c->isfloat = rule[i].isfloat; |
|
| 80 | - | for(j = 0; rreg[i].tregex && j < ntags; j++) { |
|
| 81 | - | if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) { |
|
| 82 | - | matched = True; |
|
| 83 | - | c->tags[j] = True; |
|
| 84 | - | } |
|
| 85 | - | } |
|
| 86 | - | } |
|
| 87 | - | if(ch.res_class) |
|
| 88 | - | XFree(ch.res_class); |
|
| 89 | - | if(ch.res_name) |
|
| 90 | - | XFree(ch.res_name); |
|
| 91 | - | } |
|
| 92 | - | if(!matched) |
|
| 93 | - | for(i = 0; i < ntags; i++) |
|
| 94 | - | c->tags[i] = seltag[i]; |
|
| 95 | - | } |
|
| 96 | - | ||
| 97 | - | void |
|
| 98 | - | tag(Arg *arg) { |
|
| 99 | - | unsigned int i; |
|
| 100 | - | ||
| 101 | - | if(!sel) |
|
| 102 | - | return; |
|
| 103 | - | for(i = 0; i < ntags; i++) |
|
| 104 | - | sel->tags[i] = (arg->i == -1) ? True : False; |
|
| 105 | - | if(arg->i >= 0 && arg->i < ntags) |
|
| 106 | - | sel->tags[arg->i] = True; |
|
| 107 | - | arrange(); |
|
| 108 | - | } |
|
| 109 | - | ||
| 110 | - | void |
|
| 111 | - | toggletag(Arg *arg) { |
|
| 112 | - | unsigned int i; |
|
| 113 | - | ||
| 114 | - | if(!sel) |
|
| 115 | - | return; |
|
| 116 | - | sel->tags[arg->i] = !sel->tags[arg->i]; |
|
| 117 | - | for(i = 0; i < ntags && !sel->tags[i]; i++); |
|
| 118 | - | if(i == ntags) |
|
| 119 | - | sel->tags[arg->i] = True; |
|
| 120 | - | arrange(); |
|
| 121 | - | } |
| 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 | - | unsigned int master = MASTER; |
|
| 7 | - | unsigned int nmaster = NMASTER; |
|
| 8 | - | ||
| 9 | - | /* static */ |
|
| 10 | - | ||
| 11 | - | static void |
|
| 12 | - | togglemax(Client *c) { |
|
| 13 | - | XEvent ev; |
|
| 14 | - | ||
| 15 | - | if(c->isfixed) |
|
| 16 | - | return; |
|
| 17 | - | if((c->ismax = !c->ismax)) { |
|
| 18 | - | c->rx = c->x; |
|
| 19 | - | c->ry = c->y; |
|
| 20 | - | c->rw = c->w; |
|
| 21 | - | c->rh = c->h; |
|
| 22 | - | resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True); |
|
| 23 | - | } |
|
| 24 | - | else |
|
| 25 | - | resize(c, c->rx, c->ry, c->rw, c->rh, True); |
|
| 26 | - | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
|
| 27 | - | } |
|
| 28 | - | ||
| 29 | - | /* extern */ |
|
| 30 | - | ||
| 31 | - | void |
|
| 32 | - | dotile(void) { |
|
| 33 | - | unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; |
|
| 34 | - | Client *c; |
|
| 35 | - | ||
| 36 | - | for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) |
|
| 37 | - | n++; |
|
| 38 | - | /* window geoms */ |
|
| 39 | - | mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); |
|
| 40 | - | mw = (n > nmaster) ? (waw * master) / 1000 : waw; |
|
| 41 | - | th = (n > nmaster) ? wah / (n - nmaster) : 0; |
|
| 42 | - | tw = waw - mw; |
|
| 43 | - | ||
| 44 | - | for(i = 0, c = clients; c; c = c->next) |
|
| 45 | - | if(isvisible(c)) { |
|
| 46 | - | if(c->isbanned) |
|
| 47 | - | XMoveWindow(dpy, c->win, c->x, c->y); |
|
| 48 | - | c->isbanned = False; |
|
| 49 | - | if(c->isfloat) |
|
| 50 | - | continue; |
|
| 51 | - | c->ismax = False; |
|
| 52 | - | nx = wax; |
|
| 53 | - | ny = way; |
|
| 54 | - | if(i < nmaster) { |
|
| 55 | - | ny += i * mh; |
|
| 56 | - | nw = mw - 2 * BORDERPX; |
|
| 57 | - | nh = mh - 2 * BORDERPX; |
|
| 58 | - | } |
|
| 59 | - | else { /* tile window */ |
|
| 60 | - | nx += mw; |
|
| 61 | - | nw = tw - 2 * BORDERPX; |
|
| 62 | - | if(th > 2 * BORDERPX) { |
|
| 63 | - | ny += (i - nmaster) * th; |
|
| 64 | - | nh = th - 2 * BORDERPX; |
|
| 65 | - | } |
|
| 66 | - | else /* fallback if th <= 2 * BORDERPX */ |
|
| 67 | - | nh = wah - 2 * BORDERPX; |
|
| 68 | - | } |
|
| 69 | - | resize(c, nx, ny, nw, nh, False); |
|
| 70 | - | i++; |
|
| 71 | - | } |
|
| 72 | - | else { |
|
| 73 | - | c->isbanned = True; |
|
| 74 | - | XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); |
|
| 75 | - | } |
|
| 76 | - | if(!sel || !isvisible(sel)) { |
|
| 77 | - | for(c = stack; c && !isvisible(c); c = c->snext); |
|
| 78 | - | focus(c); |
|
| 79 | - | } |
|
| 80 | - | restack(); |
|
| 81 | - | } |
|
| 82 | - | ||
| 83 | - | void |
|
| 84 | - | incnmaster(Arg *arg) { |
|
| 85 | - | if((arrange == dofloat) || (nmaster + arg->i < 1) |
|
| 86 | - | || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) |
|
| 87 | - | return; |
|
| 88 | - | nmaster += arg->i; |
|
| 89 | - | if(sel) |
|
| 90 | - | arrange(); |
|
| 91 | - | else |
|
| 92 | - | drawstatus(); |
|
| 93 | - | } |
|
| 94 | - | ||
| 95 | - | void |
|
| 96 | - | resizemaster(Arg *arg) { |
|
| 97 | - | if(arrange != dotile) |
|
| 98 | - | return; |
|
| 99 | - | if(arg->i == 0) |
|
| 100 | - | master = MASTER; |
|
| 101 | - | else { |
|
| 102 | - | if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX |
|
| 103 | - | || waw * (master + arg->i) / 1000 <= 2 * BORDERPX) |
|
| 104 | - | return; |
|
| 105 | - | master += arg->i; |
|
| 106 | - | } |
|
| 107 | - | arrange(); |
|
| 108 | - | } |
|
| 109 | - | ||
| 110 | - | void |
|
| 111 | - | zoom(Arg *arg) { |
|
| 112 | - | unsigned int n; |
|
| 113 | - | Client *c; |
|
| 114 | - | ||
| 115 | - | if(!sel) |
|
| 116 | - | return; |
|
| 117 | - | if(sel->isfloat || (arrange == dofloat)) { |
|
| 118 | - | togglemax(sel); |
|
| 119 | - | return; |
|
| 120 | - | } |
|
| 121 | - | for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) |
|
| 122 | - | n++; |
|
| 123 | - | ||
| 124 | - | if((c = sel) == nextmanaged(clients)) |
|
| 125 | - | if(!(c = nextmanaged(c->next))) |
|
| 126 | - | return; |
|
| 127 | - | detach(c); |
|
| 128 | - | attach(c); |
|
| 129 | - | focus(c); |
|
| 130 | - | arrange(); |
|
| 131 | - | } |
| 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 | - | /* extern */ |
|
| 7 | - | ||
| 8 | - | void (*arrange)(void) = DEFMODE; |
|
| 9 | - | ||
| 10 | - | void |
|
| 11 | - | attach(Client *c) { |
|
| 12 | - | if(clients) |
|
| 13 | - | clients->prev = c; |
|
| 14 | - | c->next = clients; |
|
| 15 | - | clients = c; |
|
| 16 | - | } |
|
| 17 | - | ||
| 18 | - | void |
|
| 19 | - | attachstack(Client *c) { |
|
| 20 | - | c->snext = stack; |
|
| 21 | - | stack = c; |
|
| 22 | - | } |
|
| 23 | - | ||
| 24 | - | void |
|
| 25 | - | dofloat(void) { |
|
| 26 | - | Client *c; |
|
| 27 | - | ||
| 28 | - | for(c = clients; c; c = c->next) { |
|
| 29 | - | if(isvisible(c)) { |
|
| 30 | - | if(c->isbanned) |
|
| 31 | - | XMoveWindow(dpy, c->win, c->x, c->y); |
|
| 32 | - | c->isbanned = False; |
|
| 33 | - | resize(c, c->x, c->y, c->w, c->h, True); |
|
| 34 | - | } |
|
| 35 | - | else { |
|
| 36 | - | c->isbanned = True; |
|
| 37 | - | XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); |
|
| 38 | - | } |
|
| 39 | - | } |
|
| 40 | - | if(!sel || !isvisible(sel)) { |
|
| 41 | - | for(c = stack; c && !isvisible(c); c = c->snext); |
|
| 42 | - | focus(c); |
|
| 43 | - | } |
|
| 44 | - | restack(); |
|
| 45 | - | } |
|
| 46 | - | ||
| 47 | - | void |
|
| 48 | - | detach(Client *c) { |
|
| 49 | - | if(c->prev) |
|
| 50 | - | c->prev->next = c->next; |
|
| 51 | - | if(c->next) |
|
| 52 | - | c->next->prev = c->prev; |
|
| 53 | - | if(c == clients) |
|
| 54 | - | clients = c->next; |
|
| 55 | - | c->next = c->prev = NULL; |
|
| 56 | - | } |
|
| 57 | - | ||
| 58 | - | void |
|
| 59 | - | detachstack(Client *c) { |
|
| 60 | - | Client **tc; |
|
| 61 | - | for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext); |
|
| 62 | - | *tc = c->snext; |
|
| 63 | - | } |
|
| 64 | - | ||
| 65 | - | void |
|
| 66 | - | focusnext(Arg *arg) { |
|
| 67 | - | Client *c; |
|
| 68 | - | ||
| 69 | - | if(!sel) |
|
| 70 | - | return; |
|
| 71 | - | for(c = sel->next; c && !isvisible(c); c = c->next); |
|
| 72 | - | if(!c) |
|
| 73 | - | for(c = clients; c && !isvisible(c); c = c->next); |
|
| 74 | - | if(c) { |
|
| 75 | - | focus(c); |
|
| 76 | - | restack(); |
|
| 77 | - | } |
|
| 78 | - | } |
|
| 79 | - | ||
| 80 | - | void |
|
| 81 | - | focusprev(Arg *arg) { |
|
| 82 | - | Client *c; |
|
| 83 | - | ||
| 84 | - | if(!sel) |
|
| 85 | - | return; |
|
| 86 | - | for(c = sel->prev; c && !isvisible(c); c = c->prev); |
|
| 87 | - | if(!c) { |
|
| 88 | - | for(c = clients; c && c->next; c = c->next); |
|
| 89 | - | for(; c && !isvisible(c); c = c->prev); |
|
| 90 | - | } |
|
| 91 | - | if(c) { |
|
| 92 | - | focus(c); |
|
| 93 | - | restack(); |
|
| 94 | - | } |
|
| 95 | - | } |
|
| 96 | - | ||
| 97 | - | Client * |
|
| 98 | - | getclient(Window w) { |
|
| 99 | - | Client *c; |
|
| 100 | - | ||
| 101 | - | for(c = clients; c; c = c->next) |
|
| 102 | - | if(c->win == w) |
|
| 103 | - | return c; |
|
| 104 | - | return NULL; |
|
| 105 | - | } |
|
| 106 | - | ||
| 107 | - | Bool |
|
| 108 | - | isvisible(Client *c) { |
|
| 109 | - | unsigned int i; |
|
| 110 | - | ||
| 111 | - | for(i = 0; i < ntags; i++) |
|
| 112 | - | if(c->tags[i] && seltag[i]) |
|
| 113 | - | return True; |
|
| 114 | - | return False; |
|
| 115 | - | } |
|
| 116 | - | ||
| 117 | - | Client * |
|
| 118 | - | nextmanaged(Client *c) { |
|
| 119 | - | for(; c && (c->isfloat || !isvisible(c)); c = c->next); |
|
| 120 | - | return c; |
|
| 121 | - | } |
|
| 122 | - | ||
| 123 | - | void |
|
| 124 | - | restack(void) { |
|
| 125 | - | Client *c; |
|
| 126 | - | XEvent ev; |
|
| 127 | - | ||
| 128 | - | drawstatus(); |
|
| 129 | - | if(!sel) |
|
| 130 | - | return; |
|
| 131 | - | if(sel->isfloat || arrange == dofloat) |
|
| 132 | - | XRaiseWindow(dpy, sel->win); |
|
| 133 | - | if(arrange != dofloat) { |
|
| 134 | - | if(!sel->isfloat) |
|
| 135 | - | XLowerWindow(dpy, sel->win); |
|
| 136 | - | for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) { |
|
| 137 | - | if(c == sel) |
|
| 138 | - | continue; |
|
| 139 | - | XLowerWindow(dpy, c->win); |
|
| 140 | - | } |
|
| 141 | - | } |
|
| 142 | - | XSync(dpy, False); |
|
| 143 | - | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
|
| 144 | - | } |
|
| 145 | - | ||
| 146 | - | void |
|
| 147 | - | togglefloat(Arg *arg) { |
|
| 148 | - | if(!sel || arrange == dofloat) |
|
| 149 | - | return; |
|
| 150 | - | sel->isfloat = !sel->isfloat; |
|
| 151 | - | arrange(); |
|
| 152 | - | } |
|
| 153 | - | ||
| 154 | - | void |
|
| 155 | - | togglemode(Arg *arg) { |
|
| 156 | - | arrange = (arrange == dofloat) ? dotile : dofloat; |
|
| 157 | - | if(sel) |
|
| 158 | - | arrange(); |
|
| 159 | - | else |
|
| 160 | - | drawstatus(); |
|
| 161 | - | } |
|
| 162 | - | ||
| 163 | - | void |
|
| 164 | - | toggleview(Arg *arg) { |
|
| 165 | - | unsigned int i; |
|
| 166 | - | ||
| 167 | - | seltag[arg->i] = !seltag[arg->i]; |
|
| 168 | - | for(i = 0; i < ntags && !seltag[i]; i++); |
|
| 169 | - | if(i == ntags) |
|
| 170 | - | seltag[arg->i] = True; /* cannot toggle last view */ |
|
| 171 | - | arrange(); |
|
| 172 | - | } |
|
| 173 | - | ||
| 174 | - | void |
|
| 175 | - | view(Arg *arg) { |
|
| 176 | - | unsigned int i; |
|
| 177 | - | ||
| 178 | - | for(i = 0; i < ntags; i++) |
|
| 179 | - | seltag[i] = (arg->i == -1) ? True : False; |
|
| 180 | - | if(arg->i >= 0 && arg->i < ntags) |
|
| 181 | - | seltag[arg->i] = True; |
|
| 182 | - | arrange(); |
|
| 183 | - | } |
|
| 184 | - |