summary refs log tree commit diff
path: root/kbfunc.c
diff options
context:
space:
mode:
authorokan <okan>2014-01-21 15:42:44 +0000
committerokan <okan>2014-01-21 15:42:44 +0000
commit371902b3c9fc6c7419f8134e96d67c8735726ff2 (patch)
tree4963c37a48000819c291dabede7d429572398352 /kbfunc.c
parent86b149ad2537061b8af6a51376835c1e1f1cc4ec (diff)
parentac3162439ad826026b499363b445e8c533313ff2 (diff)
downloadcwm-371902b3c9fc6c7419f8134e96d67c8735726ff2.tar.gz
cwm-371902b3c9fc6c7419f8134e96d67c8735726ff2.tar.xz
cwm-371902b3c9fc6c7419f8134e96d67c8735726ff2.zip
cvsimport
Diffstat (limited to 'kbfunc.c')
-rw-r--r--kbfunc.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/kbfunc.c b/kbfunc.c
index 1f7d57a..26e6d3d 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -41,6 +41,7 @@ extern sig_atomic_t	xev_quit;
 void
 kbfunc_client_lower(struct client_ctx *cc, union arg *arg)
 {
+	client_ptrsave(cc);
 	client_lower(cc);
 }
 
@@ -151,13 +152,8 @@ kbfunc_client_search(struct client_ctx *cc, union arg *arg)
 	old_cc = client_current();
 
 	TAILQ_INIT(&menuq);
-
-	TAILQ_FOREACH(cc, &Clientq, entry) {
-		mi = xcalloc(1, sizeof(*mi));
-		(void)strlcpy(mi->text, cc->name, sizeof(mi->text));
-		mi->ctx = cc;
-		TAILQ_INSERT_TAIL(&menuq, mi, entry);
-	}
+	TAILQ_FOREACH(cc, &Clientq, entry)
+		menuq_add(&menuq, cc, "%s", cc->name);
 
 	if ((mi = menu_filter(sc, &menuq, "window", NULL, 0,
 	    search_match_client, search_print_client)) != NULL) {
@@ -182,17 +178,12 @@ kbfunc_menu_search(struct client_ctx *cc, union arg *arg)
 	struct menu_q		 menuq;
 
 	TAILQ_INIT(&menuq);
-
-	TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
-		mi = xcalloc(1, sizeof(*mi));
-		(void)strlcpy(mi->text, cmd->label, sizeof(mi->text));
-		mi->ctx = cmd;
-		TAILQ_INSERT_TAIL(&menuq, mi, entry);
-	}
+	TAILQ_FOREACH(cmd, &Conf.cmdq, entry)
+		menuq_add(&menuq, cmd, "%s", cmd->name);
 
 	if ((mi = menu_filter(sc, &menuq, "application", NULL, 0,
 	    search_match_text, NULL)) != NULL)
-		u_spawn(((struct cmd *)mi->ctx)->image);
+		u_spawn(((struct cmd *)mi->ctx)->path);
 
 	menuq_clear(&menuq);
 }
@@ -238,8 +229,9 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg)
 {
 #define NPATHS 256
 	struct screen_ctx	*sc = cc->sc;
-	char			**ap, *paths[NPATHS], *path, *pathcpy, *label;
+	char			**ap, *paths[NPATHS], *path, *pathcpy;
 	char			 tpath[MAXPATHLEN];
+	const char		*label;
 	DIR			*dirp;
 	struct dirent		*dp;
 	struct menu		*mi;
@@ -284,12 +276,8 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg)
 			/* check for truncation etc */
 			if (l == -1 || l >= (int)sizeof(tpath))
 				continue;
-			if (access(tpath, X_OK) == 0) {
-				mi = xcalloc(1, sizeof(*mi));
-				(void)strlcpy(mi->text,
-				    dp->d_name, sizeof(mi->text));
-				TAILQ_INSERT_TAIL(&menuq, mi, entry);
-			}
+			if (access(tpath, X_OK) == 0)
+				menuq_add(&menuq, NULL, "%s", dp->d_name);
 		}
 		(void)closedir(dirp);
 	}
@@ -360,9 +348,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg)
 		if (p - buf + 1 > sizeof(hostbuf))
 			continue;
 		(void)strlcpy(hostbuf, buf, p - buf + 1);
-		mi = xcalloc(1, sizeof(*mi));
-		(void)strlcpy(mi->text, hostbuf, sizeof(mi->text));
-		TAILQ_INSERT_TAIL(&menuq, mi, entry);
+		menuq_add(&menuq, NULL, hostbuf);
 	}
 	free(lbuf);
 	(void)fclose(fp);