On Tue, 30 Oct 2012 17:44:25 -0500
"Kent R. Spillner" <[email protected]> wrote:
This segfaults. See comments below.
> 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.
>
> 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
[...]
> @@ -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} }
This breaks how name_to_kbfunc is currently being used;
for (iter = 0; iter < nitems(name_to_kbfunc); iter++) {
if (strcmp(name_to_kbfunc[iter]->tag, ...
I think you can see where this goes wrong with your patch
applied (hint: passing NULL to strcmp is not advised ;-) ).
> };
>
> /*
> 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++) {
I suppose this is why you added the NULL entry in the array ...
> + mi = xcalloc(1, sizeof(*mi));
> + (void)strlcpy(mi->text, func->tag, sizeof(mi->text));
> + mi->ctx = func;
> + TAILQ_INSERT_TAIL(&menuq, mi, entry);
> + }
Cheers,
Thomas.