dwm-meillo

changeset 5:e5018cae273f

added several other stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Mon, 10 Jul 2006 22:16:48 +0200
parents 991bd8b0771e
children e0cefb3981c8
files Makefile bar.c client.c config.h draw.c draw.h event.c menu.c util.c util.h wm.c wm.h
diffstat 12 files changed, 476 insertions(+), 39 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Mon Jul 10 19:47:35 2006 +0200
     1.2 +++ b/Makefile	Mon Jul 10 22:16:48 2006 +0200
     1.3 @@ -3,11 +3,11 @@
     1.4  
     1.5  include config.mk
     1.6  
     1.7 -WMSRC = wm.c draw.c util.c
     1.8 +WMSRC = bar.c client.c draw.c event.c util.c wm.c
     1.9  WMOBJ = ${WMSRC:.c=.o}
    1.10  MENSRC = menu.c draw.c util.c
    1.11  MENOBJ = ${MENSRC:.c=.o}
    1.12 -MAN = gridwm.1
    1.13 +MAN1 = gridwm.1 gridmenu.1
    1.14  BIN = gridwm gridmenu     
    1.15  
    1.16  all: config gridwm gridmenu
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/bar.c	Mon Jul 10 22:16:48 2006 +0200
     2.3 @@ -0,0 +1,18 @@
     2.4 +/*
     2.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     2.6 + * See LICENSE file for license details.
     2.7 + */
     2.8 +
     2.9 +#include "wm.h"
    2.10 +
    2.11 +void
    2.12 +draw_bar()
    2.13 +{
    2.14 +	brush.rect = barrect;
    2.15 +	brush.rect.x = brush.rect.y = 0;
    2.16 +	draw(dpy, &brush, False, 0);
    2.17 +
    2.18 +	XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width,
    2.19 +			barrect.height, 0, 0);
    2.20 +	XFlush(dpy);
    2.21 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/client.c	Mon Jul 10 22:16:48 2006 +0200
     3.3 @@ -0,0 +1,89 @@
     3.4 +/*
     3.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     3.6 + * See LICENSE file for license details.
     3.7 + */
     3.8 +
     3.9 +#include <string.h>
    3.10 +#include <X11/Xatom.h>
    3.11 +
    3.12 +#include "util.h"
    3.13 +#include "wm.h"
    3.14 +
    3.15 +static void
    3.16 +update_client_name(Client *c)
    3.17 +{
    3.18 +	XTextProperty name;
    3.19 +	int n;
    3.20 +	char **list = 0;
    3.21 +
    3.22 +	name.nitems = 0;
    3.23 +	c->name[0] = 0;
    3.24 +	XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
    3.25 +	if(!name.nitems)
    3.26 +		XGetWMName(dpy, c->win, &name);
    3.27 +	if(!name.nitems)
    3.28 +		return;
    3.29 +	if(name.encoding == XA_STRING)
    3.30 +		strncpy(c->name, (char *)name.value, sizeof(c->name));
    3.31 +	else {
    3.32 +		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
    3.33 +				&& n > 0 && *list)
    3.34 +		{
    3.35 +			strncpy(c->name, *list, sizeof(c->name));
    3.36 +			XFreeStringList(list);
    3.37 +		}
    3.38 +	}
    3.39 +	XFree(name.value);
    3.40 +}
    3.41 +
    3.42 +Client *
    3.43 +create_client(Window w, XWindowAttributes *wa)
    3.44 +{
    3.45 +	Client *c;
    3.46 +	XSetWindowAttributes twa;
    3.47 +	long msize;
    3.48 +
    3.49 +	c = emallocz(sizeof(Client));
    3.50 +	c->win = w;
    3.51 +	c->r[RFloat].x = wa->x;
    3.52 +	c->r[RFloat].y = wa->y;
    3.53 +	c->r[RFloat].width = wa->width;
    3.54 +	c->r[RFloat].height = wa->height;
    3.55 +	c->border = wa->border_width;
    3.56 +	XSetWindowBorderWidth(dpy, c->win, 0);
    3.57 +	c->proto = win_proto(c->win);
    3.58 +	XGetTransientForHint(dpy, c->win, &c->trans);
    3.59 +	if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
    3.60 +		c->size.flags = PSize;
    3.61 +	c->fixedsize =
    3.62 +		(c->size.flags & PMinSize && c->size.flags & PMaxSize
    3.63 +		 && c->size.min_width == c->size.max_width
    3.64 +		 && c->size.min_height == c->size.max_height);
    3.65 +	XAddToSaveSet(dpy, c->win);
    3.66 +	update_client_name(c);
    3.67 +	twa.override_redirect = 1;
    3.68 +	twa.background_pixmap = ParentRelative;
    3.69 +	twa.event_mask = ExposureMask;
    3.70 +
    3.71 +	c->title = XCreateWindow(dpy, root, c->r[RFloat].x, c->r[RFloat].y,
    3.72 +			c->r[RFloat].width, barrect.height, 0,
    3.73 +			DefaultDepth(dpy, screen), CopyFromParent,
    3.74 +			DefaultVisual(dpy, screen),
    3.75 +			CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
    3.76 +	XFlush(dpy);
    3.77 +
    3.78 +#if 0
    3.79 +	for(t=&client, i=0; *t; t=&(*t)->next, i++);
    3.80 +	c->next = *t; /* *t == nil */
    3.81 +	*t = c;
    3.82 +#endif
    3.83 +	return c;
    3.84 +}
    3.85 +
    3.86 +void
    3.87 +manage(Client *c)
    3.88 +{
    3.89 +	XMapRaised(dpy, c->win);
    3.90 +	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    3.91 +	XFlush(dpy);
    3.92 +}
     4.1 --- a/config.h	Mon Jul 10 19:47:35 2006 +0200
     4.2 +++ b/config.h	Mon Jul 10 22:16:48 2006 +0200
     4.3 @@ -4,6 +4,6 @@
     4.4   */
     4.5  
     4.6  #define FONT		"-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*"
     4.7 -#define FGCOLOR		"#000000"
     4.8 -#define BGCOLOR		"#ffaa00"
     4.9 +#define BGCOLOR		"#000000"
    4.10 +#define FGCOLOR		"#ffaa00"
    4.11  #define BORDERCOLOR	"#000000"
     5.1 --- a/draw.c	Mon Jul 10 19:47:35 2006 +0200
     5.2 +++ b/draw.c	Mon Jul 10 22:16:48 2006 +0200
     5.3 @@ -162,3 +162,9 @@
     5.4  	}
     5.5  	font->height = font->ascent + font->descent;
     5.6  }
     5.7 +
     5.8 +unsigned int
     5.9 +labelheight(Fnt *font)
    5.10 +{
    5.11 +	return font->height + 4;
    5.12 +}
     6.1 --- a/draw.h	Mon Jul 10 19:47:35 2006 +0200
     6.2 +++ b/draw.h	Mon Jul 10 22:16:48 2006 +0200
     6.3 @@ -33,3 +33,4 @@
     6.4  extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
     6.5  extern unsigned int textwidth_l(Fnt *font, char *text, unsigned int len);
     6.6  extern unsigned int textwidth(Fnt *font, char *text);
     6.7 +extern unsigned int labelheight(Fnt *font);
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/event.c	Mon Jul 10 22:16:48 2006 +0200
     7.3 @@ -0,0 +1,264 @@
     7.4 +/*
     7.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     7.6 + * See LICENSE file for license details.
     7.7 + */
     7.8 +
     7.9 +#include <fcntl.h>
    7.10 +#include <stdlib.h>
    7.11 +#include <string.h>
    7.12 +#include <X11/keysym.h>
    7.13 +
    7.14 +#include "wm.h"
    7.15 +
    7.16 +/* local functions */
    7.17 +static void configurerequest(XEvent *e);
    7.18 +static void destroynotify(XEvent *e);
    7.19 +static void enternotify(XEvent *e);
    7.20 +static void leavenotify(XEvent *e);
    7.21 +static void expose(XEvent *e);
    7.22 +static void keypress(XEvent *e);
    7.23 +static void keymapnotify(XEvent *e);
    7.24 +static void maprequest(XEvent *e);
    7.25 +static void propertynotify(XEvent *e);
    7.26 +static void unmapnotify(XEvent *e);
    7.27 +
    7.28 +void (*handler[LASTEvent]) (XEvent *) = {
    7.29 +	[ConfigureRequest] = configurerequest,
    7.30 +	[DestroyNotify] = destroynotify,
    7.31 +	[EnterNotify] = enternotify,
    7.32 +	[LeaveNotify] = leavenotify,
    7.33 +	[Expose] = expose,
    7.34 +	[KeyPress] = keypress,
    7.35 +	[KeymapNotify] = keymapnotify,
    7.36 +	[MapRequest] = maprequest,
    7.37 +	[PropertyNotify] = propertynotify,
    7.38 +	[UnmapNotify] = unmapnotify
    7.39 +};
    7.40 +
    7.41 +unsigned int
    7.42 +flush_masked_events(long even_mask)
    7.43 +{
    7.44 +	XEvent ev;
    7.45 +	unsigned int n = 0;
    7.46 +	while(XCheckMaskEvent(dpy, even_mask, &ev)) n++;
    7.47 +	return n;
    7.48 +}
    7.49 +
    7.50 +static void
    7.51 +configurerequest(XEvent *e)
    7.52 +{
    7.53 +#if 0
    7.54 +	XConfigureRequestEvent *ev = &e->xconfigurerequest;
    7.55 +	XWindowChanges wc;
    7.56 +	XRectangle *frect;
    7.57 +	Client *c;
    7.58 +
    7.59 +	c = client_of_win(ev->window);
    7.60 +	ev->value_mask &= ~CWSibling;
    7.61 +	if(c) {
    7.62 +		gravitate_client(c, True);
    7.63 +
    7.64 +		if(ev->value_mask & CWX)
    7.65 +			c->rect.x = ev->x;
    7.66 +		if(ev->value_mask & CWY)
    7.67 +			c->rect.y = ev->y;
    7.68 +		if(ev->value_mask & CWWidth)
    7.69 +			c->rect.width = ev->width;
    7.70 +		if(ev->value_mask & CWHeight)
    7.71 +			c->rect.height = ev->height;
    7.72 +		if(ev->value_mask & CWBorderWidth)
    7.73 +			c->border = ev->border_width;
    7.74 +
    7.75 +		gravitate_client(c, False);
    7.76 +
    7.77 +		if(c->frame) {
    7.78 +			if(c->sel->area->floating)
    7.79 +				frect=&c->sel->rect;
    7.80 +			else
    7.81 +				frect=&c->sel->revert;
    7.82 +
    7.83 +			if(c->rect.width >= screen->rect.width && c->rect.height >= screen->rect.height) {
    7.84 +				frect->y = wc.y = -height_of_bar();
    7.85 +				frect->x = wc.x = -def.border;
    7.86 +			}
    7.87 +			else {
    7.88 +				frect->y = wc.y = c->rect.y - height_of_bar();
    7.89 +				frect->x = wc.x = c->rect.x - def.border;
    7.90 +			}
    7.91 +			frect->width = wc.width = c->rect.width + 2 * def.border;
    7.92 +			frect->height = wc.height = c->rect.height + def.border
    7.93 +				+ height_of_bar();
    7.94 +			wc.border_width = 1;
    7.95 +			wc.sibling = None;
    7.96 +			wc.stack_mode = ev->detail;
    7.97 +			if(c->sel->area->view != screen->sel)
    7.98 +				wc.x += 2 * screen->rect.width;
    7.99 +			if(c->sel->area->floating) {
   7.100 +				XConfigureWindow(dpy, c->framewin, ev->value_mask, &wc);
   7.101 +				configure_client(c);
   7.102 +			}
   7.103 +		}
   7.104 +	}
   7.105 +
   7.106 +	wc.x = ev->x;
   7.107 +	wc.y = ev->y;
   7.108 +	wc.width = ev->width;
   7.109 +	wc.height = ev->height;
   7.110 +
   7.111 +	if(c && c->frame) {
   7.112 +		wc.x = def.border;
   7.113 +		wc.y = height_of_bar();
   7.114 +		wc.width = c->sel->rect.width - 2 * def.border;
   7.115 +		wc.height = c->sel->rect.height - def.border - height_of_bar();
   7.116 +	}
   7.117 +
   7.118 +	wc.border_width = 0;
   7.119 +	wc.sibling = None;
   7.120 +	wc.stack_mode = Above;
   7.121 +	ev->value_mask &= ~CWStackMode;
   7.122 +	ev->value_mask |= CWBorderWidth;
   7.123 +	XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
   7.124 +
   7.125 +	XFlush(dpy);
   7.126 +#endif
   7.127 +}
   7.128 +
   7.129 +static void
   7.130 +destroynotify(XEvent *e)
   7.131 +{
   7.132 +#if 0
   7.133 +	Client *c;
   7.134 +	XDestroyWindowEvent *ev = &e->xdestroywindow;
   7.135 +
   7.136 +	if((c = client_of_win(ev->window)))
   7.137 +		destroy_client(c);
   7.138 +#endif
   7.139 +}
   7.140 +
   7.141 +static void
   7.142 +enternotify(XEvent *e)
   7.143 +{
   7.144 +#if 0
   7.145 +	XCrossingEvent *ev = &e->xcrossing;
   7.146 +	Client *c;
   7.147 +
   7.148 +	if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
   7.149 +		return;
   7.150 +
   7.151 +	if((c = client_of_win(ev->window))) {
   7.152 +		Frame *f = c->sel;
   7.153 +		Area *a = f->area;
   7.154 +		if(a->mode == Colmax)
   7.155 +			c = a->sel->client;
   7.156 +		focus(c, False);
   7.157 +	}
   7.158 +	else if(ev->window == root) {
   7.159 +		sel_screen = True;
   7.160 +		draw_frames();
   7.161 +	}
   7.162 +#endif
   7.163 +}
   7.164 +
   7.165 +static void
   7.166 +leavenotify(XEvent *e)
   7.167 +{
   7.168 +	XCrossingEvent *ev = &e->xcrossing;
   7.169 +
   7.170 +	if((ev->window == root) && !ev->same_screen) {
   7.171 +		sel_screen = True;
   7.172 +		/*draw_frames();*/
   7.173 +	}
   7.174 +}
   7.175 +
   7.176 +static void
   7.177 +expose(XEvent *e)
   7.178 +{
   7.179 +	XExposeEvent *ev = &e->xexpose;
   7.180 +
   7.181 +	if(ev->count == 0) {
   7.182 +		if(ev->window == barwin)
   7.183 +			draw_bar();
   7.184 +	}
   7.185 +}
   7.186 +
   7.187 +static void
   7.188 +keypress(XEvent *e)
   7.189 +{
   7.190 +#if 0
   7.191 +	XKeyEvent *ev = &e->xkey;
   7.192 +	KeySym k = 0;
   7.193 +	char buf[32];
   7.194 +	int n;
   7.195 +	static Frame *f;
   7.196 +
   7.197 +
   7.198 +	ev->state &= valid_mask;
   7.199 +	if((f = frame_of_win(ev->window))) {
   7.200 +		buf[0] = 0;
   7.201 +		n = XLookupString(ev, buf, sizeof(buf), &k, 0);
   7.202 +		if(IsFunctionKey(k) || IsKeypadKey(k) || IsMiscFunctionKey(k)
   7.203 +				|| IsPFKey(k) || IsPrivateKeypadKey(k))
   7.204 +			return;
   7.205 +		buf[n] = 0;
   7.206 +		blitz_kpress_input(&f->tagbar, ev->state, k, buf);
   7.207 +	}
   7.208 +	else
   7.209 +		key(root, ev->state, (KeyCode) ev->keycode);
   7.210 +#endif
   7.211 +}
   7.212 +
   7.213 +static void
   7.214 +keymapnotify(XEvent *e)
   7.215 +{
   7.216 +#if 0
   7.217 +	update_keys();
   7.218 +#endif
   7.219 +}
   7.220 +
   7.221 +static void
   7.222 +maprequest(XEvent *e)
   7.223 +{
   7.224 +#if 0
   7.225 +	XMapRequestEvent *ev = &e->xmaprequest;
   7.226 +	static XWindowAttributes wa;
   7.227 +
   7.228 +	if(!XGetWindowAttributes(dpy, ev->window, &wa))
   7.229 +		return;
   7.230 +
   7.231 +	if(wa.override_redirect) {
   7.232 +		XSelectInput(dpy, ev->window,
   7.233 +				(StructureNotifyMask | PropertyChangeMask));
   7.234 +		return;
   7.235 +	}
   7.236 +
   7.237 +	if(!client_of_win(ev->window))
   7.238 +		manage_client(create_client(ev->window, &wa));
   7.239 +#endif
   7.240 +}
   7.241 +
   7.242 +static void
   7.243 +propertynotify(XEvent *e)
   7.244 +{
   7.245 +#if 0
   7.246 +	XPropertyEvent *ev = &e->xproperty;
   7.247 +	Client *c;
   7.248 +
   7.249 +	if(ev->state == PropertyDelete)
   7.250 +		return; /* ignore */
   7.251 +
   7.252 +	if((c = client_of_win(ev->window)))
   7.253 +		prop_client(c, ev);
   7.254 +#endif
   7.255 +}
   7.256 +
   7.257 +static void
   7.258 +unmapnotify(XEvent *e)
   7.259 +{
   7.260 +#if 0
   7.261 +	Client *c;
   7.262 +	XUnmapEvent *ev = &e->xunmap;
   7.263 +
   7.264 +	if((c = client_of_win(ev->window)))
   7.265 +		destroy_client(c);
   7.266 +#endif
   7.267 +}
     8.1 --- a/menu.c	Mon Jul 10 19:47:35 2006 +0200
     8.2 +++ b/menu.c	Mon Jul 10 22:16:48 2006 +0200
     8.3 @@ -53,7 +53,7 @@
     8.4  
     8.5  static Brush brush = {0};
     8.6  
     8.7 -static void draw_menu(void);
     8.8 +static void draw_menu();
     8.9  static void kpress(XKeyEvent * e);
    8.10  
    8.11  static char version[] = "gridmenu - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    8.12 @@ -397,11 +397,10 @@
    8.13  
    8.14  	wa.override_redirect = 1;
    8.15  	wa.background_pixmap = ParentRelative;
    8.16 -	wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask
    8.17 -		| SubstructureRedirectMask | SubstructureNotifyMask;
    8.18 +	wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
    8.19  
    8.20  	rect.width = DisplayWidth(dpy, screen);
    8.21 -	rect.height = brush.font.height + 4;
    8.22 +	rect.height = labelheight(&brush.font);
    8.23  	rect.y = DisplayHeight(dpy, screen) - rect.height;
    8.24  	rect.x = 0;
    8.25  
    8.26 @@ -413,7 +412,7 @@
    8.27  	XFlush(dpy);
    8.28  
    8.29  	/* pixmap */
    8.30 -	brush.gc = XCreateGC(dpy, win, 0, 0);
    8.31 +	brush.gc = XCreateGC(dpy, root, 0, 0);
    8.32  	brush.drawable = XCreatePixmap(dpy, win, rect.width, rect.height,
    8.33  			DefaultDepth(dpy, screen));
    8.34  	XFlush(dpy);
     9.1 --- a/util.c	Mon Jul 10 19:47:35 2006 +0200
     9.2 +++ b/util.c	Mon Jul 10 22:16:48 2006 +0200
     9.3 @@ -7,6 +7,11 @@
     9.4  #include <stdio.h>
     9.5  #include <stdlib.h>
     9.6  #include <string.h>
     9.7 +#include <sys/types.h>
     9.8 +#include <sys/wait.h>
     9.9 +#include <unistd.h>
    9.10 +
    9.11 +#include "util.h"
    9.12  
    9.13  void
    9.14  error(char *errstr, ...) {
    9.15 @@ -75,3 +80,21 @@
    9.16  	*p1 = *p2;
    9.17  	*p2 = tmp;
    9.18  }
    9.19 +
    9.20 +void
    9.21 +spawn(Display *dpy, const char *shell, const char *cmd)
    9.22 +{
    9.23 +	if(!cmd || !shell)
    9.24 +		return;
    9.25 +	if(fork() == 0) {
    9.26 +		if(fork() == 0) {
    9.27 +			if(dpy)
    9.28 +				close(ConnectionNumber(dpy));
    9.29 +			execl(shell, shell, "-c", cmd, (const char *)0);
    9.30 +			fprintf(stderr, "gridwm: execl %s", shell);
    9.31 +			perror(" failed");
    9.32 +		}
    9.33 +		exit (0);
    9.34 +	}
    9.35 +	wait(0);
    9.36 +}
    10.1 --- a/util.h	Mon Jul 10 19:47:35 2006 +0200
    10.2 +++ b/util.h	Mon Jul 10 22:16:48 2006 +0200
    10.3 @@ -2,6 +2,7 @@
    10.4   * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
    10.5   * See LICENSE file for license details.
    10.6   */
    10.7 +#include <X11/Xlib.h>
    10.8  
    10.9  extern void error(char *errstr, ...);
   10.10  extern void *emallocz(unsigned int size);
   10.11 @@ -12,5 +13,6 @@
   10.12  		if(!(a)) \
   10.13  			failed_assert(#a, __FILE__, __LINE__); \
   10.14  	} while (0)
   10.15 -void failed_assert(char *a, char *file, int line);
   10.16 -void swap(void **p1, void **p2);
   10.17 +extern void failed_assert(char *a, char *file, int line);
   10.18 +extern void swap(void **p1, void **p2);
   10.19 +extern void spawn(Display *dpy, const char *shell, const char *cmd);
    11.1 --- a/wm.c	Mon Jul 10 19:47:35 2006 +0200
    11.2 +++ b/wm.c	Mon Jul 10 22:16:48 2006 +0200
    11.3 @@ -15,15 +15,15 @@
    11.4  
    11.5  /* X structs */
    11.6  Display *dpy;
    11.7 -Window root;
    11.8 -XRectangle rect;
    11.9 -Pixmap pmap;
   11.10 -Atom wm_atom[WMLast];
   11.11 -Atom net_atom[NetLast];
   11.12 +Window root, barwin;
   11.13 +Atom wm_atom[WMLast], net_atom[NetLast];
   11.14  Cursor cursor[CurLast];
   11.15 +XRectangle rect, barrect;
   11.16 +Bool running = True;
   11.17  
   11.18 +char *bartext, *shell;
   11.19  int screen, sel_screen;
   11.20 -unsigned int kmask, numlock_mask;
   11.21 +unsigned int lock_mask, numlock_mask;
   11.22  
   11.23  /* draw structs */
   11.24  Brush brush = {0};
   11.25 @@ -166,7 +166,7 @@
   11.26  	}
   11.27  	XFreeModifiermap(modmap);
   11.28  
   11.29 -	kmask = 255 & ~(numlock_mask | LockMask);
   11.30 +	lock_mask = 255 & ~(numlock_mask | LockMask);
   11.31  }
   11.32  
   11.33  static void
   11.34 @@ -187,6 +187,7 @@
   11.35  	XSetWindowAttributes wa;
   11.36  	unsigned int mask;
   11.37  	Window w;
   11.38 +	XEvent ev;
   11.39  
   11.40  	/* command line args */
   11.41  	for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
   11.42 @@ -218,6 +219,9 @@
   11.43  	if(other_wm_running)
   11.44  		error("gridwm: another window manager is already running\n");
   11.45  
   11.46 +	if(!(shell = getenv("SHELL")))
   11.47 +		shell = "/bin/sh";
   11.48 +
   11.49  	rect.x = rect.y = 0;
   11.50  	rect.width = DisplayWidth(dpy, screen);
   11.51  	rect.height = DisplayHeight(dpy, screen);
   11.52 @@ -244,18 +248,41 @@
   11.53  
   11.54  	init_lock_keys();
   11.55  
   11.56 -	pmap = XCreatePixmap(dpy, root, rect.width, rect.height,
   11.57 +	brush.drawable = XCreatePixmap(dpy, root, rect.width, rect.height,
   11.58  			DefaultDepth(dpy, screen));
   11.59 +	brush.gc = XCreateGC(dpy, root, 0, 0);
   11.60 +
   11.61 +	/* style */
   11.62 +	loadcolors(dpy, screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR);
   11.63 +	loadfont(dpy, &brush.font, FONT);
   11.64 +
   11.65 +	wa.override_redirect = 1;
   11.66 +	wa.background_pixmap = ParentRelative;
   11.67 +	wa.event_mask = ExposureMask;
   11.68 +
   11.69 +	barrect = rect;
   11.70 +	barrect.height = labelheight(&brush.font);
   11.71 +	barrect.y = rect.height - barrect.height;
   11.72 +	barwin = XCreateWindow(dpy, root, barrect.x, barrect.y,
   11.73 +			barrect.width, barrect.height, 0, DefaultDepth(dpy, screen),
   11.74 +			CopyFromParent, DefaultVisual(dpy, screen),
   11.75 +			CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
   11.76 +	bartext = 0;
   11.77 +	XDefineCursor(dpy, barwin, cursor[CurNormal]);
   11.78 +	XMapRaised(dpy, barwin);
   11.79 +	draw_bar();
   11.80  
   11.81  	wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
   11.82  	wa.cursor = cursor[CurNormal];
   11.83  	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   11.84  
   11.85 -	/* style */
   11.86 -	loadcolors(dpy, screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR);
   11.87 -	loadfont(dpy, &brush.font, FONT);
   11.88 +	scan_wins();
   11.89  
   11.90 -	scan_wins();
   11.91 +	while(running) {
   11.92 +		XNextEvent(dpy, &ev);
   11.93 +		if(handler[ev.type])
   11.94 +			(handler[ev.type]) (&ev); /* call handler */
   11.95 +	}
   11.96  
   11.97  	cleanup();
   11.98  	XCloseDisplay(dpy);
    12.1 --- a/wm.h	Mon Jul 10 19:47:35 2006 +0200
    12.2 +++ b/wm.h	Mon Jul 10 22:16:48 2006 +0200
    12.3 @@ -9,16 +9,14 @@
    12.4  
    12.5  #include <X11/Xutil.h>
    12.6  
    12.7 -/* WM atoms */
    12.8 +/* atoms */
    12.9  enum { WMState, WMProtocols, WMDelete, WMLast };
   12.10 -
   12.11 -/* NET atoms */
   12.12  enum { NetSupported, NetWMName, NetLast };
   12.13  
   12.14 -/* Cursor */
   12.15 +/* cursor */
   12.16  enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
   12.17  
   12.18 -/* Rects */
   12.19 +/* rects */
   12.20  enum { RFloat, RGrid, RLast };
   12.21  
   12.22  typedef struct Client Client;
   12.23 @@ -28,35 +26,45 @@
   12.24  	Tag *tag;
   12.25  	char name[256];
   12.26  	int proto;
   12.27 +	unsigned int border;
   12.28 +	Bool fixedsize;
   12.29  	Window win;
   12.30  	Window trans;
   12.31  	Window title;
   12.32 -	GC gc;
   12.33  	XSizeHints size;
   12.34  	XRectangle r[RLast];
   12.35  	Client *next;
   12.36 -	Client *tnext;
   12.37 -	Client *tprev;
   12.38 +	Client *snext;
   12.39  };
   12.40  
   12.41  struct Tag {
   12.42  	char name[256];
   12.43 -	Client *clients;
   12.44 -	Client *sel;
   12.45 +	Client *stack;
   12.46  	XRectangle r;
   12.47 +	Tag *next;
   12.48 +	Tag *cnext;
   12.49  };
   12.50  
   12.51  extern Display *dpy;
   12.52 -extern Window root;
   12.53 -extern XRectangle rect;
   12.54 -extern Atom wm_atom[WMLast];
   12.55 -extern Atom net_atom[NetLast];
   12.56 +extern Window root, barwin;
   12.57 +extern Atom wm_atom[WMLast], net_atom[NetLast];
   12.58  extern Cursor cursor[CurLast];
   12.59 -extern Pixmap pmap;
   12.60 +extern XRectangle rect, barrect;
   12.61 +extern Bool running;
   12.62 +extern void (*handler[LASTEvent]) (XEvent *);
   12.63  
   12.64  extern int screen, sel_screen;
   12.65 -extern unsigned int kmask, numlock_mask;
   12.66 +extern unsigned int lock_mask, numlock_mask;
   12.67 +extern char *bartext, *shell;
   12.68  
   12.69  extern Brush brush;
   12.70  
   12.71 +/* bar.c */
   12.72 +extern void draw_bar();
   12.73 +
   12.74 +/* client.c */
   12.75 +extern Client *create_client(Window w, XWindowAttributes *wa);
   12.76 +extern void manage(Client *c);
   12.77 +
   12.78  /* wm.c */
   12.79 +extern int win_proto(Window w);