diff options
| author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-11-08 23:11:48 +0100 |
|---|---|---|
| committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-11-08 23:11:48 +0100 |
| commit | 5ed9c481968a45f5032f1011d92ab8d5237aeba1 (patch) | |
| tree | 4176e5b79c1b39566bb496c5c113fc2c04a82b27 /dwm.c | |
| parent | unboolification (diff) | |
| download | dwm-5ed9c481968a45f5032f1011d92ab8d5237aeba1.tar.gz dwm-5ed9c481968a45f5032f1011d92ab8d5237aeba1.zip | |
code-style consistency
Diffstat (limited to '')
| -rw-r--r-- | dwm.c | 936 |
1 files changed, 503 insertions, 433 deletions
| @@ -275,7 +275,8 @@ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; | |||
| 275 | 275 | ||
| 276 | /* function implementations */ | 276 | /* function implementations */ |
| 277 | void | 277 | void |
| 278 | applyrules(Client *c) { | 278 | applyrules(Client *c) |
| 279 | { | ||
| 279 | const char *class, *instance; | 280 | const char *class, *instance; |
| 280 | unsigned int i; | 281 | unsigned int i; |
| 281 | const Rule *r; | 282 | const Rule *r; |
| @@ -289,126 +290,131 @@ applyrules(Client *c) { | |||
| 289 | class = ch.res_class ? ch.res_class : broken; | 290 | class = ch.res_class ? ch.res_class : broken; |
| 290 | instance = ch.res_name ? ch.res_name : broken; | 291 | instance = ch.res_name ? ch.res_name : broken; |
| 291 | 292 | ||
| 292 | for(i = 0; i < LENGTH(rules); i++) { | 293 | for (i = 0; i < LENGTH(rules); i++) { |
| 293 | r = &rules[i]; | 294 | r = &rules[i]; |
| 294 | if((!r->title || strstr(c->name, r->title)) | 295 | if ((!r->title || strstr(c->name, r->title)) |
| 295 | && (!r->class || strstr(class, r->class)) | 296 | && (!r->class || strstr(class, r->class)) |
| 296 | && (!r->instance || strstr(instance, r->instance))) | 297 | && (!r->instance || strstr(instance, r->instance))) |
| 297 | { | 298 | { |
| 298 | c->isfloating = r->isfloating; | 299 | c->isfloating = r->isfloating; |
| 299 | c->tags |= r->tags; | 300 | c->tags |= r->tags; |
| 300 | for(m = mons; m && m->num != r->monitor; m = m->next); | 301 | for (m = mons; m && m->num != r->monitor; m = m->next); |
| 301 | if(m) | 302 | if (m) |
| 302 | c->mon = m; | 303 | c->mon = m; |
| 303 | } | 304 | } |
| 304 | } | 305 | } |
| 305 | if(ch.res_class) | 306 | if (ch.res_class) |
| 306 | XFree(ch.res_class); | 307 | XFree(ch.res_class); |
| 307 | if(ch.res_name) | 308 | if (ch.res_name) |
| 308 | XFree(ch.res_name); | 309 | XFree(ch.res_name); |
| 309 | c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; | 310 | c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; |
| 310 | } | 311 | } |
| 311 | 312 | ||
| 312 | int | 313 | int |
| 313 | applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) { | 314 | applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) |
| 315 | { | ||
| 314 | int baseismin; | 316 | int baseismin; |
| 315 | Monitor *m = c->mon; | 317 | Monitor *m = c->mon; |
| 316 | 318 | ||
| 317 | /* set minimum possible */ | 319 | /* set minimum possible */ |
| 318 | *w = MAX(1, *w); | 320 | *w = MAX(1, *w); |
| 319 | *h = MAX(1, *h); | 321 | *h = MAX(1, *h); |
| 320 | if(interact) { | 322 | if (interact) { |
| 321 | if(*x > sw) | 323 | if (*x > sw) |
| 322 | *x = sw - WIDTH(c); | 324 | *x = sw - WIDTH(c); |
| 323 | if(*y > sh) | 325 | if (*y > sh) |
| 324 | *y = sh - HEIGHT(c); | 326 | *y = sh - HEIGHT(c); |
| 325 | if(*x + *w + 2 * c->bw < 0) | 327 | if (*x + *w + 2 * c->bw < 0) |
| 326 | *x = 0; | 328 | *x = 0; |
| 327 | if(*y + *h + 2 * c->bw < 0) | 329 | if (*y + *h + 2 * c->bw < 0) |
| 328 | *y = 0; | 330 | *y = 0; |
| 329 | } | 331 | } else { |
| 330 | else { | 332 | if (*x >= m->wx + m->ww) |
| 331 | if(*x >= m->wx + m->ww) | ||
| 332 | *x = m->wx + m->ww - WIDTH(c); | 333 | *x = m->wx + m->ww - WIDTH(c); |
| 333 | if(*y >= m->wy + m->wh) | 334 | if (*y >= m->wy + m->wh) |
| 334 | *y = m->wy + m->wh - HEIGHT(c); | 335 | *y = m->wy + m->wh - HEIGHT(c); |
| 335 | if(*x + *w + 2 * c->bw <= m->wx) | 336 | if (*x + *w + 2 * c->bw <= m->wx) |
| 336 | *x = m->wx; | 337 | *x = m->wx; |
| 337 | if(*y + *h + 2 * c->bw <= m->wy) | 338 | if (*y + *h + 2 * c->bw <= m->wy) |
| 338 | *y = m->wy; | 339 | *y = m->wy; |
| 339 | } | 340 | } |
| 340 | if(*h < bh) | 341 | if (*h < bh) |
| 341 | *h = bh; | 342 | *h = bh; |
| 342 | if(*w < bh) | 343 | if (*w < bh) |
| 343 | *w = bh; | 344 | *w = bh; |
| 344 | if(resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) { | 345 | if (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) { |
| 345 | /* see last two sentences in ICCCM 4.1.2.3 */ | 346 | /* see last two sentences in ICCCM 4.1.2.3 */ |
| 346 | baseismin = c->basew == c->minw && c->baseh == c->minh; | 347 | baseismin = c->basew == c->minw && c->baseh == c->minh; |
| 347 | if(!baseismin) { /* temporarily remove base dimensions */ | 348 | if (!baseismin) { /* temporarily remove base dimensions */ |
| 348 | *w -= c->basew; | 349 | *w -= c->basew; |
| 349 | *h -= c->baseh; | 350 | *h -= c->baseh; |
| 350 | } | 351 | } |
| 351 | /* adjust for aspect limits */ | 352 | /* adjust for aspect limits */ |
| 352 | if(c->mina > 0 && c->maxa > 0) { | 353 | if (c->mina > 0 && c->maxa > 0) { |
| 353 | if(c->maxa < (float)*w / *h) | 354 | if (c->maxa < (float)*w / *h) |
| 354 | *w = *h * c->maxa + 0.5; | 355 | *w = *h * c->maxa + 0.5; |
| 355 | else if(c->mina < (float)*h / *w) | 356 | else if (c->mina < (float)*h / *w) |
| 356 | *h = *w * c->mina + 0.5; | 357 | *h = *w * c->mina + 0.5; |
| 357 | } | 358 | } |
| 358 | if(baseismin) { /* increment calculation requires this */ | 359 | if (baseismin) { /* increment calculation requires this */ |
| 359 | *w -= c->basew; | 360 | *w -= c->basew; |
| 360 | *h -= c->baseh; | 361 | *h -= c->baseh; |
| 361 | } | 362 | } |
| 362 | /* adjust for increment value */ | 363 | /* adjust for increment value */ |
| 363 | if(c->incw) | 364 | if (c->incw) |
| 364 | *w -= *w % c->incw; | 365 | *w -= *w % c->incw; |
| 365 | if(c->inch) | 366 | if (c->inch) |
| 366 | *h -= *h % c->inch; | 367 | *h -= *h % c->inch; |
| 367 | /* restore base dimensions */ | 368 | /* restore base dimensions */ |
| 368 | *w = MAX(*w + c->basew, c->minw); | 369 | *w = MAX(*w + c->basew, c->minw); |
| 369 | *h = MAX(*h + c->baseh, c->minh); | 370 | *h = MAX(*h + c->baseh, c->minh); |
| 370 | if(c->maxw) | 371 | if (c->maxw) |
| 371 | *w = MIN(*w, c->maxw); | 372 | *w = MIN(*w, c->maxw); |
| 372 | if(c->maxh) | 373 | if (c->maxh) |
| 373 | *h = MIN(*h, c->maxh); | 374 | *h = MIN(*h, c->maxh); |
| 374 | } | 375 | } |
| 375 | return *x != c->x || *y != c->y || *w != c->w || *h != c->h; | 376 | return *x != c->x || *y != c->y || *w != c->w || *h != c->h; |
| 376 | } | 377 | } |
| 377 | 378 | ||
| 378 | void | 379 | void |
| 379 | arrange(Monitor *m) { | 380 | arrange(Monitor *m) |
| 380 | if(m) | 381 | { |
| 382 | if (m) | ||
| 381 | showhide(m->stack); | 383 | showhide(m->stack); |
| 382 | else for(m = mons; m; m = m->next) | 384 | else for (m = mons; m; m = m->next) |
| 383 | showhide(m->stack); | 385 | showhide(m->stack); |
| 384 | if(m) { | 386 | if (m) { |
| 385 | arrangemon(m); | 387 | arrangemon(m); |
| 386 | restack(m); | 388 | restack(m); |
| 387 | } else for(m = mons; m; m = m->next) | 389 | } else for (m = mons; m; m = m->next) |
| 388 | arrangemon(m); | 390 | arrangemon(m); |
| 389 | } | 391 | } |
| 390 | 392 | ||
| 391 | void | 393 | void |
| 392 | arrangemon(Monitor *m) { | 394 | arrangemon(Monitor *m) |
| 395 | { | ||
| 393 | strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol); | 396 | strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol); |
| 394 | if(m->lt[m->sellt]->arrange) | 397 | if (m->lt[m->sellt]->arrange) |
| 395 | m->lt[m->sellt]->arrange(m); | 398 | m->lt[m->sellt]->arrange(m); |
| 396 | } | 399 | } |
| 397 | 400 | ||
| 398 | void | 401 | void |
| 399 | attach(Client *c) { | 402 | attach(Client *c) |
| 403 | { | ||
| 400 | c->next = c->mon->clients; | 404 | c->next = c->mon->clients; |
| 401 | c->mon->clients = c; | 405 | c->mon->clients = c; |
| 402 | } | 406 | } |
| 403 | 407 | ||
| 404 | void | 408 | void |
| 405 | attachstack(Client *c) { | 409 | attachstack(Client *c) |
| 410 | { | ||
| 406 | c->snext = c->mon->stack; | 411 | c->snext = c->mon->stack; |
| 407 | c->mon->stack = c; | 412 | c->mon->stack = c; |
| 408 | } | 413 | } |
| 409 | 414 | ||
| 410 | void | 415 | void |
| 411 | buttonpress(XEvent *e) { | 416 | buttonpress(XEvent *e) |
| 417 | { | ||
| 412 | unsigned int i, x, click; | 418 | unsigned int i, x, click; |
| 413 | Arg arg = {0}; | 419 | Arg arg = {0}; |
| 414 | Client *c; | 420 | Client *c; |
| @@ -417,39 +423,38 @@ buttonpress(XEvent *e) { | |||
| 417 | 423 | ||
| 418 | click = ClkRootWin; | 424 | click = ClkRootWin; |
| 419 | /* focus monitor if necessary */ | 425 | /* focus monitor if necessary */ |
| 420 | if((m = wintomon(ev->window)) && m != selmon) { | 426 | if ((m = wintomon(ev->window)) && m != selmon) { |
| 421 | unfocus(selmon->sel, 1); | 427 | unfocus(selmon->sel, 1); |
| 422 | selmon = m; | 428 | selmon = m; |
| 423 | focus(NULL); | 429 | focus(NULL); |
| 424 | } | 430 | } |
| 425 | if(ev->window == selmon->barwin) { | 431 | if (ev->window == selmon->barwin) { |
| 426 | i = x = 0; | 432 | i = x = 0; |
| 427 | do | 433 | do |
| 428 | x += TEXTW(tags[i]); | 434 | x += TEXTW(tags[i]); |
| 429 | while(ev->x >= x && ++i < LENGTH(tags)); | 435 | while (ev->x >= x && ++i < LENGTH(tags)); |
| 430 | if(i < LENGTH(tags)) { | 436 | if (i < LENGTH(tags)) { |
| 431 | click = ClkTagBar; | 437 | click = ClkTagBar; |
| 432 | arg.ui = 1 << i; | 438 | arg.ui = 1 << i; |
| 433 | } | 439 | } else if (ev->x < x + blw) |
| 434 | else if(ev->x < x + blw) | ||
| 435 | click = ClkLtSymbol; | 440 | click = ClkLtSymbol; |
| 436 | else if(ev->x > selmon->ww - TEXTW(stext)) | 441 | else if (ev->x > selmon->ww - TEXTW(stext)) |
| 437 | click = ClkStatusText; | 442 | click = ClkStatusText; |
| 438 | else | 443 | else |
| 439 | click = ClkWinTitle; | 444 | click = ClkWinTitle; |
| 440 | } | 445 | } else if ((c = wintoclient(ev->window))) { |
| 441 | else if((c = wintoclient(ev->window))) { | ||
| 442 | focus(c); | 446 | focus(c); |
| 443 | click = ClkClientWin; | 447 | click = ClkClientWin; |
| 444 | } | 448 | } |
| 445 | for(i = 0; i < LENGTH(buttons); i++) | 449 | for (i = 0; i < LENGTH(buttons); i++) |
| 446 | if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button | 450 | if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button |
| 447 | && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) | 451 | && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) |
| 448 | buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); | 452 | buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); |
| 449 | } | 453 | } |
| 450 | 454 | ||
| 451 | void | 455 | void |
| 452 | checkotherwm(void) { | 456 | checkotherwm(void) |
| 457 | { | ||
| 453 | xerrorxlib = XSetErrorHandler(xerrorstart); | 458 | xerrorxlib = XSetErrorHandler(xerrorstart); |
| 454 | /* this causes an error if some other window manager is running */ | 459 | /* this causes an error if some other window manager is running */ |
| 455 | XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); | 460 | XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); |
| @@ -459,7 +464,8 @@ checkotherwm(void) { | |||
| 459 | } | 464 | } |
| 460 | 465 | ||
| 461 | void | 466 | void |
| 462 | cleanup(void) { | 467 | cleanup(void) |
| 468 | { | ||
| 463 | Arg a = {.ui = ~0}; | 469 | Arg a = {.ui = ~0}; |
| 464 | Layout foo = { "", NULL }; | 470 | Layout foo = { "", NULL }; |
| 465 | Monitor *m; | 471 | Monitor *m; |
| @@ -467,15 +473,15 @@ cleanup(void) { | |||
| 467 | 473 | ||
| 468 | view(&a); | 474 | view(&a); |
| 469 | selmon->lt[selmon->sellt] = &foo; | 475 | selmon->lt[selmon->sellt] = &foo; |
| 470 | for(m = mons; m; m = m->next) | 476 | for (m = mons; m; m = m->next) |
| 471 | while(m->stack) | 477 | while (m->stack) |
| 472 | unmanage(m->stack, 0); | 478 | unmanage(m->stack, 0); |
| 473 | XUngrabKey(dpy, AnyKey, AnyModifier, root); | 479 | XUngrabKey(dpy, AnyKey, AnyModifier, root); |
| 474 | while(mons) | 480 | while (mons) |
| 475 | cleanupmon(mons); | 481 | cleanupmon(mons); |
| 476 | for(i = 0; i < CurLast; i++) | 482 | for (i = 0; i < CurLast; i++) |
| 477 | drw_cur_free(drw, cursor[i]); | 483 | drw_cur_free(drw, cursor[i]); |
| 478 | for(i = 0; i < SchemeLast; i++) { | 484 | for (i = 0; i < SchemeLast; i++) { |
| 479 | drw_clr_free(scheme[i].border); | 485 | drw_clr_free(scheme[i].border); |
| 480 | drw_clr_free(scheme[i].bg); | 486 | drw_clr_free(scheme[i].bg); |
| 481 | drw_clr_free(scheme[i].fg); | 487 | drw_clr_free(scheme[i].fg); |
| @@ -487,13 +493,14 @@ cleanup(void) { | |||
| 487 | } | 493 | } |
| 488 | 494 | ||
| 489 | void | 495 | void |
| 490 | cleanupmon(Monitor *mon) { | 496 | cleanupmon(Monitor *mon) |
| 497 | { | ||
| 491 | Monitor *m; | 498 | Monitor *m; |
| 492 | 499 | ||
| 493 | if(mon == mons) | 500 | if (mon == mons) |
| 494 | mons = mons->next; | 501 | mons = mons->next; |
| 495 | else { | 502 | else { |
| 496 | for(m = mons; m && m->next != mon; m = m->next); | 503 | for (m = mons; m && m->next != mon; m = m->next); |
| 497 | m->next = mon->next; | 504 | m->next = mon->next; |
| 498 | } | 505 | } |
| 499 | XUnmapWindow(dpy, mon->barwin); | 506 | XUnmapWindow(dpy, mon->barwin); |
| @@ -502,11 +509,12 @@ cleanupmon(Monitor *mon) { | |||
| 502 | } | 509 | } |
| 503 | 510 | ||
| 504 | void | 511 | void |
| 505 | clearurgent(Client *c) { | 512 | clearurgent(Client *c) |
| 513 | { | ||
| 506 | XWMHints *wmh; | 514 | XWMHints *wmh; |
| 507 | 515 | ||
| 508 | c->isurgent = 0; | 516 | c->isurgent = 0; |
| 509 | if(!(wmh = XGetWMHints(dpy, c->win))) | 517 | if (!(wmh = XGetWMHints(dpy, c->win))) |
| 510 | return; | 518 | return; |
| 511 | wmh->flags &= ~XUrgencyHint; | 519 | wmh->flags &= ~XUrgencyHint; |
| 512 | XSetWMHints(dpy, c->win, wmh); | 520 | XSetWMHints(dpy, c->win, wmh); |
| @@ -514,19 +522,19 @@ clearurgent(Client *c) { | |||
| 514 | } | 522 | } |
| 515 | 523 | ||
| 516 | void | 524 | void |
| 517 | clientmessage(XEvent *e) { | 525 | clientmessage(XEvent *e) |
| 526 | { | ||
| 518 | XClientMessageEvent *cme = &e->xclient; | 527 | XClientMessageEvent *cme = &e->xclient; |
| 519 | Client *c = wintoclient(cme->window); | 528 | Client *c = wintoclient(cme->window); |
| 520 | 529 | ||
| 521 | if(!c) | 530 | if (!c) |
| 522 | return; | 531 | return; |
| 523 | if(cme->message_type == netatom[NetWMState]) { | 532 | if (cme->message_type == netatom[NetWMState]) { |
| 524 | if(cme->data.l[1] == netatom[NetWMFullscreen] || cme->data.l[2] == netatom[NetWMFullscreen]) | 533 | if (cme->data.l[1] == netatom[NetWMFullscreen] || cme->data.l[2] == netatom[NetWMFullscreen]) |
| 525 | setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ | 534 | setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ |
| 526 | || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen))); | 535 | || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen))); |
| 527 | } | 536 | } else if (cme->message_type == netatom[NetActiveWindow]) { |
| 528 | else if(cme->message_type == netatom[NetActiveWindow]) { | 537 | if (!ISVISIBLE(c)) { |
| 529 | if(!ISVISIBLE(c)) { | ||
| 530 | c->mon->seltags ^= 1; | 538 | c->mon->seltags ^= 1; |
| 531 | c->mon->tagset[c->mon->seltags] = c->tags; | 539 | c->mon->tagset[c->mon->seltags] = c->tags; |
| 532 | } | 540 | } |
| @@ -535,7 +543,8 @@ clientmessage(XEvent *e) { | |||
| 535 | } | 543 | } |
| 536 | 544 | ||
| 537 | void | 545 | void |
| 538 | configure(Client *c) { | 546 | configure(Client *c) |
| 547 | { | ||
| 539 | XConfigureEvent ce; | 548 | XConfigureEvent ce; |
| 540 | 549 | ||
| 541 | ce.type = ConfigureNotify; | 550 | ce.type = ConfigureNotify; |
| @@ -553,20 +562,21 @@ configure(Client *c) { | |||
| 553 | } | 562 | } |
| 554 | 563 | ||
| 555 | void | 564 | void |
| 556 | configurenotify(XEvent *e) { | 565 | configurenotify(XEvent *e) |
| 566 | { | ||
| 557 | Monitor *m; | 567 | Monitor *m; |
| 558 | XConfigureEvent *ev = &e->xconfigure; | 568 | XConfigureEvent *ev = &e->xconfigure; |
| 559 | int dirty; | 569 | int dirty; |
| 560 | 570 | ||
| 561 | /* TODO: updategeom handling sucks, needs to be simplified */ | 571 | /* TODO: updategeom handling sucks, needs to be simplified */ |
| 562 | if(ev->window == root) { | 572 | if (ev->window == root) { |
| 563 | dirty = (sw != ev->width || sh != ev->height); | 573 | dirty = (sw != ev->width || sh != ev->height); |
| 564 | sw = ev->width; | 574 | sw = ev->width; |
| 565 | sh = ev->height; | 575 | sh = ev->height; |
| 566 | if(updategeom() || dirty) { | 576 | if (updategeom() || dirty) { |
| 567 | drw_resize(drw, sw, bh); | 577 | drw_resize(drw, sw, bh); |
| 568 | updatebars(); | 578 | updatebars(); |
| 569 | for(m = mons; m; m = m->next) | 579 | for (m = mons; m; m = m->next) |
| 570 | XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); | 580 | XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); |
| 571 | focus(NULL); | 581 | focus(NULL); |
| 572 | arrange(NULL); | 582 | arrange(NULL); |
| @@ -575,46 +585,45 @@ configurenotify(XEvent *e) { | |||
| 575 | } | 585 | } |
| 576 | 586 | ||
| 577 | void | 587 | void |
| 578 | configurerequest(XEvent *e) { | 588 | configurerequest(XEvent *e) |
| 589 | { | ||
| 579 | Client *c; | 590 | Client *c; |
| 580 | Monitor *m; | 591 | Monitor *m; |
| 581 | XConfigureRequestEvent *ev = &e->xconfigurerequest; | 592 | XConfigureRequestEvent *ev = &e->xconfigurerequest; |
| 582 | XWindowChanges wc; | 593 | XWindowChanges wc; |
| 583 | 594 | ||
| 584 | if((c = wintoclient(ev->window))) { | 595 | if ((c = wintoclient(ev->window))) { |
| 585 | if(ev->value_mask & CWBorderWidth) | 596 | if (ev->value_mask & CWBorderWidth) |
| 586 | c->bw = ev->border_width; | 597 | c->bw = ev->border_width; |
| 587 | else if(c->isfloating || !selmon->lt[selmon->sellt]->arrange) { | 598 | else if (c->isfloating || !selmon->lt[selmon->sellt]->arrange) { |
| 588 | m = c->mon; | 599 | m = c->mon; |
| 589 | if(ev->value_mask & CWX) { | 600 | if (ev->value_mask & CWX) { |
| 590 | c->oldx = c->x; | 601 | c->oldx = c->x; |
| 591 | c->x = m->mx + ev->x; | 602 | c->x = m->mx + ev->x; |
| 592 | } | 603 | } |
| 593 | if(ev->value_mask & CWY) { | 604 | if (ev->value_mask & CWY) { |
| 594 | c->oldy = c->y; | 605 | c->oldy = c->y; |
| 595 | c->y = m->my + ev->y; | 606 | c->y = m->my + ev->y; |
| 596 | } | 607 | } |
| 597 | if(ev->value_mask & CWWidth) { | 608 | if (ev->value_mask & CWWidth) { |
| 598 | c->oldw = c->w; | 609 | c->oldw = c->w; |
| 599 | c->w = ev->width; | 610 | c->w = ev->width; |
| 600 | } | 611 | } |
| 601 | if(ev->value_mask & CWHeight) { | 612 | if (ev->value_mask & CWHeight) { |
| 602 | c->oldh = c->h; | 613 | c->oldh = c->h; |
| 603 | c->h = ev->height; | 614 | c->h = ev->height; |
| 604 | } | 615 | } |
| 605 | if((c->x + c->w) > m->mx + m->mw && c->isfloating) | 616 | if ((c->x + c->w) > m->mx + m->mw && c->isfloating) |
| 606 | c->x = m->mx + (m->mw / 2 - WIDTH(c) / 2); /* center in x direction */ | 617 | c->x = m->mx + (m->mw / 2 - WIDTH(c) / 2); /* center in x direction */ |
| 607 | if((c->y + c->h) > m->my + m->mh && c->isfloating) | 618 | if ((c->y + c->h) > m->my + m->mh && c->isfloating) |
| 608 | c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2); /* center in y direction */ | 619 | c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2); /* center in y direction */ |
| 609 | if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))) | 620 | if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))) |
| 610 | configure(c); | 621 | configure(c); |
| 611 | if(ISVISIBLE(c)) | 622 | if (ISVISIBLE(c)) |
| 612 | XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); | 623 | XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); |
| 613 | } | 624 | } else |
| 614 | else | ||
| 615 | configure(c); | 625 | configure(c); |
| 616 | } | 626 | } else { |
| 617 | else { | ||
| 618 | wc.x = ev->x; | 627 | wc.x = ev->x; |
| 619 | wc.y = ev->y; | 628 | wc.y = ev->y; |
| 620 | wc.width = ev->width; | 629 | wc.width = ev->width; |
| @@ -628,7 +637,8 @@ configurerequest(XEvent *e) { | |||
| 628 | } | 637 | } |
| 629 | 638 | ||
| 630 | Monitor * | 639 | Monitor * |
| 631 | createmon(void) { | 640 | createmon(void) |
| 641 | { | ||
| 632 | Monitor *m; | 642 | Monitor *m; |
| 633 | 643 | ||
| 634 | m = ecalloc(1, sizeof(Monitor)); | 644 | m = ecalloc(1, sizeof(Monitor)); |
| @@ -644,65 +654,69 @@ createmon(void) { | |||
| 644 | } | 654 | } |
| 645 | 655 | ||
| 646 | void | 656 | void |
| 647 | destroynotify(XEvent *e) { | 657 | destroynotify(XEvent *e) |
| 658 | { | ||
| 648 | Client *c; | 659 | Client *c; |
| 649 | XDestroyWindowEvent *ev = &e->xdestroywindow; | 660 | XDestroyWindowEvent *ev = &e->xdestroywindow; |
| 650 | 661 | ||
| 651 | if((c = wintoclient(ev->window))) | 662 | if ((c = wintoclient(ev->window))) |
| 652 | unmanage(c, 1); | 663 | unmanage(c, 1); |
| 653 | } | 664 | } |
| 654 | 665 | ||
| 655 | void | 666 | void |
| 656 | detach(Client *c) { | 667 | detach(Client *c) |
| 668 | { | ||
| 657 | Client **tc; | 669 | Client **tc; |
| 658 | 670 | ||
| 659 | for(tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next); | 671 | for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next); |
| 660 | *tc = c->next; | 672 | *tc = c->next; |
| 661 | } | 673 | } |
| 662 | 674 | ||
| 663 | void | 675 | void |
| 664 | detachstack(Client *c) { | 676 | detachstack(Client *c) |
| 677 | { | ||
| 665 | Client **tc, *t; | 678 | Client **tc, *t; |
| 666 | 679 | ||
| 667 | for(tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext); | 680 | for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext); |
| 668 | *tc = c->snext; | 681 | *tc = c->snext; |
| 669 | 682 | ||
| 670 | if(c == c->mon->sel) { | 683 | if (c == c->mon->sel) { |
| 671 | for(t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext); | 684 | for (t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext); |
| 672 | c->mon->sel = t; | 685 | c->mon->sel = t; |
| 673 | } | 686 | } |
| 674 | } | 687 | } |
| 675 | 688 | ||
| 676 | Monitor * | 689 | Monitor * |
| 677 | dirtomon(int dir) { | 690 | dirtomon(int dir) |
| 691 | { | ||
| 678 | Monitor *m = NULL; | 692 | Monitor *m = NULL; |
| 679 | 693 | ||
| 680 | if(dir > 0) { | 694 | if (dir > 0) { |
| 681 | if(!(m = selmon->next)) | 695 | if (!(m = selmon->next)) |
| 682 | m = mons; | 696 | m = mons; |
| 683 | } | 697 | } else if (selmon == mons) |
| 684 | else if(selmon == mons) | 698 | for (m = mons; m->next; m = m->next); |
| 685 | for(m = mons; m->next; m = m->next); | ||
| 686 | else | 699 | else |
| 687 | for(m = mons; m->next != selmon; m = m->next); | 700 | for (m = mons; m->next != selmon; m = m->next); |
| 688 | return m; | 701 | return m; |
| 689 | } | 702 | } |
| 690 | 703 | ||
| 691 | void | 704 | void |
| 692 | drawbar(Monitor *m) { | 705 | drawbar(Monitor *m) |
| 706 | { | ||
| 693 | int x, xx, w, dx; | 707 | int x, xx, w, dx; |
| 694 | unsigned int i, occ = 0, urg = 0; | 708 | unsigned int i, occ = 0, urg = 0; |
| 695 | Client *c; | 709 | Client *c; |
| 696 | 710 | ||
| 697 | dx = (drw->fonts[0]->ascent + drw->fonts[0]->descent + 2) / 4; | 711 | dx = (drw->fonts[0]->ascent + drw->fonts[0]->descent + 2) / 4; |
| 698 | 712 | ||
| 699 | for(c = m->clients; c; c = c->next) { | 713 | for (c = m->clients; c; c = c->next) { |
| 700 | occ |= c->tags; | 714 | occ |= c->tags; |
| 701 | if(c->isurgent) | 715 | if (c->isurgent) |
| 702 | urg |= c->tags; | 716 | urg |= c->tags; |
| 703 | } | 717 | } |
| 704 | x = 0; | 718 | x = 0; |
| 705 | for(i = 0; i < LENGTH(tags); i++) { | 719 | for (i = 0; i < LENGTH(tags); i++) { |
| 706 | w = TEXTW(tags[i]); | 720 | w = TEXTW(tags[i]); |
| 707 | drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]); | 721 | drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]); |
| 708 | drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i); | 722 | drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i); |
| @@ -715,25 +729,23 @@ drawbar(Monitor *m) { | |||
| 715 | drw_text(drw, x, 0, w, bh, m->ltsymbol, 0); | 729 | drw_text(drw, x, 0, w, bh, m->ltsymbol, 0); |
| 716 | x += w; | 730 | x += w; |
| 717 | xx = x; | 731 | xx = x; |
| 718 | if(m == selmon) { /* status is only drawn on selected monitor */ | 732 | if (m == selmon) { /* status is only drawn on selected monitor */ |
| 719 | w = TEXTW(stext); | 733 | w = TEXTW(stext); |
| 720 | x = m->ww - w; | 734 | x = m->ww - w; |
| 721 | if(x < xx) { | 735 | if (x < xx) { |
| 722 | x = xx; | 736 | x = xx; |
| 723 | w = m->ww - xx; | 737 | w = m->ww - xx; |
| 724 | } | 738 | } |
| 725 | drw_text(drw, x, 0, w, bh, stext, 0); | 739 | drw_text(drw, x, 0, w, bh, stext, 0); |
| 726 | } | 740 | } else |
| 727 | else | ||
| 728 | x = m->ww; | 741 | x = m->ww; |
| 729 | if((w = x - xx) > bh) { | 742 | if ((w = x - xx) > bh) { |
| 730 | x = xx; | 743 | x = xx; |
| 731 | if(m->sel) { | 744 | if (m->sel) { |
| 732 | drw_setscheme(drw, m == selmon ? &scheme[SchemeSel] : &scheme[SchemeNorm]); | 745 | drw_setscheme(drw, m == selmon ? &scheme[SchemeSel] : &scheme[SchemeNorm]); |
| 733 | drw_text(drw, x, 0, w, bh, m->sel->name, 0); | 746 | drw_text(drw, x, 0, w, bh, m->sel->name, 0); |
| 734 | drw_rect(drw, x + 1, 1, dx, dx, m->sel->isfixed, m->sel->isfloating, 0); | 747 | drw_rect(drw, x + 1, 1, dx, dx, m->sel->isfixed, m->sel->isfloating, 0); |
| 735 | } | 748 | } else { |
| 736 | else { | ||
| 737 | drw_setscheme(drw, &scheme[SchemeNorm]); | 749 | drw_setscheme(drw, &scheme[SchemeNorm]); |
| 738 | drw_rect(drw, x, 0, w, bh, 1, 0, 1); | 750 | drw_rect(drw, x, 0, w, bh, 1, 0, 1); |
| 739 | } | 751 | } |
| @@ -742,60 +754,62 @@ drawbar(Monitor *m) { | |||
| 742 | } | 754 | } |
| 743 | 755 | ||
| 744 | void | 756 | void |
| 745 | drawbars(void) { | 757 | drawbars(void) |
| 758 | { | ||
| 746 | Monitor *m; | 759 | Monitor *m; |
| 747 | 760 | ||
| 748 | for(m = mons; m; m = m->next) | 761 | for (m = mons; m; m = m->next) |
| 749 | drawbar(m); | 762 | drawbar(m); |
| 750 | } | 763 | } |
| 751 | 764 | ||
| 752 | void | 765 | void |
| 753 | enternotify(XEvent *e) { | 766 | enternotify(XEvent *e) |
| 767 | { | ||
| 754 | Client *c; | 768 | Client *c; |
| 755 | Monitor *m; | 769 | Monitor *m; |
| 756 | XCrossingEvent *ev = &e->xcrossing; | 770 | XCrossingEvent *ev = &e->xcrossing; |
| 757 | 771 | ||
| 758 | if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) | 772 | if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) |
| 759 | return; | 773 | return; |
| 760 | c = wintoclient(ev->window); | 774 | c = wintoclient(ev->window); |
| 761 | m = c ? c->mon : wintomon(ev->window); | 775 | m = c ? c->mon : wintomon(ev->window); |
| 762 | if(m != selmon) { | 776 | if (m != selmon) { |
| 763 | unfocus(selmon->sel, 1); | 777 | unfocus(selmon->sel, 1); |
| 764 | selmon = m; | 778 | selmon = m; |
| 765 | } | 779 | } else if (!c || c == selmon->sel) |
| 766 | else if(!c || c == selmon->sel) | ||
| 767 | return; | 780 | return; |
| 768 | focus(c); | 781 | focus(c); |
| 769 | } | 782 | } |
| 770 | 783 | ||
| 771 | void | 784 | void |
| 772 | expose(XEvent *e) { | 785 | expose(XEvent *e) |
| 786 | { | ||
| 773 | Monitor *m; | 787 | Monitor *m; |
| 774 | XExposeEvent *ev = &e->xexpose; | 788 | XExposeEvent *ev = &e->xexpose; |
| 775 | 789 | ||
| 776 | if(ev->count == 0 && (m = wintomon(ev->window))) | 790 | if (ev->count == 0 && (m = wintomon(ev->window))) |
| 777 | drawbar(m); | 791 | drawbar(m); |
| 778 | } | 792 | } |
| 779 | 793 | ||
| 780 | void | 794 | void |
| 781 | focus(Client *c) { | 795 | focus(Client *c) |
| 782 | if(!c || !ISVISIBLE(c)) | 796 | { |
| 783 | for(c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); | 797 | if (!c || !ISVISIBLE(c)) |
| 784 | /* was if(selmon->sel) */ | 798 | for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); |
| 785 | if(selmon->sel && selmon->sel != c) | 799 | /* was if (selmon->sel) */ |
| 800 | if (selmon->sel && selmon->sel != c) | ||
| 786 | unfocus(selmon->sel, 0); | 801 | unfocus(selmon->sel, 0); |
| 787 | if(c) { | 802 | if (c) { |
| 788 | if(c->mon != selmon) | 803 | if (c->mon != selmon) |
| 789 | selmon = c->mon; | 804 | selmon = c->mon; |
| 790 | if(c->isurgent) | 805 | if (c->isurgent) |
| 791 | clearurgent(c); | 806 | clearurgent(c); |
| 792 | detachstack(c); | 807 | detachstack(c); |
| 793 | attachstack(c); | 808 | attachstack(c); |
| 794 | grabbuttons(c, 1); | 809 | grabbuttons(c, 1); |
| 795 | XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->pix); | 810 | XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->pix); |
| 796 | setfocus(c); | 811 | setfocus(c); |
| 797 | } | 812 | } else { |
| 798 | else { | ||
| 799 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); | 813 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); |
| 800 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); | 814 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); |
| 801 | } | 815 | } |
| @@ -803,21 +817,24 @@ focus(Client *c) { | |||
| 803 | drawbars(); | 817 | drawbars(); |
| 804 | } | 818 | } |
| 805 | 819 | ||
| 820 | /* there are some broken focus acquiring clients */ | ||
| 806 | void | 821 | void |
| 807 | focusin(XEvent *e) { /* there are some broken focus acquiring clients */ | 822 | focusin(XEvent *e) |
| 823 | { | ||
| 808 | XFocusChangeEvent *ev = &e->xfocus; | 824 | XFocusChangeEvent *ev = &e->xfocus; |
| 809 | 825 | ||
| 810 | if(selmon->sel && ev->window != selmon->sel->win) | 826 | if (selmon->sel && ev->window != selmon->sel->win) |
| 811 | setfocus(selmon->sel); | 827 | setfocus(selmon->sel); |
| 812 | } | 828 | } |
| 813 | 829 | ||
| 814 | void | 830 | void |
| 815 | focusmon(const Arg *arg) { | 831 | focusmon(const Arg *arg) |
| 832 | { | ||
| 816 | Monitor *m; | 833 | Monitor *m; |
| 817 | 834 | ||
| 818 | if(!mons->next) | 835 | if (!mons->next) |
| 819 | return; | 836 | return; |
| 820 | if((m = dirtomon(arg->i)) == selmon) | 837 | if ((m = dirtomon(arg->i)) == selmon) |
| 821 | return; | 838 | return; |
| 822 | unfocus(selmon->sel, 0); /* s/1/0/ fixes input focus issues | 839 | unfocus(selmon->sel, 0); /* s/1/0/ fixes input focus issues |
| 823 | in gedit and anjuta */ | 840 | in gedit and anjuta */ |
| @@ -826,39 +843,40 @@ focusmon(const Arg *arg) { | |||
| 826 | } | 843 | } |
| 827 | 844 | ||
| 828 | void | 845 | void |
| 829 | focusstack(const Arg *arg) { | 846 | focusstack(const Arg *arg) |
| 847 | { | ||
| 830 | Client *c = NULL, *i; | 848 | Client *c = NULL, *i; |
| 831 | 849 | ||
| 832 | if(!selmon->sel) | 850 | if (!selmon->sel) |
| 833 | return; | 851 | return; |
| 834 | if(arg->i > 0) { | 852 | if (arg->i > 0) { |
| 835 | for(c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); | 853 | for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); |
| 836 | if(!c) | 854 | if (!c) |
| 837 | for(c = selmon->clients; c && !ISVISIBLE(c); c = c->next); | 855 | for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next); |
| 838 | } | 856 | } else { |
| 839 | else { | 857 | for (i = selmon->clients; i != selmon->sel; i = i->next) |
| 840 | for(i = selmon->clients; i != selmon->sel; i = i->next) | 858 | if (ISVISIBLE(i)) |
| 841 | if(ISVISIBLE(i)) | ||
| 842 | c = i; | 859 | c = i; |
| 843 | if(!c) | 860 | if (!c) |
| 844 | for(; i; i = i->next) | 861 | for (; i; i = i->next) |
| 845 | if(ISVISIBLE(i)) | 862 | if (ISVISIBLE(i)) |
| 846 | c = i; | 863 | c = i; |
| 847 | } | 864 | } |
| 848 | if(c) { | 865 | if (c) { |
| 849 | focus(c); | 866 | focus(c); |
| 850 | restack(selmon); | 867 | restack(selmon); |
| 851 | } | 868 | } |
| 852 | } | 869 | } |
| 853 | 870 | ||
| 854 | Atom | 871 | Atom |
| 855 | getatomprop(Client *c, Atom prop) { | 872 | getatomprop(Client *c, Atom prop) |
| 873 | { | ||
| 856 | int di; | 874 | int di; |
| 857 | unsigned long dl; | 875 | unsigned long dl; |
| 858 | unsigned char *p = NULL; | 876 | unsigned char *p = NULL; |
| 859 | Atom da, atom = None; | 877 | Atom da, atom = None; |
| 860 | 878 | ||
| 861 | if(XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM, | 879 | if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM, |
| 862 | &da, &di, &dl, &dl, &p) == Success && p) { | 880 | &da, &di, &dl, &dl, &p) == Success && p) { |
| 863 | atom = *(Atom *)p; | 881 | atom = *(Atom *)p; |
| 864 | XFree(p); | 882 | XFree(p); |
| @@ -867,7 +885,8 @@ getatomprop(Client *c, Atom prop) { | |||
| 867 | } | 885 | } |
| 868 | 886 | ||
| 869 | int | 887 | int |
| 870 | getrootptr(int *x, int *y) { | 888 | getrootptr(int *x, int *y) |
| 889 | { | ||
| 871 | int di; | 890 | int di; |
| 872 | unsigned int dui; | 891 | unsigned int dui; |
| 873 | Window dummy; | 892 | Window dummy; |
| @@ -876,38 +895,40 @@ getrootptr(int *x, int *y) { | |||
| 876 | } | 895 | } |
| 877 | 896 | ||
| 878 | long | 897 | long |
| 879 | getstate(Window w) { | 898 | getstate(Window w) |
| 899 | { | ||
| 880 | int format; | 900 | int format; |
| 881 | long result = -1; | 901 | long result = -1; |
| 882 | unsigned char *p = NULL; | 902 | unsigned char *p = NULL; |
| 883 | unsigned long n, extra; | 903 | unsigned long n, extra; |
| 884 | Atom real; | 904 | Atom real; |
| 885 | 905 | ||
| 886 | if(XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState], | 906 | if (XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState], |
| 887 | &real, &format, &n, &extra, (unsigned char **)&p) != Success) | 907 | &real, &format, &n, &extra, (unsigned char **)&p) != Success) |
| 888 | return -1; | 908 | return -1; |
| 889 | if(n != 0) | 909 | if (n != 0) |
| 890 | result = *p; | 910 | result = *p; |
| 891 | XFree(p); | 911 | XFree(p); |
| 892 | return result; | 912 | return result; |
| 893 | } | 913 | } |
| 894 | 914 | ||
| 895 | int | 915 | int |
| 896 | gettextprop(Window w, Atom atom, char *text, unsigned int size) { | 916 | gettextprop(Window w, Atom atom, char *text, unsigned int size) |
| 917 | { | ||
| 897 | char **list = NULL; | 918 | char **list = NULL; |
| 898 | int n; | 919 | int n; |
| 899 | XTextProperty name; | 920 | XTextProperty name; |
| 900 | 921 | ||
| 901 | if(!text || size == 0) | 922 | if (!text || size == 0) |
| 902 | return 0; | 923 | return 0; |
| 903 | text[0] = '\0'; | 924 | text[0] = '\0'; |
| 904 | XGetTextProperty(dpy, w, &name, atom); | 925 | XGetTextProperty(dpy, w, &name, atom); |
| 905 | if(!name.nitems) | 926 | if (!name.nitems) |
| 906 | return 0; | 927 | return 0; |
| 907 | if(name.encoding == XA_STRING) | 928 | if (name.encoding == XA_STRING) |
| 908 | strncpy(text, (char *)name.value, size - 1); | 929 | strncpy(text, (char *)name.value, size - 1); |
| 909 | else { | 930 | else { |
| 910 | if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) { | 931 | if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) { |
| 911 | strncpy(text, *list, size - 1); | 932 | strncpy(text, *list, size - 1); |
| 912 | XFreeStringList(list); | 933 | XFreeStringList(list); |
| 913 | } | 934 | } |
| @@ -918,29 +939,30 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) { | |||
| 918 | } | 939 | } |
| 919 | 940 | ||
| 920 | void | 941 | void |
| 921 | grabbuttons(Client *c, int focused) { | 942 | grabbuttons(Client *c, int focused) |
| 943 | { | ||
| 922 | updatenumlockmask(); | 944 | updatenumlockmask(); |
| 923 | { | 945 | { |
| 924 | unsigned int i, j; | 946 | unsigned int i, j; |
| 925 | unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; | 947 | unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; |
| 926 | XUngrabButton(dpy, AnyButton, AnyModifier, c->win); | 948 | XUngrabButton(dpy, AnyButton, AnyModifier, c->win); |
| 927 | if(focused) { | 949 | if (focused) { |
| 928 | for(i = 0; i < LENGTH(buttons); i++) | 950 | for (i = 0; i < LENGTH(buttons); i++) |
| 929 | if(buttons[i].click == ClkClientWin) | 951 | if (buttons[i].click == ClkClientWin) |
| 930 | for(j = 0; j < LENGTH(modifiers); j++) | 952 | for (j = 0; j < LENGTH(modifiers); j++) |
| 931 | XGrabButton(dpy, buttons[i].button, | 953 | XGrabButton(dpy, buttons[i].button, |
| 932 | buttons[i].mask | modifiers[j], | 954 | buttons[i].mask | modifiers[j], |
| 933 | c->win, False, BUTTONMASK, | 955 | c->win, False, BUTTONMASK, |
| 934 | GrabModeAsync, GrabModeSync, None, None); | 956 | GrabModeAsync, GrabModeSync, None, None); |
| 935 | } | 957 | } else |
| 936 | else | ||
| 937 | XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, | 958 | XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, |
| 938 | BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); | 959 | BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); |
| 939 | } | 960 | } |
| 940 | } | 961 | } |
| 941 | 962 | ||
| 942 | void | 963 | void |
| 943 | grabkeys(void) { | 964 | grabkeys(void) |
| 965 | { | ||
| 944 | updatenumlockmask(); | 966 | updatenumlockmask(); |
| 945 | { | 967 | { |
| 946 | unsigned int i, j; | 968 | unsigned int i, j; |
| @@ -948,25 +970,27 @@ grabkeys(void) { | |||
| 948 | KeyCode code; | 970 | KeyCode code; |
| 949 | 971 | ||
| 950 | XUngrabKey(dpy, AnyKey, AnyModifier, root); | 972 | XUngrabKey(dpy, AnyKey, AnyModifier, root); |
| 951 | for(i = 0; i < LENGTH(keys); i++) | 973 | for (i = 0; i < LENGTH(keys); i++) |
| 952 | if((code = XKeysymToKeycode(dpy, keys[i].keysym))) | 974 | if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) |
| 953 | for(j = 0; j < LENGTH(modifiers); j++) | 975 | for (j = 0; j < LENGTH(modifiers); j++) |
| 954 | XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, | 976 | XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, |
| 955 | True, GrabModeAsync, GrabModeAsync); | 977 | True, GrabModeAsync, GrabModeAsync); |
| 956 | } | 978 | } |
| 957 | } | 979 | } |
| 958 | 980 | ||
| 959 | void | 981 | void |
| 960 | incnmaster(const Arg *arg) { | 982 | incnmaster(const Arg *arg) |
| 983 | { | ||
| 961 | selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); | 984 | selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); |
| 962 | arrange(selmon); | 985 | arrange(selmon); |
| 963 | } | 986 | } |
| 964 | 987 | ||
| 965 | #ifdef XINERAMA | 988 | #ifdef XINERAMA |
| 966 | static int | 989 | static int |
| 967 | isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) { | 990 | isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) |
| 968 | while(n--) | 991 | { |
| 969 | if(unique[n].x_org == info->x_org && unique[n].y_org == info->y_org | 992 | while (n--) |
| 993 | if (unique[n].x_org == info->x_org && unique[n].y_org == info->y_org | ||
| 970 | && unique[n].width == info->width && unique[n].height == info->height) | 994 | && unique[n].width == info->width && unique[n].height == info->height) |
| 971 | return 0; | 995 | return 0; |
| 972 | return 1; | 996 | return 1; |
| @@ -974,25 +998,27 @@ isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) { | |||
| 974 | #endif /* XINERAMA */ | 998 | #endif /* XINERAMA */ |
| 975 | 999 | ||
| 976 | void | 1000 | void |
| 977 | keypress(XEvent *e) { | 1001 | keypress(XEvent *e) |
| 1002 | { | ||
| 978 | unsigned int i; | 1003 | unsigned int i; |
| 979 | KeySym keysym; | 1004 | KeySym keysym; |
| 980 | XKeyEvent *ev; | 1005 | XKeyEvent *ev; |
| 981 | 1006 | ||
| 982 | ev = &e->xkey; | 1007 | ev = &e->xkey; |
| 983 | keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); | 1008 | keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); |
| 984 | for(i = 0; i < LENGTH(keys); i++) | 1009 | for (i = 0; i < LENGTH(keys); i++) |
| 985 | if(keysym == keys[i].keysym | 1010 | if (keysym == keys[i].keysym |
| 986 | && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) | 1011 | && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) |
| 987 | && keys[i].func) | 1012 | && keys[i].func) |
| 988 | keys[i].func(&(keys[i].arg)); | 1013 | keys[i].func(&(keys[i].arg)); |
| 989 | } | 1014 | } |
| 990 | 1015 | ||
| 991 | void | 1016 | void |
| 992 | killclient(const Arg *arg) { | 1017 | killclient(const Arg *arg) |
| 993 | if(!selmon->sel) | 1018 | { |
| 1019 | if (!selmon->sel) | ||
| 994 | return; | 1020 | return; |
| 995 | if(!sendevent(selmon->sel, wmatom[WMDelete])) { | 1021 | if (!sendevent(selmon->sel, wmatom[WMDelete])) { |
| 996 | XGrabServer(dpy); | 1022 | XGrabServer(dpy); |
| 997 | XSetErrorHandler(xerrordummy); | 1023 | XSetErrorHandler(xerrordummy); |
| 998 | XSetCloseDownMode(dpy, DestroyAll); | 1024 | XSetCloseDownMode(dpy, DestroyAll); |
| @@ -1004,7 +1030,8 @@ killclient(const Arg *arg) { | |||
| 1004 | } | 1030 | } |
| 1005 | 1031 | ||
| 1006 | void | 1032 | void |
| 1007 | manage(Window w, XWindowAttributes *wa) { | 1033 | manage(Window w, XWindowAttributes *wa) |
| 1034 | { | ||
| 1008 | Client *c, *t = NULL; | 1035 | Client *c, *t = NULL; |
| 1009 | Window trans = None; | 1036 | Window trans = None; |
| 1010 | XWindowChanges wc; | 1037 | XWindowChanges wc; |
| @@ -1012,11 +1039,10 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 1012 | c = ecalloc(1, sizeof(Client)); | 1039 | c = ecalloc(1, sizeof(Client)); |
| 1013 | c->win = w; | 1040 | c->win = w; |
| 1014 | updatetitle(c); | 1041 | updatetitle(c); |
| 1015 | if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { | 1042 | if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { |
| 1016 | c->mon = t->mon; | 1043 | c->mon = t->mon; |
| 1017 | c->tags = t->tags; | 1044 | c->tags = t->tags; |
| 1018 | } | 1045 | } else { |
| 1019 | else { | ||
| 1020 | c->mon = selmon; | 1046 | c->mon = selmon; |
| 1021 | applyrules(c); | 1047 | applyrules(c); |
| 1022 | } | 1048 | } |
| @@ -1027,9 +1053,9 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 1027 | c->h = c->oldh = wa->height; | 1053 | c->h = c->oldh = wa->height; |
| 1028 | c->oldbw = wa->border_width; | 1054 | c->oldbw = wa->border_width; |
| 1029 | 1055 | ||
| 1030 | if(c->x + WIDTH(c) > c->mon->mx + c->mon->mw) | 1056 | if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw) |
| 1031 | c->x = c->mon->mx + c->mon->mw - WIDTH(c); | 1057 | c->x = c->mon->mx + c->mon->mw - WIDTH(c); |
| 1032 | if(c->y + HEIGHT(c) > c->mon->my + c->mon->mh) | 1058 | if (c->y + HEIGHT(c) > c->mon->my + c->mon->mh) |
| 1033 | c->y = c->mon->my + c->mon->mh - HEIGHT(c); | 1059 | c->y = c->mon->my + c->mon->mh - HEIGHT(c); |
| 1034 | c->x = MAX(c->x, c->mon->mx); | 1060 | c->x = MAX(c->x, c->mon->mx); |
| 1035 | /* only fix client y-offset, if the client center might cover the bar */ | 1061 | /* only fix client y-offset, if the client center might cover the bar */ |
| @@ -1046,9 +1072,9 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 1046 | updatewmhints(c); | 1072 | updatewmhints(c); |
| 1047 | XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); | 1073 | XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); |
| 1048 | grabbuttons(c, 0); | 1074 | grabbuttons(c, 0); |
| 1049 | if(!c->isfloating) | 1075 | if (!c->isfloating) |
| 1050 | c->isfloating = c->oldstate = trans != None || c->isfixed; | 1076 | c->isfloating = c->oldstate = trans != None || c->isfixed; |
| 1051 | if(c->isfloating) | 1077 | if (c->isfloating) |
| 1052 | XRaiseWindow(dpy, c->win); | 1078 | XRaiseWindow(dpy, c->win); |
| 1053 | attach(c); | 1079 | attach(c); |
| 1054 | attachstack(c); | 1080 | attachstack(c); |
| @@ -1065,50 +1091,54 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 1065 | } | 1091 | } |
| 1066 | 1092 | ||
| 1067 | void | 1093 | void |
| 1068 | mappingnotify(XEvent *e) { | 1094 | mappingnotify(XEvent *e) |
| 1095 | { | ||
| 1069 | XMappingEvent *ev = &e->xmapping; | 1096 | XMappingEvent *ev = &e->xmapping; |
| 1070 | 1097 | ||
| 1071 | XRefreshKeyboardMapping(ev); | 1098 | XRefreshKeyboardMapping(ev); |
| 1072 | if(ev->request == MappingKeyboard) | 1099 | if (ev->request == MappingKeyboard) |
| 1073 | grabkeys(); | 1100 | grabkeys(); |
| 1074 | } | 1101 | } |
| 1075 | 1102 | ||
| 1076 | void | 1103 | void |
| 1077 | maprequest(XEvent *e) { | 1104 | maprequest(XEvent *e) |
| 1105 | { | ||
| 1078 | static XWindowAttributes wa; | 1106 | static XWindowAttributes wa; |
| 1079 | XMapRequestEvent *ev = &e->xmaprequest; | 1107 | XMapRequestEvent *ev = &e->xmaprequest; |
| 1080 | 1108 | ||
| 1081 | if(!XGetWindowAttributes(dpy, ev->window, &wa)) | 1109 | if (!XGetWindowAttributes(dpy, ev->window, &wa)) |
| 1082 | return; | 1110 | return; |
| 1083 | if(wa.override_redirect) | 1111 | if (wa.override_redirect) |
| 1084 | return; | 1112 | return; |
| 1085 | if(!wintoclient(ev->window)) | 1113 | if (!wintoclient(ev->window)) |
| 1086 | manage(ev->window, &wa); | 1114 | manage(ev->window, &wa); |
| 1087 | } | 1115 | } |
| 1088 | 1116 | ||
| 1089 | void | 1117 | void |
| 1090 | monocle(Monitor *m) { | 1118 | monocle(Monitor *m) |
| 1119 | { | ||
| 1091 | unsigned int n = 0; | 1120 | unsigned int n = 0; |
| 1092 | Client *c; | 1121 | Client *c; |
| 1093 | 1122 | ||
| 1094 | for(c = m->clients; c; c = c->next) | 1123 | for (c = m->clients; c; c = c->next) |
| 1095 | if(ISVISIBLE(c)) | 1124 | if (ISVISIBLE(c)) |
| 1096 | n++; | 1125 | n++; |
| 1097 | if(n > 0) /* override layout symbol */ | 1126 | if (n > 0) /* override layout symbol */ |
| 1098 | snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n); | 1127 | snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n); |
| 1099 | for(c = nexttiled(m->clients); c; c = nexttiled(c->next)) | 1128 | for (c = nexttiled(m->clients); c; c = nexttiled(c->next)) |
| 1100 | resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); | 1129 | resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); |
| 1101 | } | 1130 | } |
| 1102 | 1131 | ||
| 1103 | void | 1132 | void |
| 1104 | motionnotify(XEvent *e) { | 1133 | motionnotify(XEvent *e) |
| 1134 | { | ||
| 1105 | static Monitor *mon = NULL; | 1135 | static Monitor *mon = NULL; |
| 1106 | Monitor *m; | 1136 | Monitor *m; |
| 1107 | XMotionEvent *ev = &e->xmotion; | 1137 | XMotionEvent *ev = &e->xmotion; |
| 1108 | 1138 | ||
| 1109 | if(ev->window != root) | 1139 | if (ev->window != root) |
| 1110 | return; | 1140 | return; |
| 1111 | if((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) { | 1141 | if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) { |
| 1112 | unfocus(selmon->sel, 1); | 1142 | unfocus(selmon->sel, 1); |
| 1113 | selmon = m; | 1143 | selmon = m; |
| 1114 | focus(NULL); | 1144 | focus(NULL); |
| @@ -1117,24 +1147,25 @@ motionnotify(XEvent *e) { | |||
| 1117 | } | 1147 | } |
| 1118 | 1148 | ||
| 1119 | void | 1149 | void |
| 1120 | movemouse(const Arg *arg) { | 1150 | movemouse(const Arg *arg) |
| 1151 | { | ||
| 1121 | int x, y, ocx, ocy, nx, ny; | 1152 | int x, y, ocx, ocy, nx, ny; |
| 1122 | Client *c; | 1153 | Client *c; |
| 1123 | Monitor *m; | 1154 | Monitor *m; |
| 1124 | XEvent ev; | 1155 | XEvent ev; |
| 1125 | Time lasttime = 0; | 1156 | Time lasttime = 0; |
| 1126 | 1157 | ||
| 1127 | if(!(c = selmon->sel)) | 1158 | if (!(c = selmon->sel)) |
| 1128 | return; | 1159 | return; |
| 1129 | if(c->isfullscreen) /* no support moving fullscreen windows by mouse */ | 1160 | if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ |
| 1130 | return; | 1161 | return; |
| 1131 | restack(selmon); | 1162 | restack(selmon); |
| 1132 | ocx = c->x; | 1163 | ocx = c->x; |
| 1133 | ocy = c->y; | 1164 | ocy = c->y; |
| 1134 | if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, | 1165 | if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, |
| 1135 | None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess) | 1166 | None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess) |
| 1136 | return; | 1167 | return; |
| 1137 | if(!getrootptr(&x, &y)) | 1168 | if (!getrootptr(&x, &y)) |
| 1138 | return; | 1169 | return; |
| 1139 | do { | 1170 | do { |
| 1140 | XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); | 1171 | XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); |
| @@ -1151,27 +1182,27 @@ movemouse(const Arg *arg) { | |||
| 1151 | 1182 | ||
| 1152 | nx = ocx + (ev.xmotion.x - x); | 1183 | nx = ocx + (ev.xmotion.x - x); |
| 1153 | ny = ocy + (ev.xmotion.y - y); | 1184 | ny = ocy + (ev.xmotion.y - y); |
| 1154 | if(nx >= selmon->wx && nx <= selmon->wx + selmon->ww | 1185 | if (nx >= selmon->wx && nx <= selmon->wx + selmon->ww |
| 1155 | && ny >= selmon->wy && ny <= selmon->wy + selmon->wh) { | 1186 | && ny >= selmon->wy && ny <= selmon->wy + selmon->wh) { |
| 1156 | if(abs(selmon->wx - nx) < snap) | 1187 | if (abs(selmon->wx - nx) < snap) |
| 1157 | nx = selmon->wx; | 1188 | nx = selmon->wx; |
| 1158 | else if(abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap) | 1189 | else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap) |
| 1159 | nx = selmon->wx + selmon->ww - WIDTH(c); | 1190 | nx = selmon->wx + selmon->ww - WIDTH(c); |
| 1160 | if(abs(selmon->wy - ny) < snap) | 1191 | if (abs(selmon->wy - ny) < snap) |
| 1161 | ny = selmon->wy; | 1192 | ny = selmon->wy; |
| 1162 | else if(abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap) | 1193 | else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap) |
| 1163 | ny = selmon->wy + selmon->wh - HEIGHT(c); | 1194 | ny = selmon->wy + selmon->wh - HEIGHT(c); |
| 1164 | if(!c->isfloating && selmon->lt[selmon->sellt]->arrange | 1195 | if (!c->isfloating && selmon->lt[selmon->sellt]->arrange |
| 1165 | && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) | 1196 | && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) |
| 1166 | togglefloating(NULL); | 1197 | togglefloating(NULL); |
| 1167 | } | 1198 | } |
| 1168 | if(!selmon->lt[selmon->sellt]->arrange || c->isfloating) | 1199 | if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) |
| 1169 | resize(c, nx, ny, c->w, c->h, 1); | 1200 | resize(c, nx, ny, c->w, c->h, 1); |
| 1170 | break; | 1201 | break; |
| 1171 | } | 1202 | } |
| 1172 | } while(ev.type != ButtonRelease); | 1203 | } while (ev.type != ButtonRelease); |
| 1173 | XUngrabPointer(dpy, CurrentTime); | 1204 | XUngrabPointer(dpy, CurrentTime); |
| 1174 | if((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { | 1205 | if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { |
| 1175 | sendmon(c, m); | 1206 | sendmon(c, m); |
| 1176 | selmon = m; | 1207 | selmon = m; |
| 1177 | focus(NULL); | 1208 | focus(NULL); |
| @@ -1179,13 +1210,15 @@ movemouse(const Arg *arg) { | |||
| 1179 | } | 1210 | } |
| 1180 | 1211 | ||
| 1181 | Client * | 1212 | Client * |
| 1182 | nexttiled(Client *c) { | 1213 | nexttiled(Client *c) |
| 1183 | for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next); | 1214 | { |
| 1215 | for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next); | ||
| 1184 | return c; | 1216 | return c; |
| 1185 | } | 1217 | } |
| 1186 | 1218 | ||
| 1187 | void | 1219 | void |
| 1188 | pop(Client *c) { | 1220 | pop(Client *c) |
| 1221 | { | ||
| 1189 | detach(c); | 1222 | detach(c); |
| 1190 | attach(c); | 1223 | attach(c); |
| 1191 | focus(c); | 1224 | focus(c); |
| @@ -1193,20 +1226,21 @@ pop(Client *c) { | |||
| 1193 | } | 1226 | } |
| 1194 | 1227 | ||
| 1195 | void | 1228 | void |
| 1196 | propertynotify(XEvent *e) { | 1229 | propertynotify(XEvent *e) |
| 1230 | { | ||
| 1197 | Client *c; | 1231 | Client *c; |
| 1198 | Window trans; | 1232 | Window trans; |
| 1199 | XPropertyEvent *ev = &e->xproperty; | 1233 | XPropertyEvent *ev = &e->xproperty; |
| 1200 | 1234 | ||
| 1201 | if((ev->window == root) && (ev->atom == XA_WM_NAME)) | 1235 | if ((ev->window == root) && (ev->atom == XA_WM_NAME)) |
| 1202 | updatestatus(); | 1236 | updatestatus(); |
| 1203 | else if(ev->state == PropertyDelete) | 1237 | else if (ev->state == PropertyDelete) |
| 1204 | return; /* ignore */ | 1238 | return; /* ignore */ |
| 1205 | else if((c = wintoclient(ev->window))) { | 1239 | else if ((c = wintoclient(ev->window))) { |
| 1206 | switch(ev->atom) { | 1240 | switch(ev->atom) { |
| 1207 | default: break; | 1241 | default: break; |
| 1208 | case XA_WM_TRANSIENT_FOR: | 1242 | case XA_WM_TRANSIENT_FOR: |
| 1209 | if(!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) && | 1243 | if (!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) && |
| 1210 | (c->isfloating = (wintoclient(trans)) != NULL)) | 1244 | (c->isfloating = (wintoclient(trans)) != NULL)) |
| 1211 | arrange(c->mon); | 1245 | arrange(c->mon); |
| 1212 | break; | 1246 | break; |
| @@ -1218,28 +1252,30 @@ propertynotify(XEvent *e) { | |||
| 1218 | drawbars(); | 1252 | drawbars(); |
| 1219 | break; | 1253 | break; |
| 1220 | } | 1254 | } |
| 1221 | if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { | 1255 | if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { |
| 1222 | updatetitle(c); | 1256 | updatetitle(c); |
| 1223 | if(c == c->mon->sel) | 1257 | if (c == c->mon->sel) |
| 1224 | drawbar(c->mon); | 1258 | drawbar(c->mon); |
| 1225 | } | 1259 | } |
| 1226 | if(ev->atom == netatom[NetWMWindowType]) | 1260 | if (ev->atom == netatom[NetWMWindowType]) |
| 1227 | updatewindowtype(c); | 1261 | updatewindowtype(c); |
| 1228 | } | 1262 | } |
| 1229 | } | 1263 | } |
| 1230 | 1264 | ||
| 1231 | void | 1265 | void |
| 1232 | quit(const Arg *arg) { | 1266 | quit(const Arg *arg) |
| 1267 | { | ||
| 1233 | running = 0; | 1268 | running = 0; |
| 1234 | } | 1269 | } |
| 1235 | 1270 | ||
| 1236 | Monitor * | 1271 | Monitor * |
| 1237 | recttomon(int x, int y, int w, int h) { | 1272 | recttomon(int x, int y, int w, int h) |
| 1273 | { | ||
| 1238 | Monitor *m, *r = selmon; | 1274 | Monitor *m, *r = selmon; |
| 1239 | int a, area = 0; | 1275 | int a, area = 0; |
| 1240 | 1276 | ||
| 1241 | for(m = mons; m; m = m->next) | 1277 | for (m = mons; m; m = m->next) |
| 1242 | if((a = INTERSECT(x, y, w, h, m)) > area) { | 1278 | if ((a = INTERSECT(x, y, w, h, m)) > area) { |
| 1243 | area = a; | 1279 | area = a; |
| 1244 | r = m; | 1280 | r = m; |
| 1245 | } | 1281 | } |
| @@ -1247,13 +1283,15 @@ recttomon(int x, int y, int w, int h) { | |||
| 1247 | } | 1283 | } |
| 1248 | 1284 | ||
| 1249 | void | 1285 | void |
| 1250 | resize(Client *c, int x, int y, int w, int h, int interact) { | 1286 | resize(Client *c, int x, int y, int w, int h, int interact) |
| 1251 | if(applysizehints(c, &x, &y, &w, &h, interact)) | 1287 | { |
| 1288 | if (applysizehints(c, &x, &y, &w, &h, interact)) | ||
| 1252 | resizeclient(c, x, y, w, h); | 1289 | resizeclient(c, x, y, w, h); |
| 1253 | } | 1290 | } |
| 1254 | 1291 | ||
| 1255 | void | 1292 | void |
| 1256 | resizeclient(Client *c, int x, int y, int w, int h) { | 1293 | resizeclient(Client *c, int x, int y, int w, int h) |
| 1294 | { | ||
| 1257 | XWindowChanges wc; | 1295 | XWindowChanges wc; |
| 1258 | 1296 | ||
| 1259 | c->oldx = c->x; c->x = wc.x = x; | 1297 | c->oldx = c->x; c->x = wc.x = x; |
| @@ -1267,21 +1305,22 @@ resizeclient(Client *c, int x, int y, int w, int h) { | |||
| 1267 | } | 1305 | } |
| 1268 | 1306 | ||
| 1269 | void | 1307 | void |
| 1270 | resizemouse(const Arg *arg) { | 1308 | resizemouse(const Arg *arg) |
| 1309 | { | ||
| 1271 | int ocx, ocy, nw, nh; | 1310 | int ocx, ocy, nw, nh; |
| 1272 | Client *c; | 1311 | Client *c; |
| 1273 | Monitor *m; | 1312 | Monitor *m; |
| 1274 | XEvent ev; | 1313 | XEvent ev; |
| 1275 | Time lasttime = 0; | 1314 | Time lasttime = 0; |
| 1276 | 1315 | ||
| 1277 | if(!(c = selmon->sel)) | 1316 | if (!(c = selmon->sel)) |
| 1278 | return; | 1317 | return; |
| 1279 | if(c->isfullscreen) /* no support resizing fullscreen windows by mouse */ | 1318 | if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ |
| 1280 | return; | 1319 | return; |
| 1281 | restack(selmon); | 1320 | restack(selmon); |
| 1282 | ocx = c->x; | 1321 | ocx = c->x; |
| 1283 | ocy = c->y; | 1322 | ocy = c->y; |
| 1284 | if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, | 1323 | if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, |
| 1285 | None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) | 1324 | None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) |
| 1286 | return; | 1325 | return; |
| 1287 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); | 1326 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); |
| @@ -1300,22 +1339,22 @@ resizemouse(const Arg *arg) { | |||
| 1300 | 1339 | ||
| 1301 | nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); | 1340 | nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); |
| 1302 | nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); | 1341 | nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); |
| 1303 | if(c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww | 1342 | if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww |
| 1304 | && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh) | 1343 | && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh) |
| 1305 | { | 1344 | { |
| 1306 | if(!c->isfloating && selmon->lt[selmon->sellt]->arrange | 1345 | if (!c->isfloating && selmon->lt[selmon->sellt]->arrange |
| 1307 | && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) | 1346 | && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) |
| 1308 | togglefloating(NULL); | 1347 | togglefloating(NULL); |
| 1309 | } | 1348 | } |
| 1310 | if(!selmon->lt[selmon->sellt]->arrange || c->isfloating) | 1349 | if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) |
| 1311 | resize(c, c->x, c->y, nw, nh, 1); | 1350 | resize(c, c->x, c->y, nw, nh, 1); |
| 1312 | break; | 1351 | break; |
| 1313 | } | 1352 | } |
| 1314 | } while(ev.type != ButtonRelease); | 1353 | } while (ev.type != ButtonRelease); |
| 1315 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); | 1354 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); |
| 1316 | XUngrabPointer(dpy, CurrentTime); | 1355 | XUngrabPointer(dpy, CurrentTime); |
| 1317 | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | 1356 | while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
| 1318 | if((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { | 1357 | if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { |
| 1319 | sendmon(c, m); | 1358 | sendmon(c, m); |
| 1320 | selmon = m; | 1359 | selmon = m; |
| 1321 | focus(NULL); | 1360 | focus(NULL); |
| @@ -1323,68 +1362,72 @@ resizemouse(const Arg *arg) { | |||
| 1323 | } | 1362 | } |
| 1324 | 1363 | ||
| 1325 | void | 1364 | void |
| 1326 | restack(Monitor *m) { | 1365 | restack(Monitor *m) |
| 1366 | { | ||
| 1327 | Client *c; | 1367 | Client *c; |
| 1328 | XEvent ev; | 1368 | XEvent ev; |
| 1329 | XWindowChanges wc; | 1369 | XWindowChanges wc; |
| 1330 | 1370 | ||
| 1331 | drawbar(m); | 1371 | drawbar(m); |
| 1332 | if(!m->sel) | 1372 | if (!m->sel) |
| 1333 | return; | 1373 | return; |
| 1334 | if(m->sel->isfloating || !m->lt[m->sellt]->arrange) | 1374 | if (m->sel->isfloating || !m->lt[m->sellt]->arrange) |
| 1335 | XRaiseWindow(dpy, m->sel->win); | 1375 | XRaiseWindow(dpy, m->sel->win); |
| 1336 | if(m->lt[m->sellt]->arrange) { | 1376 | if (m->lt[m->sellt]->arrange) { |
| 1337 | wc.stack_mode = Below; | 1377 | wc.stack_mode = Below; |
| 1338 | wc.sibling = m->barwin; | 1378 | wc.sibling = m->barwin; |
| 1339 | for(c = m->stack; c; c = c->snext) | 1379 | for (c = m->stack; c; c = c->snext) |
| 1340 | if(!c->isfloating && ISVISIBLE(c)) { | 1380 | if (!c->isfloating && ISVISIBLE(c)) { |
| 1341 | XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); | 1381 | XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); |
| 1342 | wc.sibling = c->win; | 1382 | wc.sibling = c->win; |
| 1343 | } | 1383 | } |
| 1344 | } | 1384 | } |
| 1345 | XSync(dpy, False); | 1385 | XSync(dpy, False); |
| 1346 | while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); | 1386 | while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); |
| 1347 | } | 1387 | } |
| 1348 | 1388 | ||
| 1349 | void | 1389 | void |
| 1350 | run(void) { | 1390 | run(void) |
| 1391 | { | ||
| 1351 | XEvent ev; | 1392 | XEvent ev; |
| 1352 | /* main event loop */ | 1393 | /* main event loop */ |
| 1353 | XSync(dpy, False); | 1394 | XSync(dpy, False); |
| 1354 | while(running && !XNextEvent(dpy, &ev)) | 1395 | while (running && !XNextEvent(dpy, &ev)) |
| 1355 | if(handler[ev.type]) | 1396 | if (handler[ev.type]) |
| 1356 | handler[ev.type](&ev); /* call handler */ | 1397 | handler[ev.type](&ev); /* call handler */ |
| 1357 | } | 1398 | } |
| 1358 | 1399 | ||
| 1359 | void | 1400 | void |
| 1360 | scan(void) { | 1401 | scan(void) |
| 1402 | { | ||
| 1361 | unsigned int i, num; | 1403 | unsigned int i, num; |
| 1362 | Window d1, d2, *wins = NULL; | 1404 | Window d1, d2, *wins = NULL; |
| 1363 | XWindowAttributes wa; | 1405 | XWindowAttributes wa; |
| 1364 | 1406 | ||
| 1365 | if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { | 1407 | if (XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { |
| 1366 | for(i = 0; i < num; i++) { | 1408 | for (i = 0; i < num; i++) { |
| 1367 | if(!XGetWindowAttributes(dpy, wins[i], &wa) | 1409 | if (!XGetWindowAttributes(dpy, wins[i], &wa) |
| 1368 | || wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) | 1410 | || wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) |
| 1369 | continue; | 1411 | continue; |
| 1370 | if(wa.map_state == IsViewable || getstate(wins[i]) == IconicState) | 1412 | if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState) |
| 1371 | manage(wins[i], &wa); | 1413 | manage(wins[i], &wa); |
| 1372 | } | 1414 | } |
| 1373 | for(i = 0; i < num; i++) { /* now the transients */ | 1415 | for (i = 0; i < num; i++) { /* now the transients */ |
| 1374 | if(!XGetWindowAttributes(dpy, wins[i], &wa)) | 1416 | if (!XGetWindowAttributes(dpy, wins[i], &wa)) |
| 1375 | continue; | 1417 | continue; |
| 1376 | if(XGetTransientForHint(dpy, wins[i], &d1) | 1418 | if (XGetTransientForHint(dpy, wins[i], &d1) |
| 1377 | && (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)) | 1419 | && (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)) |
| 1378 | manage(wins[i], &wa); | 1420 | manage(wins[i], &wa); |
| 1379 | } | 1421 | } |
| 1380 | if(wins) | 1422 | if (wins) |
| 1381 | XFree(wins); | 1423 | XFree(wins); |
| 1382 | } | 1424 | } |
| 1383 | } | 1425 | } |
| 1384 | 1426 | ||
| 1385 | void | 1427 | void |
| 1386 | sendmon(Client *c, Monitor *m) { | 1428 | sendmon(Client *c, Monitor *m) |
| 1387 | if(c->mon == m) | 1429 | { |
| 1430 | if (c->mon == m) | ||
| 1388 | return; | 1431 | return; |
| 1389 | unfocus(c, 1); | 1432 | unfocus(c, 1); |
| 1390 | detach(c); | 1433 | detach(c); |
| @@ -1398,7 +1441,8 @@ sendmon(Client *c, Monitor *m) { | |||
| 1398 | } | 1441 | } |
| 1399 | 1442 | ||
| 1400 | void | 1443 | void |
| 1401 | setclientstate(Client *c, long state) { | 1444 | setclientstate(Client *c, long state) |
| 1445 | { | ||
| 1402 | long data[] = { state, None }; | 1446 | long data[] = { state, None }; |
| 1403 | 1447 | ||
| 1404 | XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, | 1448 | XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, |
| @@ -1406,18 +1450,19 @@ setclientstate(Client *c, long state) { | |||
| 1406 | } | 1450 | } |
| 1407 | 1451 | ||
| 1408 | int | 1452 | int |
| 1409 | sendevent(Client *c, Atom proto) { | 1453 | sendevent(Client *c, Atom proto) |
| 1454 | { | ||
| 1410 | int n; | 1455 | int n; |
| 1411 | Atom *protocols; | 1456 | Atom *protocols; |
| 1412 | int exists = 0; | 1457 | int exists = 0; |
| 1413 | XEvent ev; | 1458 | XEvent ev; |
| 1414 | 1459 | ||
| 1415 | if(XGetWMProtocols(dpy, c->win, &protocols, &n)) { | 1460 | if (XGetWMProtocols(dpy, c->win, &protocols, &n)) { |
| 1416 | while(!exists && n--) | 1461 | while (!exists && n--) |
| 1417 | exists = protocols[n] == proto; | 1462 | exists = protocols[n] == proto; |
| 1418 | XFree(protocols); | 1463 | XFree(protocols); |
| 1419 | } | 1464 | } |
| 1420 | if(exists) { | 1465 | if (exists) { |
| 1421 | ev.type = ClientMessage; | 1466 | ev.type = ClientMessage; |
| 1422 | ev.xclient.window = c->win; | 1467 | ev.xclient.window = c->win; |
| 1423 | ev.xclient.message_type = wmatom[WMProtocols]; | 1468 | ev.xclient.message_type = wmatom[WMProtocols]; |
| @@ -1430,8 +1475,9 @@ sendevent(Client *c, Atom proto) { | |||
| 1430 | } | 1475 | } |
| 1431 | 1476 | ||
| 1432 | void | 1477 | void |
| 1433 | setfocus(Client *c) { | 1478 | setfocus(Client *c) |
| 1434 | if(!c->neverfocus) { | 1479 | { |
| 1480 | if (!c->neverfocus) { | ||
| 1435 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); | 1481 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); |
| 1436 | XChangeProperty(dpy, root, netatom[NetActiveWindow], | 1482 | XChangeProperty(dpy, root, netatom[NetActiveWindow], |
| 1437 | XA_WINDOW, 32, PropModeReplace, | 1483 | XA_WINDOW, 32, PropModeReplace, |
| @@ -1441,8 +1487,9 @@ setfocus(Client *c) { | |||
| 1441 | } | 1487 | } |
| 1442 | 1488 | ||
| 1443 | void | 1489 | void |
| 1444 | setfullscreen(Client *c, int fullscreen) { | 1490 | setfullscreen(Client *c, int fullscreen) |
| 1445 | if(fullscreen && !c->isfullscreen) { | 1491 | { |
| 1492 | if (fullscreen && !c->isfullscreen) { | ||
| 1446 | XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, | 1493 | XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, |
| 1447 | PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1); | 1494 | PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1); |
| 1448 | c->isfullscreen = 1; | 1495 | c->isfullscreen = 1; |
| @@ -1452,8 +1499,7 @@ setfullscreen(Client *c, int fullscreen) { | |||
| 1452 | c->isfloating = 1; | 1499 | c->isfloating = 1; |
| 1453 | resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); | 1500 | resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); |
| 1454 | XRaiseWindow(dpy, c->win); | 1501 | XRaiseWindow(dpy, c->win); |
| 1455 | } | 1502 | } else if (!fullscreen && c->isfullscreen){ |
| 1456 | else if(!fullscreen && c->isfullscreen){ | ||
| 1457 | XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, | 1503 | XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, |
| 1458 | PropModeReplace, (unsigned char*)0, 0); | 1504 | PropModeReplace, (unsigned char*)0, 0); |
| 1459 | c->isfullscreen = 0; | 1505 | c->isfullscreen = 0; |
| @@ -1469,13 +1515,14 @@ setfullscreen(Client *c, int fullscreen) { | |||
| 1469 | } | 1515 | } |
| 1470 | 1516 | ||
| 1471 | void | 1517 | void |
| 1472 | setlayout(const Arg *arg) { | 1518 | setlayout(const Arg *arg) |
| 1473 | if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) | 1519 | { |
| 1520 | if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) | ||
| 1474 | selmon->sellt ^= 1; | 1521 | selmon->sellt ^= 1; |
| 1475 | if(arg && arg->v) | 1522 | if (arg && arg->v) |
| 1476 | selmon->lt[selmon->sellt] = (Layout *)arg->v; | 1523 | selmon->lt[selmon->sellt] = (Layout *)arg->v; |
| 1477 | strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); | 1524 | strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); |
| 1478 | if(selmon->sel) | 1525 | if (selmon->sel) |
| 1479 | arrange(selmon); | 1526 | arrange(selmon); |
| 1480 | else | 1527 | else |
| 1481 | drawbar(selmon); | 1528 | drawbar(selmon); |
| @@ -1483,20 +1530,22 @@ setlayout(const Arg *arg) { | |||
| 1483 | 1530 | ||
| 1484 | /* arg > 1.0 will set mfact absolutly */ | 1531 | /* arg > 1.0 will set mfact absolutly */ |
| 1485 | void | 1532 | void |
| 1486 | setmfact(const Arg *arg) { | 1533 | setmfact(const Arg *arg) |
| 1534 | { | ||
| 1487 | float f; | 1535 | float f; |
| 1488 | 1536 | ||
| 1489 | if(!arg || !selmon->lt[selmon->sellt]->arrange) | 1537 | if (!arg || !selmon->lt[selmon->sellt]->arrange) |
| 1490 | return; | 1538 | return; |
| 1491 | f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; | 1539 | f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; |
| 1492 | if(f < 0.1 || f > 0.9) | 1540 | if (f < 0.1 || f > 0.9) |
| 1493 | return; | 1541 | return; |
| 1494 | selmon->mfact = f; | 1542 | selmon->mfact = f; |
| 1495 | arrange(selmon); | 1543 | arrange(selmon); |
| 1496 | } | 1544 | } |
| 1497 | 1545 | ||
| 1498 | void | 1546 | void |
| 1499 | setup(void) { | 1547 | setup(void) |
| 1548 | { | ||
| 1500 | XSetWindowAttributes wa; | 1549 | XSetWindowAttributes wa; |
| 1501 | 1550 | ||
| 1502 | /* clean up any zombies immediately */ | 1551 | /* clean up any zombies immediately */ |
| @@ -1555,34 +1604,38 @@ setup(void) { | |||
| 1555 | } | 1604 | } |
| 1556 | 1605 | ||
| 1557 | void | 1606 | void |
| 1558 | showhide(Client *c) { | 1607 | showhide(Client *c) |
| 1559 | if(!c) | 1608 | { |
| 1609 | if (!c) | ||
| 1560 | return; | 1610 | return; |
| 1561 | if(ISVISIBLE(c)) { /* show clients top down */ | 1611 | if (ISVISIBLE(c)) { |
| 1612 | /* show clients top down */ | ||
| 1562 | XMoveWindow(dpy, c->win, c->x, c->y); | 1613 | XMoveWindow(dpy, c->win, c->x, c->y); |
| 1563 | if((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen) | 1614 | if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen) |
| 1564 | resize(c, c->x, c->y, c->w, c->h, 0); | 1615 | resize(c, c->x, c->y, c->w, c->h, 0); |
| 1565 | showhide(c->snext); | 1616 | showhide(c->snext); |
| 1566 | } | 1617 | } else { |
| 1567 | else { /* hide clients bottom up */ | 1618 | /* hide clients bottom up */ |
| 1568 | showhide(c->snext); | 1619 | showhide(c->snext); |
| 1569 | XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y); | 1620 | XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y); |
| 1570 | } | 1621 | } |
| 1571 | } | 1622 | } |
| 1572 | 1623 | ||
| 1573 | void | 1624 | void |
| 1574 | sigchld(int unused) { | 1625 | sigchld(int unused) |
| 1575 | if(signal(SIGCHLD, sigchld) == SIG_ERR) | 1626 | { |
| 1627 | if (signal(SIGCHLD, sigchld) == SIG_ERR) | ||
| 1576 | die("can't install SIGCHLD handler:"); | 1628 | die("can't install SIGCHLD handler:"); |
| 1577 | while(0 < waitpid(-1, NULL, WNOHANG)); | 1629 | while (0 < waitpid(-1, NULL, WNOHANG)); |
| 1578 | } | 1630 | } |
| 1579 | 1631 | ||
| 1580 | void | 1632 | void |
| 1581 | spawn(const Arg *arg) { | 1633 | spawn(const Arg *arg) |
| 1582 | if(arg->v == dmenucmd) | 1634 | { |
| 1635 | if (arg->v == dmenucmd) | ||
| 1583 | dmenumon[0] = '0' + selmon->num; | 1636 | dmenumon[0] = '0' + selmon->num; |
| 1584 | if(fork() == 0) { | 1637 | if (fork() == 0) { |
| 1585 | if(dpy) | 1638 | if (dpy) |
| 1586 | close(ConnectionNumber(dpy)); | 1639 | close(ConnectionNumber(dpy)); |
| 1587 | setsid(); | 1640 | setsid(); |
| 1588 | execvp(((char **)arg->v)[0], (char **)arg->v); | 1641 | execvp(((char **)arg->v)[0], (char **)arg->v); |
| @@ -1593,8 +1646,9 @@ spawn(const Arg *arg) { | |||
| 1593 | } | 1646 | } |
| 1594 | 1647 | ||
| 1595 | void | 1648 | void |
| 1596 | tag(const Arg *arg) { | 1649 | tag(const Arg *arg) |
| 1597 | if(selmon->sel && arg->ui & TAGMASK) { | 1650 | { |
| 1651 | if (selmon->sel && arg->ui & TAGMASK) { | ||
| 1598 | selmon->sel->tags = arg->ui & TAGMASK; | 1652 | selmon->sel->tags = arg->ui & TAGMASK; |
| 1599 | focus(NULL); | 1653 | focus(NULL); |
| 1600 | arrange(selmon); | 1654 | arrange(selmon); |
| @@ -1602,32 +1656,33 @@ tag(const Arg *arg) { | |||
| 1602 | } | 1656 | } |
| 1603 | 1657 | ||
| 1604 | void | 1658 | void |
| 1605 | tagmon(const Arg *arg) { | 1659 | tagmon(const Arg *arg) |
| 1606 | if(!selmon->sel || !mons->next) | 1660 | { |
| 1661 | if (!selmon->sel || !mons->next) | ||
| 1607 | return; | 1662 | return; |
| 1608 | sendmon(selmon->sel, dirtomon(arg->i)); | 1663 | sendmon(selmon->sel, dirtomon(arg->i)); |
| 1609 | } | 1664 | } |
| 1610 | 1665 | ||
| 1611 | void | 1666 | void |
| 1612 | tile(Monitor *m) { | 1667 | tile(Monitor *m) |
| 1668 | { | ||
| 1613 | unsigned int i, n, h, mw, my, ty; | 1669 | unsigned int i, n, h, mw, my, ty; |
| 1614 | Client *c; | 1670 | Client *c; |
| 1615 | 1671 | ||
| 1616 | for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); | 1672 | for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); |
| 1617 | if(n == 0) | 1673 | if (n == 0) |
| 1618 | return; | 1674 | return; |
| 1619 | 1675 | ||
| 1620 | if(n > m->nmaster) | 1676 | if (n > m->nmaster) |
| 1621 | mw = m->nmaster ? m->ww * m->mfact : 0; | 1677 | mw = m->nmaster ? m->ww * m->mfact : 0; |
| 1622 | else | 1678 | else |
| 1623 | mw = m->ww; | 1679 | mw = m->ww; |
| 1624 | for(i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) | 1680 | for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) |
| 1625 | if(i < m->nmaster) { | 1681 | if (i < m->nmaster) { |
| 1626 | h = (m->wh - my) / (MIN(n, m->nmaster) - i); | 1682 | h = (m->wh - my) / (MIN(n, m->nmaster) - i); |
| 1627 | resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); | 1683 | resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); |
| 1628 | my += HEIGHT(c); | 1684 | my += HEIGHT(c); |
| 1629 | } | 1685 | } else { |
| 1630 | else { | ||
| 1631 | h = (m->wh - ty) / (n - i); | 1686 | h = (m->wh - ty) / (n - i); |
| 1632 | resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); | 1687 | resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); |
| 1633 | ty += HEIGHT(c); | 1688 | ty += HEIGHT(c); |
| @@ -1635,7 +1690,8 @@ tile(Monitor *m) { | |||
| 1635 | } | 1690 | } |
| 1636 | 1691 | ||
| 1637 | void | 1692 | void |
| 1638 | togglebar(const Arg *arg) { | 1693 | togglebar(const Arg *arg) |
| 1694 | { | ||
| 1639 | selmon->showbar = !selmon->showbar; | 1695 | selmon->showbar = !selmon->showbar; |
| 1640 | updatebarpos(selmon); | 1696 | updatebarpos(selmon); |
| 1641 | XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); | 1697 | XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); |
| @@ -1643,26 +1699,28 @@ togglebar(const Arg *arg) { | |||
| 1643 | } | 1699 | } |
| 1644 | 1700 | ||
| 1645 | void | 1701 | void |
| 1646 | togglefloating(const Arg *arg) { | 1702 | togglefloating(const Arg *arg) |
| 1647 | if(!selmon->sel) | 1703 | { |
| 1704 | if (!selmon->sel) | ||
| 1648 | return; | 1705 | return; |
| 1649 | if(selmon->sel->isfullscreen) /* no support for fullscreen windows */ | 1706 | if (selmon->sel->isfullscreen) /* no support for fullscreen windows */ |
| 1650 | return; | 1707 | return; |
| 1651 | selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed; | 1708 | selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed; |
| 1652 | if(selmon->sel->isfloating) | 1709 | if (selmon->sel->isfloating) |
| 1653 | resize(selmon->sel, selmon->sel->x, selmon->sel->y, | 1710 | resize(selmon->sel, selmon->sel->x, selmon->sel->y, |
| 1654 | selmon->sel->w, selmon->sel->h, 0); | 1711 | selmon->sel->w, selmon->sel->h, 0); |
| 1655 | arrange(selmon); | 1712 | arrange(selmon); |
| 1656 | } | 1713 | } |
| 1657 | 1714 | ||
| 1658 | void | 1715 | void |
| 1659 | toggletag(const Arg *arg) { | 1716 | toggletag(const Arg *arg) |
| 1717 | { | ||
| 1660 | unsigned int newtags; | 1718 | unsigned int newtags; |
| 1661 | 1719 | ||
| 1662 | if(!selmon->sel) | 1720 | if (!selmon->sel) |
| 1663 | return; | 1721 | return; |
| 1664 | newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); | 1722 | newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); |
| 1665 | if(newtags) { | 1723 | if (newtags) { |
| 1666 | selmon->sel->tags = newtags; | 1724 | selmon->sel->tags = newtags; |
| 1667 | focus(NULL); | 1725 | focus(NULL); |
| 1668 | arrange(selmon); | 1726 | arrange(selmon); |
| @@ -1670,10 +1728,11 @@ toggletag(const Arg *arg) { | |||
| 1670 | } | 1728 | } |
| 1671 | 1729 | ||
| 1672 | void | 1730 | void |
| 1673 | toggleview(const Arg *arg) { | 1731 | toggleview(const Arg *arg) |
| 1732 | { | ||
| 1674 | unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); | 1733 | unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); |
| 1675 | 1734 | ||
| 1676 | if(newtagset) { | 1735 | if (newtagset) { |
| 1677 | selmon->tagset[selmon->seltags] = newtagset; | 1736 | selmon->tagset[selmon->seltags] = newtagset; |
| 1678 | focus(NULL); | 1737 | focus(NULL); |
| 1679 | arrange(selmon); | 1738 | arrange(selmon); |
| @@ -1681,26 +1740,28 @@ toggleview(const Arg *arg) { | |||
| 1681 | } | 1740 | } |
| 1682 | 1741 | ||
| 1683 | void | 1742 | void |
| 1684 | unfocus(Client *c, int setfocus) { | 1743 | unfocus(Client *c, int setfocus) |
| 1685 | if(!c) | 1744 | { |
| 1745 | if (!c) | ||
| 1686 | return; | 1746 | return; |
| 1687 | grabbuttons(c, 0); | 1747 | grabbuttons(c, 0); |
| 1688 | XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->pix); | 1748 | XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->pix); |
| 1689 | if(setfocus) { | 1749 | if (setfocus) { |
| 1690 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); | 1750 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); |
| 1691 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); | 1751 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); |
| 1692 | } | 1752 | } |
| 1693 | } | 1753 | } |
| 1694 | 1754 | ||
| 1695 | void | 1755 | void |
| 1696 | unmanage(Client *c, int destroyed) { | 1756 | unmanage(Client *c, int destroyed) |
| 1757 | { | ||
| 1697 | Monitor *m = c->mon; | 1758 | Monitor *m = c->mon; |
| 1698 | XWindowChanges wc; | 1759 | XWindowChanges wc; |
| 1699 | 1760 | ||
| 1700 | /* The server grab construct avoids race conditions. */ | 1761 | /* The server grab construct avoids race conditions. */ |
| 1701 | detach(c); | 1762 | detach(c); |
| 1702 | detachstack(c); | 1763 | detachstack(c); |
| 1703 | if(!destroyed) { | 1764 | if (!destroyed) { |
| 1704 | wc.border_width = c->oldbw; | 1765 | wc.border_width = c->oldbw; |
| 1705 | XGrabServer(dpy); | 1766 | XGrabServer(dpy); |
| 1706 | XSetErrorHandler(xerrordummy); | 1767 | XSetErrorHandler(xerrordummy); |
| @@ -1718,12 +1779,13 @@ unmanage(Client *c, int destroyed) { | |||
| 1718 | } | 1779 | } |
| 1719 | 1780 | ||
| 1720 | void | 1781 | void |
| 1721 | unmapnotify(XEvent *e) { | 1782 | unmapnotify(XEvent *e) |
| 1783 | { | ||
| 1722 | Client *c; | 1784 | Client *c; |
| 1723 | XUnmapEvent *ev = &e->xunmap; | 1785 | XUnmapEvent *ev = &e->xunmap; |
| 1724 | 1786 | ||
| 1725 | if((c = wintoclient(ev->window))) { | 1787 | if ((c = wintoclient(ev->window))) { |
| 1726 | if(ev->send_event) | 1788 | if (ev->send_event) |
| 1727 | setclientstate(c, WithdrawnState); | 1789 | setclientstate(c, WithdrawnState); |
| 1728 | else | 1790 | else |
| 1729 | unmanage(c, 0); | 1791 | unmanage(c, 0); |
| @@ -1731,14 +1793,15 @@ unmapnotify(XEvent *e) { | |||
| 1731 | } | 1793 | } |
| 1732 | 1794 | ||
| 1733 | void | 1795 | void |
| 1734 | updatebars(void) { | 1796 | updatebars(void) |
| 1797 | { | ||
| 1735 | Monitor *m; | 1798 | Monitor *m; |
| 1736 | XSetWindowAttributes wa = { | 1799 | XSetWindowAttributes wa = { |
| 1737 | .override_redirect = True, | 1800 | .override_redirect = True, |
| 1738 | .background_pixmap = ParentRelative, | 1801 | .background_pixmap = ParentRelative, |
| 1739 | .event_mask = ButtonPressMask|ExposureMask | 1802 | .event_mask = ButtonPressMask|ExposureMask |
| 1740 | }; | 1803 | }; |
| 1741 | for(m = mons; m; m = m->next) { | 1804 | for (m = mons; m; m = m->next) { |
| 1742 | if (m->barwin) | 1805 | if (m->barwin) |
| 1743 | continue; | 1806 | continue; |
| 1744 | m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), | 1807 | m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), |
| @@ -1750,61 +1813,63 @@ updatebars(void) { | |||
| 1750 | } | 1813 | } |
| 1751 | 1814 | ||
| 1752 | void | 1815 | void |
| 1753 | updatebarpos(Monitor *m) { | 1816 | updatebarpos(Monitor *m) |
| 1817 | { | ||
| 1754 | m->wy = m->my; | 1818 | m->wy = m->my; |
| 1755 | m->wh = m->mh; | 1819 | m->wh = m->mh; |
| 1756 | if(m->showbar) { | 1820 | if (m->showbar) { |
| 1757 | m->wh -= bh; | 1821 | m->wh -= bh; |
| 1758 | m->by = m->topbar ? m->wy : m->wy + m->wh; | 1822 | m->by = m->topbar ? m->wy : m->wy + m->wh; |
| 1759 | m->wy = m->topbar ? m->wy + bh : m->wy; | 1823 | m->wy = m->topbar ? m->wy + bh : m->wy; |
| 1760 | } | 1824 | } else |
| 1761 | else | ||
| 1762 | m->by = -bh; | 1825 | m->by = -bh; |
| 1763 | } | 1826 | } |
| 1764 | 1827 | ||
| 1765 | void | 1828 | void |
| 1766 | updateclientlist() { | 1829 | updateclientlist() |
| 1830 | { | ||
| 1767 | Client *c; | 1831 | Client *c; |
| 1768 | Monitor *m; | 1832 | Monitor *m; |
| 1769 | 1833 | ||
| 1770 | XDeleteProperty(dpy, root, netatom[NetClientList]); | 1834 | XDeleteProperty(dpy, root, netatom[NetClientList]); |
| 1771 | for(m = mons; m; m = m->next) | 1835 | for (m = mons; m; m = m->next) |
| 1772 | for(c = m->clients; c; c = c->next) | 1836 | for (c = m->clients; c; c = c->next) |
| 1773 | XChangeProperty(dpy, root, netatom[NetClientList], | 1837 | XChangeProperty(dpy, root, netatom[NetClientList], |
| 1774 | XA_WINDOW, 32, PropModeAppend, | 1838 | XA_WINDOW, 32, PropModeAppend, |
| 1775 | (unsigned char *) &(c->win), 1); | 1839 | (unsigned char *) &(c->win), 1); |
| 1776 | } | 1840 | } |
| 1777 | 1841 | ||
| 1778 | int | 1842 | int |
| 1779 | updategeom(void) { | 1843 | updategeom(void) |
| 1844 | { | ||
| 1780 | int dirty = 0; | 1845 | int dirty = 0; |
| 1781 | 1846 | ||
| 1782 | #ifdef XINERAMA | 1847 | #ifdef XINERAMA |
| 1783 | if(XineramaIsActive(dpy)) { | 1848 | if (XineramaIsActive(dpy)) { |
| 1784 | int i, j, n, nn; | 1849 | int i, j, n, nn; |
| 1785 | Client *c; | 1850 | Client *c; |
| 1786 | Monitor *m; | 1851 | Monitor *m; |
| 1787 | XineramaScreenInfo *info = XineramaQueryScreens(dpy, &nn); | 1852 | XineramaScreenInfo *info = XineramaQueryScreens(dpy, &nn); |
| 1788 | XineramaScreenInfo *unique = NULL; | 1853 | XineramaScreenInfo *unique = NULL; |
| 1789 | 1854 | ||
| 1790 | for(n = 0, m = mons; m; m = m->next, n++); | 1855 | for (n = 0, m = mons; m; m = m->next, n++); |
| 1791 | /* only consider unique geometries as separate screens */ | 1856 | /* only consider unique geometries as separate screens */ |
| 1792 | unique = ecalloc(nn, sizeof(XineramaScreenInfo)); | 1857 | unique = ecalloc(nn, sizeof(XineramaScreenInfo)); |
| 1793 | for(i = 0, j = 0; i < nn; i++) | 1858 | for (i = 0, j = 0; i < nn; i++) |
| 1794 | if(isuniquegeom(unique, j, &info[i])) | 1859 | if (isuniquegeom(unique, j, &info[i])) |
| 1795 | memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); | 1860 | memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); |
| 1796 | XFree(info); | 1861 | XFree(info); |
| 1797 | nn = j; | 1862 | nn = j; |
| 1798 | if(n <= nn) { | 1863 | if (n <= nn) { |
| 1799 | for(i = 0; i < (nn - n); i++) { /* new monitors available */ | 1864 | for (i = 0; i < (nn - n); i++) { /* new monitors available */ |
| 1800 | for(m = mons; m && m->next; m = m->next); | 1865 | for (m = mons; m && m->next; m = m->next); |
| 1801 | if(m) | 1866 | if (m) |
| 1802 | m->next = createmon(); | 1867 | m->next = createmon(); |
| 1803 | else | 1868 | else |
| 1804 | mons = createmon(); | 1869 | mons = createmon(); |
| 1805 | } | 1870 | } |
| 1806 | for(i = 0, m = mons; i < nn && m; m = m->next, i++) | 1871 | for (i = 0, m = mons; i < nn && m; m = m->next, i++) |
| 1807 | if(i >= n | 1872 | if (i >= n |
| 1808 | || (unique[i].x_org != m->mx || unique[i].y_org != m->my | 1873 | || (unique[i].x_org != m->mx || unique[i].y_org != m->my |
| 1809 | || unique[i].width != m->mw || unique[i].height != m->mh)) | 1874 | || unique[i].width != m->mw || unique[i].height != m->mh)) |
| 1810 | { | 1875 | { |
| @@ -1816,11 +1881,11 @@ updategeom(void) { | |||
| 1816 | m->mh = m->wh = unique[i].height; | 1881 | m->mh = m->wh = unique[i].height; |
| 1817 | updatebarpos(m); | 1882 | updatebarpos(m); |
| 1818 | } | 1883 | } |
| 1819 | } | 1884 | } else { |
| 1820 | else { /* less monitors available nn < n */ | 1885 | /* less monitors available nn < n */ |
| 1821 | for(i = nn; i < n; i++) { | 1886 | for (i = nn; i < n; i++) { |
| 1822 | for(m = mons; m && m->next; m = m->next); | 1887 | for (m = mons; m && m->next; m = m->next); |
| 1823 | while(m->clients) { | 1888 | while (m->clients) { |
| 1824 | dirty = 1; | 1889 | dirty = 1; |
| 1825 | c = m->clients; | 1890 | c = m->clients; |
| 1826 | m->clients = c->next; | 1891 | m->clients = c->next; |
| @@ -1829,27 +1894,26 @@ updategeom(void) { | |||
| 1829 | attach(c); | 1894 | attach(c); |
| 1830 | attachstack(c); | 1895 | attachstack(c); |
| 1831 | } | 1896 | } |
| 1832 | if(m == selmon) | 1897 | if (m == selmon) |
| 1833 | selmon = mons; | 1898 | selmon = mons; |
| 1834 | cleanupmon(m); | 1899 | cleanupmon(m); |
| 1835 | } | 1900 | } |
| 1836 | } | 1901 | } |
| 1837 | free(unique); | 1902 | free(unique); |
| 1838 | } | 1903 | } else |
| 1839 | else | ||
| 1840 | #endif /* XINERAMA */ | 1904 | #endif /* XINERAMA */ |
| 1841 | /* default monitor setup */ | 1905 | /* default monitor setup */ |
| 1842 | { | 1906 | { |
| 1843 | if(!mons) | 1907 | if (!mons) |
| 1844 | mons = createmon(); | 1908 | mons = createmon(); |
| 1845 | if(mons->mw != sw || mons->mh != sh) { | 1909 | if (mons->mw != sw || mons->mh != sh) { |
| 1846 | dirty = 1; | 1910 | dirty = 1; |
| 1847 | mons->mw = mons->ww = sw; | 1911 | mons->mw = mons->ww = sw; |
| 1848 | mons->mh = mons->wh = sh; | 1912 | mons->mh = mons->wh = sh; |
| 1849 | updatebarpos(mons); | 1913 | updatebarpos(mons); |
| 1850 | } | 1914 | } |
| 1851 | } | 1915 | } |
| 1852 | if(dirty) { | 1916 | if (dirty) { |
| 1853 | selmon = mons; | 1917 | selmon = mons; |
| 1854 | selmon = wintomon(root); | 1918 | selmon = wintomon(root); |
| 1855 | } | 1919 | } |
| @@ -1857,108 +1921,106 @@ updategeom(void) { | |||
| 1857 | } | 1921 | } |
| 1858 | 1922 | ||
| 1859 | void | 1923 | void |
| 1860 | updatenumlockmask(void) { | 1924 | updatenumlockmask(void) |
| 1925 | { | ||
| 1861 | unsigned int i, j; | 1926 | unsigned int i, j; |
| 1862 | XModifierKeymap *modmap; | 1927 | XModifierKeymap *modmap; |
| 1863 | 1928 | ||
| 1864 | numlockmask = 0; | 1929 | numlockmask = 0; |
| 1865 | modmap = XGetModifierMapping(dpy); | 1930 | modmap = XGetModifierMapping(dpy); |
| 1866 | for(i = 0; i < 8; i++) | 1931 | for (i = 0; i < 8; i++) |
| 1867 | for(j = 0; j < modmap->max_keypermod; j++) | 1932 | for (j = 0; j < modmap->max_keypermod; j++) |
| 1868 | if(modmap->modifiermap[i * modmap->max_keypermod + j] | 1933 | if (modmap->modifiermap[i * modmap->max_keypermod + j] |
| 1869 | == XKeysymToKeycode(dpy, XK_Num_Lock)) | 1934 | == XKeysymToKeycode(dpy, XK_Num_Lock)) |
| 1870 | numlockmask = (1 << i); | 1935 | numlockmask = (1 << i); |
| 1871 | XFreeModifiermap(modmap); | 1936 | XFreeModifiermap(modmap); |
| 1872 | } | 1937 | } |
| 1873 | 1938 | ||
| 1874 | void | 1939 | void |
| 1875 | updatesizehints(Client *c) { | 1940 | updatesizehints(Client *c) |
| 1941 | { | ||
| 1876 | long msize; | 1942 | long msize; |
| 1877 | XSizeHints size; | 1943 | XSizeHints size; |
| 1878 | 1944 | ||
| 1879 | if(!XGetWMNormalHints(dpy, c->win, &size, &msize)) | 1945 | if (!XGetWMNormalHints(dpy, c->win, &size, &msize)) |
| 1880 | /* size is uninitialized, ensure that size.flags aren't used */ | 1946 | /* size is uninitialized, ensure that size.flags aren't used */ |
| 1881 | size.flags = PSize; | 1947 | size.flags = PSize; |
| 1882 | if(size.flags & PBaseSize) { | 1948 | if (size.flags & PBaseSize) { |
| 1883 | c->basew = size.base_width; | 1949 | c->basew = size.base_width; |
| 1884 | c->baseh = size.base_height; | 1950 | c->baseh = size.base_height; |
| 1885 | } | 1951 | } else if (size.flags & PMinSize) { |
| 1886 | else if(size.flags & PMinSize) { | ||
| 1887 | c->basew = size.min_width; | 1952 | c->basew = size.min_width; |
| 1888 | c->baseh = size.min_height; | 1953 | c->baseh = size.min_height; |
| 1889 | } | 1954 | } else |
| 1890 | else | ||
| 1891 | c->basew = c->baseh = 0; | 1955 | c->basew = c->baseh = 0; |
| 1892 | if(size.flags & PResizeInc) { | 1956 | if (size.flags & PResizeInc) { |
| 1893 | c->incw = size.width_inc; | 1957 | c->incw = size.width_inc; |
| 1894 | c->inch = size.height_inc; | 1958 | c->inch = size.height_inc; |
| 1895 | } | 1959 | } else |
| 1896 | else | ||
| 1897 | c->incw = c->inch = 0; | 1960 | c->incw = c->inch = 0; |
| 1898 | if(size.flags & PMaxSize) { | 1961 | if (size.flags & PMaxSize) { |
| 1899 | c->maxw = size.max_width; | 1962 | c->maxw = size.max_width; |
| 1900 | c->maxh = size.max_height; | 1963 | c->maxh = size.max_height; |
| 1901 | } | 1964 | } else |
| 1902 | else | ||
| 1903 | c->maxw = c->maxh = 0; | 1965 | c->maxw = c->maxh = 0; |
| 1904 | if(size.flags & PMinSize) { | 1966 | if (size.flags & PMinSize) { |
| 1905 | c->minw = size.min_width; | 1967 | c->minw = size.min_width; |
| 1906 | c->minh = size.min_height; | 1968 | c->minh = size.min_height; |
| 1907 | } | 1969 | } else if (size.flags & PBaseSize) { |
| 1908 | else if(size.flags & PBaseSize) { | ||
| 1909 | c->minw = size.base_width; | 1970 | c->minw = size.base_width; |
| 1910 | c->minh = size.base_height; | 1971 | c->minh = size.base_height; |
| 1911 | } | 1972 | } else |
| 1912 | else | ||
| 1913 | c->minw = c->minh = 0; | 1973 | c->minw = c->minh = 0; |
| 1914 | if(size.flags & PAspect) { | 1974 | if (size.flags & PAspect) { |
| 1915 | c->mina = (float)size.min_aspect.y / size.min_aspect.x; | 1975 | c->mina = (float)size.min_aspect.y / size.min_aspect.x; |
| 1916 | c->maxa = (float)size.max_aspect.x / size.max_aspect.y; | 1976 | c->maxa = (float)size.max_aspect.x / size.max_aspect.y; |
| 1917 | } | 1977 | } else |
| 1918 | else | ||
| 1919 | c->maxa = c->mina = 0.0; | 1978 | c->maxa = c->mina = 0.0; |
| 1920 | c->isfixed = (c->maxw && c->minw && c->maxh && c->minh | 1979 | c->isfixed = (c->maxw && c->minw && c->maxh && c->minh |
| 1921 | && c->maxw == c->minw && c->maxh == c->minh); | 1980 | && c->maxw == c->minw && c->maxh == c->minh); |
| 1922 | } | 1981 | } |
| 1923 | 1982 | ||
| 1924 | void | 1983 | void |
| 1925 | updatetitle(Client *c) { | 1984 | updatetitle(Client *c) |
| 1926 | if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) | 1985 | { |
| 1986 | if (!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) | ||
| 1927 | gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name); | 1987 | gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name); |
| 1928 | if(c->name[0] == '\0') /* hack to mark broken clients */ | 1988 | if (c->name[0] == '\0') /* hack to mark broken clients */ |
| 1929 | strcpy(c->name, broken); | 1989 | strcpy(c->name, broken); |
| 1930 | } | 1990 | } |
| 1931 | 1991 | ||
| 1932 | void | 1992 | void |
| 1933 | updatestatus(void) { | 1993 | updatestatus(void) |
| 1934 | if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) | 1994 | { |
| 1995 | if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) | ||
| 1935 | strcpy(stext, "dwm-"VERSION); | 1996 | strcpy(stext, "dwm-"VERSION); |
| 1936 | drawbar(selmon); | 1997 | drawbar(selmon); |
| 1937 | } | 1998 | } |
| 1938 | 1999 | ||
| 1939 | void | 2000 | void |
| 1940 | updatewindowtype(Client *c) { | 2001 | updatewindowtype(Client *c) |
| 2002 | { | ||
| 1941 | Atom state = getatomprop(c, netatom[NetWMState]); | 2003 | Atom state = getatomprop(c, netatom[NetWMState]); |
| 1942 | Atom wtype = getatomprop(c, netatom[NetWMWindowType]); | 2004 | Atom wtype = getatomprop(c, netatom[NetWMWindowType]); |
| 1943 | 2005 | ||
| 1944 | if(state == netatom[NetWMFullscreen]) | 2006 | if (state == netatom[NetWMFullscreen]) |
| 1945 | setfullscreen(c, 1); | 2007 | setfullscreen(c, 1); |
| 1946 | if(wtype == netatom[NetWMWindowTypeDialog]) | 2008 | if (wtype == netatom[NetWMWindowTypeDialog]) |
| 1947 | c->isfloating = 1; | 2009 | c->isfloating = 1; |
| 1948 | } | 2010 | } |
| 1949 | 2011 | ||
| 1950 | void | 2012 | void |
| 1951 | updatewmhints(Client *c) { | 2013 | updatewmhints(Client *c) |
| 2014 | { | ||
| 1952 | XWMHints *wmh; | 2015 | XWMHints *wmh; |
| 1953 | 2016 | ||
| 1954 | if((wmh = XGetWMHints(dpy, c->win))) { | 2017 | if ((wmh = XGetWMHints(dpy, c->win))) { |
| 1955 | if(c == selmon->sel && wmh->flags & XUrgencyHint) { | 2018 | if (c == selmon->sel && wmh->flags & XUrgencyHint) { |
| 1956 | wmh->flags &= ~XUrgencyHint; | 2019 | wmh->flags &= ~XUrgencyHint; |
| 1957 | XSetWMHints(dpy, c->win, wmh); | 2020 | XSetWMHints(dpy, c->win, wmh); |
| 1958 | } | 2021 | } else |
| 1959 | else | ||
| 1960 | c->isurgent = (wmh->flags & XUrgencyHint) ? 1 : 0; | 2022 | c->isurgent = (wmh->flags & XUrgencyHint) ? 1 : 0; |
| 1961 | if(wmh->flags & InputHint) | 2023 | if (wmh->flags & InputHint) |
| 1962 | c->neverfocus = !wmh->input; | 2024 | c->neverfocus = !wmh->input; |
| 1963 | else | 2025 | else |
| 1964 | c->neverfocus = 0; | 2026 | c->neverfocus = 0; |
| @@ -1967,40 +2029,43 @@ updatewmhints(Client *c) { | |||
| 1967 | } | 2029 | } |
| 1968 | 2030 | ||
| 1969 | void | 2031 | void |
| 1970 | view(const Arg *arg) { | 2032 | view(const Arg *arg) |
| 1971 | if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) | 2033 | { |
| 2034 | if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) | ||
| 1972 | return; | 2035 | return; |
| 1973 | selmon->seltags ^= 1; /* toggle sel tagset */ | 2036 | selmon->seltags ^= 1; /* toggle sel tagset */ |
| 1974 | if(arg->ui & TAGMASK) | 2037 | if (arg->ui & TAGMASK) |
| 1975 | selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; | 2038 | selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; |
| 1976 | focus(NULL); | 2039 | focus(NULL); |
| 1977 | arrange(selmon); | 2040 | arrange(selmon); |
| 1978 | } | 2041 | } |
| 1979 | 2042 | ||
| 1980 | Client * | 2043 | Client * |
| 1981 | wintoclient(Window w) { | 2044 | wintoclient(Window w) |
| 2045 | { | ||
| 1982 | Client *c; | 2046 | Client *c; |
| 1983 | Monitor *m; | 2047 | Monitor *m; |
| 1984 | 2048 | ||
| 1985 | for(m = mons; m; m = m->next) | 2049 | for (m = mons; m; m = m->next) |
| 1986 | for(c = m->clients; c; c = c->next) | 2050 | for (c = m->clients; c; c = c->next) |
| 1987 | if(c->win == w) | 2051 | if (c->win == w) |
| 1988 | return c; | 2052 | return c; |
| 1989 | return NULL; | 2053 | return NULL; |
| 1990 | } | 2054 | } |
| 1991 | 2055 | ||
| 1992 | Monitor * | 2056 | Monitor * |
| 1993 | wintomon(Window w) { | 2057 | wintomon(Window w) |
| 2058 | { | ||
| 1994 | int x, y; | 2059 | int x, y; |
| 1995 | Client *c; | 2060 | Client *c; |
| 1996 | Monitor *m; | 2061 | Monitor *m; |
| 1997 | 2062 | ||
| 1998 | if(w == root && getrootptr(&x, &y)) | 2063 | if (w == root && getrootptr(&x, &y)) |
| 1999 | return recttomon(x, y, 1, 1); | 2064 | return recttomon(x, y, 1, 1); |
| 2000 | for(m = mons; m; m = m->next) | 2065 | for (m = mons; m; m = m->next) |
| 2001 | if(w == m->barwin) | 2066 | if (w == m->barwin) |
| 2002 | return m; | 2067 | return m; |
| 2003 | if((c = wintoclient(w))) | 2068 | if ((c = wintoclient(w))) |
| 2004 | return c->mon; | 2069 | return c->mon; |
| 2005 | return selmon; | 2070 | return selmon; |
| 2006 | } | 2071 | } |
| @@ -2009,8 +2074,9 @@ wintomon(Window w) { | |||
| 2009 | * ignored (especially on UnmapNotify's). Other types of errors call Xlibs | 2074 | * ignored (especially on UnmapNotify's). Other types of errors call Xlibs |
| 2010 | * default error handler, which may call exit. */ | 2075 | * default error handler, which may call exit. */ |
| 2011 | int | 2076 | int |
| 2012 | xerror(Display *dpy, XErrorEvent *ee) { | 2077 | xerror(Display *dpy, XErrorEvent *ee) |
| 2013 | if(ee->error_code == BadWindow | 2078 | { |
| 2079 | if (ee->error_code == BadWindow | ||
| 2014 | || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) | 2080 | || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) |
| 2015 | || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) | 2081 | || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) |
| 2016 | || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) | 2082 | || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) |
| @@ -2026,40 +2092,44 @@ xerror(Display *dpy, XErrorEvent *ee) { | |||
| 2026 | } | 2092 | } |
| 2027 | 2093 | ||
| 2028 | int | 2094 | int |
| 2029 | xerrordummy(Display *dpy, XErrorEvent *ee) { | 2095 | xerrordummy(Display *dpy, XErrorEvent *ee) |
| 2096 | { | ||
| 2030 | return 0; | 2097 | return 0; |
| 2031 | } | 2098 | } |
| 2032 | 2099 | ||
| 2033 | /* Startup Error handler to check if another window manager | 2100 | /* Startup Error handler to check if another window manager |
| 2034 | * is already running. */ | 2101 | * is already running. */ |
| 2035 | int | 2102 | int |
| 2036 | xerrorstart(Display *dpy, XErrorEvent *ee) { | 2103 | xerrorstart(Display *dpy, XErrorEvent *ee) |
| 2104 | { | ||
| 2037 | die("dwm: another window manager is already running\n"); | 2105 | die("dwm: another window manager is already running\n"); |
| 2038 | return -1; | 2106 | return -1; |
| 2039 | } | 2107 | } |
| 2040 | 2108 | ||
| 2041 | void | 2109 | void |
| 2042 | zoom(const Arg *arg) { | 2110 | zoom(const Arg *arg) |
| 2111 | { | ||
| 2043 | Client *c = selmon->sel; | 2112 | Client *c = selmon->sel; |
| 2044 | 2113 | ||
| 2045 | if(!selmon->lt[selmon->sellt]->arrange | 2114 | if (!selmon->lt[selmon->sellt]->arrange |
| 2046 | || (selmon->sel && selmon->sel->isfloating)) | 2115 | || (selmon->sel && selmon->sel->isfloating)) |
| 2047 | return; | 2116 | return; |
| 2048 | if(c == nexttiled(selmon->clients)) | 2117 | if (c == nexttiled(selmon->clients)) |
| 2049 | if(!c || !(c = nexttiled(c->next))) | 2118 | if (!c || !(c = nexttiled(c->next))) |
| 2050 | return; | 2119 | return; |
| 2051 | pop(c); | 2120 | pop(c); |
| 2052 | } | 2121 | } |
| 2053 | 2122 | ||
| 2054 | int | 2123 | int |
| 2055 | main(int argc, char *argv[]) { | 2124 | main(int argc, char *argv[]) |
| 2056 | if(argc == 2 && !strcmp("-v", argv[1])) | 2125 | { |
| 2057 | die("dwm-"VERSION", © 2006-2015 dwm engineers, see LICENSE for details\n"); | 2126 | if (argc == 2 && !strcmp("-v", argv[1])) |
| 2058 | else if(argc != 1) | 2127 | die("dwm-"VERSION "\n"); |
| 2128 | else if (argc != 1) | ||
| 2059 | die("usage: dwm [-v]\n"); | 2129 | die("usage: dwm [-v]\n"); |
| 2060 | if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) | 2130 | if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) |
| 2061 | fputs("warning: no locale support\n", stderr); | 2131 | fputs("warning: no locale support\n", stderr); |
| 2062 | if(!(dpy = XOpenDisplay(NULL))) | 2132 | if (!(dpy = XOpenDisplay(NULL))) |
| 2063 | die("dwm: cannot open display\n"); | 2133 | die("dwm: cannot open display\n"); |
| 2064 | checkotherwm(); | 2134 | checkotherwm(); |
| 2065 | setup(); | 2135 | setup(); |
