summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2013-05-02 20:18:35 +0000
committerokan <okan>2013-05-02 20:18:35 +0000
commite91c7162623a0b83fe83a528d7a382f268b22a8b (patch)
treef738cd16efdb9220ea52af123e0ecf3180fc2d3c
parent0d209028be47411cf2e7515dc3ce7ea9d9dc8c3c (diff)
downloadcwm-e91c7162623a0b83fe83a528d7a382f268b22a8b.tar.gz
cwm-e91c7162623a0b83fe83a528d7a382f268b22a8b.tar.xz
cwm-e91c7162623a0b83fe83a528d7a382f268b22a8b.zip
- no need to position and size the menu window before an Expose event
  since we'll be calculating required size later anyway; allows us to
  consolidate all prompt/display/search string building goop into
  menu_draw.
- reset the pos/size of menuwin when leaving a menu.
- reverse the 'prompt' NULL check to be consistent with 'initial' one
  and fix a whitespace nit while here.
-rw-r--r--menu.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/menu.c b/menu.c
index 4a5c54f..898bf2c 100644
--- a/menu.c
+++ b/menu.c
@@ -42,7 +42,7 @@ enum ctltype {
 };
 
 struct menu_ctx {
-	struct screen_ctx 	*sc;
+	struct screen_ctx	*sc;
 	char			 searchstr[MENU_MAXENTRY + 1];
 	char			 dispstr[MENU_MAXENTRY*2 + 1];
 	char			 promptstr[MENU_MAXENTRY + 1];
@@ -112,21 +112,14 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
 
 	mc.sc = sc;
 	mc.flags = flags;
-	if (prompt == NULL) {
+	if (prompt != NULL) {
+		evmask = MENUMASK | KEYMASK; /* accept keys as well */
+		(void)strlcpy(mc.promptstr, prompt, sizeof(mc.promptstr));
+		mc.hasprompt = 1;
+	} else {
 		evmask = MENUMASK;
-		mc.promptstr[0] = '\0';
 		mc.list = 1;
-	} else {
-		evmask = MENUMASK | KEYMASK; /* only accept keys if prompt */
-		(void)snprintf(mc.promptstr, sizeof(mc.promptstr), "%s%s",
-		    prompt, PROMPT_SCHAR);
-		(void)snprintf(mc.dispstr, sizeof(mc.dispstr), "%s%s%s",
-		    mc.promptstr, mc.searchstr, PROMPT_ECHAR);
-		mc.width = font_width(sc->xftfont, mc.dispstr,
-		    strlen(mc.dispstr));
-		mc.hasprompt = 1;
 	}
-	mc.height = sc->xftfont->height + 1;
 
 	if (initial != NULL)
 		(void)strlcpy(mc.searchstr, initial, sizeof(mc.searchstr));
@@ -137,7 +130,6 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, char *prompt,
 	mc.print = print;
 	mc.entry = mc.prev = -1;
 
-	XMoveResizeWindow(X_Dpy, sc->menuwin, mc.x, mc.y, mc.width, mc.height);
 	XSelectInput(X_Dpy, sc->menuwin, evmask);
 	XMapRaised(X_Dpy, sc->menuwin);
 
@@ -193,6 +185,7 @@ out:
 		xu_ptr_setpos(sc->rootwin, xsave, ysave);
 	xu_ptr_ungrab();
 
+	XMoveResizeWindow(X_Dpy, sc->menuwin, 0, 0, 1, 1);
 	XUnmapWindow(X_Dpy, sc->menuwin);
 	XUngrabKeyboard(X_Dpy, CurrentTime);
 
@@ -372,8 +365,8 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
 	mc->width = 0;
 	mc->height = 0;
 	if (mc->hasprompt) {
-		(void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s",
-		    mc->promptstr, mc->searchstr, PROMPT_ECHAR);
+		(void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s",
+		    mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR);
 		mc->width = font_width(sc->xftfont, mc->dispstr,
 		    strlen(mc->dispstr));
 		mc->height = sc->xftfont->height + 1;