dwm

my fork of dwm
Index Commits Files Refs README LICENSE
commit 3aad92202d58208c4197857d3f17c535ba0bd56a
parent efa7e514012865fcb3e9ea6e7d5b5c87d84353e5
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Thu, 13 Jul 2006 19:55:07 +0200

new stuff

Diffstat:
Mclient.c | 122++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Mconfig.mk | 2+-
Mdev.c | 12++++++------
Mdwm.h | 24++++++++++++++++--------
Mmain.c | 4++--
5 files changed, 103 insertions(+), 61 deletions(-)
diff --git a/client.c b/client.c
@@ -3,21 +3,19 @@
  * See LICENSE file for license details.
  */
 
-#include <math.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
 #include <X11/Xatom.h>
 #include <X11/Xutil.h>
 
 #include "dwm.h"
 
-static void (*arrange)(Arg *) = floating;
+static void (*arrange)(Arg *) = tiling;
 
-static void
-center(Client *c)
-{
-    XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
-}
+static Rule rule[] = {
+    { "Firefox-bin", "Gecko", { [Twww] = "www" } },
+};
 
 static Client *
 next(Client *c)
@@ -29,18 +27,18 @@ next(Client *c)
 void
 zoom(Arg *arg)
 {
-    Client **l;
+    Client **l, *old;
 
-    if(!sel)
+    if(!(old = sel))
         return;
 
     for(l = &clients; *l && *l != sel; l = &(*l)->next);
     *l = sel->next;
 
-    sel->next = clients; /* pop */
-    clients = sel;
+    old->next = clients; /* pop */
+    clients = old;
+    sel = old;
     arrange(NULL);
-    center(sel);
     focus(sel);
 }
 
@@ -119,39 +117,38 @@ void
 tiling(Arg *arg)
 {
     Client *c;
-    int n, cols, rows, gw, gh, i, j;
-    float rt, fd;
+    int n, i, w, h;
 
+    w = sw - mw;
     arrange = tiling;
-    for(n = 0, c = clients; c; c = next(c->next), n++);
-    if(n) {
-        rt = sqrt(n);
-        if(modff(rt, &fd) < 0.5)
-            rows = floor(rt);
-        else
-            rows = ceil(rt);
-        if(rows * rows < n)
-            cols = rows + 1;
-        else
-            cols = rows;
+    for(n = 0, c = clients; c; c = c->next)
+        if(c->tags[tsel])
+            n++;
 
-        gw = (sw - 2)  / cols;
-        gh = (sh - 2) / rows;
-    }
-    else
-        cols = rows = gw = gh = 0;
+    h = (n > 2) ? sh / (n - 2) : sh;
 
-    for(i = j = 0, c = clients; c; c = c->next) {
+    for(i = 0, c = clients; c; c = c->next) {
         if(c->tags[tsel]) {
-            c->x = i * gw;
-            c->y = j * gh;
-            c->w = gw;
-            c->h = gh;
-            resize(c);
-            if(++i == cols) {
-                j++;
-                i = 0;
+            if(n == 1) {
+                c->x = sx;
+                c->y = sy;
+                c->w = sw;
+                c->h = sh;
             }
+            else if(i == 1) {
+                c->x = sx;
+                c->y = sy;
+                c->w = mw;
+                c->h = sh;
+            }
+            else {
+                c->x = sx + mw;
+                c->y = sy + (i - 2) * h;
+                c->w = w;
+                c->h = h;
+            }
+            resize(c);
+            i++;
         }
         else
             ban_client(c);
@@ -175,7 +172,6 @@ prevc(Arg *arg)
 
     if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
         craise(c);
-        center(c);
         focus(c);
     }
 }
@@ -192,7 +188,6 @@ nextc(Arg *arg)
         c = next(clients);
     if(c) {
         craise(c);
-        center(c);
         c->revert = sel;
         focus(c);
     }
@@ -323,6 +318,43 @@ focus(Client *c)
     discard_events(EnterWindowMask);
 }
 
+static void
+init_tags(Client *c)
+{
+    XClassHint ch;
+    static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
+    unsigned int i, j;
+    Bool matched = False;
+
+    if(!len) {
+        c->tags[tsel] = tags[tsel];
+        return;
+    }
+
+    if(XGetClassHint(dpy, c->win, &ch)) {
+        if(ch.res_class && ch.res_name) {
+            fprintf(stderr, "%s:%s\n", ch.res_class, ch.res_name);
+            for(i = 0; i < len; i++)
+                if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
+                    && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
+                {
+            fprintf(stderr, "->>>%s:%s\n", ch.res_class, ch.res_name);
+                    for(j = 0; j < TLast; j++)
+                        c->tags[j] = rule[i].tags[j];
+                    matched = True;
+                    break;
+                }
+        }
+        if(ch.res_class)
+            XFree(ch.res_class);
+        if(ch.res_name)
+            XFree(ch.res_name);
+    }
+
+    if(!matched)
+        c->tags[tsel] = tags[tsel];
+}
+
 void
 manage(Window w, XWindowAttributes *wa)
 {
@@ -346,13 +378,13 @@ manage(Window w, XWindowAttributes *wa)
     twa.background_pixmap = ParentRelative;
     twa.event_mask = ExposureMask;
 
-    c->tags[tsel] = tags[tsel];
     c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
             0, DefaultDepth(dpy, screen), CopyFromParent,
             DefaultVisual(dpy, screen),
             CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
 
     update_name(c);
+    init_tags(c);
 
     for(l = &clients; *l; l = &(*l)->next);
     c->next = *l; /* *l == nil */
@@ -368,8 +400,10 @@ manage(Window w, XWindowAttributes *wa)
     XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
             GrabModeAsync, GrabModeSync, None, None);
     arrange(NULL);
-    center(c);
-    focus(c);
+    if(c->tags[tsel])
+        focus(c);
+    else
+        ban_client(c);
 }
 
 void
