JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
simplified detach()
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 188e445..3d9a063 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -459,16 +459,10 @@ destroynotify(XEvent *e) {
 
 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
@@ -723,19 +717,18 @@ gettextprop(Window w, Atom atom, char *text, uint size) {
 
 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
@@ -962,7 +955,7 @@ monocle(void) {
        Client *c;
 
        for(c = nexttiled(clients); c; c = nexttiled(c->next))
-               resize(c, wx, wy, ww, wh, resizehints);
+               resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints);
 }
 
 void
@@ -1643,6 +1636,8 @@ updatewmhints(Client *c) {
 
 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;
@@ -1704,7 +1699,9 @@ main(int argc, char *argv[]) {
        else if(argc != 1)
                eprint("usage: dwm [-v]\n");
 
-       setlocale(LC_CTYPE, "");
+       if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
+               fprintf(stderr, "warning: no locale support\n");
+
        if(!(dpy = XOpenDisplay(0)))
                eprint("dwm: cannot open display\n");