layout.c
author Anselm R. Garbe <garbeam@gmail.com>
Sat, 18 Aug 2007 14:20:56 +0200
changeset 964 777a9d9ce70b
parent 963 7416c26a14db
child 965 b3f4b0b3a5d7
permissions -rw-r--r--
hmm I doubt the usefulness of storing this information...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
910
c13cb8c6b7a5 referred to LICENSE file
Anselm R. Garbe <arg@suckless.org>
parents: 909
diff changeset
     1
/* See LICENSE file for copyright and license details. */
76
4bd49f404f10 proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents: 75
diff changeset
     2
#include "dwm.h"
825
bef1854ce739 fixed some issues due to the Arg->const char * transition
Anselm R. Garbe <arg@suckless.org>
parents: 823
diff changeset
     3
#include <stdlib.h>
964
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
     4
#include <string.h>
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
     5
#include <X11/Xatom.h>
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
     6
#include <X11/Xutil.h>
75
f08271b7cb20 rearranged several stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
     7
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
     8
/* static */
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
     9
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    10
typedef struct {
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    11
	const char *symbol;
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    12
	void (*arrange)(void);
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    13
} Layout;
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    14
782
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
    15
unsigned int blw = 0;
964
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
    16
static char prop[128];
963
7416c26a14db cleaned up settags-handling
Anselm R. Garbe <garbeam@gmail.com>
parents: 961
diff changeset
    17
static unsigned int ltidx = 0; /* default */
773
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
    18
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    19
static void
949
99ee5c370f94 tags should be persistent now during X server run
Anselm R. Garbe <garbeam@gmail.com>
parents: 946
diff changeset
    20
floating(void) { /* default floating layout */
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    21
	Client *c;
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    22
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    23
	for(c = clients; c; c = c->next)
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    24
		if(isvisible(c))
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    25
			resize(c, c->x, c->y, c->w, c->h, True);
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    26
}
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    27
782
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
    28
static unsigned int nlayouts = 0;
773
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
    29
784
74722317b171 renamed floating into swimming (this does not clash with C naming conventions and fits better the fish symbol) - also in man page
Anselm R. Garbe <arg@suckless.org>
parents: 782
diff changeset
    30
LAYOUTS
74722317b171 renamed floating into swimming (this does not clash with C naming conventions and fits better the fish symbol) - also in man page
Anselm R. Garbe <arg@suckless.org>
parents: 782
diff changeset
    31
74722317b171 renamed floating into swimming (this does not clash with C naming conventions and fits better the fish symbol) - also in man page
Anselm R. Garbe <arg@suckless.org>
parents: 782
diff changeset
    32
/* extern */
74722317b171 renamed floating into swimming (this does not clash with C naming conventions and fits better the fish symbol) - also in man page
Anselm R. Garbe <arg@suckless.org>
parents: 782
diff changeset
    33
74722317b171 renamed floating into swimming (this does not clash with C naming conventions and fits better the fish symbol) - also in man page
Anselm R. Garbe <arg@suckless.org>
parents: 782
diff changeset
    34
void
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    35
arrange(void) {
944
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    36
	Client *c;
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    37
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    38
	for(c = clients; c; c = c->next)
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    39
		if(isvisible(c))
944
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    40
			unban(c);
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    41
		else
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    42
			ban(c);
963
7416c26a14db cleaned up settags-handling
Anselm R. Garbe <garbeam@gmail.com>
parents: 961
diff changeset
    43
	layouts[ltidx].arrange();
944
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    44
	focus(NULL);
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    45
	restack();
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    46
}
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    47
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
    48
