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