summary refs log tree commit diff
path: root/menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c74
1 files changed, 24 insertions, 50 deletions
diff --git a/menu.c b/menu.c
index d3db032..9323463 100644
--- a/menu.c
+++ b/menu.c
@@ -48,7 +48,6 @@ struct menu_ctx {
 	char			 searchstr[MENU_MAXENTRY + 1];
 	char			 dispstr[MENU_MAXENTRY*2 + 1];
 	char			 promptstr[MENU_MAXENTRY + 1];
-	int			 hasprompt;
 	int			 list;
 	int			 listing;
 	int			 changed;
@@ -85,15 +84,13 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, const char *prompt,
 	struct menu		*mi = NULL;
 	XEvent			 e;
 	Window			 focuswin;
-	int			 evmask, focusrevert;
-	int			 xsave, ysave, xcur, ycur;
+	int			 focusrevert, xsave, ysave, xcur, ycur;
 
 	TAILQ_INIT(&resultq);
 
-	(void)memset(&mc, 0, sizeof(mc));
-
 	xu_ptr_getpos(sc->rootwin, &xsave, &ysave);
 
+	(void)memset(&mc, 0, sizeof(mc));
 	mc.sc = sc;
 	mc.flags = flags;
 	mc.match = match;
@@ -105,19 +102,13 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, const char *prompt,
 	if (mc.flags & CWM_MENU_LIST)
 		mc.list = 1;
 
+	(void)strlcpy(mc.promptstr, prompt, sizeof(mc.promptstr));
 	if (initial != NULL)
 		(void)strlcpy(mc.searchstr, initial, sizeof(mc.searchstr));
 	else
 		mc.searchstr[0] = '\0';
 
-	evmask = MENUMASK;
-	if (prompt != NULL) {
-		evmask |= KEYMASK; /* accept keys as well */
-		(void)strlcpy(mc.promptstr, prompt, sizeof(mc.promptstr));
-		mc.hasprompt = 1;
-	}
-
-	XSelectInput(X_Dpy, sc->menu.win, evmask);
+	XSelectInput(X_Dpy, sc->menu.win, MENUMASK);
 	XMapRaised(X_Dpy, sc->menu.win);
 
 	if (XGrabPointer(X_Dpy, sc->menu.win, False, MENUGRABMASK,
@@ -137,7 +128,7 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, const char *prompt,
 	for (;;) {
 		mc.changed = 0;
 
-		XWindowEvent(X_Dpy, sc->menu.win, evmask, &e);
+		XWindowEvent(X_Dpy, sc->menu.win, MENUMASK, &e);
 
 		switch (e.type) {
 		case KeyPress:
@@ -188,13 +179,14 @@ menu_complete_path(struct menu_ctx *mc)
 	struct screen_ctx	*sc = mc->sc;
 	struct menu		*mi, *mr;
 	struct menu_q		 menuq;
+	int			 mflags = (CWM_MENU_DUMMY);
 
 	mr = xcalloc(1, sizeof(*mr));
 
 	TAILQ_INIT(&menuq);
 
-	if ((mi = menu_filter(sc, &menuq, mc->searchstr, NULL,
-	    (CWM_MENU_DUMMY), search_match_path, search_print_text)) != NULL) {
+	if ((mi = menu_filter(sc, &menuq, mc->searchstr, NULL, mflags,
+	    search_match_path, search_print_text)) != NULL) {
 		mr->abort = mi->abort;
 		mr->dummy = mi->dummy;
 		if (mi->text[0] != '\0')
@@ -343,28 +335,19 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
 			mc->listing = 0;
 	}
 
-	mc->num = 0;
-	mc->geom.w = 0;
-	mc->geom.h = 0;
-	if (mc->hasprompt) {
-		(void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s",
-		    mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR);
-
-		XftTextExtentsUtf8(X_Dpy, sc->xftfont,
-		    (const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents);
-
-		mc->geom.w = extents.xOff;
-		mc->geom.h = sc->xftfont->height + 1;
-		mc->num = 1;
-	}
+	(void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s",
+	    mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR);
+	XftTextExtentsUtf8(X_Dpy, sc->xftfont,
+	    (const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents);
+	mc->geom.w = extents.xOff;
+	mc->geom.h = sc->xftfont->height + 1;
+	mc->num = 1;
 
 	TAILQ_FOREACH(mi, resultq, resultentry) {
 		(*mc->print)(mi, mc->listing);
-
 		XftTextExtentsUtf8(X_Dpy, sc->xftfont,
 		    (const FcChar8*)mi->print,
 		    MIN(strlen(mi->print), MENU_MAXENTRY), &extents);
-
 		mc->geom.w = MAX(mc->geom.w, extents.xOff);
 		mc->geom.h += sc->xftfont->height + 1;
 		mc->num++;
@@ -398,14 +381,11 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
 	XMoveResizeWindow(X_Dpy, sc->menu.win, mc->geom.x, mc->geom.y,
 	    mc->geom.w, mc->geom.h);
 
-	n = 0;
-	if (mc->hasprompt) {
-		XftDrawStringUtf8(sc->menu.xftdraw,
-		    &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont,
-		    0, sc->xftfont->ascent,
-		    (const FcChar8*)mc->dispstr, strlen(mc->dispstr));
-		n++;
-	}
+	n = 1;
+	XftDrawStringUtf8(sc->menu.xftdraw,
+	    &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont,
+	    0, sc->xftfont->ascent,
+	    (const FcChar8*)mc->dispstr, strlen(mc->dispstr));
 
 	TAILQ_FOREACH(mi, resultq, resultentry) {
 		int y = n * (sc->xftfont->height + 1) + sc->xftfont->ascent + 1;
@@ -420,7 +400,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
 		    (const FcChar8*)mi->print, strlen(mi->print));
 		n++;
 	}
-	if (mc->hasprompt && n > 1)
+	if (n > 1)
 		menu_draw_entry(mc, resultq, 1, 1);
 }
 
@@ -430,10 +410,7 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq,
 {
 	struct screen_ctx	*sc = mc->sc;
 	struct menu		*mi;
-	int			 color, i = 0;
-
-	if (mc->hasprompt)
-		i = 1;
+	int			 color, i = 1;
 
 	TAILQ_FOREACH(mi, resultq, resultentry)
 		if (entry == i++)
@@ -474,13 +451,10 @@ static struct menu *
 menu_handle_release(struct menu_ctx *mc, struct menu_q *resultq, int x, int y)
 {
 	struct menu		*mi;
-	int			 entry, i = 0;
+	int			 entry, i = 1;
 
 	entry = menu_calc_entry(mc, x, y);
 
-	if (mc->hasprompt)
-		i = 1;
-
 	TAILQ_FOREACH(mi, resultq, resultentry)
 		if (entry == i++)
 			break;
@@ -506,7 +480,7 @@ menu_calc_entry(struct menu_ctx *mc, int x, int y)
 	    entry < 0 || entry >= mc->num)
 		entry = -1;
 
-	if (mc->hasprompt && entry == 0)
+	if (entry == 0)
 		entry = -1;
 
 	return(entry);