From 5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63 Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Mon, 19 Feb 2007 13:00:29 +0100 Subject: introduced tile.c, some refactoring of functions --- Makefile | 2 +- config.arg.h | 2 +- config.default.h | 2 +- dwm.h | 13 ++++-- main.c | 2 +- tag.c | 2 +- tile.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++ view.c | 136 ++----------------------------------------------------- 8 files changed, 150 insertions(+), 141 deletions(-) create mode 100644 tile.c diff --git a/Makefile b/Makefile index e337ec2..18626a7 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config.mk -SRC = client.c draw.c event.c main.c tag.c util.c view.c +SRC = client.c draw.c event.c main.c tile.c tag.c util.c view.c OBJ = ${SRC:.c=.o} 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 @@ #define TAGS \ const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; -#define BORDERPX 1 #define DEFMODE dotile /* dofloat */ #define FLOATSYMBOL "><>" #define TILESYMBOL "[]=" +#define BORDERPX 1 #define FONT "-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*" #define NORMBORDERCOLOR "#333" #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 @@ #define TAGS \ const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; -#define BORDERPX 1 #define DEFMODE dotile /* dofloat */ #define FLOATSYMBOL "><>" #define TILESYMBOL "[]=" +#define BORDERPX 1 #define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*" #define NORMBORDERCOLOR "#dddddd" #define NORMBGCOLOR "#eeeeee" diff --git a/dwm.h b/dwm.h index 43b3730..c07229a 100644 --- a/dwm.h +++ b/dwm.h @@ -127,11 +127,17 @@ extern void sendevent(Window w, Atom a, long value); /* send synthetic event to extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ /* tag.c */ -extern void initrregs(void); /* initialize regexps of rules defined in config.h */ +extern void compileregexps(void); /* initialize regexps of rules defined in config.h */ extern void settags(Client *c, Client *trans); /* sets tags of c */ extern void tag(Arg *arg); /* tags c with arg's index */ extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ +/* tile.c */ +extern void dotile(void); /* arranges all windows tiled */ +extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */ +extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */ +extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ + /* util.c */ extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ 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 */ /* view.c */ extern void detach(Client *c); /* detaches c from global client list */ extern void dofloat(void); /* arranges all windows floating */ -extern void dotile(void); /* arranges all windows tiled */ extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ -extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */ extern Bool isvisible(Client *c); /* returns True if client is visible */ -extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */ +extern Client *nextmanaged(Client *c); /* returns managed successor of c */ extern void restack(void); /* restores z layers of all clients */ extern void togglefloat(Arg *arg); /* toggles focusesd client between floating/non-floating state */ extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */ extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ extern void view(Arg *arg); /* views the tag with arg's index */ -extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ diff --git a/main.c b/main.c index 5ed8981..bd19e49 100644 --- a/main.c +++ b/main.c @@ -117,7 +117,7 @@ setup(void) { wa.cursor = cursor[CurNormal]; XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); grabkeys(); - initrregs(); + compileregexps(); for(ntags = 0; tags[ntags]; ntags++); seltag = emallocz(sizeof(Bool) * ntags); seltag[0] = True; diff --git a/tag.c b/tag.c index a6db1d5..d3065d5 100644 --- a/tag.c +++ b/tag.c @@ -32,7 +32,7 @@ static unsigned int len = 0; /* extern */ void -initrregs(void) { +compileregexps(void) { unsigned int i; regex_t *reg; diff --git a/tile.c b/tile.c new file mode 100644 index 0000000..a9bc0f5 --- /dev/null +++ b/tile.c @@ -0,0 +1,132 @@ +/* (C)opyright MMVI-MMVII Anselm R. Garbe + * See LICENSE file for license details. + */ +#include "dwm.h" + +/* static */ + +static void +togglemax(Client *c) { + XEvent ev; + + if(c->isfixed) + return; + + if((c->ismax = !c->ismax)) { + c->rx = c->x; + c->ry = c->y; + c->rw = c->w; + c->rh = c->h; + resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True); + } + else + resize(c, c->rx, c->ry, c->rw, c->rh, True); + while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); +} + +/* extern */ + +void +dotile(void) { + unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; + Client *c; + + for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) + n++; + /* window geoms */ + mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); + mw = (n > nmaster) ? (waw * master) / 1000 : waw; + th = (n > nmaster) ? wah / (n - nmaster) : 0; + tw = waw - mw; + + for(i = 0, c = clients; c; c = c->next) + if(isvisible(c)) { + if(c->isbanned) + XMoveWindow(dpy, c->win, c->x, c->y); + c->isbanned = False; + if(c->isfloat) + continue; + c->ismax = False; + nx = wax; + ny = way; + if(i < nmaster) { + ny += i * mh; + nw = mw - 2 * BORDERPX; + nh = mh - 2 * BORDERPX; + } + else { /* tile window */ + nx += mw; + nw = tw - 2 * BORDERPX; + if(th > 2 * BORDERPX) { + ny += (i - nmaster) * th; + nh = th - 2 * BORDERPX; + } + else /* fallback if th <= 2 * BORDERPX */ + nh = wah - 2 * BORDERPX; + } + resize(c, nx, ny, nw, nh, False); + i++; + } + else { + c->isbanned = True; + XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); + } + if(!sel || !isvisible(sel)) { + for(c = stack; c && !isvisible(c); c = c->snext); + focus(c); + } + restack(); +} + +void +incnmaster(Arg *arg) { + if((arrange == dofloat) || (nmaster + arg->i < 1) + || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) + return; + nmaster += arg->i; + if(sel) + arrange(); + else + drawstatus(); +} + +void +resizemaster(Arg *arg) { + if(arrange != dotile) + return; + if(arg->i == 0) + master = MASTER; + else { + if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX + || waw * (master + arg->i) / 1000 <= 2 * BORDERPX) + return; + master += arg->i; + } + arrange(); +} + +void +zoom(Arg *arg) { + unsigned int n; + Client *c; + + if(!sel) + return; + if(sel->isfloat || (arrange == dofloat)) { + togglemax(sel); + return; + } + for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) + n++; + + if((c = sel) == nextmanaged(clients)) + if(!(c = nextmanaged(c->next))) + return; + detach(c); + if(clients) + clients->prev = c; + c->next = clients; + clients = c; + focus(c); + arrange(); +} diff --git a/view.c b/view.c index 66f550c..72aa04e 100644 --- a/view.c +++ b/view.c @@ -2,34 +2,6 @@ * See LICENSE file for license details. */ #include "dwm.h" -#include - -/* static */ - -static Client * -nexttiled(Client *c) { - for(; c && (c->isfloat || !isvisible(c)); c = c->next); - return c; -} - -static void -togglemax(Client *c) { - XEvent ev; - - if(c->isfixed) - return; - - if((c->ismax = !c->ismax)) { - c->rx = c->x; - c->ry = c->y; - c->rw = c->w; - c->rh = c->h; - resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True); - } - else - resize(c, c->rx, c->ry, c->rw, c->rh, True); - while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); -} /* extern */ @@ -69,58 +41,6 @@ dofloat(void) { restack(); } -void -dotile(void) { - unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; - Client *c; - - for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) - n++; - /* window geoms */ - mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); - mw = (n > nmaster) ? (waw * master) / 1000 : waw; - th = (n > nmaster) ? wah / (n - nmaster) : 0; - tw = waw - mw; - - for(i = 0, c = clients; c; c = c->next) - if(isvisible(c)) { - if(c->isbanned) - XMoveWindow(dpy, c->win, c->x, c->y); - c->isbanned = False; - if(c->isfloat) - continue; - c->ismax = False; - nx = wax; - ny = way; - if(i < nmaster) { - ny += i * mh; - nw = mw - 2 * BORDERPX; - nh = mh - 2 * BORDERPX; - } - else { /* tile window */ - nx += mw; - nw = tw - 2 * BORDERPX; - if(th > 2 * BORDERPX) { - ny += (i - nmaster) * th; - nh = th - 2 * BORDERPX; - } - else /* fallback if th <= 2 * BORDERPX */ - nh = wah - 2 * BORDERPX; - } - resize(c, nx, ny, nw, nh, False); - i++; - } - else { - c->isbanned = True; - XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); - } - if(!sel || !isvisible(sel)) { - for(c = stack; c && !isvisible(c); c = c->snext); - focus(c); - } - restack(); -} - void focusnext(Arg *arg) { Client *c; @@ -153,18 +73,6 @@ focusprev(Arg *arg) { } } -void -incnmaster(Arg *arg) { - if((arrange == dofloat) || (nmaster + arg->i < 1) - || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) - return; - nmaster += arg->i; - if(sel) - arrange(); - else - drawstatus(); -} - Bool isvisible(Client *c) { unsigned int i; @@ -175,19 +83,10 @@ isvisible(Client *c) { return False; } -void -resizemaster(Arg *arg) { - if(arrange != dotile) - return; - if(arg->i == 0) - master = MASTER; - else { - if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX - || waw * (master + arg->i) / 1000 <= 2 * BORDERPX) - return; - master += arg->i; - } - arrange(); +Client * +nextmanaged(Client *c) { + for(; c && (c->isfloat || !isvisible(c)); c = c->next); + return c; } void @@ -203,7 +102,7 @@ restack(void) { if(arrange != dofloat) { if(!sel->isfloat) XLowerWindow(dpy, sel->win); - for(c = nexttiled(clients); c; c = nexttiled(c->next)) { + for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) { if(c == sel) continue; XLowerWindow(dpy, c->win); @@ -252,28 +151,3 @@ view(Arg *arg) { arrange(); } -void -zoom(Arg *arg) { - unsigned int n; - Client *c; - - if(!sel) - return; - if(sel->isfloat || (arrange == dofloat)) { - togglemax(sel); - return; - } - for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) - n++; - - if((c = sel) == nexttiled(clients)) - if(!(c = nexttiled(c->next))) - return; - detach(c); - if(clients) - clients->prev = c; - c->next = clients; - clients = c; - focus(c); - arrange(); -} -- cgit 1.4.1-2-gfad0 256'>256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471