From 9c7e3d61414a846c6b85d62f76177a30a255423a Mon Sep 17 00:00:00 2001 From: okan Date: Fri, 29 Dec 2017 20:03:46 +0000 Subject: Convert menu-exec-wm from an abritrary exec menu, into a config-based menu from which one may configure (wm ) (and choose) specific window managers to replace the running one. 'wm cwm cwm' is included by default. No objections and seems sensible to sthen. --- kbfunc.c | 60 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'kbfunc.c') diff --git a/kbfunc.c b/kbfunc.c index cbeba36..7a205d0 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.158 2017/12/29 18:50:43 okan Exp $ + * $OpenBSD: kbfunc.c,v 1.159 2017/12/29 20:03:46 okan Exp $ */ #include @@ -545,6 +545,33 @@ kbfunc_menu_group(void *ctx, struct cargs *cargs) menuq_clear(&menuq); } +void +kbfunc_menu_wm(void *ctx, struct cargs *cargs) +{ + struct screen_ctx *sc = ctx; + struct cmd_ctx *wm; + struct menu *mi; + struct menu_q menuq; + int mflags = 0; + + if (cargs->xev == CWM_XEV_BTN) + mflags |= CWM_MENU_LIST; + + TAILQ_INIT(&menuq); + TAILQ_FOREACH(wm, &Conf.wmq, entry) + menuq_add(&menuq, wm, NULL); + + if ((mi = menu_filter(sc, &menuq, "wm", NULL, mflags, + search_match_wm, search_print_wm)) != NULL) { + wm = (struct cmd_ctx *)mi->ctx; + free(Conf.wm_argv); + Conf.wm_argv = xstrdup(wm->path); + cwm_status = CWM_EXEC_WM; + } + + menuq_clear(&menuq); +} + void kbfunc_menu_exec(void *ctx, struct cargs *cargs) { @@ -553,26 +580,13 @@ kbfunc_menu_exec(void *ctx, struct cargs *cargs) char **ap, *paths[NPATHS], *path, *pathcpy; char tpath[PATH_MAX]; struct stat sb; - const char *label; DIR *dirp; struct dirent *dp; struct menu *mi; struct menu_q menuq; - int l, i, cmd = cargs->flag; + int l, i; int mflags = (CWM_MENU_DUMMY | CWM_MENU_FILE); - switch (cmd) { - case CWM_MENU_EXEC_EXEC: - label = "exec"; - break; - case CWM_MENU_EXEC_WM: - label = "wm"; - break; - default: - errx(1, "%s: invalid cmd %d", __func__, cmd); - /* NOTREACHED */ - } - TAILQ_INIT(&menuq); if ((path = getenv("PATH")) == NULL) @@ -611,23 +625,11 @@ kbfunc_menu_exec(void *ctx, struct cargs *cargs) } free(path); - if ((mi = menu_filter(sc, &menuq, label, NULL, mflags, + if ((mi = menu_filter(sc, &menuq, "exec", NULL, mflags, search_match_exec, search_print_text)) != NULL) { if (mi->text[0] == '\0') goto out; - switch (cmd) { - case CWM_MENU_EXEC_EXEC: - u_spawn(mi->text); - break; - case CWM_MENU_EXEC_WM: - cwm_status = CWM_EXEC_WM; - free(Conf.wm_argv); - Conf.wm_argv = xstrdup(mi->text); - break; - default: - errx(1, "%s: egad, cmd changed value!", __func__); - /* NOTREACHED */ - } + u_spawn(mi->text); } out: if (mi != NULL && mi->dummy) -- cgit v1.2.3-2-gb3c3