void
956
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    49
focusnext(const char *arg) {
799
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
    50
	Client *c;
956
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    51
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    52
	if(!sel)
829
f1ec35606dbc merged focus{prev.next} into focusclient(1/-1)
Anselm R. Garbe <arg@suckless.org>
parents: 826
diff changeset
    53
		return;
956
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    54
	for(c = sel->next; c && !isvisible(c); c = c->next);
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    55
	if(!c)
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    56
		for(c = clients; c && !isvisible(c); c = c->next);
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    57
	if(c) {
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    58
		focus(c);
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    59
		restack();
831
8b84189854dc simplified focusclient()
Anselm R. Garbe <arg@suckless.org>
parents: 830
diff changeset
    60
	}
956
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    61
}
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    62
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    63
void
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    64
focusprev(const char *arg) {
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    65
	Client *c;
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    66
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    67
	if(!sel)
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    68
		return;
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    69
	for(c = sel->prev; c && !isvisible(c); c = c->prev);
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    70
	if(!c) {
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    71
		for(c = clients; c && c->next; c = c->next);
484245788760 made tag/view/toggle{tag,view} work on pointer to tags-array, there was the need to define Key key[] not static to do this. split focusclient into focusnext/prev, fixed config.*.h's
Anselm R. Garbe <garbeam@gmail.com>
parents: 949
diff changeset
    72
		for(; c && !isvisible(c); c = c->prev);
799
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
    73
	}
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
    74
	if(c) {
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
    75
		focus(c);
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
    76
		restack();
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
    77
	}
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
    78
}
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
    79
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    80
const char *
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    81
getsymbol(void)
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    82
{
963
7416c26a14db cleaned up settags-handling
Anselm R. Garbe <garbeam@gmail.com>
parents: 961
diff changeset
    83
	return layouts[ltidx].symbol;
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    84
}
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    85
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    86
Bool
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    87
isfloating(void) {
963
7416c26a14db cleaned up settags-handling
Anselm R. Garbe <garbeam@gmail.com>
parents: 961
diff changeset
    88
	return layouts[ltidx].arrange == floating;
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    89
}
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    90
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    91
Bool
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    92
isarrange(void (*func)())
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    93
{
963
7416c26a14db cleaned up settags-handling
Anselm R. Garbe <garbeam@gmail.com>
parents: 961
diff changeset
    94
	return func == layouts[ltidx].arrange;
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    95
}
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
    96
799
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
    97
void
782
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
    98
initlayouts(void) {
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
    99
	unsigned int i, w;
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
   100
963
7416c26a14db cleaned up settags-handling
Anselm R. Garbe <garbeam@gmail.com>
parents: 961
diff changeset
   101
	/* TODO deserialize ltidx if present */
958
8b502be8b8e0 made plural arrays
Anselm R. Garbe <garbeam@gmail.com>
parents: 956
diff changeset
   102
	nlayouts = sizeof layouts / sizeof layouts[0];
782
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
   103
	for(blw = i = 0; i < nlayouts; i++) {
958
8b502be8b8e0 made plural arrays
Anselm R. Garbe <garbeam@gmail.com>
parents: 956
diff changeset
   104
		w = textw(layouts[i].symbol);
782
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
   105
		if(w > blw)
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
   106
			blw = w;
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
   107
	}
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
   108
}
92862ab407d5 introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents: 780
diff changeset
   109
964
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   110
void
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   111
loaddwmprops(void) {
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   112
	unsigned int i;
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   113
	XTextProperty name;
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   114
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   115
	/* check if window has set a property */
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   116
	name.nitems = 0;
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   117
	XGetTextProperty(dpy, root, &name, dwmprops);
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   118
	if(name.nitems && name.encoding == XA_STRING) {
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   119
		strncpy(prop, (char *)name.value, sizeof prop - 1);
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   120
		prop[sizeof prop - 1] = '\0';
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   121
		XFree(name.value);
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   122
		for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   123
			seltags[i] = prop[i] == '1';
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   124
		if(i < sizeof prop - 1 && prop[i] != '\0') {
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   125
			i = prop[i] - '0';
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   126
			if(i < nlayouts)
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   127
				ltidx = i;
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   128
		}
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   129
	}
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   130
}
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   131
799
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
   132
Client *
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
   133
