dwm.h (view raw)
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 *
5 * dynamic window manager is designed like any other X client as well. It is
6 * driven through handling X events. In contrast to other X clients, a window
7 * manager like dwm selects for SubstructureRedirectMask on the root window, to
8 * receive events about child window appearance and disappearance. Only one X
9 * connection at a time is allowed to select for this event mask by any X
10 * server, thus only one window manager instance can be executed at a time.
11 * Any attempt to select for SubstructureRedirectMask by any connection after
12 * another connection already selected for those events, will result in an
13 * error generated by the server. Such errors are reported through calling the
14 * current X error handler.
15 *
16 * Calls to pop an X event from the event queue of the X connection are
17 * blocking. Due the fact, that dwm reads status text from standard input, a
18 * select-driven main loop has been implemented which selects for reads on the
19 * X connection and STDIN_FILENO to handle all data smoothly and without
20 * busy-loop quirks.. The event handlers of dwm are organized in an array
21 * which is accessed whenever a new event has been popped. This allows event
22 * dispatching in O(1) time.
23 *
24 * Each child window of the root window is called a client in window manager
25 * terminology, except windows which have set the override_redirect flag.
26 * Clients are organized in a global doubly-linked client list, the focus
27 * history is remembered through a global stack list. Each client contains an
28 * array of Bools of the same size as the global tags array to indicate the
29 * tags of a client. There are no other data structures to organize the clients
30 * in tag lists, because a single global list is most simple. All clients which
31 * have at least one tag enabled of the current tags viewed, will be visible on
32 * the screen, all other clients are banned to the x-location 2 * screen width.
33 * This avoids having additional layers of workspace handling.
34 *
35 * For each client dwm creates a small title window which is resized whenever
36 * the WM_NAME or _NET_WM_NAME properties are updated.
37 *
38 * Keys and tagging rules are organized as arrays as well and defined in the
39 * config.h file. These arrays are kept static in event.o and tag.o
40 * respectively, because no other part of dwm needs access to them.
41 *
42 * The current mode is represented by the arrange function pointer which wether
43 * points to dofloat or dotile.
44 */
45
46#include "config.h"
47#include <X11/Xlib.h>
48
49/* mask shorthands, used in event.c and client.c */
50#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
51#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
52#define PROTODELWIN 1
53
54enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
55enum { WMProtocols, WMDelete, WMLast }; /* default atoms */
56enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
57enum { ColFG, ColBG, ColLast }; /* color */
58
59typedef enum {
60 TopLeft, TopRight, BotLeft, BotRight
61} Corner; /* window corners */
62
63typedef union {
64 const char *cmd;
65 int i;
66} Arg; /* argument type */
67
68typedef struct {
69 int ascent;
70 int descent;
71 int height;
72 XFontSet set;
73 XFontStruct *xfont;
74} Fnt;
75
76typedef struct {
77 int x, y, w, h;
78 unsigned long norm[ColLast];
79 unsigned long sel[ColLast];
80 unsigned long status[ColLast];
81 Drawable drawable;
82 Fnt font;
83 GC gc;
84} DC; /* draw context */
85
86typedef struct Client Client;
87struct Client {
88 char name[256];
89 int proto;
90 int x, y, w, h;
91 int tx, ty, tw, th; /* title window geometry */
92 int basew, baseh, incw, inch, maxw, maxh, minw, minh;
93 int grav;
94 long flags;
95 unsigned int border, weight;
96 Bool isfloat;
97 Bool *tags;
98 Client *next;
99 Client *prev;
100 Client *snext;
101 Window win;
102 Window twin;
103};
104
105extern const char *tags[]; /* all tags */
106extern char stext[1024]; /* status text */
107extern int bx, by, bw, bh, bmw; /* bar geometry, bar mode label width */
108extern int mw, screen, sx, sy, sw, sh; /* screen geometry, master width */
109extern unsigned int ntags, numlockmask; /* number of tags, dynamic lock mask */
110extern void (*handler[LASTEvent])(XEvent *); /* event handler */
111extern void (*arrange)(Arg *); /* arrange function, indicates mode */
112extern Atom wmatom[WMLast], netatom[NetLast];
113extern Bool running, issel, maximized, *seltag; /* seltag is array of Bool */
114extern Client *clients, *sel, *stack; /* global cleint list and stack */
115extern Cursor cursor[CurLast];
116extern DC dc; /* global draw context */
117extern Display *dpy;
118extern Window root, barwin;
119
120/* client.c */
121extern void ban(Client *c); /* ban c from screen */
122extern void focus(Client *c); /* focus c, c may be NULL */
123extern Client *getclient(Window w); /* return client of w */
124extern Client *getctitle(Window w); /* return client of title window */
125extern void gravitate(Client *c, Bool invert); /* gravitate c */
126extern void killclient(Arg *arg); /* kill c nicely */
127extern void manage(Window w, XWindowAttributes *wa); /* manage new client */
128extern void resize(Client *c, Bool sizehints, Corner sticky); /* resize c*/
129extern void updatesize(Client *c); /* update the size structs of c */
130extern void updatetitle(Client *c); /* update the name of c */
131extern void togglemax(Arg *arg); /* (un)maximize c */
132extern void unmanage(Client *c); /* destroy c */
133
134/* draw.c */
135extern void drawall(); /* draw all visible client titles and the bar */
136extern void drawstatus(); /* draw the bar */
137extern void drawtitle(Client *c); /* draw title of c */
138extern unsigned long getcolor(const char *colstr); /* return color of colstr */
139extern void setfont(const char *fontstr); /* set the font for DC */
140extern unsigned int textw(const char *text); /* return the width of text in px*/
141
142/* event.c */
143extern void grabkeys(); /* grab all keys defined in config.h */
144extern void procevent(); /* process pending X events */
145
146/* main.c */
147extern int getproto(Window w); /* return protocol mask of WMProtocols property of w */
148extern void quit(Arg *arg); /* quit dwm nicely */
149extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */
150extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
151
152/* tag.c */
153extern void initrregs(); /* initialize regexps of rules defined in config.h */
154extern Client *getnext(Client *c); /* returns next visible client */
155extern Client *getprev(Client *c); /* returns previous visible client */
156extern void settags(Client *c, Client *trans); /* sets tags of c */
157extern void tag(Arg *arg); /* tags c with arg's index */
158extern void toggletag(Arg *arg); /* toggles c tags with arg's index */
159
160/* util.c */
161extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */
162extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
163extern void *erealloc(void *ptr, unsigned int size); /* reallocates memory, exits on error */
164extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */
165
166/* view.c */
167extern void detach(Client *c); /* detaches c from global client list */
168extern void dofloat(Arg *arg); /* arranges all windows floating, arg is ignored */
169extern void dotile(Arg *arg); /* arranges all windows, arg is ignored */
170extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */
171extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */
172extern Bool isvisible(Client *c); /* returns True if client is visible */
173extern void resizecol(Arg *arg); /* resizes the master width with arg's index value */
174extern void restack(); /* restores z layers of all clients */
175extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */
176extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */
177extern void view(Arg *arg); /* views the tag with arg's index */
178extern void viewall(Arg *arg); /* views all tags, arg is ignored */
179extern void zoom(Arg *arg); /* zooms the focused client to master column, arg is ignored */