summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--main.c112
1 files changed, 56 insertions, 56 deletions
diff --git a/main.c b/main.c
index a1cf245..39172ee 100644
--- a/main.c
+++ b/main.c
@@ -43,16 +43,16 @@ DC dc = {0};
43Client *clients = NULL; 43Client *clients = NULL;
44Client *sel = NULL; 44Client *sel = NULL;
45 45
46static Bool other_wm_running; 46static Bool otherwm;
47static const char version[] = 47static const char version[] =
48 "dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 48 "dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
49static int (*x_xerror) (Display *, XErrorEvent *); 49static int (*xerrorxlib)(Display *, XErrorEvent *);
50 50
51static void 51static void
52usage() { error("usage: dwm [-v]\n"); } 52usage() { eprint("usage: dwm [-v]\n"); }
53 53
54static void 54static void
55scan_wins() 55scan()
56{ 56{
57 unsigned int i, num; 57 unsigned int i, num;
58 Window *wins; 58 Window *wins;
@@ -73,6 +73,22 @@ scan_wins()
73 XFree(wins); 73 XFree(wins);
74} 74}
75 75
76static void
77cleanup()
78{
79 while(sel) {
80 resize(sel, True);
81 unmanage(sel);
82 }
83 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
84}
85
86void
87quit(Arg *arg)
88{
89 running = False;
90}
91
76static int 92static int
77win_property(Window w, Atom a, Atom t, long l, unsigned char **prop) 93win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
78{ 94{
@@ -94,7 +110,7 @@ win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
94} 110}
95 111
96int 112int
97proto(Window w) 113getproto(Window w)
98{ 114{
99 unsigned char *protocols; 115 unsigned char *protocols;
100 long res; 116 long res;
@@ -129,58 +145,42 @@ sendevent(Window w, Atom a, long value)
129} 145}
130 146
131/* 147/*
132 * There's no way to check accesses to destroyed windows, thus
133 * those cases are ignored (especially on UnmapNotify's).
134 * Other types of errors call Xlib's default error handler, which
135 * calls exit().
136 */
137int
138xerror(Display *dpy, XErrorEvent *error)
139{
140 if(error->error_code == BadWindow
141 || (error->request_code == X_SetInputFocus
142 && error->error_code == BadMatch)
143 || (error->request_code == X_PolyText8
144 && error->error_code == BadDrawable)
145 || (error->request_code == X_PolyFillRectangle
146 && error->error_code == BadDrawable)
147 || (error->request_code == X_PolySegment
148 && error->error_code == BadDrawable)
149 || (error->request_code == X_ConfigureWindow
150 && error->error_code == BadMatch)
151 || (error->request_code == X_GrabKey
152 && error->error_code == BadAccess))
153 return 0;
154 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
155 error->request_code, error->error_code);
156 return x_xerror(dpy, error); /* may call exit() */
157}
158
159/*
160 * Startup Error handler to check if another window manager 148 * Startup Error handler to check if another window manager
161 * is already running. 149 * is already running.
162 */ 150 */
163static int 151static int
164startup_xerror(Display *dpy, XErrorEvent *error) 152xerrorstart(Display *dsply, XErrorEvent *ee)
165{ 153{
166 other_wm_running = True; 154 otherwm = True;
167 return -1; 155 return -1;
168} 156}
169 157
170static void 158/*
171cleanup() 159 * There's no way to check accesses to destroyed windows, thus
172{ 160 * those cases are ignored (especially on UnmapNotify's).
173 while(sel) { 161 * Other types of errors call Xlib's default error handler, which
174 resize(sel, True); 162 * calls exit().
175 unmanage(sel); 163 */
176 } 164int
177 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); 165xerror(Display *dpy, XErrorEvent *ee)
178}
179
180void
181quit(Arg *arg)
182{ 166{
183 running = False; 167 if(ee->error_code == BadWindow
168 || (ee->request_code == X_SetInputFocus
169 && ee->error_code == BadMatch)
170 || (ee->request_code == X_PolyText8
171 && ee->error_code == BadDrawable)
172 || (ee->request_code == X_PolyFillRectangle
173 && ee->error_code == BadDrawable)
174 || (ee->request_code == X_PolySegment
175 && ee->error_code == BadDrawable)
176 || (ee->request_code == X_ConfigureWindow
177 && ee->error_code == BadMatch)
178 || (ee->request_code == X_GrabKey
179 && ee->error_code == BadAccess))
180 return 0;
181 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
182 ee->request_code, ee->error_code);
183 return xerrorxlib(dpy, ee); /* may call exit() */
184} 184}
185 185
186int 186int
@@ -208,23 +208,23 @@ main(int argc, char *argv[])
208 208
209 dpy = XOpenDisplay(0); 209 dpy = XOpenDisplay(0);
210 if(!dpy) 210 if(!dpy)
211 error("dwm: cannot connect X server\n"); 211 eprint("dwm: cannot connect X server\n");
212 212
213 screen = DefaultScreen(dpy); 213 screen = DefaultScreen(dpy);
214 root = RootWindow(dpy, screen); 214 root = RootWindow(dpy, screen);
215 215
216 /* check if another WM is already running */ 216 /* check if another WM is already running */
217 other_wm_running = False; 217 otherwm = False;
218 XSetErrorHandler(startup_xerror); 218 XSetErrorHandler(xerrorstart);
219 /* this causes an error if some other WM is running */ 219 /* this causes an error if some other WM is running */
220 XSelectInput(dpy, root, SubstructureRedirectMask); 220 XSelectInput(dpy, root, SubstructureRedirectMask);
221 XFlush(dpy); 221 XFlush(dpy);
222 222
223 if(other_wm_running) 223 if(otherwm)
224 error("dwm: another window manager is already running\n"); 224 eprint("dwm: another window manager is already running\n");
225 225
226 XSetErrorHandler(0); 226 XSetErrorHandler(0);
227 x_xerror = XSetErrorHandler(xerror); 227 xerrorxlib = XSetErrorHandler(xerror);
228 228
229 /* init atoms */ 229 /* init atoms */
230 wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); 230 wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
@@ -278,7 +278,7 @@ main(int argc, char *argv[])
278 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); 278 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
279 279
280 strcpy(stext, "dwm-"VERSION); 280 strcpy(stext, "dwm-"VERSION);
281 scan_wins(); 281 scan();
282 282
283 /* main event loop, reads status text from stdin as well */ 283 /* main event loop, reads status text from stdin as well */
284Mainloop: 284Mainloop:
@@ -292,7 +292,7 @@ Mainloop:
292 if(i == -1 && errno == EINTR) 292 if(i == -1 && errno == EINTR)
293 continue; 293 continue;
294 if(i < 0) 294 if(i < 0)
295 error("select failed\n"); 295 eprint("select failed\n");
296 else if(i > 0) { 296 else if(i > 0) {
297 if(FD_ISSET(ConnectionNumber(dpy), &rd)) { 297 if(FD_ISSET(ConnectionNumber(dpy), &rd)) {
298 while(XPending(dpy)) { 298 while(XPending(dpy)) {