aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--calmwm.h6
-rw-r--r--kbfunc.c10
-rw-r--r--menu.c64
3 files changed, 28 insertions, 52 deletions
diff --git a/calmwm.h b/calmwm.h
index 5ee66f2..0b7fcb1 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* 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_
@@ -44,9 +44,9 @@
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
-#define MENUMASK (MOUSEMASK | ButtonMotionMask | ExposureMask)
+#define MENUMASK (MOUSEMASK | ButtonMotionMask | ExposureMask | \
+ KeyPressMask | ExposureMask)
#define MENUGRABMASK (MOUSEMASK | ButtonMotionMask | StructureNotifyMask)
-#define KEYMASK (KeyPressMask | ExposureMask)
#define IGNOREMODMASK (LockMask | Mod2Mask | 0x2000)
/* direction/amount */
diff --git a/kbfunc.c b/kbfunc.c
index 54d2216..e839edd 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* 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>
@@ -466,8 +466,7 @@ kbfunc_menu_client(void *ctx, struct cargs *cargs)
}
if ((mi = menu_filter(sc, &menuq,
- (m) ? NULL : "window", NULL,
- ((m) ? CWM_MENU_LIST : 0),
+ "window", NULL, ((m) ? CWM_MENU_LIST : 0),
search_match_client, search_print_client)) != NULL) {
cc = (struct client_ctx *)mi->ctx;
if (cc->flags & CLIENT_HIDDEN)
@@ -500,8 +499,7 @@ kbfunc_menu_cmd(void *ctx, struct cargs *cargs)
}
if ((mi = menu_filter(sc, &menuq,
- (m) ? NULL : "application", NULL,
- ((m) ? CWM_MENU_LIST : 0),
+ "application", NULL, ((m) ? CWM_MENU_LIST : 0),
search_match_cmd, search_print_cmd)) != NULL) {
cmd = (struct cmd_ctx *)mi->ctx;
u_spawn(cmd->path);
@@ -527,7 +525,7 @@ kbfunc_menu_group(void *ctx, struct cargs *cargs)
}
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) {
gc = (struct group_ctx *)mi->ctx;
(group_holds_only_hidden(gc)) ?
diff --git a/menu.c b/menu.c
index 0e0eaf8..c8b7a9f 100644
--- a/menu.c
+++ b/menu.c
@@ -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);