nexttiled(Client *c) {
837
123231b9eb87 renamed untiled into floating, keeping tiled instead of tiling (afaik tiled sounds more correct) - English speakers convinced me
Anselm R. Garbe <arg@suckless.org>
parents: 831
diff changeset
   134
	for(; c && (c->isfloating || !isvisible(c)); c = c->next);
799
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
   135
	return c;
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
   136
}
30ec8b96a7f6 moved focus{next,prev} and nexttiled from client.c to layout.c (because those are not client-specific), moved toggleversatile() from layout.c to client.c (because those are client-specific)
Anselm R. Garbe <arg@suckless.org>
parents: 790
diff changeset
   137
773
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   138
void
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   139
restack(void) {
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   140
	Client *c;
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   141
	XEvent ev;
918
7c556b28f1f6 applied restack patch of anydot, with slight changes
Anselm R. Garbe <arg@suckless.org>
parents: 915
diff changeset
   142
	XWindowChanges wc;
773
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   143
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   144
	drawstatus();
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   145
	if(!sel)
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   146
		return;
961
edfafdb7084d replaced static Layout *lt with static unsigned int sellayout... (will be adapted later when _DWM_CONFIG is serialized as root window property)
Anselm R. Garbe <garbeam@gmail.com>
parents: 958
diff changeset
   147
	if(sel->isfloating || isfloating())
773
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   148
		XRaiseWindow(dpy, sel->win);
961
edfafdb7084d replaced static Layout *lt with static unsigned int sellayout... (will be adapted later when _DWM_CONFIG is serialized as root window property)
Anselm R. Garbe <garbeam@gmail.com>
parents: 958
diff changeset
   149
	if(!isfloating()) {
918
7c556b28f1f6 applied restack patch of anydot, with slight changes
Anselm R. Garbe <arg@suckless.org>
parents: 915
diff changeset
   150
		wc.stack_mode = Below;
7c556b28f1f6 applied restack patch of anydot, with slight changes
Anselm R. Garbe <arg@suckless.org>
parents: 915
diff changeset
   151
		wc.sibling = barwin;
7c556b28f1f6 applied restack patch of anydot, with slight changes
Anselm R. Garbe <arg@suckless.org>
parents: 915
diff changeset
   152
		if(!sel->isfloating) {
7c556b28f1f6 applied restack patch of anydot, with slight changes
Anselm R. Garbe <arg@suckless.org>
parents: 915
diff changeset
   153
			XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
7c556b28f1f6 applied restack patch of anydot, with slight changes
Anselm R. Garbe <arg@suckless.org>
parents: 915
diff changeset
   154
			wc.sibling = sel->win;
7c556b28f1f6 applied restack patch of anydot, with slight changes
Anselm R. Garbe <arg@suckless.org>
parents: 915
diff changeset
   155
		}
776
be103ae46dbc renamed view.c into screen.c
Anselm R. Garbe <arg@suckless.org>
parents: 775
diff changeset
   156
		for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
773
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   157
			if(c == sel)
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   158
				continue;
918
7c556b28f1f6 applied restack patch of anydot, with slight changes
Anselm R. Garbe <arg@suckless.org>
parents: 915
diff changeset
   159
			XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
7c556b28f1f6 applied restack patch of anydot, with slight changes
Anselm R. Garbe <arg@suckless.org>
parents: 915
diff changeset
   160
			wc.sibling = c->win;
773
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   161
		}
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   162
	}
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   163
	XSync(dpy, False);
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   164
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   165
}
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   166
81c5237a53b8 merged tag.c, view.c and tile.c to manage.c
Anselm R. Garbe <arg@suckless.org>
parents: 769
diff changeset
   167
void
964
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   168
savedwmprops(void) {
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   169
	unsigned int i;
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   170
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   171
	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   172
		prop[i] = seltags[i] ? '1' : '0';
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   173
	if(i < sizeof prop - 1)
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   174
		prop[i++] = (char)ltidx;
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   175
	prop[i] = '\0';
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   176
	XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   177
			PropModeReplace, (unsigned char *)prop, i);
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   178
}
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   179
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   180
void
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 819
diff changeset
   181
