aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorokan2017-12-29 20:03:46 +0000
committerokan2017-12-29 20:03:46 +0000
commit9c7e3d61414a846c6b85d62f76177a30a255423a (patch)
treeaa15f6cb2dfac7e58c47e964f980385218b2ead3
parent94fa8f6008663944358afaeb58a1217cf564a95c (diff)
downloadcwm-9c7e3d61414a846c6b85d62f76177a30a255423a.tar.gz
Convert menu-exec-wm from an abritrary exec menu, into a config-based menu from
which one may configure (wm <name> <path_and_args>) (and choose) specific window managers to replace the running one. 'wm cwm cwm' is included by default. No objections and seems sensible to sthen.
-rw-r--r--calmwm.h14
-rw-r--r--conf.c35
-rw-r--r--cwm.16
-rw-r--r--cwmrc.510
-rw-r--r--kbfunc.c60
-rw-r--r--parse.y15
-rw-r--r--search.c26
7 files changed, 118 insertions, 48 deletions
diff --git a/calmwm.h b/calmwm.h
index b2e405c..0b8f033 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.350 2017/12/29 18:50:43 okan Exp $
+ * $OpenBSD: calmwm.h,v 1.351 2017/12/29 20:03:46 okan Exp $
*/
#ifndef _CALMWM_H_
@@ -255,11 +255,8 @@ struct cmd_ctx {
char path[PATH_MAX];
};
TAILQ_HEAD(cmd_q, cmd_ctx);
+TAILQ_HEAD(wm_q, cmd_ctx);
-enum menu_exec {
- CWM_MENU_EXEC_EXEC,
- CWM_MENU_EXEC_WM
-};
#define CWM_MENU_DUMMY 0x0001
#define CWM_MENU_FILE 0x0002
#define CWM_MENU_LIST 0x0004
@@ -284,6 +281,7 @@ struct conf {
struct autogroup_q autogroupq;
struct ignore_q ignoreq;
struct cmd_q cmdq;
+ struct wm_q wmq;
int ngroups;
int stickygroups;
int nameqlen;
@@ -457,10 +455,13 @@ void search_match_cmd(struct menu_q *, struct menu_q *,
char *);
void search_match_group(struct menu_q *, struct menu_q *,
char *);
+void search_match_wm(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);
void search_print_text(struct menu *, int);
+void search_print_wm(struct menu *, int);
struct region_ctx *region_find(struct screen_ctx *, int, int);
struct geom screen_apply_gap(struct screen_ctx *, struct geom);
@@ -500,6 +501,7 @@ void kbfunc_group_alltoggle(void *, struct cargs *);
void kbfunc_menu_client(void *, struct cargs *);
void kbfunc_menu_cmd(void *, struct cargs *);
void kbfunc_menu_group(void *, struct cargs *);
+void kbfunc_menu_wm(void *, struct cargs *);
void kbfunc_menu_exec(void *, struct cargs *);
void kbfunc_menu_ssh(void *, struct cargs *);
void kbfunc_client_menu_label(void *, struct cargs *);
@@ -529,6 +531,8 @@ void conf_clear(struct conf *);
void conf_client(struct client_ctx *);
int conf_cmd_add(struct conf *, const char *,
const char *);
+int conf_wm_add(struct conf *, const char *,
+ const char *);
void conf_cursor(struct conf *);
void conf_grab_kbd(Window);
void conf_grab_mouse(Window);
diff --git a/conf.c b/conf.c
index 8267686..6d3e131 100644
--- a/conf.c
+++ b/conf.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: conf.c,v 1.236 2017/12/19 14:30:53 okan Exp $
+ * $OpenBSD: conf.c,v 1.237 2017/12/29 20:03:46 okan Exp $
*/
#include <sys/types.h>
@@ -193,10 +193,8 @@ static const struct {
CWM_MENU_WINDOW_ALL },
{ "menu-window-hidden", kbfunc_menu_client, CWM_CONTEXT_SC,
CWM_MENU_WINDOW_HIDDEN },
- { "menu-exec", kbfunc_menu_exec, CWM_CONTEXT_SC,
- CWM_MENU_EXEC_EXEC },
- { "menu-exec-wm", kbfunc_menu_exec, CWM_CONTEXT_SC,
- CWM_MENU_EXEC_WM },
+ { "menu-exec", kbfunc_menu_exec, CWM_CONTEXT_SC, 0 },
+ { "menu-exec-wm", kbfunc_menu_wm, CWM_CONTEXT_SC, 0 },
{ "terminal", kbfunc_exec_term, CWM_CONTEXT_SC, 0 },
{ "lock", kbfunc_exec_lock, CWM_CONTEXT_SC, 0 },
@@ -298,6 +296,7 @@ conf_init(struct conf *c)
TAILQ_INIT(&c->ignoreq);
TAILQ_INIT(&c->cmdq);
+ TAILQ_INIT(&c->wmq);
TAILQ_INIT(&c->keybindq);
TAILQ_INIT(&c->autogroupq);
TAILQ_INIT(&c->mousebindq);
@@ -314,6 +313,8 @@ conf_init(struct conf *c)
conf_cmd_add(c, "lock", "xlock");
conf_cmd_add(c, "term", "xterm");
+ conf_wm_add(c, "cwm", "cwm");
+
(void)snprintf(c->known_hosts, sizeof(c->known_hosts), "%s/%s",
c->homedir, ".ssh/known_hosts");
@@ -327,7 +328,7 @@ conf_clear(struct conf *c)
struct autogroup *ag;
struct bind_ctx *kb, *mb;
struct winname *wn;
- struct cmd_ctx *cmd;
+ struct cmd_ctx *cmd, *wm;
int i;
while ((cmd = TAILQ_FIRST(&c->cmdq)) != NULL) {
@@ -335,6 +336,11 @@ conf_clear(struct conf *c)
free(cmd->name);
free(cmd);
}
+ while ((wm = TAILQ_FIRST(&c->wmq)) != NULL) {
+ TAILQ_REMOVE(&c->wmq, wm, entry);
+ free(wm->name);
+ free(wm);
+ }
while ((kb = TAILQ_FIRST(&c->keybindq)) != NULL) {
TAILQ_REMOVE(&c->keybindq, kb, entry);
free(kb);
@@ -393,6 +399,23 @@ conf_cmd_remove(struct conf *c, const char *name)
}
}
+int
+conf_wm_add(struct conf *c, const char *name, const char *path)
+{
+ struct cmd_ctx *wm;
+
+ wm = xmalloc(sizeof(*wm));
+ wm->name = xstrdup(name);
+ if (strlcpy(wm->path, path, sizeof(wm->path)) >= sizeof(wm->path)) {
+ free(wm->name);
+ free(wm);
+ return(0);
+ }
+
+ TAILQ_INSERT_TAIL(&c->wmq, wm, entry);
+ return(1);
+}
+
void
conf_autogroup(struct conf *c, int num, const char *name, const char *class)
{
diff --git a/cwm.1 b/cwm.1
index 2bf5ee0..1615c7f 100644
--- a/cwm.1
+++ b/cwm.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: cwm.1,v 1.59 2017/12/27 18:46:18 okan Exp $
+.\" $OpenBSD: cwm.1,v 1.60 2017/12/29 20:03:46 okan Exp $
.\"
.\" Copyright (c) 2004,2005 Marius Aamodt Eriksen <marius@monkey.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: December 27 2017 $
+.Dd $Mdocdate: December 29 2017 $
.Dt CWM 1
.Os
.Sh NAME
@@ -143,7 +143,7 @@ will be executed via the configured terminal emulator.
.It Ic CM-w
Spawn
.Dq exec WindowManager
-dialog, allowing a switch to another window manager.
+menu, allowing a switch to another window manager.
.It Ic CMS-r
Restart.
.It Ic CMS-q
diff --git a/cwmrc.5 b/cwmrc.5
index 4e6c890..fe8c3ba 100644
--- a/cwmrc.5
+++ b/cwmrc.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: cwmrc.5,v 1.69 2017/12/07 16:25:33 okan Exp $
+.\" $OpenBSD: cwmrc.5,v 1.70 2017/12/29 20:03:46 okan Exp $
.\"
.\" Copyright (c) 2004,2005 Marius Aamodt Eriksen <marius@monkey.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: December 7 2017 $
+.Dd $Mdocdate: December 29 2017 $
.Dt CWMRC 5
.Os
.Sh NAME
@@ -245,6 +245,12 @@ A special
keyword
.Dq all
can be used to unbind all buttons.
+.It Ic wm Ar name path
+Every
+.Ar name
+entry is shown in the wm menu.
+When selected, the window manager is replaced by
+.Ar path .
.El
.Sh BIND FUNCTION LIST
.Bl -tag -width 23n -compact
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 <sys/types.h>
@@ -546,6 +546,33 @@ kbfunc_menu_group(void *ctx, struct cargs *cargs)
}
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)
{
#define NPATHS 256
@@ -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)
diff --git a/parse.y b/parse.y
index e7eaf18..b8a72cb 100644
--- a/parse.y
+++ b/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.68 2017/04/26 21:10:54 okan Exp $ */
+/* $OpenBSD: parse.y,v 1.69 2017/12/29 20:03:46 okan Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -70,7 +70,7 @@ typedef struct {
%token BINDKEY UNBINDKEY BINDMOUSE UNBINDMOUSE
%token FONTNAME STICKY GAP
-%token AUTOGROUP COMMAND IGNORE
+%token AUTOGROUP COMMAND IGNORE WM
%token YES NO BORDERWIDTH MOVEAMOUNT
%token COLOR SNAPDIST
%token ACTIVEBORDER INACTIVEBORDER URGENCYBORDER
@@ -146,6 +146,16 @@ main : FONTNAME STRING {
free($2);
free($3);
}
+ | WM STRING string {
+ if (!conf_wm_add(conf, $2, $3)) {
+ yyerror("wm name/path too long");
+ free($2);
+ free($3);
+ YYERROR;
+ }
+ free($2);
+ free($3);
+ }
| AUTOGROUP NUMBER STRING {
if ($2 < 0 || $2 > 9) {
yyerror("invalid autogroup");
@@ -317,6 +327,7 @@ lookup(char *s)
{ "unbind-mouse", UNBINDMOUSE},
{ "ungroupborder", UNGROUPBORDER},
{ "urgencyborder", URGENCYBORDER},
+ { "wm", WM},
{ "yes", YES}
};
const struct keywords *p;
diff --git a/search.c b/search.c
index 06d952b..2b58461 100644
--- a/search.c
+++ b/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.66 2017/12/13 15:10:17 okan Exp $
+ * $OpenBSD: search.c,v 1.67 2017/12/29 20:03:46 okan Exp $
*/
#include <sys/types.h>
@@ -228,6 +228,21 @@ search_match_text(struct menu_q *menuq, struct menu_q *resultq, char *search)
}
void
+search_match_wm(struct menu_q *menuq, struct menu_q *resultq, char *search)
+{
+ struct menu *mi;
+ struct cmd_ctx *wm;
+
+ TAILQ_INIT(resultq);
+ TAILQ_FOREACH(mi, menuq, entry) {
+ wm = (struct cmd_ctx *)mi->ctx;
+ if ((match_substr(search, wm->name, 0)) ||
+ (match_substr(search, wm->path, 0)))
+ TAILQ_INSERT_TAIL(resultq, mi, resultentry);
+ }
+}
+
+void
search_print_client(struct menu *mi, int listing)
{
struct client_ctx *cc = (struct client_ctx *)mi->ctx;
@@ -266,3 +281,12 @@ search_print_text(struct menu *mi, int listing)
{
(void)snprintf(mi->print, sizeof(mi->print), "%s", mi->text);
}
+
+void
+search_print_wm(struct menu *mi, int listing)
+{
+ struct cmd_ctx *wm = (struct cmd_ctx *)mi->ctx;
+
+ (void)snprintf(mi->print, sizeof(mi->print), "%s [%s]",
+ wm->name, wm->path);
+}