dwm.h 7.6 KB

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