setlayout(const char *arg) {
826
d900a3f821a3 small bugfix
Anselm R. Garbe <arg@suckless.org>
parents: 825
diff changeset
   182
	int i;
788
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   183
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 819
diff changeset
   184
	if(!arg) {
963
7416c26a14db cleaned up settags-handling
Anselm R. Garbe <garbeam@gmail.com>
parents: 961
diff changeset
   185
		if(++ltidx == nlayouts)
7416c26a14db cleaned up settags-handling
Anselm R. Garbe <garbeam@gmail.com>
parents: 961
diff changeset
   186
			ltidx = 0;;
788
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   187
	}
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   188
	else {
823
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 819
diff changeset
   189
		i = atoi(arg);
fb5cbf0bd923 replaced Arg union with const char *arg, seems cleaner to me, even if we need atoi() in some places
Anselm R. Garbe <arg@suckless.org>
parents: 819
diff changeset
   190
		if(i < 0 || i >= nlayouts)
788
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   191
			return;
963
7416c26a14db cleaned up settags-handling
Anselm R. Garbe <garbeam@gmail.com>
parents: 961
diff changeset
   192
		ltidx = i;
788
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   193
	}
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   194
	if(sel)
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
   195
		arrange();
788
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   196
	else
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   197
		drawstatus();
964
777a9d9ce70b hmm I doubt the usefulness of storing this information...
Anselm R. Garbe <garbeam@gmail.com>
parents: 963
diff changeset
   198
	savedwmprops();
788
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   199
}
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   200
a61fcdf7b4c1 replaced togglelayout with setlayout
Anselm R. Garbe <arg@suckless.org>
parents: 786
diff changeset
   201
void
878
d2ae55f83f9f made bar togglalble
Anselm R. Garbe <arg@suckless.org>
parents: 875
diff changeset
   202
togglebar(const char *arg) {
887
44755dcf1ad4 simplification
Anselm R. Garbe <arg@suckless.org>
parents: 883
diff changeset
   203
	if(bpos == BarOff)
44755dcf1ad4 simplification
Anselm R. Garbe <arg@suckless.org>
parents: 883
diff changeset
   204
		bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
883
2cbf1010be11 using BarTop as fallback if BARPOS is set to BarOff as default for toggling
Anselm R. Garbe <arg@suckless.org>
parents: 880
diff changeset
   205
	else
2cbf1010be11 using BarTop as fallback if BARPOS is set to BarOff as default for toggling
Anselm R. Garbe <arg@suckless.org>
parents: 880
diff changeset
   206
		bpos = BarOff;
878
d2ae55f83f9f made bar togglalble
Anselm R. Garbe <arg@suckless.org>
parents: 875
diff changeset
   207
	updatebarpos();
946
b938876de936 made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts
Anselm R. Garbe <garbeam@gmail.com>
parents: 944
diff changeset
   208
	arrange();
878
d2ae55f83f9f made bar togglalble
Anselm R. Garbe <arg@suckless.org>
parents: 875
diff changeset
   209
}
944
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   210
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   211
void
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   212
togglemax(const char *arg) {
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   213
	XEvent ev;
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   214
961
edfafdb7084d replaced static Layout *lt with static unsigned int sellayout... (will be adapted later when _DWM_CONFIG is serialized as root window property)
Anselm R. Garbe <garbeam@gmail.com>
parents: 958
diff changeset
   215
	if(!sel || (!isfloating() && !sel->isfloating) || sel->isfixed)
944
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   216
		return;
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   217
	if((sel->ismax = !sel->ismax)) {
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   218
		sel->rx = sel->x;
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   219
		sel->ry = sel->y;
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   220
		sel->rw = sel->w;
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   221
		sel->rh = sel->h;
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   222
		resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   223
	}
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   224
	else
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   225
		resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   226
	drawstatus();
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   227
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
bd5cf635c601 moved floating to layout.c, kept tile.c outside
Anselm R. Garbe <garbeam@gmail.com>
parents: 941
diff changeset
   228
}