aewl

annotate dwm.h @ 457:e97ad13f04dc

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