aewl

changeset 51:035617ee18d1

new stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 19:55:07 +0200
parents 148f25ed0ad7
children d18f6dd0cf23
files client.c config.mk dev.c dwm.h main.c
diffstat 5 files changed, 103 insertions(+), 61 deletions(-) [+]
line diff
     1.1 --- a/client.c	Thu Jul 13 18:21:38 2006 +0200
     1.2 +++ b/client.c	Thu Jul 13 19:55:07 2006 +0200
     1.3 @@ -3,21 +3,19 @@
     1.4   * See LICENSE file for license details.
     1.5   */
     1.6  
     1.7 -#include <math.h>
     1.8  #include <stdlib.h>
     1.9 +#include <stdio.h>
    1.10  #include <string.h>
    1.11  #include <X11/Xatom.h>
    1.12  #include <X11/Xutil.h>
    1.13  
    1.14  #include "dwm.h"
    1.15  
    1.16 -static void (*arrange)(Arg *) = floating;
    1.17 +static void (*arrange)(Arg *) = tiling;
    1.18  
    1.19 -static void
    1.20 -center(Client *c)
    1.21 -{
    1.22 -	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
    1.23 -}
    1.24 +static Rule rule[] = {
    1.25 +	{ "Firefox-bin", "Gecko", { [Twww] = "www" } },
    1.26 +};
    1.27  
    1.28  static Client *
    1.29  next(Client *c)
    1.30 @@ -29,18 +27,18 @@
    1.31  void
    1.32  zoom(Arg *arg)
    1.33  {
    1.34 -	Client **l;
    1.35 +	Client **l, *old;
    1.36  
    1.37 -	if(!sel)
    1.38 +	if(!(old = sel))
    1.39  		return;
    1.40  
    1.41  	for(l = &clients; *l && *l != sel; l = &(*l)->next);
    1.42  	*l = sel->next;
    1.43  
    1.44 -	sel->next = clients; /* pop */
    1.45 -	clients = sel;
    1.46 +	old->next = clients; /* pop */
    1.47 +	clients = old;
    1.48 +	sel = old;
    1.49  	arrange(NULL);
    1.50 -	center(sel);
    1.51  	focus(sel);
    1.52  }
    1.53  
    1.54 @@ -119,39 +117,38 @@
    1.55  tiling(Arg *arg)
    1.56  {
    1.57  	Client *c;
    1.58 -	int n, cols, rows, gw, gh, i, j;
    1.59 -    float rt, fd;
    1.60 +	int n, i, w, h;
    1.61  
    1.62 +	w = sw - mw;
    1.63  	arrange = tiling;
    1.64 -	for(n = 0, c = clients; c; c = next(c->next), n++);
    1.65 -	if(n) {
    1.66 -		rt = sqrt(n);
    1.67 -		if(modff(rt, &fd) < 0.5)
    1.68 -			rows = floor(rt);
    1.69 -		else
    1.70 -			rows = ceil(rt);
    1.71 -		if(rows * rows < n)
    1.72 -			cols = rows + 1;
    1.73 -		else
    1.74 -			cols = rows;
    1.75 +	for(n = 0, c = clients; c; c = c->next)
    1.76 +		if(c->tags[tsel])
    1.77 +			n++;
    1.78  
    1.79 -		gw = (sw - 2)  / cols;
    1.80 -		gh = (sh - 2) / rows;
    1.81 -	}
    1.82 -	else
    1.83 -		cols = rows = gw = gh = 0;
    1.84 +	h = (n > 2) ? sh / (n - 2) : sh;
    1.85  
    1.86 -	for(i = j = 0, c = clients; c; c = c->next) {
    1.87 +	for(i = 0, c = clients; c; c = c->next) {
    1.88  		if(c->tags[tsel]) {
    1.89 -			c->x = i * gw;
    1.90 -			c->y = j * gh;
    1.91 -			c->w = gw;
    1.92 -			c->h = gh;
    1.93 +			if(n == 1) {
    1.94 +				c->x = sx;
    1.95 +				c->y = sy;
    1.96 +				c->w = sw;
    1.97 +				c->h = sh;
    1.98 +			}
    1.99 +			else if(i == 1) {
   1.100 +				c->x = sx;
   1.101 +				c->y = sy;
   1.102 +				c->w = mw;
   1.103 +				c->h = sh;
   1.104 +			}
   1.105 +			else {
   1.106 +				c->x = sx + mw;
   1.107 +				c->y = sy + (i - 2) * h;
   1.108 +				c->w = w;
   1.109 +				c->h = h;
   1.110 +			}
   1.111  			resize(c);
   1.112 -			if(++i == cols) {
   1.113 -				j++;
   1.114 -				i = 0;
   1.115 -			}
   1.116 +			i++;
   1.117  		}
   1.118  		else
   1.119  			ban_client(c);
   1.120 @@ -175,7 +172,6 @@
   1.121  
   1.122  	if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
   1.123  		craise(c);
   1.124 -		center(c);
   1.125  		focus(c);
   1.126  	}
   1.127  }
   1.128 @@ -192,7 +188,6 @@
   1.129  		c = next(clients);
   1.130  	if(c) {
   1.131  		craise(c);
   1.132 -		center(c);
   1.133  		c->revert = sel;
   1.134  		focus(c);
   1.135  	}
   1.136 @@ -323,6 +318,43 @@
   1.137  	discard_events(EnterWindowMask);
   1.138  }
   1.139  
   1.140 +static void
   1.141 +init_tags(Client *c)
   1.142 +{
   1.143 +	XClassHint ch;
   1.144 +	static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
   1.145 +	unsigned int i, j;
   1.146 +	Bool matched = False;
   1.147 +
   1.148 +	if(!len) {
   1.149 +		c->tags[tsel] = tags[tsel];
   1.150 +		return;
   1.151 +	}
   1.152 +
   1.153 +	if(XGetClassHint(dpy, c->win, &ch)) {
   1.154 +		if(ch.res_class && ch.res_name) {
   1.155 +			fprintf(stderr, "%s:%s\n", ch.res_class, ch.res_name);
   1.156 +			for(i = 0; i < len; i++)
   1.157 +				if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
   1.158 +					&& !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
   1.159 +				{
   1.160 +			fprintf(stderr, "->>>%s:%s\n", ch.res_class, ch.res_name);
   1.161 +					for(j = 0; j < TLast; j++)
   1.162 +						c->tags[j] = rule[i].tags[j];
   1.163 +					matched = True;
   1.164 +					break;
   1.165 +				}
   1.166 +		}
   1.167 +		if(ch.res_class)
   1.168 +			XFree(ch.res_class);
   1.169 +		if(ch.res_name)
   1.170 +			XFree(ch.res_name);
   1.171 +	}
   1.172 +
   1.173 +	if(!matched)
   1.174 +		c->tags[tsel] = tags[tsel];
   1.175 +}
   1.176 +
   1.177  void
   1.178  manage(Window w, XWindowAttributes *wa)
   1.179  {
   1.180 @@ -346,13 +378,13 @@
   1.181  	twa.background_pixmap = ParentRelative;
   1.182  	twa.event_mask = ExposureMask;
   1.183  
   1.184 -	c->tags[tsel] = tags[tsel];
   1.185  	c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
   1.186  			0, DefaultDepth(dpy, screen), CopyFromParent,
   1.187  			DefaultVisual(dpy, screen),
   1.188  			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
   1.189  
   1.190  	update_name(c);
   1.191 +	init_tags(c);
   1.192  
   1.193  	for(l = &clients; *l; l = &(*l)->next);
   1.194  	c->next = *l; /* *l == nil */
   1.195 @@ -368,8 +400,10 @@
   1.196  	XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
   1.197  			GrabModeAsync, GrabModeSync, None, None);
   1.198  	arrange(NULL);
   1.199 -	center(c);
   1.200 -	focus(c);
   1.201 +	if(c->tags[tsel])
   1.202 +		focus(c);
   1.203 +	else
   1.204 +		ban_client(c);
   1.205  }
   1.206  
   1.207  void
     2.1 --- a/config.mk	Thu Jul 13 18:21:38 2006 +0200
     2.2 +++ b/config.mk	Thu Jul 13 19:55:07 2006 +0200
     2.3 @@ -11,7 +11,7 @@
     2.4  VERSION = 0.0
     2.5  
     2.6  # includes and libs
     2.7 -LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11
     2.8 +LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11
     2.9  
    2.10  # Linux/BSD
    2.11  CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
     3.1 --- a/dev.c	Thu Jul 13 18:21:38 2006 +0200
     3.2 +++ b/dev.c	Thu Jul 13 19:55:07 2006 +0200
     3.3 @@ -20,8 +20,7 @@
     3.4  const char *xlock[] = { "xlock", NULL };
     3.5  
     3.6  static Key key[] = {
     3.7 -	{ Mod1Mask, XK_Return, zoom, { 0 } },
     3.8 -	{ Mod1Mask, XK_t, spawn, { .argv = term } },
     3.9 +	{ Mod1Mask, XK_Return, spawn, { .argv = term } },
    3.10  	{ Mod1Mask, XK_w, spawn, { .argv = browse } },
    3.11  	{ Mod1Mask, XK_l, spawn, { .argv = xlock } },
    3.12  	{ Mod1Mask, XK_k, prevc, { 0 } },
    3.13 @@ -33,6 +32,7 @@
    3.14  	{ Mod1Mask, XK_3, view, { .i = Twww } }, 
    3.15  	{ Mod1Mask, XK_4, view, { .i = Twork } }, 
    3.16  	{ Mod1Mask, XK_space, tiling, { 0 } }, 
    3.17 +	{ Mod1Mask | ShiftMask, XK_Return, zoom, { 0 } },
    3.18  	{ Mod1Mask | ShiftMask, XK_space, floating, { 0 } }, 
    3.19  	{ Mod1Mask | ShiftMask, XK_0, tag, { .i = Tscratch } }, 
    3.20  	{ Mod1Mask | ShiftMask, XK_1, tag, { .i = Tdev } }, 
    3.21 @@ -48,10 +48,10 @@
    3.22  void
    3.23  update_keys(void)
    3.24  {
    3.25 -	unsigned int i, len;
    3.26 +	static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
    3.27 +	unsigned int i;
    3.28  	KeyCode code;
    3.29  
    3.30 -	len = sizeof(key) / sizeof(key[0]);
    3.31  	for(i = 0; i < len; i++) {
    3.32  		code = XKeysymToKeycode(dpy, key[i].keysym);
    3.33  		XUngrabKey(dpy, code, key[i].mod, root);
    3.34 @@ -63,11 +63,11 @@
    3.35  keypress(XEvent *e)
    3.36  {
    3.37  	XKeyEvent *ev = &e->xkey;
    3.38 -	unsigned int i, len;
    3.39 +	static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
    3.40 +	unsigned int i;
    3.41  	KeySym keysym;
    3.42  
    3.43  	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
    3.44 -	len = sizeof(key) / sizeof(key[0]);
    3.45  	for(i = 0; i < len; i++)
    3.46  		if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
    3.47  			if(key[i].func)
     4.1 --- a/dwm.h	Thu Jul 13 18:21:38 2006 +0200
     4.2 +++ b/dwm.h	Thu Jul 13 19:55:07 2006 +0200
     4.3 @@ -7,22 +7,24 @@
     4.4  
     4.5  /********** CUSTOMIZE **********/
     4.6  
     4.7 -#define FONT		"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
     4.8 -#define BGCOLOR		"DarkSlateGrey"
     4.9 -#define FGCOLOR		"LightSteelBlue"
    4.10 -#define BORDERCOLOR	"SlateGray"
    4.11 -#define WM_PROTOCOL_DELWIN 1
    4.12 +#define FONT				"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
    4.13 +#define BGCOLOR				"#666699"
    4.14 +#define FGCOLOR				"#ffffff"
    4.15 +#define BORDERCOLOR			"#9999CC"
    4.16 +#define MASTERW				52 /* percent */
    4.17 +#define WM_PROTOCOL_DELWIN	1
    4.18  
    4.19  /* tags */
    4.20  enum { Tscratch, Tdev, Tirc, Twww, Twork, TLast };
    4.21  
    4.22  /********** CUSTOMIZE **********/
    4.23  
    4.24 +typedef union Arg Arg;
    4.25  typedef struct DC DC;
    4.26  typedef struct Client Client;
    4.27  typedef struct Fnt Fnt;
    4.28  typedef struct Key Key;
    4.29 -typedef union Arg Arg;
    4.30 +typedef struct Rule Rule;
    4.31  
    4.32  union Arg {
    4.33  	const char **argv;
    4.34 @@ -71,6 +73,12 @@
    4.35  	Client *revert;
    4.36  };
    4.37  
    4.38 +struct Rule {
    4.39 +	const char *class;
    4.40 +	const char *instance;
    4.41 +	char *tags[TLast];
    4.42 +};
    4.43 +
    4.44  struct Key {
    4.45  	unsigned long mod;
    4.46  	KeySym keysym;
    4.47 @@ -85,8 +93,8 @@
    4.48  extern Bool running, issel;
    4.49  extern void (*handler[LASTEvent]) (XEvent *);
    4.50  
    4.51 -extern int tsel, screen, sx, sy, sw, sh, th;
    4.52 -extern char stext[1024], *tags[TLast];
    4.53 +extern int tsel, screen, sx, sy, sw, sh, mw, th;
    4.54 +extern char *tags[TLast];
    4.55  
    4.56  extern DC dc;
    4.57  extern Client *clients, *sel;
     5.1 --- a/main.c	Thu Jul 13 18:21:38 2006 +0200
     5.2 +++ b/main.c	Thu Jul 13 19:55:07 2006 +0200
     5.3 @@ -33,9 +33,8 @@
     5.4  Bool running = True;
     5.5  Bool issel;
     5.6  
     5.7 -char stext[1024];
     5.8  int tsel = Tdev; /* default tag */
     5.9 -int screen, sx, sy, sw, sh, th;
    5.10 +int screen, sx, sy, sw, sh, mw, th;
    5.11  
    5.12  DC dc = {0};
    5.13  Client *clients = NULL;
    5.14 @@ -223,6 +222,7 @@
    5.15  	sx = sy = 0;
    5.16  	sw = DisplayWidth(dpy, screen);
    5.17  	sh = DisplayHeight(dpy, screen);
    5.18 +	mw = (sw * MASTERW) / 100;
    5.19  	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
    5.20  
    5.21  	XSetErrorHandler(0);