Unconditionally show prompt on menus, regardless of invocation.

This commit is contained in:
okan 2017-12-11 20:58:18 +00:00
parent cc59c89528
commit 2a75b150b0
3 changed files with 28 additions and 52 deletions

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* *
* $OpenBSD: calmwm.h,v 1.344 2017/12/07 16:25:33 okan Exp $ * $OpenBSD: calmwm.h,v 1.345 2017/12/11 20:58:18 okan Exp $
*/ */
#ifndef _CALMWM_H_ #ifndef _CALMWM_H_
@ -44,9 +44,9 @@
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask) #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
#define MOUSEMASK (BUTTONMASK | PointerMotionMask) #define MOUSEMASK (BUTTONMASK | PointerMotionMask)
#define MENUMASK (MOUSEMASK | ButtonMotionMask | ExposureMask) #define MENUMASK (MOUSEMASK | ButtonMotionMask | ExposureMask | \
KeyPressMask | ExposureMask)
#define MENUGRABMASK (MOUSEMASK | ButtonMotionMask | StructureNotifyMask) #define MENUGRABMASK (MOUSEMASK | ButtonMotionMask | StructureNotifyMask)
#define KEYMASK (KeyPressMask | ExposureMask)
#define IGNOREMODMASK (LockMask | Mod2Mask | 0x2000) #define IGNOREMODMASK (LockMask | Mod2Mask | 0x2000)
/* direction/amount */ /* direction/amount */

View File

