rev |
line source |
garbeam@0
|
1 /*
|
garbeam@0
|
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
garbeam@0
|
3 * See LICENSE file for license details.
|
arg@457
|
4 *
|
arg@457
|
5 * dynamic window manager is designed like any other X client as well. It is
|
arg@457
|
6 * driven through handling X events. In contrast to other X clients, a window
|
arg@457
|
7 * manager like dwm selects for SubstructureRedirectMask on the root window, to
|
arg@457
|
8 * receive events about child window appearance and disappearance. Only one X
|
arg@459
|
9 * connection at a time is allowed to select for this event mask.
|
arg@457
|
10 *
|
arg@459
|
11 * Calls to fetch an X event from the event queue of the X connection are
|
arg@457
|
12 * blocking. Due the fact, that dwm reads status text from standard input, a
|
arg@457
|
13 * select-driven main loop has been implemented which selects for reads on the
|
arg@457
|
14 * X connection and STDIN_FILENO to handle all data smoothly and without
|
arg@459
|
15 * busy-loop quirks. The event handlers of dwm are organized in an array which
|
arg@459
|
16 * is accessed whenever a new event has been fetched. This allows event
|
arg@457
|
17 * dispatching in O(1) time.
|
arg@457
|
18 *
|
arg@457
|
19 * Each child window of the root window is called a client in window manager
|
arg@457
|
20 * terminology, except windows which have set the override_redirect flag.
|
arg@457
|
21 * Clients are organized in a global doubly-linked client list, the focus
|
arg@457
|
22 * history is remembered through a global stack list. Each client contains an
|
arg@457
|
23 * array of Bools of the same size as the global tags array to indicate the
|
arg@457
|
24 * tags of a client. There are no other data structures to organize the clients
|
arg@459
|
25 * in tag lists. All clients which have at least one tag enabled of the current
|
arg@459
|
26 * tags viewed, will be visible on the screen, all other clients are banned to
|
arg@459
|
27 * the x-location x + 2 * screen width. This avoids having additional layers
|
arg@459
|
28 * of workspace handling.
|
arg@457
|
29 *
|
arg@457
|
30 * For each client dwm creates a small title window which is resized whenever
|
arg@459
|
31 * the WM_NAME or _NET_WM_NAME properties are updated or the client is resized.
|
arg@459
|
32 * Keys and tagging rules are organized as arrays and defined in the config.h
|
arg@459
|
33 * file. These arrays are kept static in event.o and tag.o respectively,
|
arg@459
|
34 * because no other part of dwm needs access to them. The current mode is
|
arg@459
|
35 * represented by the arrange function pointer which wether points to dofloat
|
arg@459
|
36 * or dotile.
|
arg@457
|
37 *
|
arg@459
|
38 * To understand everything else, start with reading main.c:main().
|
garbeam@0
|
39 */
|
garbeam@0
|
40
|
arg@166
|
41 #include "config.h"
|
garbeam@32
|
42 #include <X11/Xlib.h>
|
garbeam@32
|
43
|
arg@143
|
44 /* mask shorthands, used in event.c and client.c */
|
arg@150
|
45 #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
|
arg@150
|
46 #define MOUSEMASK (BUTTONMASK | PointerMotionMask)
|
arg@157
|
47 #define PROTODELWIN 1
|
arg@143
|
48
|
arg@452
|
49 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
|
arg@452
|
50 enum { WMProtocols, WMDelete, WMLast }; /* default atoms */
|
arg@452
|
51 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
arg@452
|
52 enum { ColFG, ColBG, ColLast }; /* color */
|
arg@452
|
53
|
arg@452
|
54 typedef enum {
|
arg@452
|
55 TopLeft, TopRight, BotLeft, BotRight
|
arg@452
|
56 } Corner; /* window corners */
|
arg@452
|
57
|
arg@333
|
58 typedef union {
|
arg@189
|
59 const char *cmd;
|
garbeam@49
|
60 int i;
|
arg@452
|
61 } Arg; /* argument type */
|
arg@99
|
62
|
arg@333
|
63 typedef struct {
|
garbeam@32
|
64 int ascent;
|
garbeam@32
|
65 int descent;
|
garbeam@32
|
66 int height;
|
garbeam@84
|
67 XFontSet set;
|
garbeam@84
|
68 XFontStruct *xfont;
|
arg@333
|
69 } Fnt;
|
garbeam@32
|
70
|
arg@452
|
71 typedef struct {
|
garbeam@32
|
72 int x, y, w, h;
|
arg@353
|
73 unsigned long norm[ColLast];
|
arg@353
|
74 unsigned long sel[ColLast];
|
arg@353
|
75 unsigned long status[ColLast];
|
garbeam@84
|
76 Drawable drawable;
|
garbeam@84
|
77 Fnt font;
|
garbeam@84
|
78 GC gc;
|
arg@452
|
79 } DC; /* draw context */
|
garbeam@32
|
80
|
arg@333
|
81 typedef struct Client Client;
|
garbeam@0
|
82 struct Client {
|
garbeam@31
|
83 char name[256];
|
garbeam@13
|
84 int proto;
|
arg@115
|
85 int x, y, w, h;
|
arg@453
|
86 int tx, ty, tw, th; /* title window geometry */
|
garbeam@20
|
87 int basew, baseh, incw, inch, maxw, maxh, minw, minh;
|
garbeam@29
|
88 int grav;
|
arg@164
|
89 long flags;
|
arg@381
|
90 unsigned int border, weight;
|
garbeam@80
|
91 Bool isfloat;
|
arg@178
|
92 Bool *tags;
|
garbeam@84
|
93 Client *next;
|
arg@127
|
94 Client *prev;
|
arg@446
|
95 Client *snext;
|
garbeam@0
|
96 Window win;
|
arg@342
|
97 Window twin;
|
garbeam@0
|
98 };
|
garbeam@0
|
99
|
arg@452
|
100 extern const char *tags[]; /* all tags */
|
arg@452
|
101 extern char stext[1024]; /* status text */
|
arg@452
|
102 extern int bx, by, bw, bh, bmw; /* bar geometry, bar mode label width */
|
arg@452
|
103 extern int mw, screen, sx, sy, sw, sh; /* screen geometry, master width */
|
arg@454
|
104 extern unsigned int ntags, numlockmask; /* number of tags, dynamic lock mask */
|
arg@452
|
105 extern void (*handler[LASTEvent])(XEvent *); /* event handler */
|
arg@452
|
106 extern void (*arrange)(Arg *); /* arrange function, indicates mode */
|
garbeam@84
|
107 extern Atom wmatom[WMLast], netatom[NetLast];
|
arg@452
|
108 extern Bool running, issel, maximized, *seltag; /* seltag is array of Bool */
|
arg@454
|
109 extern Client *clients, *sel, *stack; /* global cleint list and stack */
|
garbeam@84
|
110 extern Cursor cursor[CurLast];
|
arg@454
|
111 extern DC dc; /* global draw context */
|
garbeam@84
|
112 extern Display *dpy;
|
garbeam@84
|
113 extern Window root, barwin;
|
garbeam@3
|
114
|
garbeam@5
|
115 /* client.c */
|
arg@454
|
116 extern void ban(Client *c); /* ban c from screen */
|
arg@452
|
117 extern void focus(Client *c); /* focus c, c may be NULL */
|
arg@452
|
118 extern Client *getclient(Window w); /* return client of w */
|
arg@452
|
119 extern Client *getctitle(Window w); /* return client of title window */
|
arg@452
|
120 extern void gravitate(Client *c, Bool invert); /* gravitate c */
|
arg@452
|
121 extern void killclient(Arg *arg); /* kill c nicely */
|
arg@452
|
122 extern void manage(Window w, XWindowAttributes *wa); /* manage new client */
|
arg@452
|
123 extern void resize(Client *c, Bool sizehints, Corner sticky); /* resize c*/
|
arg@454
|
124 extern void updatesize(Client *c); /* update the size structs of c */
|
arg@454
|
125 extern void updatetitle(Client *c); /* update the name of c */
|
arg@452
|
126 extern void togglemax(Arg *arg); /* (un)maximize c */
|
arg@452
|
127 extern void unmanage(Client *c); /* destroy c */
|
garbeam@13
|
128
|
garbeam@33
|
129 /* draw.c */
|
arg@452
|
130 extern void drawall(); /* draw all visible client titles and the bar */
|
arg@452
|
131 extern void drawstatus(); /* draw the bar */
|
arg@452
|
132 extern void drawtitle(Client *c); /* draw title of c */
|
arg@452
|
133 extern unsigned long getcolor(const char *colstr); /* return color of colstr */
|
arg@452
|
134 extern void setfont(const char *fontstr); /* set the font for DC */
|
arg@456
|
135 extern unsigned int textw(const char *text); /* return the width of text in px*/
|
garbeam@33
|
136
|
garbeam@75
|
137 /* event.c */
|
arg@452
|
138 extern void grabkeys(); /* grab all keys defined in config.h */
|
arg@452
|
139 extern void procevent(); /* process pending X events */
|
garbeam@18
|
140
|
garbeam@43
|
141 /* main.c */
|
arg@452
|
142 extern int getproto(Window w); /* return protocol mask of WMProtocols property of w */
|
arg@452
|
143 extern void quit(Arg *arg); /* quit dwm nicely */
|
arg@452
|
144 extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */
|
arg@452
|
145 extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
|
garbeam@43
|
146
|
garbeam@75
|
147 /* tag.c */
|
arg@452
|
148 extern void initrregs(); /* initialize regexps of rules defined in config.h */
|
arg@452
|
149 extern Client *getnext(Client *c); /* returns next visible client */
|
arg@452
|
150 extern Client *getprev(Client *c); /* returns previous visible client */
|
arg@454
|
151 extern void settags(Client *c, Client *trans); /* sets tags of c */
|
arg@456
|
152 extern void tag(Arg *arg); /* tags c with arg's index */
|
arg@456
|
153 extern void toggletag(Arg *arg); /* toggles c tags with arg's index */
|
garbeam@73
|
154
|
garbeam@32
|
155 /* util.c */
|
arg@452
|
156 extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */
|
arg@456
|
157 extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
|
arg@452
|
158 extern void *erealloc(void *ptr, unsigned int size); /* reallocates memory, exits on error */
|
arg@456
|
159 extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */
|
arg@327
|
160
|
arg@327
|
161 /* view.c */
|
arg@452
|
162 extern void detach(Client *c); /* detaches c from global client list */
|
arg@456
|
163 extern void dofloat(Arg *arg); /* arranges all windows floating, arg is ignored */
|
arg@456
|
164 extern void dotile(Arg *arg); /* arranges all windows, arg is ignored */
|
arg@452
|
165 extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */
|
arg@452
|
166 extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */
|
arg@452
|
167 extern Bool isvisible(Client *c); /* returns True if client is visible */
|
arg@456
|
168 extern void resizecol(Arg *arg); /* resizes the master width with arg's index value */
|
arg@452
|
169 extern void restack(); /* restores z layers of all clients */
|
arg@456
|
170 extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */
|
arg@456
|
171 extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */
|
arg@456
|
172 extern void view(Arg *arg); /* views the tag with arg's index */
|
arg@454
|
173 extern void viewall(Arg *arg); /* views all tags, arg is ignored */
|
arg@452
|
174 extern void zoom(Arg *arg); /* zooms the focused client to master column, arg is ignored */
|