dwm.c
author Anselm R. Garbe <garbeam@gmail.com>
Sat, 22 Sep 2007 21:55:19 +0200
changeset 1008 ac233c362502
parent 1007 1a33d975c9e6
child 1014 35461e0a4894
permissions -rw-r--r--
introduced ISTILE, which can be easily extended with other layout functions to allow reuse of setmwfact() and zoom()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
992
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
     1
/* See LICENSE file for copyright and license details.
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
     2
 *
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
     3
 * dynamic window manager is designed like any other X client as well. It is
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
     4
 * driven through handling X events. In contrast to other X clients, a window
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
     5
 * manager selects for SubstructureRedirectMask on the root window, to receive
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
     6
 * events about window (dis-)appearance.  Only one X connection at a time is
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
     7
 * allowed to select for this event mask.
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
     8
 *
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
     9
 * Calls to fetch an X event from the event queue are blocking.  Due reading
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    10
 * status text from standard input, a select()-driven main loop has been
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    11
 * implemented which selects for reads on the X connection and STDIN_FILENO to
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    12
 * handle all data smoothly. The event handlers of dwm are organized in an
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    13
 * array which is accessed whenever a new event has been fetched. This allows
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    14
 * event dispatching in O(1) time.
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    15
 *
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    16
 * Each child of the root window is called a client, except windows which have
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    17
 * set the override_redirect flag.  Clients are organized in a global
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    18
 * doubly-linked client list, the focus history is remembered through a global
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    19
 * stack list. Each client contains an array of Bools of the same size as the
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    20
 * global tags array to indicate the tags of a client.  For each client dwm
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    21
 * creates a small title window, which is resized whenever the (_NET_)WM_NAME
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    22
 * properties are updated or the client is moved/resized.
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    23
 *
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
    24
 * Keys and tagging rules are organized as arrays and defined in config.h.
992
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    25
 *
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    26
 * To understand everything else, start reading main().
d9ab31906133 backporting my intro-comment of old dwm.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 991
diff changeset
    27
 */
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    28
#include <errno.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    29
#include <locale.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    30
#include <regex.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    31
#include <stdarg.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    32
#include <stdio.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    33
#include <stdlib.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    34
#include <string.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    35
#include <unistd.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    36
#include <sys/select.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    37
#include <sys/wait.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    38
#include <X11/cursorfont.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    39
#include <X11/keysym.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    40
#include <X11/Xatom.h>
1000
55e4d698f53a there might be envs which need Xlib.h
Anselm R. Garbe <garbeam@gmail.com>
parents: 999
diff changeset
    41
