From cb900def7f4da5216d567a27a04429d3dac85ae8 Mon Sep 17 00:00:00 2001 From: okan Date: Wed, 1 Jul 2015 14:36:42 +0000 Subject: [PATCH 1/4] style --- client.c | 8 ++++---- conf.c | 4 ++-- menu.c | 9 ++++----- mousefunc.c | 6 +++--- search.c | 31 ++++--------------------------- xevents.c | 2 +- 6 files changed, 18 insertions(+), 42 deletions(-) diff --git a/client.c b/client.c index de1e8a1..cbf2cb2 100644 --- a/client.c +++ b/client.c @@ -655,7 +655,7 @@ client_cycle(struct screen_ctx *sc, int flags) oldcc = client_current(); if (oldcc == NULL) - oldcc = (flags & CWM_RCYCLE ? + oldcc = ((flags & CWM_RCYCLE) ? TAILQ_LAST(&sc->clientq, client_ctx_q) : TAILQ_FIRST(&sc->clientq)); @@ -663,7 +663,7 @@ client_cycle(struct screen_ctx *sc, int flags) while (again) { again = 0; - newcc = (flags & CWM_RCYCLE ? client_prev(newcc) : + newcc = ((flags & CWM_RCYCLE) ? client_prev(newcc) : client_next(newcc)); /* Only cycle visible and non-ignored windows. */ @@ -707,7 +707,7 @@ client_next(struct client_ctx *cc) struct screen_ctx *sc = cc->sc; struct client_ctx *ccc; - return((ccc = TAILQ_NEXT(cc, entry)) != NULL ? + return(((ccc = TAILQ_NEXT(cc, entry)) != NULL) ? ccc : TAILQ_FIRST(&sc->clientq)); } @@ -717,7 +717,7 @@ client_prev(struct client_ctx *cc) struct screen_ctx *sc = cc->sc; struct client_ctx *ccc; - return((ccc = TAILQ_PREV(cc, client_ctx_q, entry)) != NULL ? + return(((ccc = TAILQ_PREV(cc, client_ctx_q, entry)) != NULL) ? ccc : TAILQ_LAST(&sc->clientq, client_ctx_q)); } diff --git a/conf.c b/conf.c index 95054d2..d0956a1 100644 --- a/conf.c +++ b/conf.c @@ -346,8 +346,8 @@ conf_client(struct client_ctx *cc) } } - cc->bwidth = ignore ? 0 : Conf.bwidth; - cc->flags |= ignore ? CLIENT_IGNORE : 0; + cc->bwidth = (ignore) ? 0 : Conf.bwidth; + cc->flags |= (ignore) ? CLIENT_IGNORE : 0; } static const struct { diff --git a/menu.c b/menu.c index 0151ecf..15d2b7d 100644 --- a/menu.c +++ b/menu.c @@ -411,8 +411,7 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) n = 0; TAILQ_FOREACH(mi, resultq, resultentry) { - char *text = mi->print[0] != '\0' ? - mi->print : mi->text; + char *text = (mi->print[0] != '\0') ? mi->print : mi->text; int y = n * (sc->xftfont->height + 1) + sc->xftfont->ascent + 1; /* Stop drawing when menu doesn't fit inside the screen. */ @@ -444,12 +443,12 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, if (mi == NULL) return; - color = active ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG; - text = mi->print[0] != '\0' ? mi->print : mi->text; + color = (active) ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG; + text = (mi->print[0] != '\0') ? mi->print : mi->text; XftDrawRect(sc->xftdraw, &sc->xftcolor[color], 0, (sc->xftfont->height + 1) * entry, mc->geom.w, (sc->xftfont->height + 1) + sc->xftfont->descent); - color = active ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; + color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; xu_xft_draw(sc, text, color, 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); } diff --git a/mousefunc.c b/mousefunc.c index d709a3f..958fee2 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -43,8 +43,8 @@ mousefunc_sweep_calc(struct client_ctx *cc, int x, int y, int mx, int my) client_applysizehints(cc); - cc->geom.x = x <= mx ? x : x - cc->geom.w; - cc->geom.y = y <= my ? y : y - cc->geom.h; + cc->geom.x = (x <= mx) ? x : x - cc->geom.w; + cc->geom.y = (y <= my) ? y : y - cc->geom.h; } static void @@ -183,7 +183,7 @@ mousefunc_menu_group(struct client_ctx *cc, union arg *arg) if (group_holds_only_sticky(gc)) continue; menuq_add(&menuq, gc, - group_holds_only_hidden(gc) ? "%d: [%s]" : "%d: %s", + (group_holds_only_hidden(gc)) ? "%d: [%s]" : "%d: %s", gc->num, gc->name); } diff --git a/search.c b/search.c index 9013a9d..6526072 100644 --- a/search.c +++ b/search.c @@ -134,7 +134,7 @@ search_print_cmd(struct menu *mi, int i) special = 1; (void)snprintf(mi->print, sizeof(mi->print), - (special) ? "[%s]" : "%s", cmd->name); + (special) ? "[%s]" : "%s", cmd->name); } void @@ -148,35 +148,12 @@ search_print_client(struct menu *mi, int list) else if (cc->flags & CLIENT_HIDDEN) flag = '&'; - if (list) + if ((list) || (cc->matchname == cc->label)) cc->matchname = cc->name; (void)snprintf(mi->print, sizeof(mi->print), "(%d) %c[%s] %s", - cc->group ? cc->group->num : 0, flag, - cc->label ? cc->label : "", cc->matchname); - - if (!list && cc->matchname != cc->name && - strlen(mi->print) < sizeof(mi->print) - 1) { - const char *marker = ""; - char buf[MENU_MAXENTRY + 1]; - int diff; - - diff = sizeof(mi->print) - 1 - strlen(mi->print); - - /* One for the ':' */ - diff -= 1; - - if (strlen(cc->name) > diff) { - marker = ".."; - diff -= 2; - } else { - diff = strlen(cc->name); - } - - (void)strlcpy(buf, mi->print, sizeof(buf)); - (void)snprintf(mi->print, sizeof(mi->print), - "%s:%.*s%s", buf, diff, cc->name, marker); - } + (cc->group) ? cc->group->num : 0, flag, + (cc->label) ? cc->label : "", cc->matchname); } static void diff --git a/xevents.c b/xevents.c index 424a539..f75f8b5 100644 --- a/xevents.c +++ b/xevents.c @@ -279,7 +279,7 @@ xev_handle_keypress(XEvent *ee) if ((kb->modmask | modshift) != e->state) continue; - if (kb->press.keysym == (modshift == 0 ? keysym : skeysym)) + if (kb->press.keysym == ((modshift == 0) ? keysym : skeysym)) break; } From 02779e64b89267cc78b21114642391411adc897e Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 3 Jul 2015 17:11:16 +0000 Subject: [PATCH 2/4] revert previous; seems search_match_text() needs mi->text pre-populated. (only used in one place, application menu searching); re-visit later. broken application menu searching reported by Peter Kane. --- kbfunc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kbfunc.c b/kbfunc.c index 74db167..a107b95 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -178,7 +178,7 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg) TAILQ_INIT(&menuq); TAILQ_FOREACH(cmd, &Conf.cmdq, entry) - menuq_add(&menuq, cmd, NULL); + menuq_add(&menuq, cmd, "%s", cmd->name); if ((mi = menu_filter(sc, &menuq, "application", NULL, 0, search_match_text, search_print_cmd)) != NULL) From 5c2decc8d000098ef682efd21392f7205fac77cf Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 12 Jul 2015 14:21:09 +0000 Subject: [PATCH 3/4] simplify menu print text --- menu.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/menu.c b/menu.c index 15d2b7d..cb4ee7d 100644 --- a/menu.c +++ b/menu.c @@ -359,18 +359,14 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) } TAILQ_FOREACH(mi, resultq, resultentry) { - char *text; - - if (mc->print != NULL) { + if (mc->print != NULL) (*mc->print)(mi, mc->listing); - text = mi->print; - } else { - mi->print[0] = '\0'; - text = mi->text; - } + else + (void)snprintf(mi->print, sizeof(mi->print), + "%s", mi->text); - mc->geom.w = MAX(mc->geom.w, xu_xft_width(sc->xftfont, text, - MIN(strlen(text), MENU_MAXENTRY))); + mc->geom.w = MAX(mc->geom.w, xu_xft_width(sc->xftfont, + mi->print, MIN(strlen(mi->print), MENU_MAXENTRY))); mc->geom.h += sc->xftfont->height + 1; mc->num++; } @@ -411,14 +407,13 @@ menu_draw(struct menu_ctx *mc, struct menu_q *menuq, struct menu_q *resultq) n = 0; TAILQ_FOREACH(mi, resultq, resultentry) { - char *text = (mi->print[0] != '\0') ? mi->print : mi->text; int y = n * (sc->xftfont->height + 1) + sc->xftfont->ascent + 1; /* Stop drawing when menu doesn't fit inside the screen. */ if (mc->geom.y + y > area.h) break; - xu_xft_draw(sc, text, CWM_COLOR_MENU_FONT, 0, y); + xu_xft_draw(sc, mi->print, CWM_COLOR_MENU_FONT, 0, y); n++; } if (mc->hasprompt && n > 1) @@ -431,7 +426,6 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, { struct screen_ctx *sc = mc->sc; struct menu *mi; - char *text; int color, i = 0; if (mc->hasprompt) @@ -444,12 +438,11 @@ menu_draw_entry(struct menu_ctx *mc, struct menu_q *resultq, return; color = (active) ? CWM_COLOR_MENU_FG : CWM_COLOR_MENU_BG; - text = (mi->print[0] != '\0') ? mi->print : mi->text; XftDrawRect(sc->xftdraw, &sc->xftcolor[color], 0, (sc->xftfont->height + 1) * entry, mc->geom.w, (sc->xftfont->height + 1) + sc->xftfont->descent); color = (active) ? CWM_COLOR_MENU_FONT_SEL : CWM_COLOR_MENU_FONT; - xu_xft_draw(sc, text, color, + xu_xft_draw(sc, mi->print, color, 0, (sc->xftfont->height + 1) * entry + sc->xftfont->ascent + 1); } From 0d13b7c2205bd40d9fd4db016c8cf96f620c4f8d Mon Sep 17 00:00:00 2001 From: okan Date: Sun, 12 Jul 2015 14:31:47 +0000 Subject: [PATCH 4/4] introduce 'groupsearch' for group menu search; matches on either group number/shortcut and/or name. --- calmwm.h | 2 ++ conf.c | 1 + cwmrc.5 | 2 ++ kbfunc.c | 25 +++++++++++++++++++++++++ mousefunc.c | 6 ++---- search.c | 10 ++++++++++ 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/calmwm.h b/calmwm.h index 32cf00f..19c0a96 100644 --- a/calmwm.h +++ b/calmwm.h @@ -450,6 +450,7 @@ void search_match_text(struct menu_q *, struct menu_q *, char *); void search_print_client(struct menu *, int); void search_print_cmd(struct menu *, int); +void search_print_group(struct menu *, int); struct geom screen_apply_gap(struct screen_ctx *, struct geom); struct screen_ctx *screen_find(Window); @@ -496,6 +497,7 @@ void kbfunc_cwm_status(struct client_ctx *, union arg *); void kbfunc_exec(struct client_ctx *, union arg *); void kbfunc_lock(struct client_ctx *, union arg *); void kbfunc_menu_cmd(struct client_ctx *, union arg *); +void kbfunc_menu_group(struct client_ctx *, union arg *); void kbfunc_ssh(struct client_ctx *, union arg *); void kbfunc_term(struct client_ctx *, union arg *); void kbfunc_tile(struct client_ctx *, union arg *); diff --git a/conf.c b/conf.c index d0956a1..38c8c8c 100644 --- a/conf.c +++ b/conf.c @@ -360,6 +360,7 @@ static const struct { { "raise", kbfunc_client_raise, CWM_WIN, {0} }, { "search", kbfunc_client_search, 0, {0} }, { "menusearch", kbfunc_menu_cmd, 0, {0} }, + { "groupsearch", kbfunc_menu_group, 0, {0} }, { "hide", kbfunc_client_hide, CWM_WIN, {0} }, { "cycle", kbfunc_client_cycle, 0, {.i = CWM_CYCLE} }, { "rcycle", kbfunc_client_cycle, 0, {.i = CWM_RCYCLE} }, diff --git a/cwmrc.5 b/cwmrc.5 index 093060b..ee8dd78 100644 --- a/cwmrc.5 +++ b/cwmrc.5 @@ -251,6 +251,8 @@ Lock the screen. Launch window search menu. .It menusearch Launch application search menu. +.It groupsearch +Launch group search menu. .It exec Launch .Dq exec program diff --git a/kbfunc.c b/kbfunc.c index a107b95..ef4c49a 100644 --- a/kbfunc.c +++ b/kbfunc.c @@ -187,6 +187,31 @@ kbfunc_menu_cmd(struct client_ctx *cc, union arg *arg) menuq_clear(&menuq); } +void +kbfunc_menu_group(struct client_ctx *cc, union arg *arg) +{ + struct screen_ctx *sc = cc->sc; + struct group_ctx *gc; + struct menu *mi; + struct menu_q menuq; + + TAILQ_INIT(&menuq); + TAILQ_FOREACH(gc, &sc->groupq, entry) { + if (group_holds_only_sticky(gc)) + continue; + menuq_add(&menuq, gc, "%d %s", gc->num, gc->name); + } + + if ((mi = menu_filter(sc, &menuq, "group", NULL, CWM_MENU_LIST, + search_match_text, search_print_group)) != NULL) { + gc = (struct group_ctx *)mi->ctx; + (group_holds_only_hidden(gc)) ? + group_show(gc) : group_hide(gc); + } + + menuq_clear(&menuq); +} + void kbfunc_client_cycle(struct client_ctx *cc, union arg *arg) { diff --git a/mousefunc.c b/mousefunc.c index 958fee2..aef5b04 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -182,13 +182,11 @@ mousefunc_menu_group(struct client_ctx *cc, union arg *arg) TAILQ_FOREACH(gc, &sc->groupq, entry) { if (group_holds_only_sticky(gc)) continue; - menuq_add(&menuq, gc, - (group_holds_only_hidden(gc)) ? "%d: [%s]" : "%d: %s", - gc->num, gc->name); + menuq_add(&menuq, gc, "%d %s", gc->num, gc->name); } if ((mi = menu_filter(sc, &menuq, NULL, NULL, CWM_MENU_LIST, - NULL, NULL)) != NULL) { + NULL, search_print_group)) != NULL) { gc = (struct group_ctx *)mi->ctx; (group_holds_only_hidden(gc)) ? group_show(gc) : group_hide(gc); diff --git a/search.c b/search.c index 6526072..a960076 100644 --- a/search.c +++ b/search.c @@ -137,6 +137,16 @@ search_print_cmd(struct menu *mi, int i) (special) ? "[%s]" : "%s", cmd->name); } +void +search_print_group(struct menu *mi, int i) +{ + struct group_ctx *gc = (struct group_ctx *)mi->ctx; + + (void)snprintf(mi->print, sizeof(mi->print), + (group_holds_only_hidden(gc)) ? "%d: [%s]" : "%d: %s", + gc->num, gc->name); +} + void search_print_client(struct menu *mi, int list) {