dwm.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
  2. * © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
  3. * © 2007 Premysl Hruby <dfenze at gmail dot com>
  4. * © 2007 Szabolcs Nagy <nszabolcs at gmail dot com>
  5. * See LICENSE file for license details.
  6. *
  7. * dynamic window manager is designed like any other X client as well. It is
  8. * driven through handling X events. In contrast to other X clients, a window
  9. * manager selects for SubstructureRedirectMask on the root window, to receive
  10. * events about window (dis-)appearance. Only one X connection at a time is
  11. * allowed to select for this event mask.
  12. *
  13. * Calls to fetch an X event from the event queue are blocking. Due reading
  14. * status text from standard input, a select()-driven main loop has been
  15. * implemented which selects for reads on the X connection and STDIN_FILENO to
  16. * handle all data smoothly. The event handlers of dwm are organized in an
  17. * array which is accessed whenever a new event has been fetched. This allows
  18. * event dispatching in O(1) time.
  19. *
  20. * Each child of the root window is called a client, except windows which have
  21. * set the override_redirect flag. Clients are organized in a global
  22. * doubly-linked client list, the focus history is remembered through a global
  23. * stack list. Each client contains an array of Bools of the same size as the
  24. * global tags array to indicate the tags of a client. For each client dwm
  25. * creates a small title window, which is resized whenever the (_NET_)WM_NAME
  26. * properties are updated or the client is moved/resized.
  27. *
  28. * Keys and tagging rules are organized as arrays and defined in the config.h
  29. * file. These arrays are kept static in event.o and tag.o respectively,
  30. * because no other part of dwm needs access to them. The current layout is
  31. * represented by the lt pointer.
  32. *
  33. * To understand everything else, start reading main.c:main().
  34. */
  35. #include "config.h"
  36. #include <X11/Xlib.h>
  37. /* mask shorthands, used in event.c and client.c */
  38. #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
  39. enum { BarTop, BarBot, BarOff }; /* bar position */
  40. enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
  41. enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
  42. enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
  43. enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */
  44. typedef struct Client Client;
  45. struct Client {
  46. char name[256];
  47. int x, y, w, h;
  48. int rx, ry, rw, rh; /* revert geometry */
  49. int basew, baseh, incw, inch, maxw, maxh, minw, minh;
  50. int minax, maxax, minay, maxay;
  51. long flags;
  52. unsigned int border, oldborder;
  53. Bool isbanned, isfixed, ismax, isfloating;
  54. Bool *tags;
  55. Client *next;
  56. Client *prev;
  57. Client *snext;
  58. Window win;
  59. };
  60. typedef struct {
  61. int x, y, w, h;
  62. unsigned long norm[ColLast];
  63. unsigned long sel[ColLast];
  64. Drawable drawable;
  65. GC gc;
  66. struct {
  67. int ascent;
  68. int descent;
  69. int height;
  70. XFontSet set;
  71. XFontStruct *xfont;
  72. } font;
  73. } DC; /* draw context */
  74. typedef struct {
  75. const char *symbol;
  76. void (*arrange)(void);
  77. } Layout;
  78. extern const char *tags[]; /* all tags */
  79. char stext[256]; /* status text */
  80. int screen, sx, sy, sw, sh; /* screen geometry */
  81. int wax, way, wah, waw; /* windowarea geometry */
  82. unsigned int bh, blw, bpos; /* bar height, bar layout label width, bar position */
  83. unsigned int ntags, numlockmask; /* number of tags, dynamic lock mask */
  84. void (*handler[LASTEvent])(XEvent *); /* event handler */
  85. Atom wmatom[WMLast], netatom[NetLast];
  86. Bool selscreen, *seltag; /* seltag is array of Bool */
  87. Client *clients, *sel, *stack; /* global client list and stack */
  88. Cursor cursor[CurLast];
  89. DC dc; /* global draw context */
  90. Display *dpy;
  91. Layout *lt;
  92. Window root, barwin;
  93. /* client.c */
  94. void attach(Client *c); /* attaches c to global client list */
  95. void configure(Client *c); /* send synthetic configure event */
  96. void detach(Client *c); /* detaches c from global client list */
  97. void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */
  98. void killclient(const char *arg); /* kill sel nicely */
  99. void manage(Window w, XWindowAttributes *wa); /* manage new client */
  100. void resize(Client *c, int x, int y,
  101. int w, int h, Bool sizehints); /* resize with given coordinates c*/
  102. void togglefloating(const char *arg); /* toggles sel between floating/tiled state */
  103. void updatesizehints(Client *c); /* update the size hint variables of c */
  104. void updatetitle(Client *c); /* update the name of c */
  105. void unmanage(Client *c); /* destroy c */
  106. /* draw.c */
  107. void drawstatus(void); /* draw the bar */
  108. void drawtext(const char *text, unsigned long col[ColLast]); /* draw text */
  109. unsigned int textw(const char *text); /* return the width of text in px*/
  110. /* event.c */
  111. void grabkeys(void); /* grab all keys defined in config.h */
  112. /* layout.c */
  113. void floating(void); /* arranges all windows floating */
  114. void focusclient(const char *arg); /* focuses next(1)/previous(-1) visible client */
  115. void incmasterw(const char *arg); /* increments the master width with arg's index value */
  116. void incnmaster(const char *arg); /* increments nmaster with arg's index value */
  117. void initlayouts(void); /* initialize layout array */
  118. Client *nexttiled(Client *c); /* returns tiled successor of c */
  119. void restack(void); /* restores z layers of all clients */
  120. void setlayout(const char *arg); /* sets layout, NULL means next layout */
  121. void togglebar(const char *arg); /* shows/hides the bar */
  122. void togglemax(const char *arg); /* toggles maximization of floating client */
  123. void zoom(const char *arg); /* zooms the focused client to master area, arg is ignored */
  124. /* main.c */
  125. void updatebarpos(void); /* updates the bar position */
  126. void quit(const char *arg); /* quit dwm nicely */
  127. int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
  128. /* tag.c */
  129. void compileregs(void); /* initialize regexps of rules defined in config.h */
  130. Bool isvisible(Client *c); /* returns True if client is visible */
  131. void settags(Client *c, Client *trans); /* sets tags of c */
  132. void tag(const char *arg); /* tags sel with arg's index */
  133. void toggletag(const char *arg); /* toggles sel tags with arg's index */
  134. void toggleview(const char *arg); /* toggles the tag with arg's index (in)visible */
  135. void view(const char *arg); /* views the tag with arg's index */
  136. /* util.c */
  137. void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */
  138. void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
  139. void spawn(const char *arg); /* forks a new subprocess with arg's cmd */