aewl

view dwm.h @ 459:3c3f429dca99

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