view.c
author Anselm R. Garbe <arg@suckless.org>
Mon, 19 Feb 2007 13:42:39 +0100
changeset 771 05946fa53085
parent 769 dc60583894e0
child 772 a1dd3d977e25
permissions -rw-r--r--
added some new convenience functions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
644
1ed8c40dde36 corrections
arg@mig29
parents: 643
diff changeset
     1
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
     2
 * See LICENSE file for license details.
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
     3
 */
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
     4
#include "dwm.h"
430
1e8aba00964e no, reodering floating clients definately breaks the manage() policy which attaches all clients zoomed (otherwise higher-weight clients couldn't be attached zoomed, which sucks)
Anselm R. Garbe <arg@10kloc.org>
parents: 429
diff changeset
     5
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
     6
/* extern */
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
     7
533
a5567a0d3011 do* has no Arg arument anymore (never called directly)
Anselm R. Garbe <arg@10kloc.org>
parents: 532
diff changeset
     8
void (*arrange)(void) = DEFMODE;
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
     9
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    10
void
533
a5567a0d3011 do* has no Arg arument anymore (never called directly)
Anselm R. Garbe <arg@10kloc.org>
parents: 532
diff changeset
    11
dofloat(void) {
402
c7d5ff57998d removed unused vars
Anselm R. Garbe <arg@10kloc.org>
parents: 401
diff changeset
    12
	Client *c;
400
052657ff2e7b applied Sanders max_and_focus.patch
Anselm R. Garbe <arg@10kloc.org>
parents: 397
diff changeset
    13
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    14
	for(c = clients; c; c = c->next) {
760
8ed842c35e8d added ban() which takes care than a banned window is not banned again... (this reduces the overall ConfigureNotify's to clients)
Anselm R. Garbe <arg@suckless.org>
parents: 757
diff changeset
    15
		if(isvisible(c)) {
762
140bcd4782d8 removed ugly ban(), extended resize() that it only resets the size if necessary, added border_width commit to manage()
Anselm R. Garbe <arg@suckless.org>
parents: 761
diff changeset
    16
			if(c->isbanned)
140bcd4782d8 removed ugly ban(), extended resize() that it only resets the size if necessary, added border_width commit to manage()
Anselm R. Garbe <arg@suckless.org>
parents: 761
diff changeset
    17
				XMoveWindow(dpy, c->win, c->x, c->y);
760
8ed842c35e8d added ban() which takes care than a banned window is not banned again... (this reduces the overall ConfigureNotify's to clients)
Anselm R. Garbe <arg@suckless.org>
parents: 757
diff changeset
    18
			c->isbanned = False;
763
718f8d6f6f56 well, resize should be called in dofloat anyways ;)
Anselm R. Garbe <arg@suckless.org>
parents: 762
diff changeset
    19
			resize(c, c->x, c->y, c->w, c->h, True);
760
8ed842c35e8d added ban() which takes care than a banned window is not banned again... (this reduces the overall ConfigureNotify's to clients)
Anselm R. Garbe <arg@suckless.org>
parents: 757
diff changeset
    20
		}
762
140bcd4782d8 removed ugly ban(), extended resize() that it only resets the size if necessary, added border_width commit to manage()
Anselm R. Garbe <arg@suckless.org>
parents: 761
diff changeset
    21
		else {
140bcd4782d8 removed ugly ban(), extended resize() that it only resets the size if necessary, added border_width commit to manage()
Anselm R. Garbe <arg@suckless.org>
parents: 761
diff changeset
    22
			c->isbanned = True;
140bcd4782d8 removed ugly ban(), extended resize() that it only resets the size if necessary, added border_width commit to manage()
Anselm R. Garbe <arg@suckless.org>
parents: 761
diff changeset
    23
			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
140bcd4782d8 removed ugly ban(), extended resize() that it only resets the size if necessary, added border_width commit to manage()
Anselm R. Garbe <arg@suckless.org>
parents: 761
diff changeset
    24
		}
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    25
	}
446
a2e587651c79 using a global stack for focus recovery on arrange() - seems to work great
Anselm R. Garbe <arg@10kloc.org>
parents: 443
diff changeset
    26
	if(!sel || !isvisible(sel)) {
450
728c9089b079 applied sanders patch of not manipulating sel
Anselm R. Garbe <arg@10kloc.org>
parents: 446
diff changeset
    27
		for(c = stack; c && !isvisible(c); c = c->snext);
728c9089b079 applied sanders patch of not manipulating sel
Anselm R. Garbe <arg@10kloc.org>
parents: 446
diff changeset
    28
		focus(c);
446
a2e587651c79 using a global stack for focus recovery on arrange() - seems to work great
Anselm R. Garbe <arg@10kloc.org>
parents: 443
diff changeset
    29
	}
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    30
	restack();
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    31
}
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    32
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    33
void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 450
diff changeset
    34
focusnext(Arg *arg) {
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    35
	Client *c;
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    36
   
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    37
	if(!sel)
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    38
		return;
761
4e835c2a7a12 removed getnext/getprev, redundant
Anselm R. Garbe <arg@suckless.org>
parents: 760
diff changeset
    39
	for(c = sel->next; c && !isvisible(c); c = c->next);
4e835c2a7a12 removed getnext/getprev, redundant
Anselm R. Garbe <arg@suckless.org>
parents: 760
diff changeset
    40
	if(!c)
4e835c2a7a12 removed getnext/getprev, redundant
Anselm R. Garbe <arg@suckless.org>
parents: 760
diff changeset
    41
		for(c = clients; c && !isvisible(c); c = c->next);
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    42
	if(c) {
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    43
		focus(c);
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    44
		restack();
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    45
	}
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    46
}
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    47
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    48
void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 450
diff changeset
    49
focusprev(Arg *arg) {
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    50
	Client *c;
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    51
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    52
	if(!sel)
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    53
		return;
761
4e835c2a7a12 removed getnext/getprev, redundant
Anselm R. Garbe <arg@suckless.org>
parents: 760
diff changeset
    54
	for(c = sel->prev; c && !isvisible(c); c = c->prev);
4e835c2a7a12 removed getnext/getprev, redundant
Anselm R. Garbe <arg@suckless.org>
parents: 760
diff changeset
    55
	if(!c) {
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    56
		for(c = clients; c && c->next; c = c->next);
761
4e835c2a7a12 removed getnext/getprev, redundant
Anselm R. Garbe <arg@suckless.org>
parents: 760
diff changeset
    57
		for(; c && !isvisible(c); c = c->prev);
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    58
	}
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    59
	if(c) {
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    60
		focus(c);
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    61
		restack();
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    62
	}
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    63
}
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    64
420
c033e1ade281 s/growcol/resizetile/g
Anselm R. Garbe <arg@10kloc.org>
parents: 419
diff changeset
    65
Bool
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 450
diff changeset
    66
isvisible(Client *c) {
420
c033e1ade281 s/growcol/resizetile/g
Anselm R. Garbe <arg@10kloc.org>
parents: 419
diff changeset
    67
	unsigned int i;
c033e1ade281 s/growcol/resizetile/g
Anselm R. Garbe <arg@10kloc.org>
parents: 419
diff changeset
    68
c033e1ade281 s/growcol/resizetile/g
Anselm R. Garbe <arg@10kloc.org>
parents: 419
diff changeset
    69
	for(i = 0; i < ntags; i++)
c033e1ade281 s/growcol/resizetile/g
Anselm R. Garbe <arg@10kloc.org>
parents: 419
diff changeset
    70
		if(c->tags[i] && seltag[i])
c033e1ade281 s/growcol/resizetile/g
Anselm R. Garbe <arg@10kloc.org>
parents: 419
diff changeset
    71
			return True;
c033e1ade281 s/growcol/resizetile/g
Anselm R. Garbe <arg@10kloc.org>
parents: 419
diff changeset
    72
	return False;
c033e1ade281 s/growcol/resizetile/g
Anselm R. Garbe <arg@10kloc.org>
parents: 419
diff changeset
    73
}
c033e1ade281 s/growcol/resizetile/g
Anselm R. Garbe <arg@10kloc.org>
parents: 419
diff changeset
    74
769
dc60583894e0 introduced tile.c, some refactoring of functions
Anselm R. Garbe <arg@suckless.org>
parents: 765
diff changeset
    75
Client *
dc60583894e0 introduced tile.c, some refactoring of functions
Anselm R. Garbe <arg@suckless.org>
parents: 765
diff changeset
    76
nextmanaged(Client *c) {
dc60583894e0 introduced tile.c, some refactoring of functions
Anselm R. Garbe <arg@suckless.org>
parents: 765
diff changeset
    77
	for(; c && (c->isfloat || !isvisible(c)); c = c->next);
dc60583894e0 introduced tile.c, some refactoring of functions
Anselm R. Garbe <arg@suckless.org>
parents: 765
diff changeset
    78
	return c;
415
ad2b6ce6e95b I really need column growing, now pushing upstream
Anselm R. Garbe <arg@10kloc.org>
parents: 414
diff changeset
    79
}
ad2b6ce6e95b I really need column growing, now pushing upstream
Anselm R. Garbe <arg@10kloc.org>
parents: 414
diff changeset
    80
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    81
void
487
be4f90c03582 applied Jukkas patch
arg@mmvi
parents: 486
diff changeset
    82
restack(void) {
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    83
	Client *c;
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    84
	XEvent ev;
481
arg@mmvi
parents: 480
diff changeset
    85
691
5d7e363f889d changed restack, to fix undrawed tag indicators
Anselm R. Garbe <arg@suckless.org>
parents: 690
diff changeset
    86
	drawstatus();
5d7e363f889d changed restack, to fix undrawed tag indicators
Anselm R. Garbe <arg@suckless.org>
parents: 690
diff changeset
    87
	if(!sel)
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
    88
		return;
687
a76799907854 removed client title bar
Anselm R. Garbe <arg@suckless.org>
parents: 682
diff changeset
    89
	if(sel->isfloat || arrange == dofloat)
436
b3659c3c5dab sanders solution is convincing and elegant
Anselm R. Garbe <arg@10kloc.org>
parents: 433
diff changeset
    90
		XRaiseWindow(dpy, sel->win);
512
aca04c3022c1 fixed the z-layer issue described on mailinglist
Anselm R. Garbe <arg@10kloc.org>
parents: 511
diff changeset
    91
	if(arrange != dofloat) {
687
a76799907854 removed client title bar
Anselm R. Garbe <arg@suckless.org>
parents: 682
diff changeset
    92
		if(!sel->isfloat)
512
aca04c3022c1 fixed the z-layer issue described on mailinglist
Anselm R. Garbe <arg@10kloc.org>
parents: 511
diff changeset
    93
			XLowerWindow(dpy, sel->win);
769
dc60583894e0 introduced tile.c, some refactoring of functions
Anselm R. Garbe <arg@suckless.org>
parents: 765
diff changeset
    94
		for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) {
512
aca04c3022c1 fixed the z-layer issue described on mailinglist
Anselm R. Garbe <arg@10kloc.org>
parents: 511
diff changeset
    95
			if(c == sel)
aca04c3022c1 fixed the z-layer issue described on mailinglist
Anselm R. Garbe <arg@10kloc.org>
parents: 511
diff changeset
    96
				continue;
436
b3659c3c5dab sanders solution is convincing and elegant
Anselm R. Garbe <arg@10kloc.org>
parents: 433
diff changeset
    97
			XLowerWindow(dpy, c->win);
414
c6ffcc201229 don't access sel in restack without checking for NULL (multihead crashing bug)
Anselm R. Garbe <arg@10kloc.org>
parents: 402
diff changeset
    98
		}
512
aca04c3022c1 fixed the z-layer issue described on mailinglist
Anselm R. Garbe <arg@10kloc.org>
parents: 511
diff changeset
    99
	}
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   100
	XSync(dpy, False);
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   101
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   102
}
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   103
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   104
void
584
37281ebc1b5b added togglefloat to hg tip (i consider this useful for some cases), using MODKEY-Shift-space as shortcut
arg@mig29
parents: 573
diff changeset
   105
togglefloat(Arg *arg) {
751
c5f9c2d806e7 yet another consistency fix of dwm
Anselm R. Garbe <arg@suckless.org>
parents: 726
diff changeset
   106
	if(!sel || arrange == dofloat)
584
37281ebc1b5b added togglefloat to hg tip (i consider this useful for some cases), using MODKEY-Shift-space as shortcut
arg@mig29
parents: 573
diff changeset
   107
		return;
37281ebc1b5b added togglefloat to hg tip (i consider this useful for some cases), using MODKEY-Shift-space as shortcut
arg@mig29
parents: 573
diff changeset
   108
	sel->isfloat = !sel->isfloat;
37281ebc1b5b added togglefloat to hg tip (i consider this useful for some cases), using MODKEY-Shift-space as shortcut
arg@mig29
parents: 573
diff changeset
   109
	arrange();
37281ebc1b5b added togglefloat to hg tip (i consider this useful for some cases), using MODKEY-Shift-space as shortcut
arg@mig29
parents: 573
diff changeset
   110
}
37281ebc1b5b added togglefloat to hg tip (i consider this useful for some cases), using MODKEY-Shift-space as shortcut
arg@mig29
parents: 573
diff changeset
   111
37281ebc1b5b added togglefloat to hg tip (i consider this useful for some cases), using MODKEY-Shift-space as shortcut
arg@mig29
parents: 573
diff changeset
   112
void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 450
diff changeset
   113
togglemode(Arg *arg) {
333
827f8f6c9e97 separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents: 327
diff changeset
   114
	arrange = (arrange == dofloat) ? dotile : dofloat;
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   115
	if(sel)
533
a5567a0d3011 do* has no Arg arument anymore (never called directly)
Anselm R. Garbe <arg@10kloc.org>
parents: 532
diff changeset
   116
		arrange();
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   117
	else
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   118
		drawstatus();
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   119
}
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   120
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   121
void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 450
diff changeset
   122
toggleview(Arg *arg) {
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   123
	unsigned int i;
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   124
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   125
	seltag[arg->i] = !seltag[arg->i];
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   126
	for(i = 0; i < ntags && !seltag[i]; i++);
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   127
	if(i == ntags)
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   128
		seltag[arg->i] = True; /* cannot toggle last view */
533
a5567a0d3011 do* has no Arg arument anymore (never called directly)
Anselm R. Garbe <arg@10kloc.org>
parents: 532
diff changeset
   129
	arrange();
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   130
}
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   131
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   132
void
461
9d23330a5268 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents: 450
diff changeset
   133
view(Arg *arg) {
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   134
	unsigned int i;
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   135
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   136
	for(i = 0; i < ntags; i++)
594
f7dcd3ac8d6f removed viewall(), replaced with view(-1); added tag(-1) to tag a client with all tags (new key combo MODKEY-Shift-0)
arg@mig29
parents: 591
diff changeset
   137
		seltag[i] = (arg->i == -1) ? True : False;
611
c7f84f23ec5a hotfix of a serious crashing bug
arg@mig29
parents: 594
diff changeset
   138
	if(arg->i >= 0 && arg->i < ntags)
c7f84f23ec5a hotfix of a serious crashing bug
arg@mig29
parents: 594
diff changeset
   139
		seltag[arg->i] = True;
533
a5567a0d3011 do* has no Arg arument anymore (never called directly)
Anselm R. Garbe <arg@10kloc.org>
parents: 532
diff changeset
   140
	arrange();
327
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   141
}
96d09fd98e89 separated several functions into view.c
Anselm R. Garbe <arg@10kloc.org>
parents:
diff changeset
   142