static Bool other_wm_running;
static const char version[] =
"dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
-static int (*x_error_handler) (Display *, XErrorEvent *);
+static int (*x_xerror) (Display *, XErrorEvent *);
static void
usage() { error("usage: dwm [-v]\n"); }
}
int
-win_proto(Window w)
+proto(Window w)
{
unsigned char *protocols;
long res;
}
void
-send_message(Window w, Atom a, long value)
+sendevent(Window w, Atom a, long value)
{
XEvent e;
* calls exit().
*/
int
-error_handler(Display *dpy, XErrorEvent *error)
+xerror(Display *dpy, XErrorEvent *error)
{
if(error->error_code == BadWindow
|| (error->request_code == X_SetInputFocus
return 0;
fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
error->request_code, error->error_code);
- return x_error_handler(dpy, error); /* may call exit() */
+ return x_xerror(dpy, error); /* may call exit() */
}
/*
* is already running.
*/
static int
-startup_error_handler(Display *dpy, XErrorEvent *error)
+startup_xerror(Display *dpy, XErrorEvent *error)
{
other_wm_running = True;
return -1;
fd_set rd;
XSetWindowAttributes wa;
unsigned int mask;
+ Bool readstdin = True;
Window w;
XEvent ev;
/* check if another WM is already running */
other_wm_running = False;
- XSetErrorHandler(startup_error_handler);
+ XSetErrorHandler(startup_xerror);
/* this causes an error if some other WM is running */
XSelectInput(dpy, root, SubstructureRedirectMask);
XFlush(dpy);
error("dwm: another window manager is already running\n");
XSetErrorHandler(0);
- x_error_handler = XSetErrorHandler(error_handler);
+ x_xerror = XSetErrorHandler(xerror);
/* init atoms */
wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
- update_keys();
+ grabkeys();
/* style */
- dc.bg = initcolor(BGCOLOR);
- dc.fg = initcolor(FGCOLOR);
- dc.border = initcolor(BORDERCOLOR);
- initfont(FONT);
+ dc.bg = getcolor(BGCOLOR);
+ dc.fg = getcolor(FGCOLOR);
+ dc.border = getcolor(BORDERCOLOR);
+ setfont(FONT);
sx = sy = 0;
sw = DisplayWidth(dpy, screen);
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
dc.gc = XCreateGC(dpy, root, 0, 0);
- draw_bar();
+ drawstatus();
issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
Mainloop:
while(running) {
FD_ZERO(&rd);
- FD_SET(STDIN_FILENO, &rd);
+ if(readstdin)
+ FD_SET(STDIN_FILENO, &rd);
FD_SET(ConnectionNumber(dpy), &rd);
i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0);
(handler[ev.type])(&ev); /* call handler */
}
}
- if(FD_ISSET(STDIN_FILENO, &rd)) {
+ if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) {
i = n = 0;
for(;;) {
if((i = getchar()) == EOF) {
- stext[0] = 0;
+ /* broken pipe/end of producer */
+ readstdin = False;
+ strcpy(stext, "broken pipe");
goto Mainloop;
}
if(i == '\n' || n >= sizeof(stext) - 1)
stext[n++] = i;
}
stext[n] = 0;
- draw_bar();
+ drawstatus();
}
}
}