static void destroynotify(XEvent *e);
static void detach(Client *c);
static void detachstack(Client *c);
+static void die(const char *errstr, ...);
static void drawbar(void);
static void drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]);
static void drawtext(const char *text, ulong col[ColLast], Bool invert);
static void enternotify(XEvent *e);
-static void eprint(const char *errstr, ...);
static void expose(XEvent *e);
static void focus(Client *c);
static void focusin(XEvent *e);
XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
XSync(dpy, False);
if(otherwm)
- eprint("dwm: another window manager is already running\n");
+ die("dwm: another window manager is already running\n");
XSetErrorHandler(NULL);
xerrorxlib = XSetErrorHandler(xerror);
XSync(dpy, False);
void
detach(Client *c) {
- Client *i;
+ Client **tc;
- if (c != clients) {
- for(i = clients; i->next != c; i = i->next);
- i->next = c->next;
- }
- else {
- clients = c->next;
- }
- c->next = NULL;
+ for(tc = &clients; *tc && *tc != c; tc = &(*tc)->next);
+ *tc = c->next;
}
void
*tc = c->snext;
}
+void
+die(const char *errstr, ...) {
+ va_list ap;
+
+ va_start(ap, errstr);
+ vfprintf(stderr, errstr, ap);
+ va_end(ap);
+ exit(EXIT_FAILURE);
+}
+
void
drawbar(void) {
int i, x;
focus(NULL);
}
-void
-eprint(const char *errstr, ...) {
- va_list ap;
-
- va_start(ap, errstr);
- vfprintf(stderr, errstr, ap);
- va_end(ap);
- exit(EXIT_FAILURE);
-}
-
void
expose(XEvent *e) {
XExposeEvent *ev = &e->xexpose;
XColor color;
if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
- eprint("error, cannot allocate color '%s'\n", colstr);
+ die("error, cannot allocate color '%s'\n", colstr);
return color.pixel;
}
void
grabbuttons(Client *c, Bool focused) {
- int i, j;
- uint buttons[] = { Button1, Button2, Button3 };
- uint modifiers[] = { MODKEY, MODKEY|LockMask, MODKEY|numlockmask, MODKEY|numlockmask|LockMask };
+ uint i, j;
+ uint modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
- if(focused)
+ if(focused) {
for(i = 0; i < LENGTH(buttons); i++)
- for(j = 0; j < LENGTH(modifiers); j++)
- XGrabButton(dpy, buttons[i], modifiers[j], c->win, False,
- BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
- else
+ if(buttons[i].click == ClkClientWin)
+ for(j = 0; j < LENGTH(modifiers); j++)
+ XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
+ } else
XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
- BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
+ BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
}
void
dc.font.xfont = NULL;
if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
&& !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
- eprint("error, cannot load font: '%s'\n", fontstr);
+ die("error, cannot load font: '%s'\n", fontstr);
dc.font.ascent = dc.font.xfont->ascent;
dc.font.descent = dc.font.xfont->descent;
}
XWindowChanges wc;
if(!(c = calloc(1, sizeof(Client))))
- eprint("fatal: could not calloc() %u bytes\n", sizeof(Client));
+ die("fatal: could not calloc() %u bytes\n", sizeof(Client));
c->win = w;
/* geometry */
if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
if(errno == EINTR)
continue;
- eprint("select failed\n");
+ die("select failed\n");
}
if(FD_ISSET(STDIN_FILENO, &rd)) {
switch((r = read(STDIN_FILENO, sbuf + offset, len - offset))) {
void
view(const Arg *arg) {
+ if(arg && (arg->i & TAGMASK) == tagset[seltags])
+ return;
seltags ^= 1; /* toggle sel tagset */
if(arg && (arg->ui & TAGMASK))
tagset[seltags] = arg->i & TAGMASK;
int
main(int argc, char *argv[]) {
if(argc == 2 && !strcmp("-v", argv[1]))
- eprint("dwm-"VERSION", © 2006-2008 dwm engineers, see LICENSE for details\n");
+ die("dwm-"VERSION", © 2006-2008 dwm engineers, see LICENSE for details\n");
else if(argc != 1)
- eprint("usage: dwm [-v]\n");
+ die("usage: dwm [-v]\n");
if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
fprintf(stderr, "warning: no locale support\n");
if(!(dpy = XOpenDisplay(0)))
- eprint("dwm: cannot open display\n");
+ die("dwm: cannot open display\n");
checkotherwm();
setup();