about summary refs log tree commit diff stats
path: root/config.arg.h
blob: a427096568f901889714e0e0c1f772635a39efd6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* See LICENSE file for copyright and license details. */

/* appearance */
#define BARPOS			BarTop /* BarBot, BarOff */
#define BORDERPX		1
#define FONT			"-*-terminus-medium-r-*-*-12-*-*-*-*-*-iso10646-*"
#define NORMBORDERCOLOR		"#333"
#define NORMBGCOLOR		"#222"
#define NORMFGCOLOR		"#ccc"
#define SELBORDERCOLOR		"#59a"
#define SELBGCOLOR		"#555"
#define SELFGCOLOR		"#fff"

/* tagging */
#define TAGS \
const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
#define RULES \
static Rule rules[] = { \
	/* class:instance:title regex	tags regex	isfloating */ \
	{ "Firefox",			"3",		False }, \
	{ "Gimp",			NULL,		True }, \
	{ "MPlayer",			NULL,		True }, \
	{ "Acroread",			NULL,		True }, \
};

/* layout(s) */
#include "tile.h"
#define LAYOUTS \
static Layout layouts[] = { \
	/* symbol		function */ \
	{ "[]=",		tile }, /* first entry is default */ \
	{ "><>",		floating }, \
};
#define MWFACT			0.6	/* master width factor [0.1 .. 0.9] */
#define SNAP			32	/* snap pixel */

