aewl

changeset 43:989178822938

changed default colors
author Anselm R. Garbe <garbeam@wmii.de>
date Thu, 13 Jul 2006 11:43:05 +0200
parents 040a7074d23c
children a36f95a4841a
files Makefile client.c dev.c draw.c dwm.h event.c main.c util.c
diffstat 10 files changed, 465 insertions(+), 476 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Thu Jul 13 10:34:55 2006 +0200
     1.2 +++ b/Makefile	Thu Jul 13 11:43:05 2006 +0200
     1.3 @@ -3,7 +3,7 @@
     1.4  
     1.5  include config.mk
     1.6  
     1.7 -SRC = client.c dev.c draw.c event.c util.c wm.c
     1.8 +SRC = client.c dev.c draw.c event.c main.c util.c
     1.9  OBJ = ${SRC:.c=.o}
    1.10  MAN1 = dwm.1 
    1.11  BIN = dwm
    1.12 @@ -22,7 +22,7 @@
    1.13  	@echo CC $<
    1.14  	@${CC} -c ${CFLAGS} $<
    1.15  
    1.16 -${OBJ}: wm.h
    1.17 +${OBJ}: dwm.h
    1.18  
    1.19  dwm: ${OBJ}
    1.20  	@echo LD $@
     2.1 --- a/client.c	Thu Jul 13 10:34:55 2006 +0200
     2.2 +++ b/client.c	Thu Jul 13 11:43:05 2006 +0200
     2.3 @@ -9,7 +9,7 @@
     2.4  #include <X11/Xatom.h>
     2.5  #include <X11/Xutil.h>
     2.6  
     2.7 -#include "wm.h"
     2.8 +#include "dwm.h"
     2.9  
    2.10  static void floating(void);
    2.11  static void tiling(void);
    2.12 @@ -125,8 +125,8 @@
    2.13  	c->tw = 0;
    2.14  	for(i = 0; i < TLast; i++)
    2.15  		if(c->tags[i])
    2.16 -			c->tw += textw(&dc.font, c->tags[i]) + dc.font.height;
    2.17 -	c->tw += textw(&dc.font, c->name) + dc.font.height;
    2.18 +			c->tw += textw(c->tags[i]) + dc.font.height;
    2.19 +	c->tw += textw(c->name) + dc.font.height;
    2.20  	if(c->tw > c->w)
    2.21  		c->tw = c->w + 2;
    2.22  	c->tx = c->x + c->w - c->tw + 2;
    2.23 @@ -226,10 +226,12 @@
    2.24  	c->snext = stack;
    2.25  	stack = c;
    2.26  	if(old && old != c) {
    2.27 +		XSetWindowBorder(dpy, old->win, dc.bg);
    2.28  		XMapWindow(dpy, old->title);
    2.29  		draw_client(old);
    2.30  	}
    2.31  	XUnmapWindow(dpy, c->title);
    2.32 +	XSetWindowBorder(dpy, c->win, dc.fg);
    2.33  	draw_client(c);
    2.34  	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
    2.35  	XFlush(dpy);
    2.36 @@ -250,8 +252,6 @@
    2.37  	c->th = th;
    2.38  	c->border = 1;
    2.39  	update_size(c);
    2.40 -	XSetWindowBorderWidth(dpy, c->win, 1);
    2.41 -	XSetWindowBorder(dpy, c->win, dc.border);
    2.42  	XSelectInput(dpy, c->win,
    2.43  			StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
    2.44  	XGetTransientForHint(dpy, c->win, &c->trans);
    2.45 @@ -269,6 +269,7 @@
    2.46  	for(l=&clients; *l; l=&(*l)->next);
    2.47  	c->next = *l; /* *l == nil */
    2.48  	*l = c;
    2.49 +	XSetWindowBorderWidth(dpy, c->win, 1);
    2.50  	XMapRaised(dpy, c->win);
    2.51  	XMapRaised(dpy, c->title);
    2.52  	XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
    2.53 @@ -435,12 +436,12 @@
    2.54  	for(i = 0; i < TLast; i++) {
    2.55  		if(c->tags[i]) {
    2.56  			dc.x += dc.w;
    2.57 -			dc.w = textw(&dc.font, c->tags[i]) + dc.font.height;
    2.58 +			dc.w = textw(c->tags[i]) + dc.font.height;
    2.59  			draw(True, c->tags[i]);
    2.60  		}
    2.61  	}
    2.62  	dc.x += dc.w;
    2.63 -	dc.w = textw(&dc.font, c->name) + dc.font.height;
    2.64 +	dc.w = textw(c->name) + dc.font.height;
    2.65  	draw(True, c->name);
    2.66  	XCopyArea(dpy, dc.drawable, c->title, dc.gc,
    2.67  			0, 0, c->tw, c->th, 0, 0);
     3.1 --- a/dev.c	Thu Jul 13 10:34:55 2006 +0200
     3.2 +++ b/dev.c	Thu Jul 13 11:43:05 2006 +0200
     3.3 @@ -3,7 +3,7 @@
     3.4   * See LICENSE file for license details.
     3.5   */
     3.6  
     3.7 -#include "wm.h"
     3.8 +#include "dwm.h"
     3.9  
    3.10  #include <stdlib.h>
    3.11  #include <string.h>
     4.1 --- a/draw.c	Thu Jul 13 10:34:55 2006 +0200
     4.2 +++ b/draw.c	Thu Jul 13 11:43:05 2006 +0200
     4.3 @@ -8,7 +8,7 @@
     4.4  
     4.5  #include <X11/Xlocale.h>
     4.6  
     4.7 -#include "wm.h"
     4.8 +#include "dwm.h"
     4.9  
    4.10  static void
    4.11  drawborder(void)
    4.12 @@ -59,7 +59,7 @@
    4.13  	x = dc.x + (h / 2);
    4.14  
    4.15  	/* shorten text if necessary */
    4.16 -	while(len && (w = textnw(&dc.font, buf, len)) > dc.w - h)
    4.17 +	while(len && (w = textnw(buf, len)) > dc.w - h)
    4.18  		buf[--len] = 0;
    4.19  
    4.20  	if(w > dc.w)
    4.21 @@ -79,93 +79,80 @@
    4.22  	}
    4.23  }
    4.24  
    4.25 -static unsigned long
    4.26 -xinitcolors(Colormap cmap, const char *colstr)
    4.27 +unsigned long
    4.28 +initcolor(const char *colstr)
    4.29  {
    4.30  	XColor color;
    4.31 +	Colormap cmap = DefaultColormap(dpy, screen);
    4.32 +
    4.33  	XAllocNamedColor(dpy, cmap, colstr, &color, &color);
    4.34  	return color.pixel;
    4.35  }
    4.36  
    4.37 -void
    4.38 -initcolors(const char *bg, const char *fg, const char *border)
    4.39 +unsigned int
    4.40 +textnw(char *text, unsigned int len)
    4.41  {
    4.42 -	Colormap cmap = DefaultColormap(dpy, screen);
    4.43 -	dc.bg = xinitcolors(cmap, bg);
    4.44 -	dc.fg = xinitcolors(cmap, fg);
    4.45 -	dc.border = xinitcolors(cmap, border);
    4.46 +	XRectangle r;
    4.47 +	if(dc.font.set) {
    4.48 +		XmbTextExtents(dc.font.set, text, len, NULL, &r);
    4.49 +		return r.width;
    4.50 +	}
    4.51 +	return XTextWidth(dc.font.xfont, text, len);
    4.52  }
    4.53  
    4.54  unsigned int
    4.55 -textnw(Fnt *font, char *text, unsigned int len)
    4.56 +textw(char *text)
    4.57  {
    4.58 -	XRectangle r;
    4.59 -	if(font->set) {
    4.60 -		XmbTextExtents(font->set, text, len, NULL, &r);
    4.61 -		return r.width;
    4.62 -	}
    4.63 -	return XTextWidth(font->xfont, text, len);
    4.64 -}
    4.65 -
    4.66 -unsigned int
    4.67 -textw(Fnt *font, char *text)
    4.68 -{
    4.69 -	return textnw(font, text, strlen(text));
    4.70 -}
    4.71 -
    4.72 -unsigned int
    4.73 -texth(Fnt *font)
    4.74 -{
    4.75 -	return font->height + 4;
    4.76 +	return textnw(text, strlen(text));
    4.77  }
    4.78  
    4.79  void
    4.80 -initfont(Fnt *font, const char *fontstr)
    4.81 +initfont(const char *fontstr)
    4.82  {
    4.83  	char **missing, *def;
    4.84  	int i, n;
    4.85  
    4.86  	missing = NULL;
    4.87  	setlocale(LC_ALL, "");
    4.88 -	if(font->set)
    4.89 -		XFreeFontSet(dpy, font->set);
    4.90 -	font->set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
    4.91 +	if(dc.font.set)
    4.92 +		XFreeFontSet(dpy, dc.font.set);
    4.93 +	dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
    4.94  	if(missing) {
    4.95  		while(n--)
    4.96  			fprintf(stderr, "missing fontset: %s\n", missing[n]);
    4.97  		XFreeStringList(missing);
    4.98 -		if(font->set) {
    4.99 -			XFreeFontSet(dpy, font->set);
   4.100 -			font->set = NULL;
   4.101 +		if(dc.font.set) {
   4.102 +			XFreeFontSet(dpy, dc.font.set);
   4.103 +			dc.font.set = NULL;
   4.104  		}
   4.105  	}
   4.106 -	if(font->set) {
   4.107 +	if(dc.font.set) {
   4.108  		XFontSetExtents *font_extents;
   4.109  		XFontStruct **xfonts;
   4.110  		char **font_names;
   4.111  
   4.112 -		font->ascent = font->descent = 0;
   4.113 -		font_extents = XExtentsOfFontSet(font->set);
   4.114 -		n = XFontsOfFontSet(font->set, &xfonts, &font_names);
   4.115 -		for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
   4.116 -			if(font->ascent < (*xfonts)->ascent)
   4.117 -				font->ascent = (*xfonts)->ascent;
   4.118 -			if(font->descent < (*xfonts)->descent)
   4.119 -				font->descent = (*xfonts)->descent;
   4.120 +		dc.font.ascent = dc.font.descent = 0;
   4.121 +		font_extents = XExtentsOfFontSet(dc.font.set);
   4.122 +		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
   4.123 +		for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
   4.124 +			if(dc.font.ascent < (*xfonts)->ascent)
   4.125 +				dc.font.ascent = (*xfonts)->ascent;
   4.126 +			if(dc.font.descent < (*xfonts)->descent)
   4.127 +				dc.font.descent = (*xfonts)->descent;
   4.128  			xfonts++;
   4.129  		}
   4.130  	}
   4.131  	else {
   4.132 -		if(font->xfont)
   4.133 -			XFreeFont(dpy, font->xfont);
   4.134 -		font->xfont = NULL;
   4.135 -		font->xfont = XLoadQueryFont(dpy, fontstr);
   4.136 -		if (!font->xfont)
   4.137 -			font->xfont = XLoadQueryFont(dpy, "fixed");
   4.138 -		if (!font->xfont)
   4.139 +		if(dc.font.xfont)
   4.140 +			XFreeFont(dpy, dc.font.xfont);
   4.141 +		dc.font.xfont = NULL;
   4.142 +		dc.font.xfont = XLoadQueryFont(dpy, fontstr);
   4.143 +		if (!dc.font.xfont)
   4.144 +			dc.font.xfont = XLoadQueryFont(dpy, "fixed");
   4.145 +		if (!dc.font.xfont)
   4.146  			error("error, cannot init 'fixed' font\n");
   4.147 -		font->ascent = font->xfont->ascent;
   4.148 -		font->descent = font->xfont->descent;
   4.149 +		dc.font.ascent = dc.font.xfont->ascent;
   4.150 +		dc.font.descent = dc.font.xfont->descent;
   4.151  	}
   4.152 -	font->height = font->ascent + font->descent;
   4.153 +	dc.font.height = dc.font.ascent + dc.font.descent;
   4.154  }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/dwm.h	Thu Jul 13 11:43:05 2006 +0200
     5.3 @@ -0,0 +1,136 @@
     5.4 +/*
     5.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     5.6 + * See LICENSE file for license details.
     5.7 + */
     5.8 +
     5.9 +#include <X11/Xlib.h>
    5.10 +
    5.11 +/********** CUSTOMIZE **********/
    5.12 +
    5.13 +#define FONT		"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
    5.14 +#define BGCOLOR		"DarkSlateGrey"
    5.15 +#define FGCOLOR		"LightSteelBlue"
    5.16 +#define BORDERCOLOR	"SlateGray"
    5.17 +#define WM_PROTOCOL_DELWIN 1
    5.18 +
    5.19 +/* tags */
    5.20 +enum { Tscratch, Tdev, Tirc, Twww, Twork, TLast };
    5.21 +
    5.22 +/********** CUSTOMIZE **********/
    5.23 +
    5.24 +typedef struct DC DC;
    5.25 +typedef struct Client Client;
    5.26 +typedef struct Fnt Fnt;
    5.27 +typedef struct Key Key;
    5.28 +
    5.29 +/* atoms */
    5.30 +enum { WMProtocols, WMDelete, WMLast };
    5.31 +enum { NetSupported, NetWMName, NetLast };
    5.32 +
    5.33 +/* cursor */
    5.34 +enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
    5.35 +
    5.36 +struct Fnt {
    5.37 +	XFontStruct *xfont;
    5.38 +	XFontSet set;
    5.39 +	int ascent;
    5.40 +	int descent;
    5.41 +	int height;
    5.42 +};
    5.43 +
    5.44 +struct DC { /* draw context */
    5.45 +	GC gc;
    5.46 +	Drawable drawable;
    5.47 +	int x, y, w, h;
    5.48 +	Fnt font;
    5.49 +	unsigned long bg;
    5.50 +	unsigned long fg;
    5.51 +	unsigned long border;
    5.52 +};
    5.53 +
    5.54 +struct Client {
    5.55 +	char name[256];
    5.56 +	char *tags[TLast];
    5.57 +	int proto;
    5.58 +	int x, y, w, h;
    5.59 +	int tx, ty, tw, th;
    5.60 +	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
    5.61 +	int grav;
    5.62 +	unsigned int border;
    5.63 +	long flags; 
    5.64 +	Window win;
    5.65 +	Window trans;
    5.66 +	Window title;
    5.67 +	Client *next;
    5.68 +	Client *snext;
    5.69 +};
    5.70 +
    5.71 +struct Key {
    5.72 +	unsigned long mod;
    5.73 +	KeySym keysym;
    5.74 +	void (*func)(void *aux);
    5.75 +	void *aux;
    5.76 +};
    5.77 +
    5.78 +extern Display *dpy;
    5.79 +extern Window root;
    5.80 +extern Atom wm_atom[WMLast], net_atom[NetLast];
    5.81 +extern Cursor cursor[CurLast];
    5.82 +extern Bool running, issel;
    5.83 +extern void (*handler[LASTEvent]) (XEvent *);
    5.84 +
    5.85 +extern int tsel, screen, sx, sy, sw, sh, th;
    5.86 +extern char stext[1024], *tags[TLast];
    5.87 +
    5.88 +extern DC dc;
    5.89 +extern Client *clients, *stack;
    5.90 +
    5.91 +/* client.c */
    5.92 +extern void manage(Window w, XWindowAttributes *wa);
    5.93 +extern void unmanage(Client *c);
    5.94 +extern Client *getclient(Window w);
    5.95 +extern void focus(Client *c);
    5.96 +extern void update_name(Client *c);
    5.97 +extern void draw_client(Client *c);
    5.98 +extern void resize(Client *c);
    5.99 +extern void update_size(Client *c);
   5.100 +extern Client *gettitle(Window w);
   5.101 +extern void craise(Client *c);
   5.102 +extern void lower(Client *c);
   5.103 +extern void ckill(void *aux);
   5.104 +extern void sel(void *aux);
   5.105 +extern void max(void *aux);
   5.106 +extern void toggle(void *aux);
   5.107 +extern void gravitate(Client *c, Bool invert);
   5.108 +
   5.109 +/* draw.c */
   5.110 +extern void draw(Bool border, const char *text);
   5.111 +extern unsigned long initcolor(const char *colstr);
   5.112 +extern void initfont(const char *fontstr);
   5.113 +extern unsigned int textnw(char *text, unsigned int len);
   5.114 +extern unsigned int textw(char *text);
   5.115 +extern unsigned int texth(void);
   5.116 +
   5.117 +/* event.c */
   5.118 +extern void discard_events(long even_mask);
   5.119 +
   5.120 +/* dev.c */
   5.121 +extern void update_keys(void);
   5.122 +extern void keypress(XEvent *e);
   5.123 +extern void mresize(Client *c);
   5.124 +extern void mmove(Client *c);
   5.125 +
   5.126 +/* main.c */
   5.127 +extern int error_handler(Display *dsply, XErrorEvent *e);
   5.128 +extern void send_message(Window w, Atom a, long value);
   5.129 +extern int win_proto(Window w);
   5.130 +extern void quit(void *aux);
   5.131 +
   5.132 +/* util.c */
   5.133 +extern void error(const char *errstr, ...);
   5.134 +extern void *emallocz(unsigned int size);
   5.135 +extern void *emalloc(unsigned int size);
   5.136 +extern void *erealloc(void *ptr, unsigned int size);
   5.137 +extern char *estrdup(const char *str);
   5.138 +extern void spawn(char *argv[]);
   5.139 +extern void swap(void **p1, void **p2);
     6.1 --- a/event.c	Thu Jul 13 10:34:55 2006 +0200
     6.2 +++ b/event.c	Thu Jul 13 11:43:05 2006 +0200
     6.3 @@ -9,7 +9,7 @@
     6.4  #include <X11/keysym.h>
     6.5  #include <X11/Xatom.h>
     6.6  
     6.7 -#include "wm.h"
     6.8 +#include "dwm.h"
     6.9  
    6.10  /* local functions */
    6.11  static void buttonpress(XEvent *e);
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/main.c	Thu Jul 13 11:43:05 2006 +0200
     7.3 @@ -0,0 +1,274 @@
     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 <stdarg.h>
    7.10 +#include <stdio.h>
    7.11 +#include <stdlib.h>
    7.12 +
    7.13 +#include <X11/cursorfont.h>
    7.14 +#include <X11/Xatom.h>
    7.15 +#include <X11/Xproto.h>
    7.16 +
    7.17 +#include "dwm.h"
    7.18 +
    7.19 +/********** CUSTOMIZE **********/
    7.20 +
    7.21 +char *tags[TLast] = {
    7.22 +	[Tscratch] = "scratch",
    7.23 +	[Tdev] = "dev",
    7.24 +	[Tirc] = "irc",
    7.25 +	[Twww] = "www",
    7.26 +	[Twork] = "work",
    7.27 +};
    7.28 +
    7.29 +/********** CUSTOMIZE **********/
    7.30 +
    7.31 +/* X structs */
    7.32 +Display *dpy;
    7.33 +Window root, barwin;
    7.34 +Atom wm_atom[WMLast], net_atom[NetLast];
    7.35 +Cursor cursor[CurLast];
    7.36 +Bool running = True;
    7.37 +Bool issel;
    7.38 +
    7.39 +char stext[1024];
    7.40 +int tsel = Tdev; /* default tag */
    7.41 +int screen, sx, sy, sw, sh, th;
    7.42 +
    7.43 +DC dc = {0};
    7.44 +Client *clients = NULL;
    7.45 +Client *stack = NULL;
    7.46 +
    7.47 +static Bool other_wm_running;
    7.48 +static const char version[] =
    7.49 +	"dwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    7.50 +static int (*x_error_handler) (Display *, XErrorEvent *);
    7.51 +
    7.52 +static void
    7.53 +usage() {	error("usage: dwm [-v]\n"); }
    7.54 +
    7.55 +static void
    7.56 +scan_wins()
    7.57 +{
    7.58 +	unsigned int i, num;
    7.59 +	Window *wins;
    7.60 +	XWindowAttributes wa;
    7.61 +	Window d1, d2;
    7.62 +
    7.63 +	if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
    7.64 +		for(i = 0; i < num; i++) {
    7.65 +			if(!XGetWindowAttributes(dpy, wins[i], &wa))
    7.66 +				continue;
    7.67 +			if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
    7.68 +				continue;
    7.69 +			if(wa.map_state == IsViewable)
    7.70 +				manage(wins[i], &wa);
    7.71 +		}
    7.72 +	}
    7.73 +	if(wins)
    7.74 +		XFree(wins);
    7.75 +}
    7.76 +
    7.77 +static int
    7.78 +win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
    7.79 +{
    7.80 +	Atom real;
    7.81 +	int format;
    7.82 +	unsigned long res, extra;
    7.83 +	int status;
    7.84 +
    7.85 +	status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
    7.86 +			&res, &extra, prop);
    7.87 +
    7.88 +	if(status != Success || *prop == 0) {
    7.89 +		return 0;
    7.90 +	}
    7.91 +	if(res == 0) {
    7.92 +		free((void *) *prop);
    7.93 +	}
    7.94 +	return res;
    7.95 +}
    7.96 +
    7.97 +int
    7.98 +win_proto(Window w)
    7.99 +{
   7.100 +	unsigned char *protocols;
   7.101 +	long res;
   7.102 +	int protos = 0;
   7.103 +	int i;
   7.104 +
   7.105 +	res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, &protocols);
   7.106 +	if(res <= 0) {
   7.107 +		return protos;
   7.108 +	}
   7.109 +	for(i = 0; i < res; i++) {
   7.110 +		if(protocols[i] == wm_atom[WMDelete])
   7.111 +			protos |= WM_PROTOCOL_DELWIN;
   7.112 +	}
   7.113 +	free((char *) protocols);
   7.114 +	return protos;
   7.115 +}
   7.116 +
   7.117 +void
   7.118 +send_message(Window w, Atom a, long value)
   7.119 +{
   7.120 +	XEvent e;
   7.121 +
   7.122 +	e.type = ClientMessage;
   7.123 +	e.xclient.window = w;
   7.124 +	e.xclient.message_type = a;
   7.125 +	e.xclient.format = 32;
   7.126 +	e.xclient.data.l[0] = value;
   7.127 +	e.xclient.data.l[1] = CurrentTime;
   7.128 +	XSendEvent(dpy, w, False, NoEventMask, &e);
   7.129 +	XFlush(dpy);
   7.130 +}
   7.131 +
   7.132 +/*
   7.133 + * There's no way to check accesses to destroyed windows, thus
   7.134 + * those cases are ignored (especially on UnmapNotify's).
   7.135 + * Other types of errors call Xlib's default error handler, which
   7.136 + * calls exit().
   7.137 + */
   7.138 +int
   7.139 +error_handler(Display *dpy, XErrorEvent *error)
   7.140 +{
   7.141 +	if(error->error_code == BadWindow
   7.142 +			|| (error->request_code == X_SetInputFocus
   7.143 +				&& error->error_code == BadMatch)
   7.144 +			|| (error->request_code == X_PolyText8
   7.145 +				&& error->error_code == BadDrawable)
   7.146 +			|| (error->request_code == X_PolyFillRectangle
   7.147 +				&& error->error_code == BadDrawable)
   7.148 +			|| (error->request_code == X_PolySegment
   7.149 +				&& error->error_code == BadDrawable)
   7.150 +			|| (error->request_code == X_ConfigureWindow
   7.151 +				&& error->error_code == BadMatch)
   7.152 +			|| (error->request_code == X_GrabKey
   7.153 +				&& error->error_code == BadAccess))
   7.154 +		return 0;
   7.155 +	fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
   7.156 +			error->request_code, error->error_code);
   7.157 +	return x_error_handler(dpy, error); /* may call exit() */
   7.158 +}
   7.159 +
   7.160 +/*
   7.161 + * Startup Error handler to check if another window manager
   7.162 + * is already running.
   7.163 + */
   7.164 +static int
   7.165 +startup_error_handler(Display *dpy, XErrorEvent *error)
   7.166 +{
   7.167 +	other_wm_running = True;
   7.168 +	return -1;
   7.169 +}
   7.170 +
   7.171 +static void
   7.172 +cleanup()
   7.173 +{
   7.174 +	while(clients)
   7.175 +		unmanage(clients);
   7.176 +	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
   7.177 +}
   7.178 +
   7.179 +void
   7.180 +quit(void *aux)
   7.181 +{
   7.182 +	running = False;
   7.183 +}
   7.184 +
   7.185 +int
   7.186 +main(int argc, char *argv[])
   7.187 +{
   7.188 +	int i;
   7.189 +	XSetWindowAttributes wa;
   7.190 +	unsigned int mask;
   7.191 +	Window w;
   7.192 +	XEvent ev;
   7.193 +
   7.194 +	/* command line args */
   7.195 +	for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
   7.196 +		switch (argv[i][1]) {
   7.197 +		case 'v':
   7.198 +			fprintf(stdout, "%s", version);
   7.199 +			exit(0);
   7.200 +			break;
   7.201 +		default:
   7.202 +			usage();
   7.203 +			break;
   7.204 +		}
   7.205 +	}
   7.206 +
   7.207 +	dpy = XOpenDisplay(0);
   7.208 +	if(!dpy)
   7.209 +		error("dwm: cannot connect X server\n");
   7.210 +
   7.211 +	screen = DefaultScreen(dpy);
   7.212 +	root = RootWindow(dpy, screen);
   7.213 +
   7.214 +	/* check if another WM is already running */
   7.215 +	other_wm_running = False;
   7.216 +	XSetErrorHandler(startup_error_handler);
   7.217 +	/* this causes an error if some other WM is running */
   7.218 +	XSelectInput(dpy, root, SubstructureRedirectMask);
   7.219 +	XFlush(dpy);
   7.220 +
   7.221 +	if(other_wm_running)
   7.222 +		error("dwm: another window manager is already running\n");
   7.223 +
   7.224 +	sx = sy = 0;
   7.225 +	sw = DisplayWidth(dpy, screen);
   7.226 +	sh = DisplayHeight(dpy, screen);
   7.227 +	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
   7.228 +
   7.229 +	XSetErrorHandler(0);
   7.230 +	x_error_handler = XSetErrorHandler(error_handler);
   7.231 +
   7.232 +	/* init atoms */
   7.233 +	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
   7.234 +	wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
   7.235 +	net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
   7.236 +	net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
   7.237 +
   7.238 +	XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
   7.239 +			PropModeReplace, (unsigned char *) net_atom, NetLast);
   7.240 +
   7.241 +
   7.242 +	/* init cursors */
   7.243 +	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
   7.244 +	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
   7.245 +	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
   7.246 +
   7.247 +	update_keys();
   7.248 +
   7.249 +	/* style */
   7.250 +	dc.bg = initcolor(BGCOLOR);
   7.251 +	dc.fg = initcolor(FGCOLOR);
   7.252 +	dc.border = initcolor(BORDERCOLOR);
   7.253 +	initfont(FONT);
   7.254 +
   7.255 +	th = dc.font.height + 4;
   7.256 +
   7.257 +	dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen));
   7.258 +	dc.gc = XCreateGC(dpy, root, 0, 0);
   7.259 +
   7.260 +	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
   7.261 +					| LeaveWindowMask;
   7.262 +	wa.cursor = cursor[CurNormal];
   7.263 +	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   7.264 +
   7.265 +	scan_wins();
   7.266 +
   7.267 +	while(running) {
   7.268 +		XNextEvent(dpy, &ev);
   7.269 +		if(handler[ev.type])
   7.270 +			(handler[ev.type])(&ev); /* call handler */
   7.271 +	}
   7.272 +
   7.273 +	cleanup();
   7.274 +	XCloseDisplay(dpy);
   7.275 +
   7.276 +	return 0;
   7.277 +}
     8.1 --- a/util.c	Thu Jul 13 10:34:55 2006 +0200
     8.2 +++ b/util.c	Thu Jul 13 11:43:05 2006 +0200
     8.3 @@ -11,7 +11,7 @@
     8.4  #include <sys/wait.h>
     8.5  #include <unistd.h>
     8.6  
     8.7 -#include "wm.h"
     8.8 +#include "dwm.h"
     8.9  
    8.10  void
    8.11  error(const char *errstr, ...) {
     9.1 --- a/wm.c	Thu Jul 13 10:34:55 2006 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,272 +0,0 @@
     9.4 -/*
     9.5 - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     9.6 - * See LICENSE file for license details.
     9.7 - */
     9.8 -
     9.9 -#include <stdarg.h>
    9.10 -#include <stdio.h>
    9.11 -#include <stdlib.h>
    9.12 -
    9.13 -#include <X11/cursorfont.h>
    9.14 -#include <X11/Xatom.h>
    9.15 -#include <X11/Xproto.h>
    9.16 -
    9.17 -#include "wm.h"
    9.18 -
    9.19 -/********** CUSTOMIZE **********/
    9.20 -
    9.21 -char *tags[TLast] = {
    9.22 -	[Tscratch] = "scratch",
    9.23 -	[Tdev] = "dev",
    9.24 -	[Tirc] = "irc",
    9.25 -	[Twww] = "www",
    9.26 -	[Twork] = "work",
    9.27 -};
    9.28 -
    9.29 -/********** CUSTOMIZE **********/
    9.30 -
    9.31 -/* X structs */
    9.32 -Display *dpy;
    9.33 -Window root, barwin;
    9.34 -Atom wm_atom[WMLast], net_atom[NetLast];
    9.35 -Cursor cursor[CurLast];
    9.36 -Bool running = True;
    9.37 -Bool issel;
    9.38 -
    9.39 -char stext[1024];
    9.40 -int tsel = Tdev; /* default tag */
    9.41 -int screen, sx, sy, sw, sh, th;
    9.42 -
    9.43 -DC dc = {0};
    9.44 -Client *clients = NULL;
    9.45 -Client *stack = NULL;
    9.46 -
    9.47 -static Bool other_wm_running;
    9.48 -static const char version[] =
    9.49 -	"dwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
    9.50 -static int (*x_error_handler) (Display *, XErrorEvent *);
    9.51 -
    9.52 -static void
    9.53 -usage() {	error("usage: dwm [-v]\n"); }
    9.54 -
    9.55 -static void
    9.56 -scan_wins()
    9.57 -{
    9.58 -	unsigned int i, num;
    9.59 -	Window *wins;
    9.60 -	XWindowAttributes wa;
    9.61 -	Window d1, d2;
    9.62 -
    9.63 -	if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
    9.64 -		for(i = 0; i < num; i++) {
    9.65 -			if(!XGetWindowAttributes(dpy, wins[i], &wa))
    9.66 -				continue;
    9.67 -			if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
    9.68 -				continue;
    9.69 -			if(wa.map_state == IsViewable)
    9.70 -				manage(wins[i], &wa);
    9.71 -		}
    9.72 -	}
    9.73 -	if(wins)
    9.74 -		XFree(wins);
    9.75 -}
    9.76 -
    9.77 -static int
    9.78 -win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
    9.79 -{
    9.80 -	Atom real;
    9.81 -	int format;
    9.82 -	unsigned long res, extra;
    9.83 -	int status;
    9.84 -
    9.85 -	status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
    9.86 -			&res, &extra, prop);
    9.87 -
    9.88 -	if(status != Success || *prop == 0) {
    9.89 -		return 0;
    9.90 -	}
    9.91 -	if(res == 0) {
    9.92 -		free((void *) *prop);
    9.93 -	}
    9.94 -	return res;
    9.95 -}
    9.96 -
    9.97 -int
    9.98 -win_proto(Window w)
    9.99 -{
   9.100 -	unsigned char *protocols;
   9.101 -	long res;
   9.102 -	int protos = 0;
   9.103 -	int i;
   9.104 -
   9.105 -	res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, &protocols);
   9.106 -	if(res <= 0) {
   9.107 -		return protos;
   9.108 -	}
   9.109 -	for(i = 0; i < res; i++) {
   9.110 -		if(protocols[i] == wm_atom[WMDelete])
   9.111 -			protos |= WM_PROTOCOL_DELWIN;
   9.112 -	}
   9.113 -	free((char *) protocols);
   9.114 -	return protos;
   9.115 -}
   9.116 -
   9.117 -void
   9.118 -send_message(Window w, Atom a, long value)
   9.119 -{
   9.120 -	XEvent e;
   9.121 -
   9.122 -	e.type = ClientMessage;
   9.123 -	e.xclient.window = w;
   9.124 -	e.xclient.message_type = a;
   9.125 -	e.xclient.format = 32;
   9.126 -	e.xclient.data.l[0] = value;
   9.127 -	e.xclient.data.l[1] = CurrentTime;
   9.128 -	XSendEvent(dpy, w, False, NoEventMask, &e);
   9.129 -	XFlush(dpy);
   9.130 -}
   9.131 -
   9.132 -/*
   9.133 - * There's no way to check accesses to destroyed windows, thus
   9.134 - * those cases are ignored (especially on UnmapNotify's).
   9.135 - * Other types of errors call Xlib's default error handler, which
   9.136 - * calls exit().
   9.137 - */
   9.138 -int
   9.139 -error_handler(Display *dpy, XErrorEvent *error)
   9.140 -{
   9.141 -	if(error->error_code == BadWindow
   9.142 -			|| (error->request_code == X_SetInputFocus
   9.143 -				&& error->error_code == BadMatch)
   9.144 -			|| (error->request_code == X_PolyText8
   9.145 -				&& error->error_code == BadDrawable)
   9.146 -			|| (error->request_code == X_PolyFillRectangle
   9.147 -				&& error->error_code == BadDrawable)
   9.148 -			|| (error->request_code == X_PolySegment
   9.149 -				&& error->error_code == BadDrawable)
   9.150 -			|| (error->request_code == X_ConfigureWindow
   9.151 -				&& error->error_code == BadMatch)
   9.152 -			|| (error->request_code == X_GrabKey
   9.153 -				&& error->error_code == BadAccess))
   9.154 -		return 0;
   9.155 -	fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
   9.156 -			error->request_code, error->error_code);
   9.157 -	return x_error_handler(dpy, error); /* may call exit() */
   9.158 -}
   9.159 -
   9.160 -/*
   9.161 - * Startup Error handler to check if another window manager
   9.162 - * is already running.
   9.163 - */
   9.164 -static int
   9.165 -startup_error_handler(Display *dpy, XErrorEvent *error)
   9.166 -{
   9.167 -	other_wm_running = True;
   9.168 -	return -1;
   9.169 -}
   9.170 -
   9.171 -static void
   9.172 -cleanup()
   9.173 -{
   9.174 -	while(clients)
   9.175 -		unmanage(clients);
   9.176 -	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
   9.177 -}
   9.178 -
   9.179 -void
   9.180 -quit(void *aux)
   9.181 -{
   9.182 -	running = False;
   9.183 -}
   9.184 -
   9.185 -int
   9.186 -main(int argc, char *argv[])
   9.187 -{
   9.188 -	int i;
   9.189 -	XSetWindowAttributes wa;
   9.190 -	unsigned int mask;
   9.191 -	Window w;
   9.192 -	XEvent ev;
   9.193 -
   9.194 -	/* command line args */
   9.195 -	for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
   9.196 -		switch (argv[i][1]) {
   9.197 -		case 'v':
   9.198 -			fprintf(stdout, "%s", version);
   9.199 -			exit(0);
   9.200 -			break;
   9.201 -		default:
   9.202 -			usage();
   9.203 -			break;
   9.204 -		}
   9.205 -	}
   9.206 -
   9.207 -	dpy = XOpenDisplay(0);
   9.208 -	if(!dpy)
   9.209 -		error("dwm: cannot connect X server\n");
   9.210 -
   9.211 -	screen = DefaultScreen(dpy);
   9.212 -	root = RootWindow(dpy, screen);
   9.213 -
   9.214 -	/* check if another WM is already running */
   9.215 -	other_wm_running = False;
   9.216 -	XSetErrorHandler(startup_error_handler);
   9.217 -	/* this causes an error if some other WM is running */
   9.218 -	XSelectInput(dpy, root, SubstructureRedirectMask);
   9.219 -	XFlush(dpy);
   9.220 -
   9.221 -	if(other_wm_running)
   9.222 -		error("dwm: another window manager is already running\n");
   9.223 -
   9.224 -	sx = sy = 0;
   9.225 -	sw = DisplayWidth(dpy, screen);
   9.226 -	sh = DisplayHeight(dpy, screen);
   9.227 -	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
   9.228 -
   9.229 -	XSetErrorHandler(0);
   9.230 -	x_error_handler = XSetErrorHandler(error_handler);
   9.231 -
   9.232 -	/* init atoms */
   9.233 -	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
   9.234 -	wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
   9.235 -	net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
   9.236 -	net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
   9.237 -
   9.238 -	XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
   9.239 -			PropModeReplace, (unsigned char *) net_atom, NetLast);
   9.240 -
   9.241 -
   9.242 -	/* init cursors */
   9.243 -	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
   9.244 -	cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
   9.245 -	cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
   9.246 -
   9.247 -	update_keys();
   9.248 -
   9.249 -	/* style */
   9.250 -	initcolors(BGCOLOR, FGCOLOR, BORDERCOLOR);
   9.251 -	initfont(&dc.font, FONT);
   9.252 -
   9.253 -	th = texth(&dc.font);
   9.254 -
   9.255 -	dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen));
   9.256 -	dc.gc = XCreateGC(dpy, root, 0, 0);
   9.257 -
   9.258 -	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
   9.259 -					| LeaveWindowMask;
   9.260 -	wa.cursor = cursor[CurNormal];
   9.261 -	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   9.262 -
   9.263 -	scan_wins();
   9.264 -
   9.265 -	while(running) {
   9.266 -		XNextEvent(dpy, &ev);
   9.267 -		if(handler[ev.type])
   9.268 -			(handler[ev.type])(&ev); /* call handler */
   9.269 -	}
   9.270 -
   9.271 -	cleanup();
   9.272 -	XCloseDisplay(dpy);
   9.273 -
   9.274 -	return 0;
   9.275 -}
    10.1 --- a/wm.h	Thu Jul 13 10:34:55 2006 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,137 +0,0 @@
    10.4 -/*
    10.5 - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
    10.6 - * See LICENSE file for license details.
    10.7 - */
    10.8 -
    10.9 -#include <X11/Xlib.h>
   10.10 -
   10.11 -/********** CUSTOMIZE **********/
   10.12 -
   10.13 -#define FONT		"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
   10.14 -#define BGCOLOR		"#666699"
   10.15 -#define FGCOLOR		"#ffffff"
   10.16 -#define BORDERCOLOR	"#9999CC"
   10.17 -#define STATUSDELAY	10 /* seconds */
   10.18 -#define WM_PROTOCOL_DELWIN 1
   10.19 -
   10.20 -/* tags */
   10.21 -enum { Tscratch, Tdev, Tirc, Twww, Twork, TLast };
   10.22 -
   10.23 -/********** CUSTOMIZE **********/
   10.24 -
   10.25 -typedef struct DC DC;
   10.26 -typedef struct Client Client;
   10.27 -typedef struct Fnt Fnt;
   10.28 -typedef struct Key Key;
   10.29 -
   10.30 -/* atoms */
   10.31 -enum { WMProtocols, WMDelete, WMLast };
   10.32 -enum { NetSupported, NetWMName, NetLast };
   10.33 -
   10.34 -/* cursor */
   10.35 -enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
   10.36 -
   10.37 -struct Fnt {
   10.38 -	XFontStruct *xfont;
   10.39 -	XFontSet set;
   10.40 -	int ascent;
   10.41 -	int descent;
   10.42 -	int height;
   10.43 -};
   10.44 -
   10.45 -struct DC { /* draw context */
   10.46 -	GC gc;
   10.47 -	Drawable drawable;
   10.48 -	int x, y, w, h;
   10.49 -	Fnt font;
   10.50 -	unsigned long bg;
   10.51 -	unsigned long fg;
   10.52 -	unsigned long border;
   10.53 -};
   10.54 -
   10.55 -struct Client {
   10.56 -	char name[256];
   10.57 -	char *tags[TLast];
   10.58 -	int proto;
   10.59 -	int x, y, w, h;
   10.60 -	int tx, ty, tw, th;
   10.61 -	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
   10.62 -	int grav;
   10.63 -	unsigned int border;
   10.64 -	long flags; 
   10.65 -	Window win;
   10.66 -	Window trans;
   10.67 -	Window title;
   10.68 -	Client *next;
   10.69 -	Client *snext;
   10.70 -};
   10.71 -
   10.72 -struct Key {
   10.73 -	unsigned long mod;
   10.74 -	KeySym keysym;
   10.75 -	void (*func)(void *aux);
   10.76 -	void *aux;
   10.77 -};
   10.78 -
   10.79 -extern Display *dpy;
   10.80 -extern Window root;
   10.81 -extern Atom wm_atom[WMLast], net_atom[NetLast];
   10.82 -extern Cursor cursor[CurLast];
   10.83 -extern Bool running, issel;
   10.84 -extern void (*handler[LASTEvent]) (XEvent *);
   10.85 -
   10.86 -extern int tsel, screen, sx, sy, sw, sh, th;
   10.87 -extern char stext[1024], *tags[TLast];
   10.88 -
   10.89 -extern DC dc;
   10.90 -extern Client *clients, *stack;
   10.91 -
   10.92 -/* client.c */
   10.93 -extern void manage(Window w, XWindowAttributes *wa);
   10.94 -extern void unmanage(Client *c);
   10.95 -extern Client *getclient(Window w);
   10.96 -extern void focus(Client *c);
   10.97 -extern void update_name(Client *c);
   10.98 -extern void draw_client(Client *c);
   10.99 -extern void resize(Client *c);
  10.100 -extern void update_size(Client *c);
  10.101 -extern Client *gettitle(Window w);
  10.102 -extern void craise(Client *c);
  10.103 -extern void lower(Client *c);
  10.104 -extern void ckill(void *aux);
  10.105 -extern void sel(void *aux);
  10.106 -extern void max(void *aux);
  10.107 -extern void toggle(void *aux);
  10.108 -extern void gravitate(Client *c, Bool invert);
  10.109 -
  10.110 -/* draw.c */
  10.111 -extern void draw(Bool border, const char *text);
  10.112 -extern void initcolors(const char *bg, const char *fg, const char *bo);
  10.113 -extern void initfont(Fnt *font, const char *fontstr);
  10.114 -extern unsigned int textnw(Fnt *font, char *text, unsigned int len);
  10.115 -extern unsigned int textw(Fnt *font, char *text);
  10.116 -extern unsigned int texth(Fnt *font);
  10.117 -
  10.118 -/* event.c */
  10.119 -extern void discard_events(long even_mask);
  10.120 -
  10.121 -/* dev.c */
  10.122 -extern void update_keys(void);
  10.123 -extern void keypress(XEvent *e);
  10.124 -extern void mresize(Client *c);
  10.125 -extern void mmove(Client *c);
  10.126 -
  10.127 -/* util.c */
  10.128 -extern void error(const char *errstr, ...);
  10.129 -extern void *emallocz(unsigned int size);
  10.130 -extern void *emalloc(unsigned int size);
  10.131 -extern void *erealloc(void *ptr, unsigned int size);
  10.132 -extern char *estrdup(const char *str);
  10.133 -extern void spawn(char *argv[]);
  10.134 -extern void swap(void **p1, void **p2);
  10.135 -
  10.136 -/* wm.c */
  10.137 -extern int error_handler(Display *dsply, XErrorEvent *e);
  10.138 -extern void send_message(Window w, Atom a, long value);
  10.139 -extern int win_proto(Window w);
  10.140 -extern void quit(void *aux);