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