#include <X11/Xlib.h>
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    42
#include <X11/Xproto.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    43
#include <X11/Xutil.h>
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    44
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    45
/* macros */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    46
#define BUTTONMASK		(ButtonPressMask | ButtonReleaseMask)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    47
#define CLEANMASK(mask)		(mask & ~(numlockmask | LockMask))
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    48
#define MOUSEMASK		(BUTTONMASK | PointerMotionMask)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    49
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    50
/* enums */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    51
enum { BarTop, BarBot, BarOff };			/* bar position */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    52
enum { CurNormal, CurResize, CurMove, CurLast };	/* cursor */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    53
enum { ColBorder, ColFG, ColBG, ColLast };		/* color */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    54
enum { NetSupported, NetWMName, NetLast };		/* EWMH atoms */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    55
enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    56
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    57
/* typedefs */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    58
typedef struct Client Client;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    59
struct Client {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    60
	char name[256];
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    61
	int x, y, w, h;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    62
	int rx, ry, rw, rh; /* revert geometry */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    63
	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    64
	int minax, maxax, minay, maxay;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    65
	long flags; 
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    66
	unsigned int border, oldborder;
1002
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
    67
	Bool isbanned, isfixed, ismax, isfloating, wasfloating;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    68
	Bool *tags;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    69
	Client *next;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    70
	Client *prev;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    71
	Client *snext;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    72
	Window win;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    73
};
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    74
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    75
typedef struct {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    76
	int x, y, w, h;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    77
	unsigned long norm[ColLast];
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    78
	unsigned long sel[ColLast];
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    79
	Drawable drawable;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    80
	GC gc;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    81
	struct {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    82
		int ascent;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    83
		int descent;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    84
		int height;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    85
		XFontSet set;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    86
		XFontStruct *xfont;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    87
	} font;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    88
} DC; /* draw context */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    89
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    90
typedef struct {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    91
	unsigned long mod;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    92
	KeySym keysym;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    93
	void (*func)(const char *arg);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    94
	const char *arg;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    95
} Key;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    96
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    97
typedef struct {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    98
	const char *symbol;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
    99
	void (*arrange)(void);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   100
} Layout;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   101
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   102
typedef struct {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   103
	const char *prop;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   104
	const char *tags;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   105
	Bool isfloating;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   106
} Rule;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   107
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   108
typedef struct {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   109
	regex_t *propregex;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   110
	regex_t *tagregex;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   111
} Regs;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   112
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   113
/* forward declarations */
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   114
void applyrules(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   115
void arrange(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   116
void attach(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   117
void attachstack(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   118
void ban(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   119
void buttonpress(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   120
void checkotherwm(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   121
void cleanup(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   122
void compileregs(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   123
void configure(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   124
void configurenotify(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   125
void configurerequest(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   126
void destroynotify(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   127
void detach(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   128
void detachstack(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   129
void drawbar(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   130
void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   131
void drawtext(const char *text, unsigned long col[ColLast]);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   132
void *emallocz(unsigned int size);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   133
void enternotify(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   134
void eprint(const char *errstr, ...);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   135
void expose(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   136
void floating(void); /* default floating layout */
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   137
void focus(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   138
void focusnext(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   139
void focusprev(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   140
Client *getclient(Window w);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   141
unsigned long getcolor(const char *colstr);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   142
long getstate(Window w);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   143
Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   144
void grabbuttons(Client *c, Bool focused);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   145
unsigned int idxoftag(const char *tag);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   146
void initfont(const char *fontstr);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   147
Bool isarrange(void (*func)());
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   148
Bool isoccupied(unsigned int t);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   149
Bool isprotodel(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   150
Bool isvisible(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   151
void keypress(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   152
void killclient(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   153
void leavenotify(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   154
void manage(Window w, XWindowAttributes *wa);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   155
void mappingnotify(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   156
void maprequest(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   157
void movemouse(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   158
Client *nexttiled(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   159
void propertynotify(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   160
void quit(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   161
void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   162
void resizemouse(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   163
void restack(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   164
void run(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   165
void scan(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   166
void setclientstate(Client *c, long state);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   167
void setlayout(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   168
void setmwfact(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   169
void setup(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   170
void spawn(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   171
void tag(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   172
unsigned int textnw(const char *text, unsigned int len);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   173
unsigned int textw(const char *text);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   174
void tile(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   175
void togglebar(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   176
void togglefloating(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   177
void togglemax(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   178
void toggletag(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   179
void toggleview(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   180
void unban(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   181
void unmanage(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   182
void unmapnotify(XEvent *e);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   183
void updatebarpos(void);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   184
void updatesizehints(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   185
void updatetitle(Client *c);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   186
void view(const char *arg);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   187
int xerror(Display *dpy, XErrorEvent *ee);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   188
int xerrordummy(Display *dsply, XErrorEvent *ee);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   189
int xerrorstart(Display *dsply, XErrorEvent *ee);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   190
void zoom(const char *arg);
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   191
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   192
/* variables */
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   193
char stext[256];
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   194
double mwfact;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   195
int screen, sx, sy, sw, sh, wax, way, waw, wah;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   196
int (*xerrorxlib)(Display *, XErrorEvent *);
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   197
unsigned int bh, bpos, ntags;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   198
unsigned int blw = 0;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   199
unsigned int ltidx = 0; /* default */
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   200
unsigned int nlayouts = 0;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   201
unsigned int nrules = 0;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   202
unsigned int numlockmask = 0;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   203
void (*handler[LASTEvent]) (XEvent *) = {
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   204
	[ButtonPress] = buttonpress,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   205
	[ConfigureRequest] = configurerequest,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   206
	[ConfigureNotify] = configurenotify,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   207
	[DestroyNotify] = destroynotify,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   208
	[EnterNotify] = enternotify,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   209
	[LeaveNotify] = leavenotify,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   210
	[Expose] = expose,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   211
	[KeyPress] = keypress,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   212
	[MappingNotify] = mappingnotify,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   213
	[MapRequest] = maprequest,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   214
	[PropertyNotify] = propertynotify,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   215
	[UnmapNotify] = unmapnotify
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   216
};
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   217
Atom wmatom[WMLast], netatom[NetLast];
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   218
Bool otherwm, readin;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   219
Bool running = True;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   220
Bool *seltags;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   221
Bool selscreen = True;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   222
Client *clients = NULL;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   223
Client *sel = NULL;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   224
Client *stack = NULL;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   225
Cursor cursor[CurLast];
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   226
Display *dpy;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   227
DC dc = {0};
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   228
Window barwin, root;
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   229
Regs *regs = NULL;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   230
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   231
/* configuration, allows nested code to access above variables */
994
201550f99b8e macros which have been defined in config.h can only be used at function level, however you can nest code into config.h now for implementing a different layout (just for example), eg. #include "supertile.c"
Anselm R. Garbe <garbeam@gmail.com>
parents: 993
diff changeset
   232
#include "config.h"
201550f99b8e macros which have been defined in config.h can only be used at function level, however you can nest code into config.h now for implementing a different layout (just for example), eg. #include "supertile.c"
Anselm R. Garbe <garbeam@gmail.com>
parents: 993
diff changeset
   233
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   234
/* functions*/
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   235
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   236
applyrules(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   237
	static char buf[512];
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   238
	unsigned int i, j;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   239
	regmatch_t tmp;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   240
	Bool matched = False;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   241
	XClassHint ch = { 0 };
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   242
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   243
	/* rule matching */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   244
	XGetClassHint(dpy, c->win, &ch);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   245
	snprintf(buf, sizeof buf, "%s:%s:%s",
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   246
			ch.res_class ? ch.res_class : "",
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   247
			ch.res_name ? ch.res_name : "", c->name);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   248
	for(i = 0; i < nrules; i++)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   249
		if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   250
			c->isfloating = rules[i].isfloating;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   251
			for(j = 0; regs[i].tagregex && j < ntags; j++) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   252
				if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   253
					matched = True;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   254
					c->tags[j] = True;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   255
				}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   256
			}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   257
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   258
	if(ch.res_class)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   259
		XFree(ch.res_class);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   260
	if(ch.res_name)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   261
		XFree(ch.res_name);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   262
	if(!matched)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   263
		for(i = 0; i < ntags; i++)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   264
			c->tags[i] = seltags[i];
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   265
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   266
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   267
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   268
arrange(void) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   269
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   270
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   271
	for(c = clients; c; c = c->next)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   272
		if(isvisible(c))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   273
			unban(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   274
		else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   275
			ban(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   276
	layouts[ltidx].arrange();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   277
	focus(NULL);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   278
	restack();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   279
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   280
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   281
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   282
attach(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   283
	if(clients)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   284
		clients->prev = c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   285
	c->next = clients;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   286
	clients = c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   287
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   288
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   289
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   290
attachstack(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   291
	c->snext = stack;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   292
	stack = c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   293
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   294
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   295
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   296
ban(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   297
	if(c->isbanned)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   298
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   299
	XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   300
	c->isbanned = True;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   301
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   302
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   303
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   304
buttonpress(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   305
	unsigned int i, x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   306
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   307
	XButtonPressedEvent *ev = &e->xbutton;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   308
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   309
	if(barwin == ev->window) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   310
		x = 0;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   311
		for(i = 0; i < ntags; i++) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   312
			x += textw(tags[i]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   313
			if(ev->x < x) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   314
				if(ev->button == Button1) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   315
					if(ev->state & MODKEY)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   316
						tag(tags[i]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   317
					else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   318
						view(tags[i]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   319
				}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   320
				else if(ev->button == Button3) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   321
					if(ev->state & MODKEY)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   322
						toggletag(tags[i]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   323
					else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   324
						toggleview(tags[i]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   325
				}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   326
				return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   327
			}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   328
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   329
		if((ev->x < x + blw) && ev->button == Button1)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   330
			setlayout(NULL);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   331
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   332
	else if((c = getclient(ev->window))) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   333
		focus(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   334
		if(CLEANMASK(ev->state) != MODKEY)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   335
			return;
998
854a324f5c92 now tiled windows can be resized/moved, their floating state will be toggled implicitely
Anselm R. Garbe <garbeam@gmail.com>
parents: 997
diff changeset
   336
		if(ev->button == Button1) {
1003
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
   337
			if(isarrange(floating) || c->isfloating)
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
   338
				restack();
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
   339
			else
998
854a324f5c92 now tiled windows can be resized/moved, their floating state will be toggled implicitely
Anselm R. Garbe <garbeam@gmail.com>
parents: 997
diff changeset
   340
				togglefloating(NULL);
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   341
			movemouse(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   342
		}
999
d036b2f17567 Mod1-Button2 on a floating but not-fixed client will make it tiled again
Anselm R. Garbe <garbeam@gmail.com>
parents: 998
diff changeset
   343
		else if(ev->button == Button2) {
1008
ac233c362502 introduced ISTILE, which can be easily extended with other layout functions to allow reuse of setmwfact() and zoom()
Anselm R. Garbe <garbeam@gmail.com>
parents: 1007
diff changeset
   344
			if(ISTILE && !c->isfixed && c->isfloating)
999
d036b2f17567 Mod1-Button2 on a floating but not-fixed client will make it tiled again
Anselm R. Garbe <garbeam@gmail.com>
parents: 998
diff changeset
   345
				togglefloating(NULL);
d036b2f17567 Mod1-Button2 on a floating but not-fixed client will make it tiled again
Anselm R. Garbe <garbeam@gmail.com>
parents: 998
diff changeset
   346
			else
d036b2f17567 Mod1-Button2 on a floating but not-fixed client will make it tiled again
Anselm R. Garbe <garbeam@gmail.com>
parents: 998
diff changeset
   347
				zoom(NULL);
d036b2f17567 Mod1-Button2 on a floating but not-fixed client will make it tiled again
Anselm R. Garbe <garbeam@gmail.com>
parents: 998
diff changeset
   348
		}
998
854a324f5c92 now tiled windows can be resized/moved, their floating state will be toggled implicitely
Anselm R. Garbe <garbeam@gmail.com>
parents: 997
diff changeset
   349
		else if(ev->button == Button3 && !c->isfixed) {
1003
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
   350
			if(isarrange(floating) || c->isfloating)
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
   351
				restack();
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
   352
			else
998
854a324f5c92 now tiled windows can be resized/moved, their floating state will be toggled implicitely
Anselm R. Garbe <garbeam@gmail.com>
parents: 997
diff changeset
   353
				togglefloating(NULL);
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   354
			resizemouse(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   355
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   356
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   357
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   358
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   359
void
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   360
checkotherwm(void) {
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   361
	otherwm = False;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   362
	XSetErrorHandler(xerrorstart);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   363
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   364
	/* this causes an error if some other window manager is running */
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   365
	XSelectInput(dpy, root, SubstructureRedirectMask);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   366
	XSync(dpy, False);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   367
	if(otherwm)
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   368
		eprint("dwm: another window manager is already running\n");
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   369
	XSync(dpy, False);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   370
	XSetErrorHandler(NULL);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   371
	xerrorxlib = XSetErrorHandler(xerror);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   372
	XSync(dpy, False);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   373
}
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   374
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   375
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   376
cleanup(void) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   377
	close(STDIN_FILENO);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   378
	while(stack) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   379
		unban(stack);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   380
		unmanage(stack);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   381
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   382
	if(dc.font.set)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   383
		XFreeFontSet(dpy, dc.font.set);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   384
	else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   385
		XFreeFont(dpy, dc.font.xfont);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   386
	XUngrabKey(dpy, AnyKey, AnyModifier, root);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   387
	XFreePixmap(dpy, dc.drawable);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   388
	XFreeGC(dpy, dc.gc);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   389
	XDestroyWindow(dpy, barwin);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   390
	XFreeCursor(dpy, cursor[CurNormal]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   391
	XFreeCursor(dpy, cursor[CurResize]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   392
	XFreeCursor(dpy, cursor[CurMove]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   393
	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   394
	XSync(dpy, False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   395
	free(seltags);
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   396
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   397
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   398
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   399
compileregs(void) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   400
	unsigned int i;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   401
	regex_t *reg;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   402
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   403
	if(regs)
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   404
		return;
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   405
	nrules = sizeof rules / sizeof rules[0];
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   406
	regs = emallocz(nrules * sizeof(Regs));
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   407
	for(i = 0; i < nrules; i++) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   408
		if(rules[i].prop) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   409
			reg = emallocz(sizeof(regex_t));
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   410
			if(regcomp(reg, rules[i].prop, REG_EXTENDED))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   411
				free(reg);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   412
			else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   413
				regs[i].propregex = reg;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   414
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   415
		if(rules[i].tags) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   416
			reg = emallocz(sizeof(regex_t));
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   417
			if(regcomp(reg, rules[i].tags, REG_EXTENDED))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   418
				free(reg);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   419
			else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   420
				regs[i].tagregex = reg;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   421
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   422
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   423
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   424
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   425
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   426
configure(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   427
	XConfigureEvent ce;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   428
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   429
	ce.type = ConfigureNotify;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   430
	ce.display = dpy;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   431
	ce.event = c->win;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   432
	ce.window = c->win;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   433
	ce.x = c->x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   434
	ce.y = c->y;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   435
	ce.width = c->w;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   436
	ce.height = c->h;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   437
	ce.border_width = c->border;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   438
	ce.above = None;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   439
	ce.override_redirect = False;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   440
	XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   441
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   442
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   443
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   444
configurenotify(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   445
	XConfigureEvent *ev = &e->xconfigure;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   446
1003
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
   447
	if(ev->window == root && (ev->width != sw || ev->height != sh)) {
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   448
		sw = ev->width;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   449
		sh = ev->height;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   450
		XFreePixmap(dpy, dc.drawable);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   451
		dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   452
		XResizeWindow(dpy, barwin, sw, bh);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   453
		updatebarpos();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   454
		arrange();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   455
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   456
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   457
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   458
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   459
configurerequest(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   460
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   461
	XConfigureRequestEvent *ev = &e->xconfigurerequest;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   462
	XWindowChanges wc;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   463
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   464
	if((c = getclient(ev->window))) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   465
		c->ismax = False;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   466
		if(ev->value_mask & CWBorderWidth)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   467
			c->border = ev->border_width;
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   468
		if(c->isfixed || c->isfloating || isarrange(floating)) {
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   469
			if(ev->value_mask & CWX)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   470
				c->x = ev->x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   471
			if(ev->value_mask & CWY)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   472
				c->y = ev->y;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   473
			if(ev->value_mask & CWWidth)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   474
				c->w = ev->width;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   475
			if(ev->value_mask & CWHeight)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   476
				c->h = ev->height;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   477
			if((c->x + c->w) > sw && c->isfloating)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   478
				c->x = sw / 2 - c->w / 2; /* center in x direction */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   479
			if((c->y + c->h) > sh && c->isfloating)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   480
				c->y = sh / 2 - c->h / 2; /* center in y direction */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   481
			if((ev->value_mask & (CWX | CWY))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   482
			&& !(ev->value_mask & (CWWidth | CWHeight)))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   483
				configure(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   484
			if(isvisible(c))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   485
				XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   486
		}
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   487
		else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   488
			configure(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   489
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   490
	else {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   491
		wc.x = ev->x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   492
		wc.y = ev->y;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   493
		wc.width = ev->width;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   494
		wc.height = ev->height;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   495
		wc.border_width = ev->border_width;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   496
		wc.sibling = ev->above;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   497
		wc.stack_mode = ev->detail;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   498
		XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   499
	}
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   500
	XSync(dpy, False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   501
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   502
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   503
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   504
destroynotify(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   505
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   506
	XDestroyWindowEvent *ev = &e->xdestroywindow;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   507
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   508
	if((c = getclient(ev->window)))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   509
		unmanage(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   510
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   511
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   512
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   513
detach(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   514
	if(c->prev)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   515
		c->prev->next = c->next;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   516
	if(c->next)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   517
		c->next->prev = c->prev;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   518
	if(c == clients)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   519
		clients = c->next;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   520
	c->next = c->prev = NULL;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   521
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   522
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   523
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   524
detachstack(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   525
	Client **tc;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   526
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   527
	for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   528
	*tc = c->snext;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   529
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   530
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   531
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   532
drawbar(void) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   533
	int i, x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   534
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   535
	dc.x = dc.y = 0;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   536
	for(i = 0; i < ntags; i++) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   537
		dc.w = textw(tags[i]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   538
		if(seltags[i]) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   539
			drawtext(tags[i], dc.sel);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   540
			drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   541
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   542
		else {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   543
			drawtext(tags[i], dc.norm);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   544
			drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   545
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   546
		dc.x += dc.w;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   547
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   548
	dc.w = blw;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   549
	drawtext(layouts[ltidx].symbol, dc.norm);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   550
	x = dc.x + dc.w;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   551
	dc.w = textw(stext);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   552
	dc.x = sw - dc.w;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   553
	if(dc.x < x) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   554
		dc.x = x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   555
		dc.w = sw - x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   556
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   557
	drawtext(stext, dc.norm);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   558
	if((dc.w = dc.x - x) > bh) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   559
		dc.x = x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   560
		if(sel) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   561
			drawtext(sel->name, dc.sel);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   562
			drawsquare(sel->ismax, sel->isfloating, dc.sel);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   563
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   564
		else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   565
			drawtext(NULL, dc.norm);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   566
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   567
	XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   568
	XSync(dpy, False);
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   569
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   570
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   571
void
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   572
drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   573
	int x;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   574
	XGCValues gcv;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   575
	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   576
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   577
	gcv.foreground = col[ColFG];
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   578
	XChangeGC(dpy, dc.gc, GCForeground, &gcv);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   579
	x = (dc.font.ascent + dc.font.descent + 2) / 4;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   580
	r.x = dc.x + 1;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   581
	r.y = dc.y + 1;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   582
	if(filled) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   583
		r.width = r.height = x + 1;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   584
		XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   585
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   586
	else if(empty) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   587
		r.width = r.height = x;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   588
		XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   589
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   590
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   591
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   592
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   593
drawtext(const char *text, unsigned long col[ColLast]) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   594
	int x, y, w, h;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   595
	static char buf[256];
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   596
	unsigned int len, olen;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   597
	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   598
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   599
	XSetForeground(dpy, dc.gc, col[ColBG]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   600
	XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   601
	if(!text)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   602
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   603
	w = 0;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   604
	olen = len = strlen(text);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   605
	if(len >= sizeof buf)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   606
		len = sizeof buf - 1;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   607
	memcpy(buf, text, len);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   608
	buf[len] = 0;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   609
	h = dc.font.ascent + dc.font.descent;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   610
	y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   611
	x = dc.x + (h / 2);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   612
	/* shorten text if necessary */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   613
	while(len && (w = textnw(buf, len)) > dc.w - h)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   614
		buf[--len] = 0;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   615
	if(len < olen) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   616
		if(len > 1)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   617
			buf[len - 1] = '.';
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   618
		if(len > 2)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   619
			buf[len - 2] = '.';
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   620
		if(len > 3)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   621
			buf[len - 3] = '.';
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   622
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   623
	if(w > dc.w)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   624
		return; /* too long */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   625
	XSetForeground(dpy, dc.gc, col[ColFG]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   626
	if(dc.font.set)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   627
		XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   628
	else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   629
		XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   630
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   631
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   632
void *
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   633
emallocz(unsigned int size) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   634
	void *res = calloc(1, size);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   635
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   636
	if(!res)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   637
		eprint("fatal: could not malloc() %u bytes\n", size);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   638
	return res;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   639
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   640
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   641
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   642
enternotify(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   643
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   644
	XCrossingEvent *ev = &e->xcrossing;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   645
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   646
	if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   647
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   648
	if((c = getclient(ev->window)))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   649
		focus(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   650
	else if(ev->window == root) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   651
		selscreen = True;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   652
		focus(NULL);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   653
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   654
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   655
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   656
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   657
eprint(const char *errstr, ...) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   658
	va_list ap;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   659
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   660
	va_start(ap, errstr);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   661
	vfprintf(stderr, errstr, ap);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   662
	va_end(ap);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   663
	exit(EXIT_FAILURE);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   664
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   665
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   666
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   667
expose(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   668
	XExposeEvent *ev = &e->xexpose;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   669
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   670
	if(ev->count == 0) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   671
		if(barwin == ev->window)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   672
			drawbar();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   673
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   674
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   675
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   676
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   677
floating(void) { /* default floating layout */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   678
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   679
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   680
	for(c = clients; c; c = c->next)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   681
		if(isvisible(c))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   682
			resize(c, c->x, c->y, c->w, c->h, True);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   683
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   684
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   685
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   686
focus(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   687
	if((!c && selscreen) || (c && !isvisible(c)))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   688
		for(c = stack; c && !isvisible(c); c = c->snext);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   689
	if(sel && sel != c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   690
		grabbuttons(sel, False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   691
		XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   692
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   693
	if(c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   694
		detachstack(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   695
		attachstack(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   696
		grabbuttons(c, True);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   697
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   698
	sel = c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   699
	drawbar();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   700
	if(!selscreen)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   701
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   702
	if(c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   703
		XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   704
		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   705
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   706
	else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   707
		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   708
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   709
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   710
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   711
focusnext(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   712
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   713
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   714
	if(!sel)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   715
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   716
	for(c = sel->next; c && !isvisible(c); c = c->next);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   717
	if(!c)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   718
		for(c = clients; c && !isvisible(c); c = c->next);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   719
	if(c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   720
		focus(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   721
		restack();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   722
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   723
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   724
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   725
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   726
focusprev(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   727
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   728
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   729
	if(!sel)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   730
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   731
	for(c = sel->prev; c && !isvisible(c); c = c->prev);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   732
	if(!c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   733
		for(c = clients; c && c->next; c = c->next);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   734
		for(; c && !isvisible(c); c = c->prev);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   735
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   736
	if(c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   737
		focus(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   738
		restack();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   739
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   740
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   741
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   742
Client *
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   743
getclient(Window w) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   744
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   745
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   746
	for(c = clients; c && c->win != w; c = c->next);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   747
	return c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   748
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   749
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   750
unsigned long
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   751
getcolor(const char *colstr) {
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   752
	Colormap cmap = DefaultColormap(dpy, screen);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   753
	XColor color;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   754
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   755
	if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   756
		eprint("error, cannot allocate color '%s'\n", colstr);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   757
	return color.pixel;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   758
}
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
   759
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   760
long
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   761
getstate(Window w) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   762
	int format, status;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   763
	long result = -1;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   764
	unsigned char *p = NULL;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   765
	unsigned long n, extra;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   766
	Atom real;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   767
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   768
	status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   769
			&real, &format, &n, &extra, (unsigned char **)&p);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   770
	if(status != Success)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   771
		return -1;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   772
	if(n != 0)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   773
		result = *p;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   774
	XFree(p);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   775
	return result;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   776
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   777
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   778
Bool
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   779
gettextprop(Window w, Atom atom, char *text, unsigned int size) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   780
	char **list = NULL;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   781
	int n;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   782
	XTextProperty name;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   783
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   784
	if(!text || size == 0)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   785
		return False;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   786
	text[0] = '\0';
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   787
	XGetTextProperty(dpy, w, &name, atom);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   788
	if(!name.nitems)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   789
		return False;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   790
	if(name.encoding == XA_STRING)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   791
		strncpy(text, (char *)name.value, size - 1);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   792
	else {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   793
		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   794
		&& n > 0 && *list)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   795
		{
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   796
			strncpy(text, *list, size - 1);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   797
			XFreeStringList(list);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   798
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   799
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   800
	text[size - 1] = '\0';
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   801
	XFree(name.value);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   802
	return True;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   803
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   804
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   805
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   806
grabbuttons(Client *c, Bool focused) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   807
	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   808
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   809
	if(focused) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   810
		XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   811
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   812
		XGrabButton(dpy, Button1, MODKEY | LockMask, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   813
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   814
		XGrabButton(dpy, Button1, MODKEY | numlockmask, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   815
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   816
		XGrabButton(dpy, Button1, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   817
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   818
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   819
		XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   820
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   821
		XGrabButton(dpy, Button2, MODKEY | LockMask, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   822
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   823
		XGrabButton(dpy, Button2, MODKEY | numlockmask, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   824
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   825
		XGrabButton(dpy, Button2, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   826
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   827
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   828
		XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   829
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   830
		XGrabButton(dpy, Button3, MODKEY | LockMask, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   831
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   832
		XGrabButton(dpy, Button3, MODKEY | numlockmask, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   833
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   834
		XGrabButton(dpy, Button3, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   835
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   836
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   837
	else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   838
		XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   839
				GrabModeAsync, GrabModeSync, None, None);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   840
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   841
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   842
unsigned int
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   843
idxoftag(const char *tag) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   844
	unsigned int i;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   845
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   846
	for(i = 0; i < ntags; i++)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   847
		if(tags[i] == tag)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   848
			return i;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   849
	return 0;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   850
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   851
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   852
void
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   853
initfont(const char *fontstr) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   854
	char *def, **missing;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   855
	int i, n;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   856
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   857
	missing = NULL;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   858
	if(dc.font.set)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   859
		XFreeFontSet(dpy, dc.font.set);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   860
	dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   861
	if(missing) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   862
		while(n--)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   863
			fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   864
		XFreeStringList(missing);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   865
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   866
	if(dc.font.set) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   867
		XFontSetExtents *font_extents;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   868
		XFontStruct **xfonts;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   869
		char **font_names;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   870
		dc.font.ascent = dc.font.descent = 0;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   871
		font_extents = XExtentsOfFontSet(dc.font.set);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   872
		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   873
		for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   874
			if(dc.font.ascent < (*xfonts)->ascent)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   875
				dc.font.ascent = (*xfonts)->ascent;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   876
			if(dc.font.descent < (*xfonts)->descent)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   877
				dc.font.descent = (*xfonts)->descent;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   878
			xfonts++;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   879
		}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   880
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   881
	else {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   882
		if(dc.font.xfont)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   883
			XFreeFont(dpy, dc.font.xfont);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   884
		dc.font.xfont = NULL;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   885
		if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
1003
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
   886
		&& !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   887
			eprint("error, cannot load font: '%s'\n", fontstr);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   888
		dc.font.ascent = dc.font.xfont->ascent;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   889
		dc.font.descent = dc.font.xfont->descent;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   890
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   891
	dc.font.height = dc.font.ascent + dc.font.descent;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   892
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   893
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   894
Bool
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   895
isarrange(void (*func)())
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   896
{
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   897
	return func == layouts[ltidx].arrange;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   898
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   899
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   900
Bool
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   901
isoccupied(unsigned int t) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   902
	Client *c;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   903
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   904
	for(c = clients; c; c = c->next)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   905
		if(c->tags[t])
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   906
			return True;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   907
	return False;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   908
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   909
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   910
Bool
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   911
isprotodel(Client *c) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   912
	int i, n;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   913
	Atom *protocols;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   914
	Bool ret = False;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   915
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   916
	if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   917
		for(i = 0; !ret && i < n; i++)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   918
			if(protocols[i] == wmatom[WMDelete])
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   919
				ret = True;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   920
		XFree(protocols);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   921
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   922
	return ret;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   923
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   924
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   925
Bool
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   926
isvisible(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   927
	unsigned int i;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   928
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   929
	for(i = 0; i < ntags; i++)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   930
		if(c->tags[i] && seltags[i])
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   931
			return True;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   932
	return False;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   933
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   934
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   935
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   936
keypress(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   937
	KEYS
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   938
	unsigned int len = sizeof keys / sizeof keys[0];
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   939
	unsigned int i;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   940
	KeyCode code;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   941
	KeySym keysym;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   942
	XKeyEvent *ev;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   943
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   944
	if(!e) { /* grabkeys */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   945
		XUngrabKey(dpy, AnyKey, AnyModifier, root);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   946
		for(i = 0; i < len; i++) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   947
			code = XKeysymToKeycode(dpy, keys[i].keysym);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   948
			XGrabKey(dpy, code, keys[i].mod, root, True,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   949
					GrabModeAsync, GrabModeAsync);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   950
			XGrabKey(dpy, code, keys[i].mod | LockMask, root, True,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   951
					GrabModeAsync, GrabModeAsync);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   952
			XGrabKey(dpy, code, keys[i].mod | numlockmask, root, True,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   953
					GrabModeAsync, GrabModeAsync);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   954
			XGrabKey(dpy, code, keys[i].mod | numlockmask | LockMask, root, True,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   955
					GrabModeAsync, GrabModeAsync);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   956
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   957
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   958
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   959
	ev = &e->xkey;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   960
	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   961
	for(i = 0; i < len; i++)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   962
		if(keysym == keys[i].keysym
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   963
		&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   964
		{
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   965
			if(keys[i].func)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   966
				keys[i].func(keys[i].arg);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   967
		}
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   968
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   969
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   970
void
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   971
killclient(const char *arg) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   972
	XEvent ev;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   973
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   974
	if(!sel)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   975
		return;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   976
	if(isprotodel(sel)) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   977
		ev.type = ClientMessage;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   978
		ev.xclient.window = sel->win;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   979
		ev.xclient.message_type = wmatom[WMProtocols];
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   980
		ev.xclient.format = 32;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   981
		ev.xclient.data.l[0] = wmatom[WMDelete];
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   982
		ev.xclient.data.l[1] = CurrentTime;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   983
		XSendEvent(dpy, sel->win, False, NoEventMask, &ev);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   984
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   985
	else
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   986
		XKillClient(dpy, sel->win);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   987
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
   988
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   989
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   990
leavenotify(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   991
	XCrossingEvent *ev = &e->xcrossing;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   992
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   993
	if((ev->window == root) && !ev->same_screen) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   994
		selscreen = False;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   995
		focus(NULL);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   996
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   997
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
   998
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
   999
void
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1000
manage(Window w, XWindowAttributes *wa) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1001
	unsigned int i;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1002
	Client *c, *t = NULL;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1003
	Window trans;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1004
	Status rettrans;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1005
	XWindowChanges wc;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1006
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1007
	c = emallocz(sizeof(Client));
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1008
	c->tags = emallocz(ntags * sizeof(Bool));
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1009
	c->win = w;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1010
	c->x = wa->x;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1011
	c->y = wa->y;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1012
	c->w = wa->width;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1013
	c->h = wa->height;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1014
	c->oldborder = wa->border_width;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1015
	if(c->w == sw && c->h == sh) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1016
		c->x = sx;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1017
		c->y = sy;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1018
		c->border = wa->border_width;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1019
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1020
	else {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1021
		if(c->x + c->w + 2 * c->border > wax + waw)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1022
			c->x = wax + waw - c->w - 2 * c->border;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1023
		if(c->y + c->h + 2 * c->border > way + wah)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1024
			c->y = way + wah - c->h - 2 * c->border;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1025
		if(c->x < wax)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1026
			c->x = wax;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1027
		if(c->y < way)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1028
			c->y = way;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1029
		c->border = BORDERPX;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1030
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1031
	wc.border_width = c->border;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1032
	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1033
	XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1034
	configure(c); /* propagates border_width, if size doesn't change */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1035
	updatesizehints(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1036
	XSelectInput(dpy, w,
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1037
		StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1038
	grabbuttons(c, False);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1039
	updatetitle(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1040
	if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1041
		for(t = clients; t && t->win != trans; t = t->next);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1042
	if(t)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1043
		for(i = 0; i < ntags; i++)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1044
			c->tags[i] = t->tags[i];
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1045
	applyrules(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1046
	if(!c->isfloating)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1047
		c->isfloating = (rettrans == Success) || c->isfixed;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1048
	attach(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1049
	attachstack(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1050
	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1051
	ban(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1052
	XMapWindow(dpy, c->win);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1053
	setclientstate(c, NormalState);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1054
	arrange();
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1055
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1056
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1057
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1058
mappingnotify(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1059
	XMappingEvent *ev = &e->xmapping;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1060
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1061
	XRefreshKeyboardMapping(ev);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1062
	if(ev->request == MappingKeyboard)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1063
		keypress(NULL);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1064
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1065
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1066
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1067
maprequest(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1068
	static XWindowAttributes wa;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1069
	XMapRequestEvent *ev = &e->xmaprequest;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1070
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1071
	if(!XGetWindowAttributes(dpy, ev->window, &wa))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1072
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1073
	if(wa.override_redirect)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1074
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1075
	if(!getclient(ev->window))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1076
		manage(ev->window, &wa);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1077
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1078
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1079
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1080
movemouse(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1081
	int x1, y1, ocx, ocy, di, nx, ny;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1082
	unsigned int dui;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1083
	Window dummy;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1084
	XEvent ev;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1085
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1086
	ocx = nx = c->x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1087
	ocy = ny = c->y;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1088
	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1089
			None, cursor[CurMove], CurrentTime) != GrabSuccess)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1090
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1091
	c->ismax = False;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1092
	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1093
	for(;;) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1094
		XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1095
		switch (ev.type) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1096
		case ButtonRelease:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1097
			XUngrabPointer(dpy, CurrentTime);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1098
			return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1099
		case ConfigureRequest:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1100
		case Expose:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1101
		case MapRequest:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1102
			handler[ev.type](&ev);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1103
			break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1104
		case MotionNotify:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1105
			XSync(dpy, False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1106
			nx = ocx + (ev.xmotion.x - x1);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1107
			ny = ocy + (ev.xmotion.y - y1);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1108
			if(abs(wax + nx) < SNAP)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1109
				nx = wax;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1110
			else if(abs((wax + waw) - (nx + c->w + 2 * c->border)) < SNAP)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1111
				nx = wax + waw - c->w - 2 * c->border;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1112
			if(abs(way - ny) < SNAP)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1113
				ny = way;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1114
			else if(abs((way + wah) - (ny + c->h + 2 * c->border)) < SNAP)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1115
				ny = way + wah - c->h - 2 * c->border;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1116
			resize(c, nx, ny, c->w, c->h, False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1117
			break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1118
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1119
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1120
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1121
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1122
Client *
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1123
nexttiled(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1124
	for(; c && (c->isfloating || !isvisible(c)); c = c->next);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1125
	return c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1126
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1127
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1128
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1129
propertynotify(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1130
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1131
	Window trans;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1132
	XPropertyEvent *ev = &e->xproperty;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1133
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1134
	if(ev->state == PropertyDelete)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1135
		return; /* ignore */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1136
	if((c = getclient(ev->window))) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1137
		switch (ev->atom) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1138
			default: break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1139
			case XA_WM_TRANSIENT_FOR:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1140
				XGetTransientForHint(dpy, c->win, &trans);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1141
				if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1142
					arrange();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1143
				break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1144
			case XA_WM_NORMAL_HINTS:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1145
				updatesizehints(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1146
				break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1147
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1148
		if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1149
			updatetitle(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1150
			if(c == sel)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1151
				drawbar();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1152
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1153
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1154
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1155
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1156
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1157
quit(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1158
	readin = running = False;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1159
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1160
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1161
void
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1162
resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1163
	double dx, dy, max, min, ratio;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1164
	XWindowChanges wc; 
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1165
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1166
	if(sizehints) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1167
		if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1168
			dx = (double)(w - c->basew);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1169
			dy = (double)(h - c->baseh);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1170
			min = (double)(c->minax) / (double)(c->minay);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1171
			max = (double)(c->maxax) / (double)(c->maxay);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1172
			ratio = dx / dy;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1173
			if(max > 0 && min > 0 && ratio > 0) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1174
				if(ratio < min) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1175
					dy = (dx * min + dy) / (min * min + 1);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1176
					dx = dy * min;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1177
					w = (int)dx + c->basew;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1178
					h = (int)dy + c->baseh;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1179
				}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1180
				else if(ratio > max) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1181
					dy = (dx * min + dy) / (max * max + 1);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1182
					dx = dy * min;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1183
					w = (int)dx + c->basew;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1184
					h = (int)dy + c->baseh;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1185
				}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1186
			}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1187
		}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1188
		if(c->minw && w < c->minw)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1189
			w = c->minw;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1190
		if(c->minh && h < c->minh)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1191
			h = c->minh;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1192
		if(c->maxw && w > c->maxw)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1193
			w = c->maxw;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1194
		if(c->maxh && h > c->maxh)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1195
			h = c->maxh;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1196
		if(c->incw)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1197
			w -= (w - c->basew) % c->incw;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1198
		if(c->inch)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1199
			h -= (h - c->baseh) % c->inch;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1200
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1201
	if(w <= 0 || h <= 0)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1202
		return;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1203
	/* offscreen appearance fixes */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1204
	if(x > sw)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1205
		x = sw - w - 2 * c->border;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1206
	if(y > sh)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1207
		y = sh - h - 2 * c->border;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1208
	if(x + w + 2 * c->border < sx)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1209
		x = sx;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1210
	if(y + h + 2 * c->border < sy)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1211
		y = sy;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1212
	if(c->x != x || c->y != y || c->w != w || c->h != h) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1213
		c->x = wc.x = x;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1214
		c->y = wc.y = y;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1215
		c->w = wc.width = w;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1216
		c->h = wc.height = h;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1217
		wc.border_width = c->border;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1218
		XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1219
		configure(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1220
		XSync(dpy, False);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1221
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1222
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1223
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1224
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1225
resizemouse(Client *c) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1226
	int ocx, ocy;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1227
	int nw, nh;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1228
	XEvent ev;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1229
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1230
	ocx = c->x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1231
	ocy = c->y;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1232
	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1233
			None, cursor[CurResize], CurrentTime) != GrabSuccess)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1234
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1235
	c->ismax = False;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1236
	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1237
	for(;;) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1238
		XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask , &ev);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1239
		switch(ev.type) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1240
		case ButtonRelease:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1241
			XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1242
					c->w + c->border - 1, c->h + c->border - 1);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1243
			XUngrabPointer(dpy, CurrentTime);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1244
			while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1245
			return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1246
		case ConfigureRequest:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1247
		case Expose:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1248
		case MapRequest:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1249
			handler[ev.type](&ev);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1250
			break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1251
		case MotionNotify:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1252
			XSync(dpy, False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1253
			if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1254
				nw = 1;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1255
			if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1256
				nh = 1;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1257
			resize(c, c->x, c->y, nw, nh, True);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1258
			break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1259
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1260
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1261
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1262
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1263
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1264
restack(void) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1265
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1266
	XEvent ev;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1267
	XWindowChanges wc;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1268
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1269
	drawbar();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1270
	if(!sel)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1271
		return;
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1272
	if(sel->isfloating || isarrange(floating))
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1273
		XRaiseWindow(dpy, sel->win);
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1274
	if(!isarrange(floating)) {
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1275
		wc.stack_mode = Below;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1276
		wc.sibling = barwin;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1277
		if(!sel->isfloating) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1278
			XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1279
			wc.sibling = sel->win;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1280
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1281
		for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1282
			if(c == sel)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1283
				continue;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1284
			XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1285
			wc.sibling = c->win;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1286
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1287
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1288
	XSync(dpy, False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1289
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1290
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1291
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1292
void
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1293
run(void) {
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1294
	char *p;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1295
	int r, xfd;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1296
	fd_set rd;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1297
	XEvent ev;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1298
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1299
	/* main event loop, also reads status text from stdin */
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1300
	XSync(dpy, False);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1301
	xfd = ConnectionNumber(dpy);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1302
	readin = True;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1303
	while(running) {
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1304
		FD_ZERO(&rd);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1305
		if(readin)
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1306
			FD_SET(STDIN_FILENO, &rd);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1307
		FD_SET(xfd, &rd);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1308
		if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1309
			if(errno == EINTR)
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1310
				continue;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1311
			eprint("select failed\n");
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1312
		}
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1313
		if(FD_ISSET(STDIN_FILENO, &rd)) {
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1314
			switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) {
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1315
			case -1:
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1316
				strncpy(stext, strerror(errno), sizeof stext - 1);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1317
				stext[sizeof stext - 1] = '\0';
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1318
				readin = False;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1319
				break;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1320
			case 0:
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1321
				strncpy(stext, "EOF", 4);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1322
				readin = False;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1323
				break;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1324
			default:
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1325
				for(stext[r] = '\0', p = stext + strlen(stext) - 1; p >= stext && *p == '\n'; *p-- = '\0');
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1326
				for(; p >= stext && *p != '\n'; --p);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1327
				if(p > stext)
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1328
					strncpy(stext, p + 1, sizeof stext);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1329
			}
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1330
			drawbar();
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1331
		}
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1332
		while(XPending(dpy)) {
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1333
			XNextEvent(dpy, &ev);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1334
			if(handler[ev.type])
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1335
				(handler[ev.type])(&ev); /* call handler */
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1336
		}
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1337
	}
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1338
}
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1339
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1340
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1341
scan(void) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1342
	unsigned int i, num;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1343
	Window *wins, d1, d2;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1344
	XWindowAttributes wa;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1345
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1346
	wins = NULL;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1347
	if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1348
		for(i = 0; i < num; i++) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1349
			if(!XGetWindowAttributes(dpy, wins[i], &wa)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1350
			|| wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1351
				continue;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1352
			if(wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1353
				manage(wins[i], &wa);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1354
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1355
		for(i = 0; i < num; i++) { /* now the transients */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1356
			if(!XGetWindowAttributes(dpy, wins[i], &wa))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1357
				continue;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1358
			if(XGetTransientForHint(dpy, wins[i], &d1)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1359
			&& (wa.map_state == IsViewable || getstate(wins[i]) == IconicState))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1360
				manage(wins[i], &wa);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1361
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1362
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1363
	if(wins)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1364
		XFree(wins);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1365
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1366
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1367
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1368
setclientstate(Client *c, long state) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1369
	long data[] = {state, None};
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1370
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1371
	XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1372
			PropModeReplace, (unsigned char *)data, 2);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1373
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1374
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1375
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1376
setlayout(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1377
	unsigned int i;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1378
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1379
	if(!arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1380
		if(++ltidx == nlayouts)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1381
			ltidx = 0;;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1382
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1383
	else {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1384
		for(i = 0; i < nlayouts; i++)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1385
			if(!strcmp(arg, layouts[i].symbol))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1386
				break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1387
		if(i == nlayouts)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1388
			return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1389
		ltidx = i;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1390
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1391
	if(sel)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1392
		arrange();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1393
	else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1394
		drawbar();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1395
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1396
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1397
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1398
setmwfact(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1399
	double delta;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1400
1008
ac233c362502 introduced ISTILE, which can be easily extended with other layout functions to allow reuse of setmwfact() and zoom()
Anselm R. Garbe <garbeam@gmail.com>
parents: 1007
diff changeset
  1401
	if(!ISTILE)
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1402
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1403
	/* arg handling, manipulate mwfact */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1404
	if(arg == NULL)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1405
		mwfact = MWFACT;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1406
	else if(1 == sscanf(arg, "%lf", &delta)) {
1003
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
  1407
		if(arg[0] == '+' || arg[0] == '-')
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
  1408
			mwfact += delta;
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
  1409
		else
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1410
			mwfact = delta;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1411
		if(mwfact < 0.1)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1412
			mwfact = 0.1;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1413
		else if(mwfact > 0.9)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1414
			mwfact = 0.9;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1415
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1416
	arrange();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1417
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1418
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1419
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1420
setup(void) {
1005
2acc60d6dfe2 cosmetic fix
Anselm R. Garbe <garbeam@gmail.com>
parents: 1004
diff changeset
  1421
	int d;
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1422
	unsigned int i, j, mask;
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1423
	Window w;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1424
	XModifierKeymap *modmap;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1425
	XSetWindowAttributes wa;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1426
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1427
	/* init atoms */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1428
	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1429
	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1430
	wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1431
	wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1432
	netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1433
	netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1434
	XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1435
			PropModeReplace, (unsigned char *) netatom, NetLast);
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1436
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1437
	/* init cursors */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1438
	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1439
	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1440
	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1441
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1442
	/* init geometry */
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1443
	sx = sy = 0;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1444
	sw = DisplayWidth(dpy, screen);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1445
	sh = DisplayHeight(dpy, screen);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1446
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1447
	/* init modifier map */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1448
	modmap = XGetModifierMapping(dpy);
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1449
	for(i = 0; i < 8; i++)
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1450
		for(j = 0; j < modmap->max_keypermod; j++) {
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1451
			if(modmap->modifiermap[i * modmap->max_keypermod + j]
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1452
			== XKeysymToKeycode(dpy, XK_Num_Lock))
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1453
				numlockmask = (1 << i);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1454
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1455
	XFreeModifiermap(modmap);
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1456
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1457
	/* select for events */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1458
	wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1459
		| EnterWindowMask | LeaveWindowMask | StructureNotifyMask;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1460
	wa.cursor = cursor[CurNormal];
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1461
	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1462
	XSelectInput(dpy, root, wa.event_mask);
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1463
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1464
	/* grab keys */
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1465
	keypress(NULL);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1466
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1467
	/* init tags */
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1468
	compileregs();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1469
	for(ntags = 0; tags[ntags]; ntags++);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1470
	seltags = emallocz(sizeof(Bool) * ntags);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1471
	seltags[0] = True;
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1472
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1473
	/* init appearance */
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1474
	dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1475
	dc.norm[ColBG] = getcolor(NORMBGCOLOR);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1476
	dc.norm[ColFG] = getcolor(NORMFGCOLOR);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1477
	dc.sel[ColBorder] = getcolor(SELBORDERCOLOR);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1478
	dc.sel[ColBG] = getcolor(SELBGCOLOR);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1479
	dc.sel[ColFG] = getcolor(SELFGCOLOR);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1480
	initfont(FONT);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1481
	dc.h = bh = dc.font.height + 2;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1482
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1483
	/* init layouts */
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1484
	mwfact = MWFACT;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1485
	nlayouts = sizeof layouts / sizeof layouts[0];
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1486
	for(blw = i = 0; i < nlayouts; i++) {
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1487
		j = textw(layouts[i].symbol);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1488
		if(j > blw)
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1489
			blw = j;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1490
	}
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1491
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1492
	/* init bar */
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1493
	bpos = BARPOS;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1494
	wa.override_redirect = 1;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1495
	wa.background_pixmap = ParentRelative;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1496
	wa.event_mask = ButtonPressMask | ExposureMask;
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1497
	barwin = XCreateWindow(dpy, root, sx, sy, sw, bh, 0,
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1498
			DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1499
			CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1500
	XDefineCursor(dpy, barwin, cursor[CurNormal]);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1501
	updatebarpos();
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1502
	XMapRaised(dpy, barwin);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1503
	strcpy(stext, "dwm-"VERSION);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1504
	dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1505
	dc.gc = XCreateGC(dpy, root, 0, 0);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1506
	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1507
	if(!dc.font.set)
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1508
		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1509
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1510
	/* multihead support */
1005
2acc60d6dfe2 cosmetic fix
Anselm R. Garbe <garbeam@gmail.com>
parents: 1004
diff changeset
  1511
	selscreen = XQueryPointer(dpy, root, &w, &w, &d, &d, &d, &d, &mask);
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1512
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1513
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1514
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1515
spawn(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1516
	static char *shell = NULL;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1517
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1518
	if(!shell && !(shell = getenv("SHELL")))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1519
		shell = "/bin/sh";
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1520
	if(!arg)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1521
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1522
	/* The double-fork construct avoids zombie processes and keeps the code
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1523
	 * clean from stupid signal handlers. */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1524
	if(fork() == 0) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1525
		if(fork() == 0) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1526
			if(dpy)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1527
				close(ConnectionNumber(dpy));
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1528
			setsid();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1529
			execl(shell, shell, "-c", arg, (char *)NULL);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1530
			fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1531
			perror(" failed");
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1532
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1533
		exit(0);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1534
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1535
	wait(0);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1536
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1537
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1538
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1539
tag(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1540
	unsigned int i;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1541
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1542
	if(!sel)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1543
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1544
	for(i = 0; i < ntags; i++)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1545
		sel->tags[i] = arg == NULL;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1546
	i = idxoftag(arg);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1547
	if(i >= 0 && i < ntags)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1548
		sel->tags[i] = True;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1549
	arrange();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1550
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1551
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1552
unsigned int
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1553
textnw(const char *text, unsigned int len) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1554
	XRectangle r;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1555
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1556
	if(dc.font.set) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1557
		XmbTextExtents(dc.font.set, text, len, NULL, &r);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1558
		return r.width;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1559
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1560
	return XTextWidth(dc.font.xfont, text, len);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1561
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1562
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1563
unsigned int
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1564
textw(const char *text) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1565
	return textnw(text, strlen(text)) + dc.font.height;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1566
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1567
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1568
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1569
tile(void) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1570
	unsigned int i, n, nx, ny, nw, nh, mw, th;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1571
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1572
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1573
	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1574
		n++;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1575
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1576
	/* window geoms */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1577
	mw = (n == 1) ? waw : mwfact * waw;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1578
	th = (n > 1) ? wah / (n - 1) : 0;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1579
	if(n > 1 && th < bh)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1580
		th = wah;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1581
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1582
	nx = wax;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1583
	ny = way;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1584
	for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1585
		c->ismax = False;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1586
		if(i == 0) { /* master */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1587
			nw = mw - 2 * c->border;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1588
			nh = wah - 2 * c->border;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1589
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1590
		else {  /* tile window */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1591
			if(i == 1) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1592
				ny = way;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1593
				nx += mw;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1594
			}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1595
			nw = waw - mw - 2 * c->border;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1596
			if(i + 1 == n) /* remainder */
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1597
				nh = (way + wah) - ny - 2 * c->border;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1598
			else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1599
				nh = th - 2 * c->border;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1600
		}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1601
		resize(c, nx, ny, nw, nh, RESIZEHINTS);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1602
		if(n > 1 && th != wah)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1603
			ny += nh + 2 * c->border;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1604
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1605
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1606
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1607
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1608
togglebar(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1609
	if(bpos == BarOff)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1610
		bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1611
	else
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1612
		bpos = BarOff;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1613
	updatebarpos();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1614
	arrange();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1615
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1616
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1617
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1618
togglefloating(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1619
	if(!sel)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1620
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1621
	sel->isfloating = !sel->isfloating;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1622
	if(sel->isfloating)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1623
		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1624
	arrange();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1625
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1626
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1627
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1628
togglemax(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1629
	XEvent ev;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1630
1002
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
  1631
	if(!sel || sel->isfixed)
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1632
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1633
	if((sel->ismax = !sel->ismax)) {
1002
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
  1634
		if(isarrange(floating) || sel->isfloating)
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
  1635
			sel->wasfloating = True;
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
  1636
		else {
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
  1637
			togglefloating(NULL);
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
  1638
			sel->wasfloating = False;
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
  1639
		}
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1640
		sel->rx = sel->x;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1641
		sel->ry = sel->y;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1642
		sel->rw = sel->w;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1643
		sel->rh = sel->h;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1644
		resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1645
	}
1002
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
  1646
	else {
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1647
		resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
1003
19d4ccea9745 applied Peters patch, applied yiyus hint to initfont
arg@suckless.org
parents: 1002
diff changeset
  1648
		if(!sel->wasfloating)
1002
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
  1649
			togglefloating(NULL);
5cc2be8efeb4 applied Peter Hartlich's togglemax patch to allow toggling tiled clients to maximum
Anselm R. Garbe <garbeam@gmail.com>
parents: 1001
diff changeset
  1650
	}
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1651
	drawbar();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1652
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1653
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1654
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1655
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1656
toggletag(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1657
	unsigned int i, j;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1658
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1659
	if(!sel)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1660
		return;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1661
	i = idxoftag(arg);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1662
	sel->tags[i] = !sel->tags[i];
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1663
	for(j = 0; j < ntags && !sel->tags[j]; j++);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1664
	if(j == ntags)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1665
		sel->tags[i] = True;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1666
	arrange();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1667
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1668
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1669
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1670
toggleview(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1671
	unsigned int i, j;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1672
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1673
	i = idxoftag(arg);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1674
	seltags[i] = !seltags[i];
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1675
	for(j = 0; j < ntags && !seltags[j]; j++);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1676
	if(j == ntags)
1004
9bb192795c5a fixed a comment
Anselm R. Garbe <garbeam@gmail.com>
parents: 1003
diff changeset
  1677
		seltags[i] = True; /* at least one tag must be viewed */
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1678
	arrange();
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1679
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1680
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1681
void
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1682
unban(Client *c) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1683
	if(!c->isbanned)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1684
		return;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1685
	XMoveWindow(dpy, c->win, c->x, c->y);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1686
	c->isbanned = False;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1687
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1688
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1689
void
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1690
unmanage(Client *c) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1691
	XWindowChanges wc;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1692
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1693
	wc.border_width = c->oldborder;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1694
	/* The server grab construct avoids race conditions. */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1695
	XGrabServer(dpy);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1696
	XSetErrorHandler(xerrordummy);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1697
	XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1698
	detach(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1699
	detachstack(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1700
	if(sel == c)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1701
		focus(NULL);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1702
	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1703
	setclientstate(c, WithdrawnState);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1704
	free(c->tags);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1705
	free(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1706
	XSync(dpy, False);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1707
	XSetErrorHandler(xerror);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1708
	XUngrabServer(dpy);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1709
	arrange();
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1710
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1711
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1712
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1713
unmapnotify(XEvent *e) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1714
	Client *c;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1715
	XUnmapEvent *ev = &e->xunmap;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1716
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1717
	if((c = getclient(ev->window)))
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1718
		unmanage(c);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1719
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1720
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1721
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1722
updatebarpos(void) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1723
	XEvent ev;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1724
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1725
	wax = sx;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1726
	way = sy;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1727
	wah = sh;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1728
	waw = sw;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1729
	switch(bpos) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1730
	default:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1731
		wah -= bh;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1732
		way += bh;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1733
		XMoveWindow(dpy, barwin, sx, sy);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1734
		break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1735
	case BarBot:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1736
		wah -= bh;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1737
		XMoveWindow(dpy, barwin, sx, sy + wah);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1738
		break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1739
	case BarOff:
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1740
		XMoveWindow(dpy, barwin, sx, sy - bh);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1741
		break;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1742
	}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1743
	XSync(dpy, False);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1744
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1745
}
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1746
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1747
void
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1748
updatesizehints(Client *c) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1749
	long msize;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1750
	XSizeHints size;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1751
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1752
	if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1753
		size.flags = PSize;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1754
	c->flags = size.flags;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1755
	if(c->flags & PBaseSize) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1756
		c->basew = size.base_width;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1757
		c->baseh = size.base_height;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1758
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1759
	else if(c->flags & PMinSize) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1760
		c->basew = size.min_width;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1761
		c->baseh = size.min_height;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1762
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1763
	else
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1764
		c->basew = c->baseh = 0;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1765
	if(c->flags & PResizeInc) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1766
		c->incw = size.width_inc;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1767
		c->inch = size.height_inc;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1768
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1769
	else
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1770
		c->incw = c->inch = 0;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1771
	if(c->flags & PMaxSize) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1772
		c->maxw = size.max_width;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1773
		c->maxh = size.max_height;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1774
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1775
	else
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1776
		c->maxw = c->maxh = 0;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1777
	if(c->flags & PMinSize) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1778
		c->minw = size.min_width;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1779
		c->minh = size.min_height;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1780
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1781
	else if(c->flags & PBaseSize) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1782
		c->minw = size.base_width;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1783
		c->minh = size.base_height;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1784
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1785
	else
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1786
		c->minw = c->minh = 0;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1787
	if(c->flags & PAspect) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1788
		c->minax = size.min_aspect.x;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1789
		c->maxax = size.max_aspect.x;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1790
		c->minay = size.min_aspect.y;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1791
		c->maxay = size.max_aspect.y;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1792
	}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1793
	else
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1794
		c->minax = c->maxax = c->minay = c->maxay = 0;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1795
	c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1796
			&& c->maxw == c->minw && c->maxh == c->minh);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1797
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1798
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1799
void
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1800
updatetitle(Client *c) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1801
	if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1802
		gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1803
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1804
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1805
/* There's no way to check accesses to destroyed windows, thus those cases are
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1806
 * ignored (especially on UnmapNotify's).  Other types of errors call Xlibs
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1807
 * default error handler, which may call exit.  */
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1808
int
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1809
xerror(Display *dpy, XErrorEvent *ee) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1810
	if(ee->error_code == BadWindow
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1811
	|| (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1812
	|| (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1813
	|| (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1814
	|| (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1815
	|| (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1816
	|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1817
	|| (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1818
		return 0;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1819
	fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1820
		ee->request_code, ee->error_code);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1821
	return xerrorxlib(dpy, ee); /* may call exit */
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1822
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1823
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1824
int
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1825
xerrordummy(Display *dsply, XErrorEvent *ee) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1826
	return 0;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1827
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1828
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1829
/* Startup Error handler to check if another window manager
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1830
 * is already running. */
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1831
int
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1832
xerrorstart(Display *dsply, XErrorEvent *ee) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1833
	otherwm = True;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1834
	return -1;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1835
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1836
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1837
void
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1838
view(const char *arg) {
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1839
	unsigned int i;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1840
996
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1841
	for(i = 0; i < ntags; i++)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1842
		seltags[i] = arg == NULL;
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1843
	i = idxoftag(arg);
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1844
	if(i >= 0 && i < ntags)
b4d47b6a8ba8 ordered all functions alphabetically
Anselm R. Garbe <garbeam@gmail.com>
parents: 995
diff changeset
  1845
		seltags[i] = True;
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1846
	arrange();
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1847
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1848
1001
2477f818215c made all stuff non-static - so you can choose wether to use dwm the static or the extern way when extending it
arg@suckless.org
parents: 1000
diff changeset
  1849
void
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1850
zoom(const char *arg) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1851
	Client *c;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1852
1008
ac233c362502 introduced ISTILE, which can be easily extended with other layout functions to allow reuse of setmwfact() and zoom()
Anselm R. Garbe <garbeam@gmail.com>
parents: 1007
diff changeset
  1853
	if(!sel || !ISTILE || sel->isfloating)
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1854
		return;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1855
	if((c = sel) == nexttiled(clients))
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1856
		if(!(c = nexttiled(c->next)))
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1857
			return;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1858
	detach(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1859
	attach(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1860
	focus(c);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1861
	arrange();
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1862
}
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1863
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1864
int
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1865
main(int argc, char *argv[]) {
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1866
	if(argc == 2 && !strcmp("-v", argv[1]))
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1867
		eprint("dwm-"VERSION", © 2006-2007 A. R. Garbe, S. van Dijk, J. Salmi, P. Hruby, S. Nagy\n");
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1868
	else if(argc != 1)
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1869
		eprint("usage: dwm [-v]\n");
994
201550f99b8e macros which have been defined in config.h can only be used at function level, however you can nest code into config.h now for implementing a different layout (just for example), eg. #include "supertile.c"
Anselm R. Garbe <garbeam@gmail.com>
parents: 993
diff changeset
  1870
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1871
	setlocale(LC_CTYPE, "");
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1872
	if(!(dpy = XOpenDisplay(0)))
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1873
		eprint("dwm: cannot open display\n");
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1874
	screen = DefaultScreen(dpy);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1875
	root = RootWindow(dpy, screen);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1876
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1877
	checkotherwm();
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1878
	setup();
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1879
	drawbar();
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1880
	scan();
997
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1881
	run();
8e721021e636 some more rearrangements
Anselm R. Garbe <garbeam@gmail.com>
parents: 996
diff changeset
  1882
	cleanup();
990
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1883
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1884
	XCloseDisplay(dpy);
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1885
	return 0;
70f6fcd100b7 micromizing dwm step 1
Anselm R. Garbe <garbeam@gmail.com>
parents:
diff changeset
  1886
}