paulo@0: /* (C)opyright MMVI-MMVII Anselm R. Garbe paulo@0: * See LICENSE file for license details. paulo@0: * paulo@0: * dynamic window manager is designed like any other X client as well. It is paulo@0: * driven through handling X events. In contrast to other X clients, a window paulo@0: * manager selects for SubstructureRedirectMask on the root window, to receive paulo@0: * events about window (dis-)appearance. Only one X connection at a time is paulo@0: * allowed to select for this event mask. paulo@0: * paulo@0: * Calls to fetch an X event from the event queue are blocking. Due reading paulo@0: * status text from standard input, a select()-driven main loop has been paulo@0: * implemented which selects for reads on the X connection and STDIN_FILENO to paulo@0: * handle all data smoothly. The event handlers of dwm are organized in an paulo@0: * array which is accessed whenever a new event has been fetched. This allows paulo@0: * event dispatching in O(1) time. paulo@0: * paulo@0: * Each child of the root window is called a client, except windows which have paulo@0: * set the override_redirect flag. Clients are organized in a global paulo@0: * doubly-linked client list, the focus history is remembered through a global paulo@0: * stack list. Each client contains an array of Bools of the same size as the paulo@0: * global tags array to indicate the tags of a client. For each client dwm paulo@0: * creates a small title window, which is resized whenever the (_NET_)WM_NAME paulo@0: * properties are updated or the client is moved/resized. paulo@0: * paulo@0: * Keys and tagging rules are organized as arrays and defined in the config.h paulo@0: * file. These arrays are kept static in event.o and tag.o respectively, paulo@0: * because no other part of dwm needs access to them. The current layout is paulo@0: * represented by the lt pointer. paulo@0: * paulo@0: * To understand everything else, start reading main.c:main(). paulo@0: */ paulo@0: paulo@0: #include "config.h" paulo@0: #include paulo@0: paulo@0: /* mask shorthands, used in event.c and client.c */ paulo@0: #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask) paulo@0: paulo@0: enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ paulo@0: enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */ paulo@0: enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ paulo@0: enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ paulo@0: paulo@0: typedef union { paulo@0: const char *cmd; paulo@0: int i; paulo@0: } Arg; /* argument type */ paulo@0: paulo@0: typedef struct { paulo@0: int ascent; paulo@0: int descent; paulo@0: int height; paulo@0: XFontSet set; paulo@0: XFontStruct *xfont; paulo@0: } Fnt; paulo@0: paulo@0: typedef struct { paulo@0: int x, y, w, h; paulo@0: unsigned long norm[ColLast]; paulo@0: unsigned long sel[ColLast]; paulo@0: Drawable drawable; paulo@0: Fnt font; paulo@0: GC gc; paulo@0: } DC; /* draw context */ paulo@0: paulo@0: typedef struct Client Client; paulo@0: struct Client { paulo@0: char name[256]; paulo@0: int x, y, w, h; paulo@0: int rx, ry, rw, rh; /* revert geometry */ paulo@0: int basew, baseh, incw, inch, maxw, maxh, minw, minh; paulo@0: int minax, minay, maxax, maxay; paulo@0: long flags; paulo@0: unsigned int border; paulo@0: Bool isbanned, isfixed, ismax, isversatile; paulo@0: Bool *tags; paulo@0: Client *next; paulo@0: Client *prev; paulo@0: Client *snext; paulo@0: Window win; paulo@0: }; paulo@0: paulo@0: typedef struct { paulo@0: const char *symbol; paulo@0: void (*arrange)(void); paulo@0: } Layout; paulo@0: paulo@0: extern const char *tags[]; /* all tags */ paulo@0: extern char stext[256]; /* status text */ paulo@0: extern int screen, sx, sy, sw, sh; /* screen geometry */ paulo@0: extern int wax, way, wah, waw; /* windowarea geometry */ paulo@0: extern unsigned int bh, blw; /* bar height, bar layout label width */ paulo@0: extern unsigned int master, nmaster; /* master percent, number of master clients */ paulo@0: extern unsigned int ntags, numlockmask; /* number of tags, dynamic lock mask */ paulo@0: extern void (*handler[LASTEvent])(XEvent *); /* event handler */ paulo@0: extern Atom wmatom[WMLast], netatom[NetLast]; paulo@0: extern Bool selscreen, *seltag; /* seltag is array of Bool */ paulo@0: extern Client *clients, *sel, *stack; /* global client list and stack */ paulo@0: extern Cursor cursor[CurLast]; paulo@0: extern DC dc; /* global draw context */ paulo@0: extern Display *dpy; paulo@0: extern Layout *lt; paulo@0: extern Window root, barwin; paulo@0: paulo@0: /* client.c */ paulo@0: extern void configure(Client *c); /* send synthetic configure event */ paulo@0: extern void focus(Client *c); /* focus c, c may be NULL */ paulo@0: extern void killclient(Arg *arg); /* kill c nicely */ paulo@0: extern void manage(Window w, XWindowAttributes *wa); /* manage new client */ paulo@0: extern void resize(Client *c, int x, int y, paulo@0: int w, int h, Bool sizehints); /* resize with given coordinates c*/ paulo@0: extern void toggleversatile(Arg *arg); /* toggles focused client between versatile/and non-versatile state */ paulo@0: extern void updatesizehints(Client *c); /* update the size hint variables of c */ paulo@0: extern void updatetitle(Client *c); /* update the name of c */ paulo@0: extern void unmanage(Client *c); /* destroy c */ paulo@0: extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ paulo@0: extern void pushup(Arg *arg); paulo@0: extern void pushdown(Arg *arg); paulo@0: extern void moveresize(Arg *arg); paulo@0: paulo@0: /* draw.c */ paulo@0: extern void drawstatus(void); /* draw the bar */ paulo@0: extern void drawtext(const char *text, paulo@0: unsigned long col[ColLast]); /* draw text */ paulo@0: extern unsigned int textw(const char *text); /* return the width of text in px*/ paulo@0: paulo@0: /* event.c */ paulo@0: extern void grabkeys(void); /* grab all keys defined in config.h */ paulo@0: paulo@0: /* layout.c */ paulo@0: extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ paulo@0: extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ paulo@0: extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */ paulo@0: extern void initlayouts(void); /* initialize layout array */ paulo@0: extern Client *nexttiled(Client *c); /* returns tiled successor of c */ paulo@0: extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */ paulo@0: extern void restack(void); /* restores z layers of all clients */ paulo@0: extern void setlayout(Arg *arg); /* sets layout, -1 toggles */ paulo@0: extern void versatile(void); /* arranges all windows versatile */ paulo@0: paulo@0: /* main.c */ paulo@0: extern void quit(Arg *arg); /* quit dwm nicely */ paulo@0: extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ paulo@0: extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ paulo@0: paulo@0: /* tag.c */ paulo@0: extern void compileregs(void); /* initialize regexps of rules defined in config.h */ paulo@0: extern Bool isvisible(Client *c); /* returns True if client is visible */ paulo@0: extern void settags(Client *c, Client *trans); /* sets tags of c */ paulo@0: extern void tag(Arg *arg); /* tags c with arg's index */ paulo@0: extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ paulo@0: extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ paulo@0: extern void view(Arg *arg); /* views the tag with arg's index */ paulo@0: extern void last_view(Arg *arg); /* go to last viewed tag */ paulo@0: paulo@0: /* util.c */ paulo@0: extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ paulo@0: extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ paulo@0: extern void spawn(Arg *arg); /* forks a new subprocess with arg's cmd */ paulo@0: