summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--calmwm.h6
-rw-r--r--client.c152
-rw-r--r--conf.c16
-rw-r--r--group.c5
-rw-r--r--kbfunc.c25
-rw-r--r--menu.c35
-rw-r--r--mousefunc.c12
-rw-r--r--screen.c98
-rw-r--r--search.c28
-rw-r--r--xevents.c80
11 files changed, 246 insertions, 215 deletions
diff --git a/Makefile b/Makefile
index 10f8737..b73b653 100644
--- a/Makefile
+++ b/Makefile
@@ -14,11 +14,11 @@ OBJS=		calmwm.o screen.o xmalloc.o client.o menu.o \
 		kbfunc.o mousefunc.o strlcpy.o strlcat.o y.tab.o \
 		strtonum.o fgetln.o reallocarray.o
 
-CPPFLAGS+=	`pkg-config --cflags fontconfig x11 xft xinerama xrandr`
+CPPFLAGS+=	`pkg-config --cflags fontconfig x11 xft xrandr`
 
 CFLAGS?=	-Wall -O2 -g -D_GNU_SOURCE
 
-LDFLAGS+=	`pkg-config --libs fontconfig x11 xft xinerama xrandr`
+LDFLAGS+=	`pkg-config --libs fontconfig x11 xft xrandr`
 
 MANPREFIX?=	${PREFIX}/share/man
 
diff --git a/calmwm.h b/calmwm.h
index 99bad1f..9fe819b 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -49,7 +49,6 @@ size_t strlcpy(char *, const char *, size_t);
 #include <X11/Xproto.h>
 #include <X11/Xutil.h>
 #include <X11/cursorfont.h>
-#include <X11/extensions/Xinerama.h>
 #include <X11/extensions/Xrandr.h>
 #include <X11/keysym.h>
 
@@ -471,10 +470,11 @@ void			 search_match_path_any(struct menu_q *, struct menu_q *,
 void			 search_match_text(struct menu_q *, struct menu_q *,
 			     char *);
 void			 search_print_client(struct menu *, int);
+void			 search_print_cmd(struct menu *, int);
 
+struct geom		 screen_apply_gap(struct screen_ctx *, struct geom);
 struct screen_ctx	*screen_find(Window);
-struct geom		 screen_find_xinerama(struct screen_ctx *,
-    			     int, int, int);
+struct geom		 screen_area(struct screen_ctx *, int, int, int);
 void			 screen_init(int);
 void			 screen_update_geometry(struct screen_ctx *);
 void			 screen_updatestackingorder(struct screen_ctx *);
diff --git a/client.c b/client.c
index f8b4e92..7332402 100644
--- a/client.c
+++ b/client.c
@@ -21,7 +21,6 @@
 #include <sys/types.h>
 #include "queue.h"
 
-#include <assert.h>
 #include <err.h>
 #include <errno.h>
 #include <limits.h>
@@ -44,21 +43,6 @@ static int			 client_inbound(struct client_ctx *, int, int);
 struct client_ctx	*curcc = NULL;
 
 struct client_ctx *
-client_find(Window win)
-{
-	struct screen_ctx	*sc;
-	struct client_ctx	*cc;
-
-	TAILQ_FOREACH(sc, &Screenq, entry) {
-		TAILQ_FOREACH(cc, &sc->clientq, entry) {
-			if (cc->win == win)
-				return(cc);
-		}
-	}
-	return(NULL);
-}
-
-struct client_ctx *
 client_init(Window win, struct screen_ctx *sc)
 {
 	struct client_ctx	*cc;
@@ -71,7 +55,8 @@ client_init(Window win, struct screen_ctx *sc)
 		return(NULL);
 
 	if (sc == NULL) {
-		sc = screen_find(wattr.root);
+		if ((sc = screen_find(wattr.root)) == NULL)
+			return(NULL);
 		mapped = 1;
 	} else {
 		if (wattr.override_redirect || wattr.map_state != IsViewable)
@@ -143,6 +128,21 @@ client_init(Window win, struct screen_ctx *sc)
 	return(cc);
 }
 
+struct client_ctx *
+client_find(Window win)
+{
+	struct screen_ctx	*sc;
+	struct client_ctx	*cc;
+
+	TAILQ_FOREACH(sc, &Screenq, entry) {
+		TAILQ_FOREACH(cc, &sc->clientq, entry) {
+			if (cc->win == win)
+				return(cc);
+		}
+	}
+	return(NULL);
+}
+
 void
 client_delete(struct client_ctx *cc)
 {
@@ -265,7 +265,7 @@ void
 client_toggle_fullscreen(struct client_ctx *cc)
 {
 	struct screen_ctx	*sc = cc->sc;
-	struct geom		 xine;
+	struct geom		 area;
 
 	if ((cc->flags & CLIENT_FREEZE) &&
 	    !(cc->flags & CLIENT_FULLSCREEN))
@@ -280,12 +280,12 @@ client_toggle_fullscreen(struct client_ctx *cc)
 
 	cc->fullgeom = cc->geom;
 
-	xine = screen_find_xinerama(sc,
+	area = screen_area(sc,
 	    cc->geom.x + cc->geom.w / 2,
 	    cc->geom.y + cc->geom.h / 2, CWM_NOGAP);
 
 	cc->bwidth = 0;
-	cc->geom = xine;
+	cc->geom = area;
 	cc->flags |= (CLIENT_FULLSCREEN | CLIENT_FREEZE);
 
 resize:
@@ -297,7 +297,7 @@ void
 client_toggle_maximize(struct client_ctx *cc)
 {
 	struct screen_ctx	*sc = cc->sc;
-	struct geom		 xine;
+	struct geom		 area;
 
 	if (cc->flags & (CLIENT_FREEZE|CLIENT_STICKY))
 		return;
@@ -323,14 +323,14 @@ client_toggle_maximize(struct client_ctx *cc)
 	 * that's probably more fair than if just the origin of
 	 * a window is poking over a boundary
 	 */
-	xine = screen_find_xinerama(sc,
+	area = screen_area(sc,
 	    cc->geom.x + cc->geom.w / 2,
 	    cc->geom.y + cc->geom.h / 2, CWM_GAP);
 
-	cc->geom.x = xine.x;
-	cc->geom.y = xine.y;
-	cc->geom.w = xine.w - (cc->bwidth * 2);
-	cc->geom.h = xine.h - (cc->bwidth * 2);
+	cc->geom.x = area.x;
+	cc->geom.y = area.y;
+	cc->geom.w = area.w - (cc->bwidth * 2);
+	cc->geom.h = area.h - (cc->bwidth * 2);
 	cc->flags |= CLIENT_MAXIMIZED;
 
 resize:
@@ -342,7 +342,7 @@ void
 client_toggle_vmaximize(struct client_ctx *cc)
 {
 	struct screen_ctx	*sc = cc->sc;
-	struct geom		 xine;
+	struct geom		 area;
 
 	if (cc->flags & (CLIENT_FREEZE|CLIENT_STICKY))
 		return;
@@ -357,12 +357,12 @@ client_toggle_vmaximize(struct client_ctx *cc)
 	cc->savegeom.y = cc->geom.y;
 	cc->savegeom.h = cc->geom.h;
 
-	xine = screen_find_xinerama(sc,
+	area = screen_area(sc,
 	    cc->geom.x + cc->geom.w / 2,
 	    cc->geom.y + cc->geom.h / 2, CWM_GAP);
 
-	cc->geom.y = xine.y;
-	cc->geom.h = xine.h - (cc->bwidth * 2);
+	cc->geom.y = area.y;
+	cc->geom.h = area.h - (cc->bwidth * 2);
 	cc->flags |= CLIENT_VMAXIMIZED;
 
 resize:
@@ -374,7 +374,7 @@ void
 client_toggle_hmaximize(struct client_ctx *cc)
 {
 	struct screen_ctx	*sc = cc->sc;
-	struct geom		 xine;
+	struct geom		 area;
 
 	if (cc->flags & (CLIENT_FREEZE|CLIENT_STICKY))
 		return;
@@ -389,12 +389,12 @@ client_toggle_hmaximize(struct client_ctx *cc)
 	cc->savegeom.x = cc->geom.x;
 	cc->savegeom.w = cc->geom.w;
 
-	xine = screen_find_xinerama(sc,
+	area = screen_area(sc,
 	    cc->geom.x + cc->geom.w / 2,
 	    cc->geom.y + cc->geom.h / 2, CWM_GAP);
 
-	cc->geom.x = xine.x;
-	cc->geom.w = xine.w - (cc->bwidth * 2);
+	cc->geom.x = area.x;
+	cc->geom.w = area.w - (cc->bwidth * 2);
 	cc->flags |= CLIENT_HMAXIMIZED;
 
 resize:
@@ -635,8 +635,8 @@ match:
 
 	/* Now, do some garbage collection. */
 	if (cc->nameqlen > CLIENT_MAXNAMEQLEN) {
-		wn = TAILQ_FIRST(&cc->nameq);
-		assert(wn != NULL);
+		if ((wn = TAILQ_FIRST(&cc->nameq)) == NULL)
+			errx(1, "client_setname: window name queue empty");
 		TAILQ_REMOVE(&cc->nameq, wn, entry);
 		free(wn->name);
 		free(wn);
@@ -740,33 +740,33 @@ client_placecalc(struct client_ctx *cc)
 		cc->geom.x = MIN(cc->geom.x, xslack);
 		cc->geom.y = MIN(cc->geom.y, yslack);
 	} else {
-		struct geom		 xine;
+		struct geom		 area;
 		int			 xmouse, ymouse;
 
 		xu_ptr_getpos(sc->rootwin, &xmouse, &ymouse);
-		xine = screen_find_xinerama(sc, xmouse, ymouse, CWM_GAP);
-		xine.w += xine.x;
-		xine.h += xine.y;
-		xmouse = MAX(xmouse, xine.x) - cc->geom.w / 2;
-		ymouse = MAX(ymouse, xine.y) - cc->geom.h / 2;
+		area = screen_area(sc, xmouse, ymouse, CWM_GAP);
+		area.w += area.x;
+		area.h += area.y;
+		xmouse = MAX(xmouse, area.x) - cc->geom.w / 2;
+		ymouse = MAX(ymouse, area.y) - cc->geom.h / 2;
 
-		xmouse = MAX(xmouse, xine.x);
-		ymouse = MAX(ymouse, xine.y);
+		xmouse = MAX(xmouse, area.x);
+		ymouse = MAX(ymouse, area.y);
 
-		xslack = xine.w - cc->geom.w - cc->bwidth * 2;
-		yslack = xine.h - cc->geom.h - cc->bwidth * 2;
+		xslack = area.w - cc->geom.w - cc->bwidth * 2;
+		yslack = area.h - cc->geom.h - cc->bwidth * 2;
 
-		if (xslack >= xine.x) {
-			cc->geom.x = MAX(MIN(xmouse, xslack), xine.x);
+		if (xslack >= area.x) {
+			cc->geom.x = MAX(MIN(xmouse, xslack), area.x);
 		} else {
-			cc->geom.x = xine.x;
-			cc->geom.w = xine.w;
+			cc->geom.x = area.x;
+			cc->geom.w = area.w;
 		}
-		if (yslack >= xine.y) {
-			cc->geom.y = MAX(MIN(ymouse, yslack), xine.y);
+		if (yslack >= area.y) {
+			cc->geom.y = MAX(MIN(ymouse, yslack), area.y);
 		} else {
-			cc->geom.y = xine.y;
-			cc->geom.h = xine.h;
+			cc->geom.y = area.y;
+			cc->geom.h = area.h;
 		}
 	}
 }
@@ -949,7 +949,7 @@ client_htile(struct client_ctx *cc)
 	struct client_ctx	*ci;
 	struct group_ctx 	*gc = cc->group;
 	struct screen_ctx 	*sc = cc->sc;
-	struct geom 		 xine;
+	struct geom 		 area;
 	int 			 i, n, mh, x, h, w;
 
 	if (!gc)
@@ -965,36 +965,36 @@ client_htile(struct client_ctx *cc)
 	if (n == 0)
 		return;
 
-	xine = screen_find_xinerama(sc,
+	area = screen_area(sc,
 	    cc->geom.x + cc->geom.w / 2,
 	    cc->geom.y + cc->geom.h / 2, CWM_GAP);
 
 	if (cc->flags & CLIENT_VMAXIMIZED ||
-	    cc->geom.h + (cc->bwidth * 2) >= xine.h)
+	    cc->geom.h + (cc->bwidth * 2) >= area.h)
 		return;
 
 	cc->flags &= ~CLIENT_HMAXIMIZED;
-	cc->geom.x = xine.x;
-	cc->geom.y = xine.y;
-	cc->geom.w = xine.w - (cc->bwidth * 2);
+	cc->geom.x = area.x;
+	cc->geom.y = area.y;
+	cc->geom.w = area.w - (cc->bwidth * 2);
 	client_resize(cc, 1);
 	client_ptrwarp(cc);
 
 	mh = cc->geom.h + (cc->bwidth * 2);
-	x = xine.x;
-	w = xine.w / n;
-	h = xine.h - mh;
+	x = area.x;
+	w = area.w / n;
+	h = area.h - mh;
 	TAILQ_FOREACH(ci, &gc->clientq, group_entry) {
 		if (ci->flags & CLIENT_HIDDEN ||
 		    ci->flags & CLIENT_IGNORE || (ci == cc))
 			continue;
 		ci->bwidth = Conf.bwidth;
-		ci->geom.y = xine.y + mh;
+		ci->geom.y = area.y + mh;
 		ci->geom.x = x;
 		ci->geom.h = h - (ci->bwidth * 2);
 		ci->geom.w = w - (ci->bwidth * 2);
 		if (i + 1 == n)
-			ci->geom.w = xine.x + xine.w -
+			ci->geom.w = area.x + area.w -
 			    ci->geom.x - (ci->bwidth * 2);
 		x += w;
 		client_resize(ci, 1);
@@ -1008,7 +1008,7 @@ client_vtile(struct client_ctx *cc)
 	struct client_ctx	*ci;
 	struct group_ctx 	*gc = cc->group;
 	struct screen_ctx 	*sc = cc->sc;
-	struct geom 		 xine;
+	struct geom 		 area;
 	int 			 i, n, mw, y, h, w;
 
 	if (!gc)
@@ -1024,36 +1024,36 @@ client_vtile(struct client_ctx *cc)
 	if (n == 0)
 		return;
 
-	xine = screen_find_xinerama(sc,
+	area = screen_area(sc,
 	    cc->geom.x + cc->geom.w / 2,
 	    cc->geom.y + cc->geom.h / 2, CWM_GAP);
 
 	if (cc->flags & CLIENT_HMAXIMIZED ||
-	    cc->geom.w + (cc->bwidth * 2) >= xine.w)
+	    cc->geom.w + (cc->bwidth * 2) >= area.w)
 		return;
 
 	cc->flags &= ~CLIENT_VMAXIMIZED;
-	cc->geom.x = xine.x;
-	cc->geom.y = xine.y;
-	cc->geom.h = xine.h - (cc->bwidth * 2);
+	cc->geom.x = area.x;
+	cc->geom.y = area.y;
+	cc->geom.h = area.h - (cc->bwidth * 2);
 	client_resize(cc, 1);
 	client_ptrwarp(cc);
 
 	mw = cc->geom.w + (cc->bwidth * 2);
-	y = xine.y;
-	h = xine.h / n;
-	w = xine.w - mw;
+	y = area.y;
+	h = area.h / n;
+	w = area.w - mw;
 	TAILQ_FOREACH(ci, &gc->clientq, group_entry) {
 		if (ci->flags & CLIENT_HIDDEN ||
 		    ci->flags & CLIENT_IGNORE || (ci == cc))
 			continue;
 		ci->bwidth = Conf.bwidth;
 		ci->geom.y = y;
-		ci->geom.x = xine.x + mw;
+		ci->geom.x = area.x + mw;
 		ci->geom.h = h - (ci->bwidth * 2);
 		ci->geom.w = w - (ci->bwidth * 2);
 		if (i + 1 == n)
-			ci->geom.h = xine.y + xine.h -
+			ci->geom.h = area.y + area.h -
 			    ci->geom.y - (ci->bwidth * 2);
 		y += h;
 		client_resize(ci, 1);
diff --git a/conf.c b/conf.c
index ce867cb..b3960fe 100644
--- a/conf.c
+++ b/conf.c
@@ -33,14 +33,14 @@
 #include "calmwm.h"
 
 static const char	*conf_bind_getmask(const char *, unsigned int *);
-static void	 	 conf_cmd_remove(struct conf *, const char *);
-static void	 	 conf_unbind_kbd(struct conf *, struct binding *);
-static void	 	 conf_unbind_mouse(struct conf *, struct binding *);
+static void		 conf_cmd_remove(struct conf *, const char *);
+static void		 conf_unbind_kbd(struct conf *, struct binding *);
+static void		 conf_unbind_mouse(struct conf *, struct binding *);
 
 int
 conf_cmd_add(struct conf *c, const char *name, const char *path)
 {
-	struct cmd	*cmd;
+	struct cmd	*cmd, *prev;
 
 	cmd = xmalloc(sizeof(*cmd));
 
@@ -54,6 +54,14 @@ conf_cmd_add(struct conf *c, const char *name, const char *path)
 	conf_cmd_remove(c, name);
 
 	TAILQ_INSERT_TAIL(&c->cmdq, cmd, entry);
+
+	/* keep queue sorted by name */
+	while ((prev = TAILQ_PREV(cmd, cmd_q, entry)) &&
+	    (strcmp(prev->name, cmd->name) > 0)) {
+		TAILQ_REMOVE(&c->cmdq, cmd, entry);
+		TAILQ_INSERT_BEFORE(prev, cmd, entry);
+	}
+
 	return(1);
 }
 
diff --git a/group.c b/group.c
index a10b130..9fe6115 100644
--- a/group.c
+++ b/group.c
@@ -22,7 +22,6 @@
 #include <sys/types.h>
 #include "queue.h"
 
-#include <assert.h>
 #include <err.h>
 #include <errno.h>
 #include <limits.h>
@@ -264,9 +263,9 @@ group_cycle(struct screen_ctx *sc, int flags)
 {
 	struct group_ctx	*gc, *showgroup = NULL;
 
-	assert(sc->group_active != NULL);
+	if (((gc = sc->group_active)) == NULL)
+		errx(1, "group_cycle: no active group");
 
-	gc = sc->group_active;
 	for (;;) {
 		gc = (flags & CWM_RCYCLE) ? TAILQ_PREV(gc, group_ctx_q,
 		    entry) : TAILQ_NEXT(gc, entry);
diff --git a/kbfunc.c b/kbfunc.c
index 68c91fa..e394b19 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -57,7 +57,7 @@ void
 kbfunc_client_moveresize(struct client_ctx *cc, union arg *arg)
 {
 	struct screen_ctx	*sc = cc->sc;
-	struct geom		 xine;
+	struct geom		 area;
 	int			 x, y, flags, amt;
 	unsigned int		 mx, my;
 
@@ -101,15 +101,15 @@ kbfunc_client_moveresize(struct client_ctx *cc, union arg *arg)
 		if (cc->geom.y > sc->view.h - 1)
 			cc->geom.y = sc->view.h - 1;
 
-		xine = screen_find_xinerama(sc,
+		area = screen_area(sc,
 		    cc->geom.x + cc->geom.w / 2,
 		    cc->geom.y + cc->geom.h / 2, CWM_GAP);
 		cc->geom.x += client_snapcalc(cc->geom.x,
 		    cc->geom.x + cc->geom.w + (cc->bwidth * 2),
-		    xine.x, xine.x + xine.w, sc->snapdist);
+		    area.x, area.x + area.w, sc->snapdist);
 		cc->geom.y += client_snapcalc(cc->geom.y,
 		    cc->geom.y + cc->geom.h + (cc->bwidth * 2),
-		    xine.y, xine.y + xine.h, sc->snapdist);
+		    area.y, area.y + area.h, sc->snapdist);
 
 		client_move(cc);
 		xu_ptr_getpos(cc->win, &x, &y);
@@ -178,10 +178,10 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg)
 
 	TAILQ_INIT(&menuq);
 	TAILQ_FOREACH(cmd, &Conf.cmdq, entry)
-		menuq_add(&menuq, cmd, "%s", cmd->name);
+		menuq_add(&menuq, cmd, NULL);
 
 	if ((mi = menu_filter(sc, &menuq, "application", NULL, 0,
-	    search_match_text, NULL)) != NULL)
+	    search_match_text, search_print_cmd)) != NULL)
 		u_spawn(((struct cmd *)mi->ctx)->path);
 
 	menuq_clear(&menuq);
@@ -335,18 +335,17 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
 	int			 l;
 	size_t			 len;
 
-	if ((fp = fopen(Conf.known_hosts, "r")) == NULL) {
-		warn("kbfunc_ssh: %s", Conf.known_hosts);
-		return;
-	}
-
 	TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
 		if (strcmp(cmd->name, "term") == 0)
 			break;
 	}
-
 	TAILQ_INIT(&menuq);
 
+	if ((fp = fopen(Conf.known_hosts, "r")) == NULL) {
+		warn("kbfunc_ssh: %s", Conf.known_hosts);
+		goto menu;
+	}
+
 	lbuf = NULL;
 	while ((buf = fgetln(fp, &len))) {
 		if (buf[len - 1] == '\n')
@@ -372,7 +371,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
 	}
 	free(lbuf);
 	(void)fclose(fp);
-
+menu:
 	if ((mi = menu_filter(sc, &menuq, "ssh", NULL, CWM_MENU_DUMMY,
 	    search_match_exec, NULL)) != NULL) {
 		if (mi->text[0] == '\0')
diff --git a/menu.c b/menu.c
index f0b864b..211264e 100644
--- a/menu.c
+++ b/menu.c
@@ -72,7 +72,7 @@ static void		 menu_draw(struct menu_ctx *, struct menu_q *,
 static void 		 menu_draw_entry(struct menu_ctx *, struct menu_q *,
 			     int, int);
 static int		 menu_calc_entry(struct menu_ctx *, int, int);
-static struct menu 	*menu_complete_path(struct menu_ctx *);
+static struct menu	*menu_complete_path(struct menu_ctx *);
 static int		 menu_keycode(XKeyEvent *, enum ctltype *, char *);
 
 struct menu *
@@ -184,6 +184,7 @@ out:
 static struct menu *
 menu_complete_path(struct menu_ctx *mc)
 {
+	struct screen_ctx	*sc = mc->sc;
 	struct menu		*mi, *mr;
 	struct menu_q		 menuq;
 
@@ -191,7 +192,7 @@ menu_complete_path(struct menu_ctx *mc)
 
 	TAILQ_INIT(&menuq);
 
-	if ((mi = menu_filter(mc->sc, &menuq, mc->searchstr, NULL,
+	if ((mi = menu_filter(sc, &menuq, mc->searchstr, NULL,
 	    CWM_MENU_DUMMY, search_match_path_any, NULL)) != NULL) {
 		mr->abort = mi->abort;
 		mr->dummy = mi->dummy;
@@ -331,7 +332,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
 {
 	struct screen_ctx	*sc = mc->sc;
 	struct menu		*mi;
-	struct geom		 xine;
+	struct geom		 area;
 	int			 n, xsave, ysave;
 
 	if (mc->list) {
@@ -374,25 +375,25 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
 		mc->num++;
 	}
 
-	xine = screen_find_xinerama(sc, mc->geom.x, mc->geom.y, CWM_GAP);
-	xine.w += xine.x - Conf.bwidth * 2;
-	xine.h += xine.y - Conf.bwidth * 2;
+	area = screen_area(sc, mc->geom.x, mc->geom.y, CWM_GAP);
+	area.w += area.x - Conf.bwidth * 2;
+	area.h += area.y - Conf.bwidth * 2;
 
 	xsave = mc->geom.x;
 	ysave = mc->geom.y;
 
 	/* Never hide the top, or left side, of the menu. */
-	if (mc->geom.x + mc->geom.w >= xine.w)
-		mc->geom.x = xine.w - mc->geom.w;
-	if (mc->geom.x < xine.x) {
-		mc->geom.x = xine.x;
-		mc->geom.w = MIN(mc->geom.w, (xine.w - xine.x));
+	if (mc->geom.x + mc->geom.w >= area.w)
+		mc->geom.x = area.w - mc->geom.w;
+	if (mc->geom.x < area.x) {
+		mc->geom.x = area.x;
+		mc->geom.w = MIN(mc->geom.w, (area.w - area.x));
 	}
-	if (mc->geom.y + mc->geom.h >= xine.h)
-		mc->geom.y = xine.h - mc->geom.h;
-	if (mc->geom.y < xine.y) {
-		mc->geom.y = xine.y;
-		mc->geom.h = MIN(mc->geom.h, (xine.h - xine.y));
+	if (mc->geom.y + mc->geom.h >= area.h)
+		mc->geom.y = area.h - mc->geom.h;
+	if (mc->geom.y < area.y) {
+		mc->geom.y = area.y;
+		mc->geom.h = MIN(mc->geom.h, (area.h - area.y));
 	}
 
 	if (mc->geom.x != xsave || mc->geom.y != ysave)
@@ -415,7 +416,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
 		int y = n * (sc->xftfont->height + 1) + sc->xftfont->ascent + 1;
 
 		/* Stop drawing when menu doesn't fit inside the screen. */
-		if (mc->geom.y + y > xine.h)
+		if (mc->geom.y + y > area.h)
 			break;
 
 		xu_xft_draw(sc, text, CWM_COLOR_MENU_FONT, 0, y);
diff --git a/mousefunc.c b/mousefunc.c
index 3c33d2a..645e652 100644
--- a/mousefunc.c
+++ b/mousefunc.c
@@ -123,7 +123,7 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg)
 	XEvent			 ev;
 	Time			 ltime = 0;
 	struct screen_ctx	*sc = cc->sc;
-	struct geom		 xine;
+	struct geom		 area;
 	int			 px, py;
 
 	client_raise(cc);
@@ -149,15 +149,15 @@ mousefunc_client_move(struct client_ctx *cc, union arg *arg)
 			cc->geom.x = ev.xmotion.x_root - px - cc->bwidth;
 			cc->geom.y = ev.xmotion.y_root - py - cc->bwidth;
 
-			xine = screen_find_xinerama(sc,
+			area = screen_area(sc,
 			    cc->geom.x + cc->geom.w / 2,
 			    cc->geom.y + cc->geom.h / 2, CWM_GAP);
 			cc->geom.x += client_snapcalc(cc->geom.x,
 			    cc->geom.x + cc->geom.w + (cc->bwidth * 2),
-			    xine.x, xine.x + xine.w, sc->snapdist);
+			    area.x, area.x + area.w, sc->snapdist);
 			cc->geom.y += client_snapcalc(cc->geom.y,
 			    cc->geom.y + cc->geom.h + (cc->bwidth * 2),
-			    xine.y, xine.y + xine.h, sc->snapdist);
+			    area.y, area.y + area.h, sc->snapdist);
 
 			client_move(cc);
 			break;
@@ -236,10 +236,10 @@ mousefunc_menu_cmd(struct client_ctx *cc, union arg *arg)
 
 	TAILQ_INIT(&menuq);
 	TAILQ_FOREACH(cmd, &Conf.cmdq, entry)
-		menuq_add(&menuq, cmd, "%s", cmd->name);
+		menuq_add(&menuq, cmd, NULL);
 
 	if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST,
-	    NULL, NULL)) != NULL)
+	    NULL, search_print_cmd)) != NULL)
 		u_spawn(((struct cmd *)mi->ctx)->path);
 
 	menuq_clear(&menuq);
diff --git a/screen.c b/screen.c
index e0aae1b..a8c4575 100644
--- a/screen.c
+++ b/screen.c
@@ -100,8 +100,8 @@ screen_find(Window win)
 		if (sc->rootwin == win)
 			return(sc);
 	}
-	/* XXX FAIL HERE */
-	return(TAILQ_FIRST(&Screenq));
+	warnx("screen_find failure win 0x%lu\n", win);
+	return(NULL);
 }
 
 void
@@ -124,68 +124,80 @@ screen_updatestackingorder(struct screen_ctx *sc)
 	}
 }
 
-/*
- * Find which xinerama screen the coordinates (x,y) is on.
- */
 struct geom
-screen_find_xinerama(struct screen_ctx *sc, int x, int y, int flags)
+screen_area(struct screen_ctx *sc, int x, int y, int flags)
 {
-	struct region_ctx	*region;
-	struct geom		 geom = sc->work;
+	struct region_ctx	*rc;
+	struct geom		 area = sc->work;
 
-	TAILQ_FOREACH(region, &sc->regionq, entry) {
-		if (x >= region->area.x && x < region->area.x+region->area.w &&
-		    y >= region->area.y && y < region->area.y+region->area.h) {
-			geom = region->area;
+	TAILQ_FOREACH(rc, &sc->regionq, entry) {
+		if ((x >= rc->area.x) && (x < (rc->area.x + rc->area.w)) &&
+		    (y >= rc->area.y) && (y < (rc->area.y + rc->area.h))) {
+			area = rc->area;
 			break;
 		}
 	}
-	if (flags & CWM_GAP) {
-		geom.x += sc->gap.left;
-		geom.y += sc->gap.top;
-		geom.w -= (sc->gap.left + sc->gap.right);
-		geom.h -= (sc->gap.top + sc->gap.bottom);
-	}
-	return(geom);
+	if (flags & CWM_GAP)
+		area = screen_apply_gap(sc, area);
+	return(area);
 }
 
 void
 screen_update_geometry(struct screen_ctx *sc)
 {
-	XineramaScreenInfo	*info = NULL;
-	struct region_ctx	*region;
-	int			 info_num = 0, i;
+	struct region_ctx	*rc;
+	int			 i;
 
 	sc->view.x = 0;
 	sc->view.y = 0;
 	sc->view.w = DisplayWidth(X_Dpy, sc->which);
 	sc->view.h = DisplayHeight(X_Dpy, sc->which);
 
-	sc->work.x = sc->view.x + sc->gap.left;
-	sc->work.y = sc->view.y + sc->gap.top;
-	sc->work.w = sc->view.w - (sc->gap.left + sc->gap.right);
-	sc->work.h = sc->view.h - (sc->gap.top + sc->gap.bottom);
-
-	/* RandR event may have a CTRC added or removed. */
-	if (XineramaIsActive(X_Dpy))
-		info = XineramaQueryScreens(X_Dpy, &info_num);
+	sc->work = screen_apply_gap(sc, sc->view);
 
-	while ((region = TAILQ_FIRST(&sc->regionq)) != NULL) {
-		TAILQ_REMOVE(&sc->regionq, region, entry);
-		free(region);
+	while ((rc = TAILQ_FIRST(&sc->regionq)) != NULL) {
+		TAILQ_REMOVE(&sc->regionq, rc, entry);
+		free(rc);
 	}
-	for (i = 0; i < info_num; i++) {
-		region = xmalloc(sizeof(*region));
-		region->num = i;
-		region->area.x = info[i].x_org;
-		region->area.y = info[i].y_org;
-		region->area.w = info[i].width;
-		region->area.h = info[i].height;
-		TAILQ_INSERT_TAIL(&sc->regionq, region, entry);
+
+	if (HasRandr) {
+		XRRScreenResources *sr;
+		XRRCrtcInfo *ci;
+
+		sr = XRRGetScreenResources(X_Dpy, sc->rootwin);
+		for (i = 0, ci = NULL; i < sr->ncrtc; i++) {
+			ci = XRRGetCrtcInfo(X_Dpy, sr, sr->crtcs[i]);
+			if (ci == NULL)
+				continue;
+			if (ci->noutput == 0) {
+				XRRFreeCrtcInfo(ci);
+				continue;
+			}
+
+			rc = xmalloc(sizeof(*rc));
+			rc->num = i;
+			rc->area.x = ci->x;
+			rc->area.y = ci->y;
+			rc->area.w = ci->width;
+			rc->area.h = ci->height;
+			TAILQ_INSERT_TAIL(&sc->regionq, rc, entry);
+
+			XRRFreeCrtcInfo(ci);
+		}
+		XRRFreeScreenResources(sr);
 	}
-	if (info)
-		XFree(info);
 
 	xu_ewmh_net_desktop_geometry(sc);
 	xu_ewmh_net_workarea(sc);
 }
+
+struct geom
+screen_apply_gap(struct screen_ctx *sc, struct geom geom)
+{
+	geom.x += sc->gap.left;
+	geom.y += sc->gap.top;
+	geom.w -= (sc->gap.left + sc->gap.right);
+	geom.h -= (sc->gap.top + sc->gap.bottom);
+
+	return(geom);
+}
diff --git a/search.c b/search.c
index 0d0eb1d..1640aff 100644
--- a/search.c
+++ b/search.c
@@ -21,7 +21,6 @@
 #include <sys/types.h>
 #include "queue.h"
 
-#include <assert.h>
 #include <err.h>
 #include <errno.h>
 #include <fnmatch.h>
@@ -43,10 +42,6 @@ static void	search_match_path_exec(struct menu_q *, struct menu_q *,
 		    char *);
 static int	strsubmatch(char *, char *, int);
 
-/*
- * Match: label, title, class.
- */
-
 void
 search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
 {
@@ -67,7 +62,7 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
 
 	TAILQ_FOREACH(mi, menuq, entry) {
 		int tier = -1, t;
-		struct client_ctx *cc = mi->ctx;
+		struct client_ctx *cc = (struct client_ctx *)mi->ctx;
 
 		/* First, try to match on labels. */
 		if (cc->label != NULL && strsubmatch(search, cc->label, 0)) {
@@ -106,7 +101,8 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
 		if ((cc->flags & CLIENT_HIDDEN) && (tier > 0))
 			tier--;
 
-		assert(tier < nitems(tierp));
+		if (tier >= nitems(tierp))
+			errx(1, "search_match_client: invalid tier");
 
 		/*
 		 * If you have a tierp, insert after it, and make it
@@ -128,13 +124,25 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search)
 }
 
 void
+search_print_cmd(struct menu *mi, int i)
+{
+	struct cmd	*cmd = (struct cmd *)mi->ctx;
+	int		 special = 0;
+
+	if ((strcmp(cmd->name, "lock") == 0) ||
+	    (strcmp(cmd->name, "term") == 0))
+		special = 1;
+
+	(void)snprintf(mi->print, sizeof(mi->print),
+		(special) ? "[%s]" : "%s", cmd->name);
+}
+
+void
 search_print_client(struct menu *mi, int list)
 {
-	struct client_ctx	*cc;
+	struct client_ctx	*cc = (struct client_ctx *)mi->ctx;
 	char			 flag = ' ';
 
-	cc = mi->ctx;
-
 	if (cc == client_current())
 		flag = '!';
 	else if (cc->flags & CLIENT_HIDDEN)
diff --git a/xevents.c b/xevents.c
index df98b2d..7a29883 100644
--- a/xevents.c
+++ b/xevents.c
@@ -240,7 +240,8 @@ xev_handle_buttonpress(XEvent *ee)
 		if (e->window != e->root)
 			return;
 		cc = &fakecc;
-		cc->sc = screen_find(e->window);
+		if ((cc->sc = screen_find(e->window)) == NULL)
+			return;
 	}
 
 	(*mb->callback)(cc, &mb->argument);
@@ -290,7 +291,8 @@ xev_handle_keypress(XEvent *ee)
 			return;
 	} else {
 		cc = &fakecc;
-		cc->sc = screen_find(e->window);
+		if ((cc->sc = screen_find(e->window)) == NULL)
+			return;
 	}
 
 	(*kb->callback)(cc, &kb->argument);
@@ -307,7 +309,8 @@ xev_handle_keyrelease(XEvent *ee)
 	KeySym			 keysym;
 	unsigned int		 i;
 
-	sc = screen_find(e->root);
+	if ((sc = screen_find(e->root)) == NULL)
+		return;
 
 	keysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 0);
 	for (i = 0; i < nitems(modkeys); i++) {
@@ -325,42 +328,43 @@ xev_handle_clientmessage(XEvent *ee)
 	struct client_ctx	*cc, *old_cc;
 	struct screen_ctx       *sc;
 
-	sc = screen_find(e->window);
-
-	if ((cc = client_find(e->window)) == NULL && e->window != sc->rootwin)
-		return;
-
-	if (e->message_type == cwmh[WM_CHANGE_STATE] && e->format == 32 &&
-	    e->data.l[0] == IconicState)
-		client_hide(cc);
-
-	if (e->message_type == ewmh[_NET_CLOSE_WINDOW])
-		client_send_delete(cc);
-
-	if (e->message_type == ewmh[_NET_ACTIVE_WINDOW] && e->format == 32) {
-		if ((old_cc = client_current()))
-			client_ptrsave(old_cc);
-		client_ptrwarp(cc);
-	}
-
-	if (e->message_type == ewmh[_NET_WM_DESKTOP] && e->format == 32) {
-		/*
-		 * The EWMH spec states that if the cardinal returned is
-		 * 0xFFFFFFFF (-1) then the window should appear on all
-		 * desktops, which in our case is assigned to group 0.
-		 */
-		if (e->data.l[0] == (unsigned long)-1)
-			group_movetogroup(cc, 0);
-		else
-			group_movetogroup(cc, e->data.l[0]);
+	if (e->message_type == cwmh[WM_CHANGE_STATE]) {
+		if ((cc = client_find(e->window)) != NULL) {
+	    		if (e->data.l[0] == IconicState)
+				client_hide(cc);
+		}
+	} else if (e->message_type == ewmh[_NET_CLOSE_WINDOW]) {
+		if ((cc = client_find(e->window)) != NULL) {
+			client_send_delete(cc);
+		}
+	} else if (e->message_type == ewmh[_NET_ACTIVE_WINDOW]) {
+		if ((cc = client_find(e->window)) != NULL) {
+			if ((old_cc = client_current()))
+				client_ptrsave(old_cc);
+			client_ptrwarp(cc);
+		}
+	} else if (e->message_type == ewmh[_NET_WM_DESKTOP]) {
+		if ((cc = client_find(e->window)) != NULL) {
+			/*
+			 * The EWMH spec states that if the cardinal returned
+			 * is 0xFFFFFFFF (-1) then the window should appear
+			 * on all desktops, in our case, group 0.
+			 */
+			if (e->data.l[0] == (unsigned long)-1)
+				group_movetogroup(cc, 0);
+			else
+				group_movetogroup(cc, e->data.l[0]);
+		}
+	} else if (e->message_type == ewmh[_NET_WM_STATE]) {
+		if ((cc = client_find(e->window)) != NULL) {
+			xu_ewmh_handle_net_wm_state_msg(cc,
+			    e->data.l[0], e->data.l[1], e->data.l[2]);
+		}
+	} else if (e->message_type == ewmh[_NET_CURRENT_DESKTOP]) {
+		if ((sc = screen_find(e->window)) != NULL) {
+			group_only(sc, e->data.l[0]);
+		}
 	}
-
-	if (e->message_type == ewmh[_NET_WM_STATE] && e->format == 32)
-		xu_ewmh_handle_net_wm_state_msg(cc,
-		    e->data.l[0], e->data.l[1], e->data.l[2]);
-
-	if (e->message_type == ewmh[_NET_CURRENT_DESKTOP] && e->format == 32)
-		group_only(sc, e->data.l[0]);
 }
 
 static void