/* key definitions */
#define MODKEY			Mod1Mask
#define KEYS \
Key keys[] = { \
	/* modifier			key		function	argument */ \
	{ MODKEY,			XK_p,		spawn, \
		"exe=`dmenu_path | dmenu -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"'" \
		" -sb '"SELBGCOLOR"' -sf '"SELFGCOLOR"'` && exec $exe" }, \
	{ MODKEY|ShiftMask,		XK_Return,	spawn, \
		"exec urxvtcd -tr -bg '#111' -fg '#eee' -cr '#eee' +sb -fn '"FONT"'" }, \
	{ MODKEY,			XK_space,	setlayout,	NULL }, \
	{ MODKEY,			XK_b,		togglebar,	NULL }, \
	{ MODKEY,			XK_j,		focusnext,	NULL }, \
	{ MODKEY,			XK_k,		focusprev,	NULL }, \
	{ MODKEY,			XK_h,		setmwfact,	"-0.05" }, \
	{ MODKEY,			XK_l,		setmwfact,	"+0.05" }, \
	{ MODKEY,			XK_m,		togglemax,	NULL }, \
	{ MODKEY,			XK_Return,	zoom,		NULL }, \
	{ MODKEY|ShiftMask,		XK_space,	togglefloating,	NULL }, \
	{ MODKEY|ShiftMask,		XK_c,		killclient,	NULL }, \
	{ MODKEY,			XK_0,		view,		NULL }, \
	{ MODKEY,			XK_1,		view,		tags[0] }, \
	{ MODKEY,			XK_2,		view,		tags[1] }, \
	{ MODKEY,			XK_3,		view,		tags[2] }, \
	{ MODKEY,			XK_4,		view,		tags[3] }, \
	{ MODKEY,			XK_5,		view,		tags[4] }, \
	{ MODKEY,			XK_6,		view,		tags[5] }, \
	{ MODKEY,			XK_7,		view,		tags[6] }, \
	{ MODKEY,			XK_8,		view,		tags[7] }, \
	{ MODKEY,			XK_9,		view,		tags[8] }, \
	{ MODKEY|ControlMask,		XK_1,		toggleview,	tags[0] }, \
	{ MODKEY|ControlMask,		XK_2,		toggleview,	tags[1] }, \
	{ MODKEY|ControlMask,		XK_3,		toggleview,	tags[2] }, \
	{ MODKEY|ControlMask,		XK_4,		toggleview,	tags[3] }, \
	{ MODKEY|ControlMask,		XK_5,		toggleview,	tags[4] }, \
	{ MODKEY|ControlMask,		XK_6,		toggleview,	tags[5] }, \
	{ MODKEY|ControlMask,		XK_7,		toggleview,	tags[6] }, \
	{ MODKEY|ControlMask,		XK_8,		toggleview,	tags[7] }, \
	{ MODKEY|ControlMask,		XK_9,		toggleview,	tags[8] }, \
	{ MODKEY|ShiftMask,		XK_0,		tag,		NULL }, \
	{ MODKEY|ShiftMask,		XK_1,		tag,		tags[0] }, \
	{ MODKEY|ShiftMask,		XK_2,		tag,		tags[1] }, \
	{ MODKEY|ShiftMask,		XK_3,		tag,		tags[2] }, \
	{ MODKEY|ShiftMask,		XK_4,		tag,		tags[3] }, \
	{ MODKEY|ShiftMask,		XK_5,		tag,		tags[4] }, \
	{ MODKEY|ShiftMask,		XK_6,		tag,		tags[5] }, \
	{ MODKEY|ShiftMask,		XK_7,		tag,		tags[6] }, \
	{ MODKEY|ShiftMask,		XK_8,		tag,		tags[7] }, \
	{ MODKEY|ShiftMask,		XK_9,		tag,		tags[8] }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_1,		toggletag,	tags[0] }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_2,		toggletag,	tags[1] }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_3,		toggletag,	tags[2] }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_4,		toggletag,	tags[3] }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_5,		toggletag,	tags[4] }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_6,		toggletag,	tags[5] }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_7,		toggletag,	tags[6] }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_8,		toggletag,	tags[7] }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_9,		toggletag,	tags[8] }, \
	{ MODKEY|ShiftMask,		XK_q,		quit,		NULL }, \
};
lass="n">root, barwin; Atom wm_atom[WMLast], net_atom[NetLast]; Cursor cursor[CurLast]; XRectangle rect, barrect; Bool running = True; Bool sel_screen; char *bartext, tag[256]; int screen; Brush brush = {0}; Client *clients = NULL; Client *stack = NULL; static Bool other_wm_running; static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; static int (*x_error_handler) (Display *, XErrorEvent *); static void usage() { fputs("usage: gridwm [-v]\n", stderr); exit(1); } static void scan_wins() { unsigned int i, num; Window *wins; XWindowAttributes wa; Window d1, d2; if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { for(i = 0; i < num; i++) { if(!XGetWindowAttributes(dpy, wins[i], &wa)) continue; if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) continue; if(wa.map_state == IsViewable) manage(wins[i], &wa); } } if(wins) XFree(wins); } static int win_property(Window w, Atom a, Atom t, long l, unsigned char **prop) { Atom real; int format; unsigned long res, extra; int status; status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, &res, &extra, prop); if(status != Success || *prop == 0) { return 0; } if(res == 0) { free((void *) *prop); } return res; } int win_proto(Window w) { Atom *protocols; long res; int protos = 0; int i; res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, ((unsigned char **) &protocols)); if(res <= 0) { return protos; } for(i = 0; i < res; i++) { if(protocols[i] == wm_atom[WMDelete]) protos |= WM_PROTOCOL_DELWIN; } free((char *) protocols); return protos; } void send_message(Window w, Atom a, long value) { XEvent e; e.type = ClientMessage; e.xclient.window = w; e.xclient.message_type = a; e.xclient.format = 32; e.xclient.data.l[0] = value; e.xclient.data.l[1] = CurrentTime; XSendEvent(dpy, w, False, NoEventMask, &e); XFlush(dpy); } /* * There's no way to check accesses to destroyed windows, thus * those cases are ignored (especially on UnmapNotify's). * Other types of errors call Xlib's default error handler, which * calls exit(). */ int error_handler(Display *dpy, XErrorEvent *error) { if(error->error_code == BadWindow || (error->request_code == X_SetInputFocus && error->error_code == BadMatch) || (error->request_code == X_PolyText8 && error->error_code == BadDrawable) || (error->request_code == X_PolyFillRectangle && error->error_code == BadDrawable) || (error->request_code == X_PolySegment && error->error_code == BadDrawable) || (error->request_code == X_ConfigureWindow && error->error_code == BadMatch) || (error->request_code == X_GrabKey && error->error_code == BadAccess)) return 0; fprintf(stderr, "gridwm: fatal error: request code=%d, error code=%d\n", error->request_code, error->error_code); return x_error_handler(dpy, error); /* may call exit() */ } /* * Startup Error handler to check if another window manager * is already running. */ static int startup_error_handler(Display *dpy, XErrorEvent *error) { other_wm_running = True; return -1; } static void cleanup() { /* Client *c; for(c=client; c; c=c->next) reparent_client(c, root, c->sel->rect.x, c->sel->rect.y); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); */ } int main(int argc, char *argv[]) { int i; XSetWindowAttributes wa; unsigned int mask; Window w; XEvent ev; /* command line args */ for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { switch (argv[i][1]) { case 'v': fprintf(stdout, "%s", version); exit(0); break; default: usage(); break; } } dpy = XOpenDisplay(0); if(!dpy) error("gridwm: cannot connect X server\n"); screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); /* check if another WM is already running */ other_wm_running = False; XSetErrorHandler(startup_error_handler); /* this causes an error if some other WM is running */ XSelectInput(dpy, root, SubstructureRedirectMask); XFlush(dpy); if(other_wm_running) error("gridwm: another window manager is already running\n"); rect.x = rect.y = 0; rect.width = DisplayWidth(dpy, screen); rect.height = DisplayHeight(dpy, screen); sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); XSetErrorHandler(0); x_error_handler = XSetErrorHandler(error_handler); /* init atoms */ wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32, PropModeReplace, (unsigned char *) net_atom, NetLast); /* init cursors */ cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); update_keys(); brush.drawable = XCreatePixmap(dpy, root, rect.width, rect.height, DefaultDepth(dpy, screen)); brush.gc = XCreateGC(dpy, root, 0, 0); /* style */ loadcolors(dpy, screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR); loadfont(dpy, &brush.font, FONT); wa.override_redirect = 1; wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask; barrect = rect; barrect.height = labelheight(&brush.font); barrect.y = rect.height - barrect.height; barwin = XCreateWindow(dpy, root, barrect.x, barrect.y, barrect.width, barrect.height, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); bartext = NULL; XDefineCursor(dpy, barwin, cursor[CurNormal]); XMapRaised(dpy, barwin); draw_bar(); wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ | LeaveWindowMask; wa.cursor = cursor[CurNormal]; XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); scan_wins(); while(running) { XNextEvent(dpy, &ev); if(handler[ev.type]) (handler[ev.type]) (&ev); /* call handler */ } cleanup(); XCloseDisplay(dpy); return 0; }