This patch causes bindings of C-Space (really C-@) to display as
C-Space, per Nicholas's request.

Testing: verified that bindings of C-@ and C-M-@ show up as C-Space and
C-M-Space, and that binding @ remains as @.

Note: I committed the patch that fixed the binding of C-Space directly,
because its implementation was obvious; it's less obvious to me whether
this patch will meet with Nicholas's approval without tweaks, so I'm
submitting it for review first.

-- 
Micah J. Cowan
http://micah.cowan.name/
Index: sf/key-string.c
===================================================================
--- sf.orig/key-string.c	2010-06-04 23:37:21.558738365 -0700
+++ sf/key-string.c	2010-06-05 00:06:46.582747559 -0700
@@ -184,6 +184,15 @@ key_string_lookup_key(int key)
 
 	*out = '\0';
 
+	/*
+	 * Special case: display C-@ as C-Space. Could do this below in
+	 * the (key >= 0 && key <= 32), but this way we let it be found
+	 * in key_string_table, for the unlikely chance that we might
+	 * change its name.
+	 */
+	if ((key & KEYC_MASK_KEY) == 0)
+	    key = ' ' | KEYC_CTRL | (key & KEYC_MASK_MOD);
+
 	/* Fill in the modifiers. */
 	if (key & KEYC_CTRL)
 		strlcat(out, "C-", sizeof out);
@@ -191,7 +200,7 @@ key_string_lookup_key(int key)
 		strlcat(out, "M-", sizeof out);
 	if (key & KEYC_SHIFT)
 		strlcat(out, "S-", sizeof out);
-	key &= ~(KEYC_CTRL|KEYC_ESCAPE|KEYC_SHIFT);
+	key &= KEYC_MASK_KEY;
 
 	/* Try the key against the string table. */
 	for (i = 0; i < nitems(key_string_table); i++) {
Index: sf/tmux.h
===================================================================
--- sf.orig/tmux.h	2010-06-04 23:56:57.190738516 -0700
+++ sf/tmux.h	2010-06-04 23:57:06.730751773 -0700
@@ -110,6 +110,10 @@ extern char   **environ;
 #define KEYC_SHIFT 0x8000
 #define KEYC_PREFIX 0x10000
 
+/* Mask to obtain key w/o modifiers */
+#define KEYC_MASK_KEY 0x01fff
+#define KEYC_MASK_MOD 0x1e000
+
 /* Other key codes. */
 enum key_code {
 	/* Mouse key. */
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to