diff options
author | Okan Demirmen <okan@cvs.openbsd.org> | 2017-12-07 16:03:11 +0000 |
---|---|---|
committer | Okan Demirmen <okan@cvs.openbsd.org> | 2017-12-07 16:03:11 +0000 |
commit | c80e4a6aa496a9f61c28c5e27eb84d754c0a07ba (patch) | |
tree | 93ea3bb08e720bdafd5e606442f59e044dd1fe62 /app/cwm | |
parent | bbe28fe1fc90890511ed9485b66d7382ce03d80e (diff) |
give command and group menus their own match callbacks
Diffstat (limited to 'app/cwm')
-rw-r--r-- | app/cwm/calmwm.h | 6 | ||||
-rw-r--r-- | app/cwm/kbfunc.c | 11 | ||||
-rw-r--r-- | app/cwm/search.c | 31 |
3 files changed, 40 insertions, 8 deletions
diff --git a/app/cwm/calmwm.h b/app/cwm/calmwm.h index cabb85d61..21fa3ae33 100644 --- a/app/cwm/calmwm.h +++ b/app/cwm/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.342 2017/12/07 15:47:14 okan Exp $ + * $OpenBSD: calmwm.h,v 1.343 2017/12/07 16:03:10 okan Exp $ */ #ifndef _CALMWM_H_ @@ -444,6 +444,10 @@ void search_match_path(struct menu_q *, struct menu_q *, char *); void search_match_text(struct menu_q *, struct menu_q *, char *); +void search_match_cmd(struct menu_q *, struct menu_q *, + char *); +void search_match_group(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); diff --git a/app/cwm/kbfunc.c b/app/cwm/kbfunc.c index a645f541e..3959046a6 100644 --- a/app/cwm/kbfunc.c +++ b/app/cwm/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.151 2017/12/07 15:39:47 okan Exp $ + * $OpenBSD: kbfunc.c,v 1.152 2017/12/07 16:03:10 okan Exp $ */ #include <sys/types.h> @@ -460,14 +460,13 @@ kbfunc_menu_cmd(void *ctx, struct cargs *cargs) if ((strcmp(cmd->name, "lock") == 0) || (strcmp(cmd->name, "term") == 0)) continue; - /* search_match_text() needs mi->text */ - menuq_add(&menuq, cmd, "%s", cmd->name); + menuq_add(&menuq, cmd, NULL); } if ((mi = menu_filter(sc, &menuq, (m) ? NULL : "application", NULL, ((m) ? CWM_MENU_LIST : 0), - search_match_text, search_print_cmd)) != NULL) { + search_match_cmd, search_print_cmd)) != NULL) { cmd = (struct cmd_ctx *)mi->ctx; u_spawn(cmd->path); } @@ -488,12 +487,12 @@ kbfunc_menu_group(void *ctx, struct cargs *cargs) TAILQ_FOREACH(gc, &sc->groupq, entry) { if (group_holds_only_sticky(gc)) continue; - menuq_add(&menuq, gc, "%d %s", gc->num, gc->name); + menuq_add(&menuq, gc, NULL); } if ((mi = menu_filter(sc, &menuq, (m) ? NULL : "group", NULL, (CWM_MENU_LIST), - search_match_text, search_print_group)) != NULL) { + search_match_group, search_print_group)) != NULL) { gc = (struct group_ctx *)mi->ctx; (group_holds_only_hidden(gc)) ? group_show(gc) : group_hide(gc); diff --git a/app/cwm/search.c b/app/cwm/search.c index 607124b07..b870c582b 100644 --- a/app/cwm/search.c +++ b/app/cwm/search.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: search.c,v 1.64 2017/12/07 15:40:54 okan Exp $ + * $OpenBSD: search.c,v 1.65 2017/12/07 16:03:10 okan Exp $ */ #include <sys/types.h> @@ -129,6 +129,35 @@ search_match_client(struct menu_q *menuq, struct menu_q *resultq, char *search) } } +void +search_match_cmd(struct menu_q *menuq, struct menu_q *resultq, char *search) +{ + struct menu *mi; + + TAILQ_INIT(resultq); + TAILQ_FOREACH(mi, menuq, entry) { + struct cmd_ctx *cmd = (struct cmd_ctx *)mi->ctx; + if (match_substr(search, cmd->name, 0)) + TAILQ_INSERT_TAIL(resultq, mi, resultentry); + } +} + +void +search_match_group(struct menu_q *menuq, struct menu_q *resultq, char *search) +{ + struct menu *mi; + char *s; + + TAILQ_INIT(resultq); + TAILQ_FOREACH(mi, menuq, entry) { + struct group_ctx *gc = (struct group_ctx *)mi->ctx; + xasprintf(&s, "%d %s", gc->num, gc->name); + if (match_substr(search, s, 0)) + TAILQ_INSERT_TAIL(resultq, mi, resultentry); + free(s); + } +} + static void match_path_type(struct menu_q *resultq, char *search, int flag) { |