143 static void configurenotify(XEvent *e); |
143 static void configurenotify(XEvent *e); |
144 static void configurerequest(XEvent *e); |
144 static void configurerequest(XEvent *e); |
145 static void destroynotify(XEvent *e); |
145 static void destroynotify(XEvent *e); |
146 static void detach(Client *c); |
146 static void detach(Client *c); |
147 static void detachstack(Client *c); |
147 static void detachstack(Client *c); |
|
148 static void die(const char *errstr, ...); |
148 static void drawbar(void); |
149 static void drawbar(void); |
149 static void drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]); |
150 static void drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]); |
150 static void drawtext(const char *text, ulong col[ColLast], Bool invert); |
151 static void drawtext(const char *text, ulong col[ColLast], Bool invert); |
151 static void enternotify(XEvent *e); |
152 static void enternotify(XEvent *e); |
152 static void eprint(const char *errstr, ...); |
|
153 static void expose(XEvent *e); |
153 static void expose(XEvent *e); |
154 static void focus(Client *c); |
154 static void focus(Client *c); |
155 static void focusin(XEvent *e); |
155 static void focusin(XEvent *e); |
156 static void focusstack(const Arg *arg); |
156 static void focusstack(const Arg *arg); |
157 static Client *getclient(Window w); |
157 static Client *getclient(Window w); |
341 |
341 |
342 /* this causes an error if some other window manager is running */ |
342 /* this causes an error if some other window manager is running */ |
343 XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); |
343 XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); |
344 XSync(dpy, False); |
344 XSync(dpy, False); |
345 if(otherwm) |
345 if(otherwm) |
346 eprint("dwm: another window manager is already running\n"); |
346 die("dwm: another window manager is already running\n"); |
347 XSetErrorHandler(NULL); |
347 XSetErrorHandler(NULL); |
348 xerrorxlib = XSetErrorHandler(xerror); |
348 xerrorxlib = XSetErrorHandler(xerror); |
349 XSync(dpy, False); |
349 XSync(dpy, False); |
350 } |
350 } |
351 |
351 |
665 getcolor(const char *colstr) { |
665 getcolor(const char *colstr) { |
666 Colormap cmap = DefaultColormap(dpy, screen); |
666 Colormap cmap = DefaultColormap(dpy, screen); |
667 XColor color; |
667 XColor color; |
668 |
668 |
669 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) |
669 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) |
670 eprint("error, cannot allocate color '%s'\n", colstr); |
670 die("error, cannot allocate color '%s'\n", colstr); |
671 return color.pixel; |
671 return color.pixel; |
672 } |
672 } |
673 |
673 |
674 long |
674 long |
675 getstate(Window w) { |
675 getstate(Window w) { |
791 if(dc.font.xfont) |
791 if(dc.font.xfont) |
792 XFreeFont(dpy, dc.font.xfont); |
792 XFreeFont(dpy, dc.font.xfont); |
793 dc.font.xfont = NULL; |
793 dc.font.xfont = NULL; |
794 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) |
794 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) |
795 && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) |
795 && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) |
796 eprint("error, cannot load font: '%s'\n", fontstr); |
796 die("error, cannot load font: '%s'\n", fontstr); |
797 dc.font.ascent = dc.font.xfont->ascent; |
797 dc.font.ascent = dc.font.xfont->ascent; |
798 dc.font.descent = dc.font.xfont->descent; |
798 dc.font.descent = dc.font.xfont->descent; |
799 } |
799 } |
800 dc.font.height = dc.font.ascent + dc.font.descent; |
800 dc.font.height = dc.font.ascent + dc.font.descent; |
801 } |
801 } |
1214 FD_SET(STDIN_FILENO, &rd); |
1214 FD_SET(STDIN_FILENO, &rd); |
1215 FD_SET(xfd, &rd); |
1215 FD_SET(xfd, &rd); |
1216 if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) { |
1216 if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) { |
1217 if(errno == EINTR) |
1217 if(errno == EINTR) |
1218 continue; |
1218 continue; |
1219 eprint("select failed\n"); |
1219 die("select failed\n"); |
1220 } |
1220 } |
1221 if(FD_ISSET(STDIN_FILENO, &rd)) { |
1221 if(FD_ISSET(STDIN_FILENO, &rd)) { |
1222 switch((r = read(STDIN_FILENO, sbuf + offset, len - offset))) { |
1222 switch((r = read(STDIN_FILENO, sbuf + offset, len - offset))) { |
1223 case -1: |
1223 case -1: |
1224 strncpy(stext, strerror(errno), len); |
1224 strncpy(stext, strerror(errno), len); |
1693 } |
1693 } |
1694 |
1694 |
1695 int |
1695 int |
1696 main(int argc, char *argv[]) { |
1696 main(int argc, char *argv[]) { |
1697 if(argc == 2 && !strcmp("-v", argv[1])) |
1697 if(argc == 2 && !strcmp("-v", argv[1])) |
1698 eprint("dwm-"VERSION", © 2006-2008 dwm engineers, see LICENSE for details\n"); |
1698 die("dwm-"VERSION", © 2006-2008 dwm engineers, see LICENSE for details\n"); |
1699 else if(argc != 1) |
1699 else if(argc != 1) |
1700 eprint("usage: dwm [-v]\n"); |
1700 die("usage: dwm [-v]\n"); |
1701 |
1701 |
1702 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) |
1702 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) |
1703 fprintf(stderr, "warning: no locale support\n"); |
1703 fprintf(stderr, "warning: no locale support\n"); |
1704 |
1704 |
1705 if(!(dpy = XOpenDisplay(0))) |
1705 if(!(dpy = XOpenDisplay(0))) |
1706 eprint("dwm: cannot open display\n"); |
1706 die("dwm: cannot open display\n"); |
1707 |
1707 |
1708 checkotherwm(); |
1708 checkotherwm(); |
1709 setup(); |
1709 setup(); |
1710 scan(); |
1710 scan(); |
1711 run(); |
1711 run(); |