summary refs log tree commit diff
diff options
context:
space:
mode:
authorokan <okan>2010-02-10 01:23:05 +0000
committerokan <okan>2010-02-10 01:23:05 +0000
commit507480a69503bd3a5924ebd8cc2e9a971efe62d9 (patch)
tree3de6541fa3cbf8d2406b2a932f40b79e2931fb64
parentc4a97053cd98160c9e0f55e2b7fb71de73616579 (diff)
downloadcwm-507480a69503bd3a5924ebd8cc2e9a971efe62d9.tar.gz
cwm-507480a69503bd3a5924ebd8cc2e9a971efe62d9.tar.xz
cwm-507480a69503bd3a5924ebd8cc2e9a971efe62d9.zip
preserve labels after an edit action is aborted; extending the menu
struct just for this is the least intrusive approach until the menu code
is reviewed.

inspired by Thomas Pfaff's report on tech@

ok oga@
-rw-r--r--calmwm.h1
-rw-r--r--kbfunc.c10
-rw-r--r--menu.c2
3 files changed, 8 insertions, 5 deletions
diff --git a/calmwm.h b/calmwm.h
index 0f82243..bb25ea6 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -320,6 +320,7 @@ struct menu {
 	char			 print[MENU_MAXENTRY + 1];
 	void			*ctx;
 	short			 dummy;
+	short			 abort;
 };
 
 TAILQ_HEAD(menu_q, menu);
diff --git a/kbfunc.c b/kbfunc.c
index 00d5212..c4ee7ed 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -400,19 +400,19 @@ kbfunc_client_label(struct client_ctx *cc, union arg *arg)
 {
 	struct menu	*mi;
 	struct menu_q	 menuq;
-	char		*current;
 
 	TAILQ_INIT(&menuq);
 
-	current = cc->label;
+	/* dummy is set, so this will always return */
+	mi = menu_filter(cc->sc, &menuq, "label", cc->label, 1,
+	    search_match_text, NULL);
 
-	if ((mi = menu_filter(cc->sc, &menuq, "label", current, 1,
-	    search_match_text, NULL)) != NULL) {
+	if (!mi->abort) {
 		if (cc->label != NULL)
 			xfree(cc->label);
 		cc->label = xstrdup(mi->text);
-		xfree(mi);
 	}
+	xfree(mi);
 }
 
 void
diff --git a/menu.c b/menu.c
index 96d6556..6b462be 100644
--- a/menu.c
+++ b/menu.c
@@ -223,6 +223,7 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
 			    mc->searchstr, sizeof(mi->text));
 			mi->dummy = 1;
 		}
+		mi->abort = 0;
 		return (mi);
 	case CTL_WIPE:
 		mc->searchstr[0] = '\0';
@@ -235,6 +236,7 @@ menu_handle_key(XEvent *e, struct menu_ctx *mc, struct menu_q *menuq,
 		mi = xmalloc(sizeof *mi);
 		mi->text[0] = '\0';
 		mi->dummy = 1;
+		mi->abort = 1;
 		return (mi);
 	default:
 		break;