From c4a8f44931713f32f250264ca00520aae30fc0e3 Mon Sep 17 00:00:00 2001 From: oga Date: Tue, 20 May 2008 14:50:51 +0000 Subject: Pull out the behaviour in grab_label and search_start into one utility function menu_filter(). The plan is to eventually merge in grab_menu too. Shrinks the code a fair bit. Also, change XMaskEvent for XWindowEvent to prevent getting exposes for other windows. This is particuarly noticable on slow machines with a LOT of xterms (todd, you're an odd man). ok okan@, todd@. --- kbfunc.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'kbfunc.c') diff --git a/kbfunc.c b/kbfunc.c index af2fc76..683da5f 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. * - * $Id: kbfunc.c,v 1.27 2008/05/19 18:53:09 oga Exp $ + * $Id: kbfunc.c,v 1.28 2008/05/20 14:50:51 oga Exp $ */ #include @@ -128,9 +128,8 @@ kbfunc_client_search(struct client_ctx *scratch, void *arg) TAILQ_INSERT_TAIL(&menuq, mi, entry); } - if ((mi = search_start(&menuq, - search_match_client, search_print_client, - "window", 0)) != NULL) { + if ((mi = menu_filter(&menuq, "window", NULL, 0, + search_match_client, search_print_client)) != NULL) { cc = (struct client_ctx *)mi->ctx; if (cc->flags & CLIENT_HIDDEN) client_unhide(cc); @@ -163,8 +162,8 @@ kbfunc_menu_search(struct client_ctx *scratch, void *arg) TAILQ_INSERT_TAIL(&menuq, mi, entry); } - if ((mi = search_start(&menuq, - search_match_text, NULL, "application", 0)) != NULL) + if ((mi = menu_filter(&menuq, "application", NULL, 0, + search_match_text, NULL)) != NULL) u_spawn(((struct cmd *)mi->ctx)->image); while ((mi = TAILQ_FIRST(&menuq)) != NULL) { @@ -301,8 +300,8 @@ kbfunc_exec(struct client_ctx *scratch, void *arg) } xfree(path); - if ((mi = search_start(&menuq, - search_match_exec, NULL, label, 1)) != NULL) { + if ((mi = menu_filter(&menuq, label, NULL, 1, + search_match_exec, NULL)) != NULL) { switch (cmd) { case CWM_EXEC_PROGRAM: u_spawn(mi->text); @@ -376,8 +375,8 @@ kbfunc_ssh(struct client_ctx *scratch, void *arg) fclose(fp); - if ((mi = search_start(&menuq, - search_match_exec, NULL, "ssh", 1)) != NULL) { + if ((mi = menu_filter(&menuq, "ssh", NULL, 1, + search_match_exec, NULL)) != NULL) { conf_reload(&Conf); l = snprintf(cmd, sizeof(cmd), "%s -e ssh %s", Conf.termpath, mi->text); @@ -396,7 +395,24 @@ kbfunc_ssh(struct client_ctx *scratch, void *arg) void kbfunc_client_label(struct client_ctx *cc, void *arg) { - grab_label(cc); + struct menu *mi; + char *current; + struct menu_q menuq; + + TAILQ_INIT(&menuq); + + if (cc->label != NULL) + current = cc->label; + else + current = NULL; + + if ((mi = menu_filter(&menuq, "label", current, 1, + search_match_text, NULL)) != NULL) { + if (cc->label != NULL) + xfree(cc->label); + cc->label = xstrdup(mi->text); + xfree(mi); + } } void -- cgit v1.2.3-2-gb3c3