Howdy-
Here is an initial attempt at adding a menu for searching/executing internal
functions. It's useful for those times you want to an unbound function, and
even when the function is bound to some key combo you haven't memorized yet
it can be faster than looking up the keybinding in the manual. It also
plays really nicely with the restart diff from earlier today as I found out
while working on kbfunc_func_search itself. ;)
I'll work on the manpage bits on the train tonight.
Thanks in advance!
Best,
Kent
Index: calmwm.h
===================================================================
RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.153
diff -p -u -r1.153 calmwm.h
--- calmwm.h 9 Sep 2012 19:47:47 -0000 1.153
+++ calmwm.h 30 Oct 2012 20:21:59 -0000
@@ -225,6 +225,13 @@ struct screen_ctx {
};
TAILQ_HEAD(screen_ctx_q, screen_ctx);
+struct func {
+ char *tag;
+ void (*handler)(struct client_ctx *, union arg *);
+ int flags;
+ union arg argument;
+};
+
struct keybinding {
TAILQ_ENTRY(keybinding) entry;
void (*callback)(struct client_ctx *, union arg *);
@@ -393,6 +400,7 @@ void kbfunc_client_vmaximize(struct
c
union arg *);
void kbfunc_cmdexec(struct client_ctx *, union arg *);
void kbfunc_exec(struct client_ctx *, union arg *);
+void kbfunc_func_search(struct client_ctx *, union arg *);
void kbfunc_lock(struct client_ctx *, union arg *);
void kbfunc_menu_search(struct client_ctx *, union arg *);
void kbfunc_moveresize(struct client_ctx *, union arg *);
@@ -501,6 +509,7 @@ extern Cursor Cursor_resize;
extern struct screen_ctx_q Screenq;
extern struct client_ctx_q Clientq;
extern struct conf Conf;
+extern struct func name_to_kbfunc[];
extern int HasXinerama, HasRandr, Randr_ev;
Index: conf.c
===================================================================
RCS file: /cvs/xenocara/app/cwm/conf.c,v
retrieving revision 1.100
diff -p -u -r1.100 conf.c
--- conf.c 29 Oct 2012 19:46:03 -0000 1.100
+++ conf.c 30 Oct 2012 20:21:59 -0000
@@ -127,6 +127,7 @@ static struct {
{ "M-Up", "raise" },
{ "M-slash", "search" },
{ "C-slash", "menusearch" },
+ { "CM-slash", "funcsearch" },
{ "M-Tab", "cycle" },
{ "MS-Tab", "rcycle" },
{ "CM-n", "label" },
@@ -312,15 +313,11 @@ conf_client(struct client_ctx *cc)
cc->flags |= ignore ? CLIENT_IGNORE : 0;
}
-static struct {
- char *tag;
- void (*handler)(struct client_ctx *, union arg *);
- int flags;
- union arg argument;
-} name_to_kbfunc[] = {
+struct func name_to_kbfunc[] = {
{ "lower", kbfunc_client_lower, KBFLAG_NEEDCLIENT, {0} },
{ "raise", kbfunc_client_raise, KBFLAG_NEEDCLIENT, {0} },
{ "search", kbfunc_client_search, 0, {0} },
+ { "funcsearch", kbfunc_func_search, KBFLAG_NEEDCLIENT, {0} },
{ "menusearch", kbfunc_menu_search, 0, {0} },
{ "hide", kbfunc_client_hide, KBFLAG_NEEDCLIENT, {0} },
{ "cycle", kbfunc_client_cycle, 0, {.i = CWM_CYCLE} },
@@ -427,6 +424,7 @@ static struct {
{.i = (CWM_LEFT|CWM_PTRMOVE|CWM_BIGMOVE)} },
{ "bigptrmoveright", kbfunc_moveresize, 0,
{.i = (CWM_RIGHT|CWM_PTRMOVE|CWM_BIGMOVE)} },
+ { NULL, NULL, 0, {0} }
};
/*
Index: kbfunc.c
===================================================================
RCS file: /cvs/xenocara/app/cwm/kbfunc.c,v
retrieving revision 1.63
diff -p -u -r1.63 kbfunc.c
--- kbfunc.c 9 Sep 2012 19:47:47 -0000 1.63
+++ kbfunc.c 30 Oct 2012 20:21:59 -0000
@@ -173,6 +173,35 @@ kbfunc_client_search(struct client_ctx *
}
void
+kbfunc_func_search(struct client_ctx *cc, union arg *arg)
+{
+ struct screen_ctx *sc = cc->sc;
+ struct func *func;
+ struct menu *mi;
+ struct menu_q menuq;
+
+ TAILQ_INIT(&menuq);
+
+ for (func = name_to_kbfunc; func->tag != NULL; func++) {
+ mi = xcalloc(1, sizeof(*mi));
+ (void)strlcpy(mi->text, func->tag, sizeof(mi->text));
+ mi->ctx = func;
+ TAILQ_INSERT_TAIL(&menuq, mi, entry);
+ }
+
+ if ((mi = menu_filter(sc, &menuq, "function", NULL, 0,
+ search_match_text, NULL)) != NULL) {
+ func = (struct func *)mi->ctx;
+ (*func->handler)(cc, &func->argument);
+ }
+
+ while ((mi = TAILQ_FIRST(&menuq)) != NULL) {
+ TAILQ_REMOVE(&menuq, mi, entry);
+ xfree(mi);
+ }
+}
+
+void
kbfunc_menu_search(struct client_ctx *cc, union arg *arg)
{
struct screen_ctx *sc = cc->sc;