all repos — dwm @ cbfc69e310e41cf0d9d4ae7529856014f2b88822

fork of suckless dynamic window manager

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.
 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 */
 40
 41#include "config.h"
 42#include <X11/Xlib.h>
 43
 44/* mask shorthands, used in event.c and client.c */
 45#define BUTTONMASK		(ButtonPressMask | ButtonReleaseMask)
 46#define MOUSEMASK		(BUTTONMASK | PointerMotionMask)
 47#define PROTODELWIN		1
 48
 49enum { NetSupported, NetWMName, NetLast };		/* EWMH atoms */
 50enum { WMProtocols, WMDelete, WMLast };			/* default atoms */
 51enum { CurNormal, CurResize, CurMove, CurLast };	/* cursor */
 52enum { ColFG, ColBG, ColLast };				/* color */
 53
 54typedef enum {
 55	TopLeft, TopRight, BotLeft, BotRight
 56} Corner; /* window corners */
 57
 58typedef union {
 59	const char *cmd;
 60	int i;
 61} Arg; /* argument type */
 62
 63typedef struct {
 64	int ascent;
 65	int descent;
 66	int height;
 67	XFontSet set;
 68	XFontStruct *xfont;
 69} Fnt;
 70
 71typedef 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 */
 80
 81typedef struct Client Client;
 82struct 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};
 99
100extern const char *tags[];			/* all tags */
101extern char stext[1024];			/* status text */
102extern int bx, by, bw, bh, bmw;			/* bar geometry, bar mode label width */
103extern int mw, screen, sx, sy, sw, sh;		/* screen geometry, master width */
104extern unsigned int ntags, numlockmask;		/* number of tags, dynamic lock mask */
105extern void (*handler[LASTEvent])(XEvent *);	/* event handler */
106extern void (*arrange)(Arg *);			/* arrange function, indicates mode  */
107extern Atom wmatom[WMLast], netatom[NetLast];
108extern Bool running, issel, maximized, *seltag;	/* seltag is array of Bool */
109extern Client *clients, *sel, *stack;		/* global cleint list and stack */
110extern Cursor cursor[CurLast];
111extern DC dc;					/* global draw context */
112extern Display *dpy;
113extern Window root, barwin;
114
115/* client.c */
116extern void ban(Client *c);			/* ban c from screen */
117extern void focus(Client *c);			/* focus c, c may be NULL */
118extern Client *getclient(Window w);		/* return client of w */
119extern Client *getctitle(Window w);		/* return client of title window */
120extern void gravitate(Client *c, Bool invert);	/* gravitate c */
121extern void killclient(Arg *arg);		/* kill c nicely */
122extern void manage(Window w, XWindowAttributes *wa);	/* manage new client */
123extern void resize(Client *c, Bool sizehints, Corner sticky); /* resize c*/
124extern void updatesize(Client *c);			/* update the size structs of c */
125extern void updatetitle(Client *c);		/* update the name of c */
126extern void togglemax(Arg *arg);		/* (un)maximize c */
127extern void unmanage(Client *c);		/* destroy c */
128
129/* draw.c */
130extern void drawall();				/* draw all visible client titles and the bar */
131extern void drawstatus();			/* draw the bar */
132extern void drawtitle(Client *c);		/* draw title of c */
133extern unsigned long getcolor(const char *colstr);	/* return color of colstr */
134extern void setfont(const char *fontstr);	/* set the font for DC */
135extern unsigned int textw(const char *text);	/* return the width of text in px*/
136
137/* event.c */
138extern void grabkeys();				/* grab all keys defined in config.h */
139extern void procevent();			/* process pending X events */
140
141/* main.c */
142extern int getproto(Window w);			/* return protocol mask of WMProtocols property of w */
143extern void quit(Arg *arg);			/* quit dwm nicely */
144extern void sendevent(Window w, Atom a, long value);	/* send synthetic event to w */
145extern int xerror(Display *dsply, XErrorEvent *ee);	/* dwm's X error handler */
146
147/* tag.c */
148extern void initrregs();			/* initialize regexps of rules defined in config.h */
149extern Client *getnext(Client *c);		/* returns next visible client */
150extern Client *getprev(Client *c);		/* returns previous visible client */
151extern void settags(Client *c, Client *trans);	/* sets tags of c */
152extern void tag(Arg *arg);			/* tags c with arg's index */
153extern void toggletag(Arg *arg);		/* toggles c tags with arg's index */
154
155/* util.c */
156extern void *emallocz(unsigned int size);	/* allocates zero-initialized memory, exits on error */
157extern void eprint(const char *errstr, ...);	/* prints errstr and exits with 1 */
158extern void *erealloc(void *ptr, unsigned int size);	/* reallocates memory, exits on error */
159extern void spawn(Arg *arg);			/* forks a new subprocess with to arg's cmd */
160
161/* view.c */
162extern void detach(Client *c);			/* detaches c from global client list */
163extern void dofloat(Arg *arg);			/* arranges all windows floating, arg is ignored */
164extern void dotile(Arg *arg);			/* arranges all windows, arg is ignored */
165extern void focusnext(Arg *arg);		/* focuses next visible client, arg is ignored  */
166extern void focusprev(Arg *arg);		/* focuses previous visible client, arg is ignored */
167extern Bool isvisible(Client *c);		/* returns True if client is visible */
168extern void resizecol(Arg *arg);		/* resizes the master width with arg's index value */
169extern void restack();				/* restores z layers of all clients */
170extern void togglemode(Arg *arg);		/* toggles global arrange function (dotile/dofloat) */
171extern void toggleview(Arg *arg);		/* toggles the tag with arg's index (in)visible */
172extern void view(Arg *arg);			/* views the tag with arg's index */
173extern void viewall(Arg *arg);			/* views all tags, arg is ignored */
174extern void zoom(Arg *arg);			/* zooms the focused client to master column, arg is ignored */