diff options
author | okan | 2017-12-11 20:58:18 +0000 |
---|---|---|
committer | okan | 2017-12-11 20:58:18 +0000 |
commit | b4bb11eff610c98b0b4399ae707c22d68fafae74 (patch) | |
tree | 5c766e59a5ac6bd35e25e805c7ac8d19db873154 /menu.c | |
parent | 2cc69c661a1ffb9a7de17e1a58657701edda41a6 (diff) | |
download | cwm-b4bb11eff610c98b0b4399ae707c22d68fafae74.tar.gz |
Unconditionally show prompt on menus, regardless of invocation.
Diffstat (limited to '')
-rw-r--r-- | menu.c | 64 |
1 files changed, 21 insertions, 43 deletions
@@ -16,7 +16,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: menu.c,v 1.102 2017/04/25 12:08:05 okan Exp $ + * $OpenBSD: menu.c,v 1.103 2017/12/11 20:58:18 okan Exp $ */ #include <sys/types.h> @@ -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,8 +84,7 @@ 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); @@ -105,19 +103,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 +129,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: @@ -343,20 +335,15 @@ 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); + (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); + 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; - } + 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); @@ -398,14 +385,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 +404,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 +414,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 +455,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 +484,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); |