@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* *
* $OpenBSD: kbfunc.c,v 1.153 2017/12/07 16:25:33 okan Exp $ * $OpenBSD: kbfunc.c,v 1.154 2017/12/11 20:58:18 okan Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -466,8 +466,7 @@ kbfunc_menu_client(void *ctx, struct cargs *cargs)
} }
if ((mi = menu_filter(sc, &menuq, if ((mi = menu_filter(sc, &menuq,
(m) ? NULL : "window", NULL, "window", NULL, ((m) ? CWM_MENU_LIST : 0),
((m) ? CWM_MENU_LIST : 0),
search_match_client, search_print_client)) != NULL) { search_match_client, search_print_client)) != NULL) {
cc = (struct client_ctx *)mi->ctx; cc = (struct client_ctx *)mi->ctx;
if (cc->flags & CLIENT_HIDDEN) if (cc->flags & CLIENT_HIDDEN)
@ -500,8 +499,7 @@ kbfunc_menu_cmd(void *ctx, struct cargs *cargs)
} }
if ((mi = menu_filter(sc, &menuq, if ((mi = menu_filter(sc, &menuq,
(m) ? NULL : "application", NULL, "application", NULL, ((m) ? CWM_MENU_LIST : 0),
((m) ? CWM_MENU_LIST : 0),
search_match_cmd, search_print_cmd)) != NULL) { search_match_cmd, search_print_cmd)) != NULL) {
cmd = (struct cmd_ctx *)mi->ctx; cmd = (struct cmd_ctx *)mi->ctx;
u_spawn(cmd->path); u_spawn(cmd->path);
@ -527,7 +525,7 @@ kbfunc_menu_group(void *ctx, struct cargs *cargs)
} }
if ((mi = menu_filter(sc, &menuq, if ((mi = menu_filter(sc, &menuq,
(m) ? NULL : "group", NULL, (CWM_MENU_LIST), "group", NULL, ((m) ? CWM_MENU_LIST : 0),
search_match_group, search_print_group)) != NULL) { search_match_group, search_print_group)) != NULL) {
gc = (struct group_ctx *)mi->ctx; gc = (struct group_ctx *)mi->ctx;
(group_holds_only_hidden(gc)) ? (group_holds_only_hidden(gc)) ?

View File

@ -16,7 +16,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * 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> #include <sys/types.h>
@ -48,7 +48,6 @@ struct menu_ctx {
char searchstr[MENU_MAXENTRY + 1]; char searchstr[MENU_MAXENTRY + 1];
char dispstr[MENU_MAXENTRY*2 + 1]; char dispstr[MENU_MAXENTRY*2 + 1];
char promptstr[MENU_MAXENTRY + 1]; char promptstr[MENU_MAXENTRY + 1];
int hasprompt;
int list; int list;
int listing; int listing;
int changed; int changed;
@ -85,8 +84,7 @@ menu_filter(struct screen_ctx *sc, struct menu_q *menuq, const char *prompt,
struct menu *mi = NULL; struct menu *mi = NULL;
XEvent e; XEvent e;
Window focuswin; Window focuswin;
int evmask, focusrevert; int focusrevert, xsave, ysave, xcur, ycur;
int xsave, ysave, xcur, ycur;
TAILQ_INIT(&resultq); 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) if (mc.flags & CWM_MENU_LIST)
mc.list = 1; mc.list = 1;
(void)strlcpy(mc.promptstr, prompt, sizeof(mc.promptstr));
if (initial != NULL) if (initial != NULL)
(void)strlcpy(mc.searchstr, initial, sizeof(mc.searchstr)); (void)strlcpy(mc.searchstr, initial, sizeof(mc.searchstr));
else else
mc.searchstr[0] = '\0'; mc.searchstr[0] = '\0';
evmask = MENUMASK; XSelectInput(X_Dpy, sc->menu.win, 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);
XMapRaised(X_Dpy, sc->menu.win); XMapRaised(X_Dpy, sc->menu.win);
if (XGrabPointer(X_Dpy, sc->menu.win, False, MENUGRABMASK, 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 (;;) { for (;;) {
mc.changed = 0; mc.changed = 0;
XWindowEvent(X_Dpy, sc->menu.win, evmask, &e); XWindowEvent(X_Dpy, sc->menu.win, MENUMASK, &e);
switch (e.type) { switch (e.type) {
case KeyPress: case KeyPress:
@ -343,20 +335,15 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq)
mc->listing = 0; mc->listing = 0;
} }
mc->num = 0; (void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s%s",
mc->geom.w = 0; mc->promptstr, PROMPT_SCHAR, mc->searchstr, PROMPT_ECHAR);
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, XftTextExtentsUtf8(X_Dpy, sc->xftfont,
(const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents); (const FcChar8*)mc->dispstr, strlen(mc->dispstr), &extents);
mc->geom.w = extents.xOff; mc->geom.w = extents.xOff;
mc->geom.h = sc->xftfont->height + 1; mc->geom.h = sc->xftfont->height + 1;
mc->num = 1; mc->num = 1;
}
TAILQ_FOREACH(mi, resultq, resultentry) { TAILQ_FOREACH(mi, resultq, resultentry) {
(*mc->print)(mi, mc->listing); (*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, XMoveResizeWindow(X_Dpy, sc->menu.win, mc->geom.x, mc->geom.y,
mc->geom.w, mc->geom.h); mc->geom.w, mc->geom.h);
n = 0; n = 1;
if (mc->hasprompt) { XftDrawStringUtf8(sc->menu.xftdraw,
XftDrawStringUtf8(sc->menu.xftdraw, &sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont,
&sc->xftcolor[CWM_COLOR_MENU_FONT], sc->xftfont, 0, sc->xftfont->ascent,
0, sc->xftfont->ascent, (const FcChar8*)mc->dispstr, strlen(mc->dispstr));
(const FcChar8*)mc->dispstr, strlen(mc->dispstr));
n++;
}
TAILQ_FOREACH(mi, resultq, resultentry) { TAILQ_FOREACH(mi, resultq, resultentry) {
int y = n * (sc->xftfont->height + 1) + sc->xftfont->ascent + 1; 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)); (const FcChar8*)mi->print, strlen(mi->print));
n++; n++;
} }
if (mc->hasprompt && n > 1) if (n > 1)
menu_draw_entry(mc, resultq, 1, 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 screen_ctx *sc = mc->sc;
struct menu *mi; struct menu *mi;
int color, i = 0; int color, i = 1;
if (mc->hasprompt)
i = 1;
TAILQ_FOREACH(mi, resultq, resultentry) TAILQ_FOREACH(mi, resultq, resultentry)
if (entry == i++) 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) menu_handle_release(struct menu_ctx *mc, struct menu_q *resultq, int x, int y)
{ {
struct menu *mi; struct menu *mi;
int entry, i = 0; int entry, i = 1;
entry = menu_calc_entry(mc, x, y); entry = menu_calc_entry(mc, x, y);
if (mc->hasprompt)
i = 1;
TAILQ_FOREACH(mi, resultq, resultentry) TAILQ_FOREACH(mi, resultq, resultentry)
if (entry == i++) if (entry == i++)
break; break;
@ -506,7 +484,7 @@ menu_calc_entry(struct menu_ctx *mc, int x, int y)
entry < 0 || entry >= mc->num) entry < 0 || entry >= mc->num)
entry = -1; entry = -1;
if (mc->hasprompt && entry == 0) if (entry == 0)
entry = -1; entry = -1;
return(entry); return(entry);