41 #include <X11/Xatom.h> |
41 #include <X11/Xatom.h> |
42 #include <X11/Xlib.h> |
42 #include <X11/Xlib.h> |
43 #include <X11/Xproto.h> |
43 #include <X11/Xproto.h> |
44 #include <X11/Xutil.h> |
44 #include <X11/Xutil.h> |
45 |
45 |
46 #include "dwm.h" |
|
47 |
|
48 /* macros */ |
46 /* macros */ |
49 #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask) |
47 #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask) |
50 #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) |
48 #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) |
51 #define MOUSEMASK (BUTTONMASK | PointerMotionMask) |
49 #define MOUSEMASK (BUTTONMASK | PointerMotionMask) |
52 |
50 |
|
51 /* enums */ |
|
52 enum { BarTop, BarBot, BarOff }; /* bar position */ |
|
53 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
|
54 enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
|
55 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
|
56 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ |
|
57 |
|
58 /* typedefs */ |
|
59 typedef struct Client Client; |
|
60 struct Client { |
|
61 char name[256]; |
|
62 int x, y, w, h; |
|
63 int rx, ry, rw, rh; /* revert geometry */ |
|
64 int basew, baseh, incw, inch, maxw, maxh, minw, minh; |
|
65 int minax, maxax, minay, maxay; |
|
66 long flags; |
|
67 unsigned int border, oldborder; |
|
68 Bool isbanned, isfixed, ismax, isfloating, wasfloating; |
|
69 Bool *tags; |
|
70 Client *next; |
|
71 Client *prev; |
|
72 Client *snext; |
|
73 Window win; |
|
74 }; |
|
75 |
|
76 typedef struct { |
|
77 int x, y, w, h; |
|
78 unsigned long norm[ColLast]; |
|
79 unsigned long sel[ColLast]; |
|
80 Drawable drawable; |
|
81 GC gc; |
|
82 struct { |
|
83 int ascent; |
|
84 int descent; |
|
85 int height; |
|
86 XFontSet set; |
|
87 XFontStruct *xfont; |
|
88 } font; |
|
89 } DC; /* draw context */ |
|
90 |
|
91 typedef struct { |
|
92 unsigned long mod; |
|
93 KeySym keysym; |
|
94 void (*func)(const char *arg); |
|
95 const char *arg; |
|
96 } Key; |
|
97 |
|
98 typedef struct { |
|
99 const char *symbol; |
|
100 void (*arrange)(void); |
|
101 } Layout; |
|
102 |
|
103 typedef struct { |
|
104 const char *prop; |
|
105 const char *tags; |
|
106 Bool isfloating; |
|
107 } Rule; |
|
108 |
|
109 typedef struct { |
|
110 regex_t *propregex; |
|
111 regex_t *tagregex; |
|
112 } Regs; |
|
113 |
|
114 /* functions */ |
|
115 void applyrules(Client *c); |
|
116 void arrange(void); |
|
117 void attach(Client *c); |
|
118 void attachstack(Client *c); |
|
119 void ban(Client *c); |
|
120 void buttonpress(XEvent *e); |
|
121 void checkotherwm(void); |
|
122 void cleanup(void); |
|
123 void compileregs(void); |
|
124 void configure(Client *c); |
|
125 void configurenotify(XEvent *e); |
|
126 void configurerequest(XEvent *e); |
|
127 void destroynotify(XEvent *e); |
|
128 void detach(Client *c); |
|
129 void detachstack(Client *c); |
|
130 void drawbar(void); |
|
131 void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]); |
|
132 void drawtext(const char *text, unsigned long col[ColLast]); |
|
133 void *emallocz(unsigned int size); |
|
134 void enternotify(XEvent *e); |
|
135 void eprint(const char *errstr, ...); |
|
136 void expose(XEvent *e); |
|
137 void floating(void); /* default floating layout */ |
|
138 void focus(Client *c); |
|
139 void focusnext(const char *arg); |
|
140 void focusprev(const char *arg); |
|
141 Client *getclient(Window w); |
|
142 unsigned long getcolor(const char *colstr); |
|
143 long getstate(Window w); |
|
144 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
|
145 void grabbuttons(Client *c, Bool focused); |
|
146 unsigned int idxoftag(const char *tag); |
|
147 void initfont(const char *fontstr); |
|
148 Bool isarrange(void (*func)()); |
|
149 Bool isoccupied(unsigned int t); |
|
150 Bool isprotodel(Client *c); |
|
151 Bool isvisible(Client *c); |
|
152 void keypress(XEvent *e); |
|
153 void killclient(const char *arg); |
|
154 void leavenotify(XEvent *e); |
|
155 void manage(Window w, XWindowAttributes *wa); |
|
156 void mappingnotify(XEvent *e); |
|
157 void maprequest(XEvent *e); |
|
158 void movemouse(Client *c); |
|
159 Client *nexttiled(Client *c); |
|
160 void propertynotify(XEvent *e); |
|
161 void quit(const char *arg); |
|
162 void resize(Client *c, int x, int y, int w, int h, Bool sizehints); |
|
163 void resizemouse(Client *c); |
|
164 void restack(void); |
|
165 void run(void); |
|
166 void scan(void); |
|
167 void setclientstate(Client *c, long state); |
|
168 void setlayout(const char *arg); |
|
169 void setmwfact(const char *arg); |
|
170 void setup(void); |
|
171 void spawn(const char *arg); |
|
172 void tag(const char *arg); |
|
173 unsigned int textnw(const char *text, unsigned int len); |
|
174 unsigned int textw(const char *text); |
|
175 void tile(void); |
|
176 void togglebar(const char *arg); |
|
177 void togglefloating(const char *arg); |
|
178 void togglemax(const char *arg); |
|
179 void toggletag(const char *arg); |
|
180 void toggleview(const char *arg); |
|
181 void unban(Client *c); |
|
182 void unmanage(Client *c); |
|
183 void unmapnotify(XEvent *e); |
|
184 void updatebarpos(void); |
|
185 void updatesizehints(Client *c); |
|
186 void updatetitle(Client *c); |
|
187 void view(const char *arg); |
|
188 void viewprevtag(const char *arg); /* views previous selected tags */ |
|
189 int xerror(Display *dpy, XErrorEvent *ee); |
|
190 int xerrordummy(Display *dsply, XErrorEvent *ee); |
|
191 int xerrorstart(Display *dsply, XErrorEvent *ee); |
|
192 void zoom(const char *arg); |
|
193 |
|
194 /* variables */ |
|
195 char stext[256]; |
|
196 double mwfact; |
|
197 int screen, sx, sy, sw, sh, wax, way, waw, wah; |
|
198 int (*xerrorxlib)(Display *, XErrorEvent *); |
|
199 unsigned int bh, bpos; |
|
200 unsigned int blw = 0; |
|
201 unsigned int ltidx = 0; /* default */ |
|
202 unsigned int nlayouts = 0; |
|
203 unsigned int nrules = 0; |
|
204 unsigned int numlockmask = 0; |
|
205 void (*handler[LASTEvent]) (XEvent *) = { |
|
206 [ButtonPress] = buttonpress, |
|
207 [ConfigureRequest] = configurerequest, |
|
208 [ConfigureNotify] = configurenotify, |
|
209 [DestroyNotify] = destroynotify, |
|
210 [EnterNotify] = enternotify, |
|
211 [LeaveNotify] = leavenotify, |
|
212 [Expose] = expose, |
|
213 [KeyPress] = keypress, |
|
214 [MappingNotify] = mappingnotify, |
|
215 [MapRequest] = maprequest, |
|
216 [PropertyNotify] = propertynotify, |
|
217 [UnmapNotify] = unmapnotify |
|
218 }; |
|
219 Atom wmatom[WMLast], netatom[NetLast]; |
|
220 Bool otherwm, readin; |
|
221 Bool running = True; |
|
222 Bool selscreen = True; |
|
223 Client *clients = NULL; |
|
224 Client *sel = NULL; |
|
225 Client *stack = NULL; |
|
226 Cursor cursor[CurLast]; |
|
227 Display *dpy; |
|
228 DC dc = {0}; |
|
229 Window barwin, root; |
|
230 Regs *regs = NULL; |
|
231 |
|
232 /* configuration, allows nested code to access above variables */ |
|
233 #include "config.h" |
|
234 |
|
235 /* statically define the number of tags. */ |
|
236 unsigned int ntags = sizeof tags / sizeof tags[0]; |
|
237 Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True}; |
|
238 Bool prevtags[sizeof tags / sizeof tags[0]] = {[0] = True}; |
53 void |
239 void |
54 applyrules(Client *c) { |
240 applyrules(Client *c) { |
55 static char buf[512]; |
241 static char buf[512]; |
56 unsigned int i, j; |
242 unsigned int i, j; |
57 regmatch_t tmp; |
243 regmatch_t tmp; |