diff --git a/config.mk b/config.mk
@@ -11,7 +11,7 @@ X11LIB = /usr/X11R6/lib
 VERSION = 0.0
 
 # includes and libs
-LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11
+LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11
 
 # Linux/BSD
 CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
diff --git a/dev.c b/dev.c
@@ -20,8 +20,7 @@ const char *browse[] = { "firefox", NULL };
 const char *xlock[] = { "xlock", NULL };
 
 static Key key[] = {
-    { Mod1Mask, XK_Return, zoom, { 0 } },
-    { Mod1Mask, XK_t, spawn, { .argv = term } },
+    { Mod1Mask, XK_Return, spawn, { .argv = term } },
     { Mod1Mask, XK_w, spawn, { .argv = browse } },
     { Mod1Mask, XK_l, spawn, { .argv = xlock } },
     { Mod1Mask, XK_k, prevc, { 0 } },
@@ -33,6 +32,7 @@ static Key key[] = {
     { Mod1Mask, XK_3, view, { .i = Twww } }, 
     { Mod1Mask, XK_4, view, { .i = Twork } }, 
     { Mod1Mask, XK_space, tiling, { 0 } }, 
+    { Mod1Mask | ShiftMask, XK_Return, zoom, { 0 } },
     { Mod1Mask | ShiftMask, XK_space, floating, { 0 } }, 
     { Mod1Mask | ShiftMask, XK_0, tag, { .i = Tscratch } }, 
     { Mod1Mask | ShiftMask, XK_1, tag, { .i = Tdev } }, 
@@ -48,10 +48,10 @@ static Key key[] = {
 void
 update_keys(void)
 {
-    unsigned int i, len;
+    static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
+    unsigned int i;
     KeyCode code;
 
-    len = sizeof(key) / sizeof(key[0]);
     for(i = 0; i < len; i++) {
         code = XKeysymToKeycode(dpy, key[i].keysym);
         XUngrabKey(dpy, code, key[i].mod, root);
@@ -63,11 +63,11 @@ void
 keypress(XEvent *e)
 {
     XKeyEvent *ev = &e->xkey;
-    unsigned int i, len;
+    static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
+    unsigned int i;
     KeySym keysym;
 
     keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
-    len = sizeof(key) / sizeof(key[0]);
     for(i = 0; i < len; i++)
         if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
             if(key[i].func)
diff --git a/dwm.h b/dwm.h
@@ -7,22 +7,24 @@
 
 /********** CUSTOMIZE **********/
 
-#define FONT        "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
-#define BGCOLOR        "DarkSlateGrey"
-#define FGCOLOR        "LightSteelBlue"
-#define BORDERCOLOR    "SlateGray"
-#define WM_PROTOCOL_DELWIN 1
+#define FONT                "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
+#define BGCOLOR                "#666699"
+#define FGCOLOR                "#ffffff"
+#define BORDERCOLOR            "#9999CC"
+#define MASTERW                52 /* percent */
+#define WM_PROTOCOL_DELWIN    1
 
 /* tags */
 enum { Tscratch, Tdev, Tirc, Twww, Twork, TLast };
 
 /********** CUSTOMIZE **********/
 
+typedef union Arg Arg;
 typedef struct DC DC;
 typedef struct Client Client;
 typedef struct Fnt Fnt;
 typedef struct Key Key;
-typedef union Arg Arg;
+typedef struct Rule Rule;
 
 union Arg {
     const char **argv;
@@ -71,6 +73,12 @@ struct Client {
     Client *revert;
 };
 
+struct Rule {
+    const char *class;
+    const char *instance;
+    char *tags[TLast];
+};
+
 struct Key {
     unsigned long mod;
     KeySym keysym;
@@ -85,8 +93,8 @@ extern Cursor cursor[CurLast];
 extern Bool running, issel;
 extern void (*handler[LASTEvent]) (XEvent *);
 
-extern int tsel, screen, sx, sy, sw, sh, th;
-extern char stext[1024], *tags[TLast];
+extern int tsel, screen, sx, sy, sw, sh, mw, th;
+extern char *tags[TLast];
 
 extern DC dc;
 extern Client *clients, *sel;
diff --git a/main.c b/main.c
@@ -33,9 +33,8 @@ Cursor cursor[CurLast];
 Bool running = True;
 Bool issel;
 
-char stext[1024];
 int tsel = Tdev; /* default tag */
-int screen, sx, sy, sw, sh, th;
+int screen, sx, sy, sw, sh, mw, th;
 
 DC dc = {0};
 Client *clients = NULL;
@@ -223,6 +222,7 @@ main(int argc, char *argv[])
     sx = sy = 0;
     sw = DisplayWidth(dpy, screen);
     sh = DisplayHeight(dpy, screen);
+    mw = (sw * MASTERW) / 100;
     issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
 
     XSetErrorHandler(0);