dwm-meillo

changeset 9:d567f430a81d

fixed several stuff (gridwm gets better and better)
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 12:52:57 +0200
parents 7066ff2fe8bc
children 703255003abb
files README client.c config.h event.c font.c key.c menu.c util.c wm.c wm.h
diffstat 10 files changed, 59 insertions(+), 141 deletions(-) [+]
line diff
     1.1 --- a/README	Tue Jul 11 11:50:18 2006 +0200
     1.2 +++ b/README	Tue Jul 11 12:52:57 2006 +0200
     1.3 @@ -2,6 +2,7 @@
     1.4  ------
     1.5  
     1.6  gridwm is an automatic X11 window manager which arranges all windows in a grid.
     1.7 +One goal is not to exceed 3kSLOC.
     1.8  
     1.9  
    1.10  Requirements
     2.1 --- a/client.c	Tue Jul 11 11:50:18 2006 +0200
     2.2 +++ b/client.c	Tue Jul 11 12:52:57 2006 +0200
     2.3 @@ -51,7 +51,6 @@
     2.4  	c->r[RFloat].height = wa->height;
     2.5  	c->border = wa->border_width;
     2.6  	XSetWindowBorderWidth(dpy, c->win, 0);
     2.7 -	c->proto = win_proto(c->win);
     2.8  	XGetTransientForHint(dpy, c->win, &c->trans);
     2.9  	if(!XGetWMNormalHints(dpy, c->win, &c->size, &msize) || !c->size.flags)
    2.10  		c->size.flags = PSize;
    2.11 @@ -59,7 +58,6 @@
    2.12  		(c->size.flags & PMinSize && c->size.flags & PMaxSize
    2.13  		 && c->size.min_width == c->size.max_width
    2.14  		 && c->size.min_height == c->size.max_height);
    2.15 -	XAddToSaveSet(dpy, c->win);
    2.16  	update_client_name(c);
    2.17  	twa.override_redirect = 1;
    2.18  	twa.background_pixmap = ParentRelative;
    2.19 @@ -87,3 +85,13 @@
    2.20  	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    2.21  	XFlush(dpy);
    2.22  }
    2.23 +
    2.24 +Client *
    2.25 +getclient(Window w)
    2.26 +{
    2.27 +	Client *c;
    2.28 +	for(c = clients; c; c = c->next)
    2.29 +		if(c->win == w)
    2.30 +			return c;
    2.31 +	return NULL;
    2.32 +}
     3.1 --- a/config.h	Tue Jul 11 11:50:18 2006 +0200
     3.2 +++ b/config.h	Tue Jul 11 12:52:57 2006 +0200
     3.3 @@ -10,4 +10,6 @@
     3.4  #define STATUSCMD	"echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \
     3.5  					" `acpi | awk '{print $4}' | sed 's/,//'`"
     3.6  #define KEYS		\
     3.7 -	{ Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn -*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*" },
     3.8 +	{ Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn '-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*'" }, \
     3.9 +	{ Mod1Mask | ShiftMask, XK_q, quit, NULL},
    3.10 +
     4.1 --- a/event.c	Tue Jul 11 11:50:18 2006 +0200
     4.2 +++ b/event.c	Tue Jul 11 12:52:57 2006 +0200
     4.3 @@ -16,7 +16,6 @@
     4.4  static void enternotify(XEvent *e);
     4.5  static void leavenotify(XEvent *e);
     4.6  static void expose(XEvent *e);
     4.7 -static void keypress(XEvent *e);
     4.8  static void keymapnotify(XEvent *e);
     4.9  static void maprequest(XEvent *e);
    4.10  static void propertynotify(XEvent *e);
    4.11 @@ -47,80 +46,36 @@
    4.12  static void
    4.13  configurerequest(XEvent *e)
    4.14  {
    4.15 -#if 0
    4.16  	XConfigureRequestEvent *ev = &e->xconfigurerequest;
    4.17  	XWindowChanges wc;
    4.18 -	XRectangle *frect;
    4.19  	Client *c;
    4.20  
    4.21 -	c = client_of_win(ev->window);
    4.22 +	c = getclient(ev->window);
    4.23  	ev->value_mask &= ~CWSibling;
    4.24  	if(c) {
    4.25 -		gravitate_client(c, True);
    4.26 -
    4.27  		if(ev->value_mask & CWX)
    4.28 -			c->rect.x = ev->x;
    4.29 +			c->r[RFloat].x = ev->x;
    4.30  		if(ev->value_mask & CWY)
    4.31 -			c->rect.y = ev->y;
    4.32 +			c->r[RFloat].y = ev->y;
    4.33  		if(ev->value_mask & CWWidth)
    4.34 -			c->rect.width = ev->width;
    4.35 +			c->r[RFloat].width = ev->width;
    4.36  		if(ev->value_mask & CWHeight)
    4.37 -			c->rect.height = ev->height;
    4.38 +			c->r[RFloat].height = ev->height;
    4.39  		if(ev->value_mask & CWBorderWidth)
    4.40  			c->border = ev->border_width;
    4.41 -
    4.42 -		gravitate_client(c, False);
    4.43 -
    4.44 -		if(c->frame) {
    4.45 -			if(c->sel->area->floating)
    4.46 -				frect=&c->sel->rect;
    4.47 -			else
    4.48 -				frect=&c->sel->revert;
    4.49 -
    4.50 -			if(c->rect.width >= screen->rect.width && c->rect.height >= screen->rect.height) {
    4.51 -				frect->y = wc.y = -height_of_bar();
    4.52 -				frect->x = wc.x = -def.border;
    4.53 -			}
    4.54 -			else {
    4.55 -				frect->y = wc.y = c->rect.y - height_of_bar();
    4.56 -				frect->x = wc.x = c->rect.x - def.border;
    4.57 -			}
    4.58 -			frect->width = wc.width = c->rect.width + 2 * def.border;
    4.59 -			frect->height = wc.height = c->rect.height + def.border
    4.60 -				+ height_of_bar();
    4.61 -			wc.border_width = 1;
    4.62 -			wc.sibling = None;
    4.63 -			wc.stack_mode = ev->detail;
    4.64 -			if(c->sel->area->view != screen->sel)
    4.65 -				wc.x += 2 * screen->rect.width;
    4.66 -			if(c->sel->area->floating) {
    4.67 -				XConfigureWindow(dpy, c->framewin, ev->value_mask, &wc);
    4.68 -				configure_client(c);
    4.69 -			}
    4.70 -		}
    4.71  	}
    4.72  
    4.73  	wc.x = ev->x;
    4.74  	wc.y = ev->y;
    4.75  	wc.width = ev->width;
    4.76  	wc.height = ev->height;
    4.77 -
    4.78 -	if(c && c->frame) {
    4.79 -		wc.x = def.border;
    4.80 -		wc.y = height_of_bar();
    4.81 -		wc.width = c->sel->rect.width - 2 * def.border;
    4.82 -		wc.height = c->sel->rect.height - def.border - height_of_bar();
    4.83 -	}
    4.84 -
    4.85  	wc.border_width = 0;
    4.86  	wc.sibling = None;
    4.87  	wc.stack_mode = Above;
    4.88  	ev->value_mask &= ~CWStackMode;
    4.89  	ev->value_mask |= CWBorderWidth;
    4.90  	XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
    4.91 -
    4.92  	XFlush(dpy);
    4.93 -#endif
    4.94  }
    4.95  
    4.96  static void
    4.97 @@ -182,32 +137,6 @@
    4.98  }
    4.99  
   4.100  static void
   4.101 -keypress(XEvent *e)
   4.102 -{
   4.103 -#if 0
   4.104 -	XKeyEvent *ev = &e->xkey;
   4.105 -	KeySym k = 0;
   4.106 -	char buf[32];
   4.107 -	int n;
   4.108 -	static Frame *f;
   4.109 -
   4.110 -
   4.111 -	ev->state &= valid_mask;
   4.112 -	if((f = frame_of_win(ev->window))) {
   4.113 -		buf[0] = 0;
   4.114 -		n = XLookupString(ev, buf, sizeof(buf), &k, 0);
   4.115 -		if(IsFunctionKey(k) || IsKeypadKey(k) || IsMiscFunctionKey(k)
   4.116 -				|| IsPFKey(k) || IsPrivateKeypadKey(k))
   4.117 -			return;
   4.118 -		buf[n] = 0;
   4.119 -		blitz_kpress_input(&f->tagbar, ev->state, k, buf);
   4.120 -	}
   4.121 -	else
   4.122 -		key(root, ev->state, (KeyCode) ev->keycode);
   4.123 -#endif
   4.124 -}
   4.125 -
   4.126 -static void
   4.127  keymapnotify(XEvent *e)
   4.128  {
   4.129  #if 0
   4.130 @@ -231,7 +160,11 @@
   4.131  	}
   4.132  
   4.133  	/*if(!client_of_win(ev->window))*/
   4.134 -		manage(create_client(ev->window, &wa));
   4.135 +		/*manage(create_client(ev->window, &wa));*/
   4.136 +	XMapRaised(dpy, ev->window);
   4.137 +	XMoveResizeWindow(dpy, ev->window, rect.x, rect.y, rect.width, rect.height - barrect.height);
   4.138 +	XSetInputFocus(dpy, ev->window, RevertToPointerRoot, CurrentTime);
   4.139 +	XFlush(dpy);
   4.140  }
   4.141  
   4.142  static void
     5.1 --- a/font.c	Tue Jul 11 11:50:18 2006 +0200
     5.2 +++ b/font.c	Tue Jul 11 12:52:57 2006 +0200
     5.3 @@ -38,7 +38,7 @@
     5.4  	font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
     5.5  	if(missing) {
     5.6  		while(n--)
     5.7 -			fprintf(stderr, "liblitz: missing fontset: %s\n", missing[n]);
     5.8 +			fprintf(stderr, "missing fontset: %s\n", missing[n]);
     5.9  		XFreeStringList(missing);
    5.10  		if(font->set) {
    5.11  			XFreeFontSet(blitz->dpy, font->set);
    5.12 @@ -72,7 +72,7 @@
    5.13  			font->xfont = XLoadQueryFont(blitz->dpy, fontname);
    5.14  		}
    5.15  		if (!font->xfont) {
    5.16 -			fprintf(stderr, "%s", "liblitz: error, cannot load 'fixed' font\n");
    5.17 +			fprintf(stderr, "%s", "error, cannot load 'fixed' font\n");
    5.18  			exit(1);
    5.19  		}
    5.20  		font->ascent = font->xfont->ascent;
     6.1 --- a/key.c	Tue Jul 11 11:50:18 2006 +0200
     6.2 +++ b/key.c	Tue Jul 11 12:52:57 2006 +0200
     6.3 @@ -24,3 +24,20 @@
     6.4  		XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync);
     6.5  	}
     6.6  }
     6.7 +
     6.8 +void
     6.9 +keypress(XEvent *e)
    6.10 +{
    6.11 +	XKeyEvent *ev = &e->xkey;
    6.12 +	unsigned int i, len;
    6.13 +	KeySym keysym;
    6.14 +
    6.15 +	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
    6.16 +	len = sizeof(key) / sizeof(key[0]);
    6.17 +	for(i = 0; i < len; i++)
    6.18 +		if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
    6.19 +			if(key[i].func)
    6.20 +				key[i].func(key[i].arg);
    6.21 +			return;
    6.22 +		}
    6.23 +}
     7.1 --- a/menu.c	Tue Jul 11 11:50:18 2006 +0200
     7.2 +++ b/menu.c	Tue Jul 11 12:52:57 2006 +0200
     7.3 @@ -358,8 +358,6 @@
     7.4  
     7.5  	char buf[256];
     7.6  
     7.7 -	fputs(STATUSCMD, stdout);
     7.8 -	fputs("\n", stdout);
     7.9  	pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD);
    7.10  	fputs(buf, stderr);
    7.11  
     8.1 --- a/util.c	Tue Jul 11 11:50:18 2006 +0200
     8.2 +++ b/util.c	Tue Jul 11 12:52:57 2006 +0200
     8.3 @@ -93,11 +93,12 @@
     8.4  		return;
     8.5  	if(fork() == 0) {
     8.6  		if(fork() == 0) {
     8.7 -			setsid();
     8.8  			if(dpy)
     8.9  				close(ConnectionNumber(dpy));
    8.10 -			execlp(shell, "shell", "-c", cmd, NULL);
    8.11 -			fprintf(stderr, "gridwm: execvp %s", cmd);
    8.12 +			setsid();
    8.13 +			fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd);
    8.14 +			execlp(shell, shell, "-c", cmd, NULL);
    8.15 +			fprintf(stderr, "gridwm: execlp %s", cmd);
    8.16  			perror(" failed");
    8.17  		}
    8.18  		exit (0);
    8.19 @@ -123,14 +124,14 @@
    8.20  	}
    8.21  
    8.22  	if(fork() == 0) {
    8.23 -		setsid();
    8.24  		if(dpy)
    8.25  			close(ConnectionNumber(dpy));
    8.26 +		setsid();
    8.27  		dup2(pfd[1], STDOUT_FILENO);
    8.28  		close(pfd[0]);
    8.29  		close(pfd[1]);
    8.30 -		execlp(shell, "shell", "-c", cmd, NULL);
    8.31 -		fprintf(stderr, "gridwm: execvp %s", cmd);
    8.32 +		execlp(shell, shell, "-c", cmd, NULL);
    8.33 +		fprintf(stderr, "gridwm: execlp %s", cmd);
    8.34  		perror(" failed");
    8.35  	}
    8.36  	else {
     9.1 --- a/wm.c	Tue Jul 11 11:50:18 2006 +0200
     9.2 +++ b/wm.c	Tue Jul 11 12:52:57 2006 +0200
     9.3 @@ -16,11 +16,11 @@
     9.4  /* X structs */
     9.5  Display *dpy;
     9.6  Window root, barwin;
     9.7 -Atom wm_atom[WMLast], net_atom[NetLast];
     9.8 +Atom net_atom[NetLast];
     9.9  Cursor cursor[CurLast];
    9.10  XRectangle rect, barrect;
    9.11  Bool running = True;
    9.12 -Client *client = NULL;
    9.13 +Client *clients = NULL;
    9.14  
    9.15  char *bartext, tag[256];
    9.16  int screen, sel_screen;
    9.17 @@ -63,46 +63,6 @@
    9.18  		XFree(wins);
    9.19  }
    9.20  
    9.21 -static int
    9.22 -win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
    9.23 -{
    9.24 -	Atom real;
    9.25 -	int format;
    9.26 -	unsigned long res, extra;
    9.27 -	int status;
    9.28 -
    9.29 -	status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
    9.30 -			&res, &extra, prop);
    9.31 -
    9.32 -	if(status != Success || *prop == NULL) {
    9.33 -		return 0;
    9.34 -	}
    9.35 -	if(res == 0)
    9.36 -		free((void *) *prop);
    9.37 -	return res;
    9.38 -}
    9.39 -
    9.40 -int
    9.41 -win_proto(Window w)
    9.42 -{
    9.43 -	Atom *protocols;
    9.44 -	long res;
    9.45 -	int protos = 0;
    9.46 -	int i;
    9.47 -
    9.48 -	res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L,
    9.49 -			((unsigned char **) &protocols));
    9.50 -	if(res <= 0) {
    9.51 -		return protos;
    9.52 -	}
    9.53 -	for(i = 0; i < res; i++) {
    9.54 -		if(protocols[i] == wm_atom[WMDelete])
    9.55 -			protos |= WM_PROTOCOL_DELWIN;
    9.56 -	}
    9.57 -	free((char *) protocols);
    9.58 -	return protos;
    9.59 -}
    9.60 -
    9.61  /*
    9.62   * There's no way to check accesses to destroyed windows, thus
    9.63   * those cases are ignored (especially on UnmapNotify's).
    9.64 @@ -201,9 +161,6 @@
    9.65  	x_error_handler = XSetErrorHandler(error_handler);
    9.66  
    9.67  	/* init atoms */
    9.68 -	wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False);
    9.69 -	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
    9.70 -	wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
    9.71  	net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
    9.72  	net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
    9.73  
    9.74 @@ -242,7 +199,8 @@
    9.75  	XMapRaised(dpy, barwin);
    9.76  	draw_bar();
    9.77  
    9.78 -	wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
    9.79 +	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
    9.80 +					| LeaveWindowMask;
    9.81  	wa.cursor = cursor[CurNormal];
    9.82  	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
    9.83  
    10.1 --- a/wm.h	Tue Jul 11 11:50:18 2006 +0200
    10.2 +++ b/wm.h	Tue Jul 11 12:52:57 2006 +0200
    10.3 @@ -10,7 +10,6 @@
    10.4  #include <X11/Xutil.h>
    10.5  
    10.6  /* atoms */
    10.7 -enum { WMState, WMProtocols, WMDelete, WMLast };
    10.8  enum { NetSupported, NetWMName, NetLast };
    10.9  
   10.10  /* cursor */
   10.11 @@ -25,7 +24,6 @@
   10.12  struct Client {
   10.13  	char name[256];
   10.14  	char tag[256];
   10.15 -	int proto;
   10.16  	unsigned int border;
   10.17  	Bool fixedsize;
   10.18  	Window win;
   10.19 @@ -46,7 +44,7 @@
   10.20  
   10.21  extern Display *dpy;
   10.22  extern Window root, barwin;
   10.23 -extern Atom wm_atom[WMLast], net_atom[NetLast];
   10.24 +extern Atom net_atom[NetLast];
   10.25  extern Cursor cursor[CurLast];
   10.26  extern XRectangle rect, barrect;
   10.27  extern Bool running;
   10.28 @@ -57,20 +55,22 @@
   10.29  extern char *bartext, tag[256];
   10.30  
   10.31  extern Brush brush;
   10.32 -extern Client *client;
   10.33 +extern Client *clients;
   10.34  
   10.35  /* bar.c */
   10.36  extern void draw_bar();
   10.37  
   10.38  /* cmd.c */
   10.39  extern void run(char *arg);
   10.40 +extern void quit(char *arg);
   10.41  
   10.42  /* client.c */
   10.43  extern Client *create_client(Window w, XWindowAttributes *wa);
   10.44  extern void manage(Client *c);
   10.45 +extern Client * getclient(Window w);
   10.46  
   10.47  /* key.c */
   10.48  extern void update_keys();
   10.49 +extern void keypress(XEvent *e);
   10.50  
   10.51  /* wm.c */
   10.52 -extern int win_proto(Window w);