repo: rxvt-unicode-sixel
action: commit
revision: 
path_from: 
revision_from: 8d802ffcbebf3a256990aedce870593230df53c6:
path_to: 
revision_to: 
git.thebackupbox.net
rxvt-unicode-sixel
git clone git://git.thebackupbox.net/rxvt-unicode-sixel
commit 8d802ffcbebf3a256990aedce870593230df53c6
Author: Emanuele Giaquinta 
Date:   Sat May 7 18:29:18 2011 +0000

    Restore support for 'list' keysym syntax in a less intrusive way.

diff --git a/doc/rxvt.1.pod b/doc/rxvt.1.pod
index 9a06601627e5b186cc78bdce3dc5a0649b9f537a..
index ..36bb2bd5d97b5fe2b3670852d959028a0cab495b 100644
--- a/doc/rxvt.1.pod
+++ b/doc/rxvt.1.pod
@@ -1164,6 +1164,20 @@ performed in an exact manner; however, the closest match is assured.
 I may contain escape values (C<\n>: newline, C<\000>: octal
 number), see RESOURCES in C for further details.

+You can define a range of keysyms in one shot by providing a I
+with pattern B, where the delimiter `/'
+should be a character not used by the strings.
+
+Its usage can be demonstrated by an example:
+
+  URxvt.keysym.M-C-0x61:    list|\033<|abc|>
+
+The above line is equivalent to the following three lines:
+
+  URxvt.keysym.Meta-Control-0x61:    \033
+  URxvt.keysym.Meta-Control-0x62:    \033
+  URxvt.keysym.Meta-Control-0x63:    \033
+
 If I takes the form of C, the specified B
 is interpreted and executed as @@RXVT_NAME@@'s control sequence. For
 example the following means "change the current locale to C
diff --git a/src/keyboard.C b/src/keyboard.C
index d803894fa588fadaf1113b79f762b1238c74800d..
index ..9fbde630f3207ef5ed794299788309e006d4d520 100644
--- a/src/keyboard.C
+++ b/src/keyboard.C
@@ -118,19 +118,52 @@ keyboard_manager::clear ()
   keymap.clear ();
 }

-// a wrapper for register_keymap,
-// so that outside codes don't have to know so much details.
-//
-// the string 'trans' is copied to an internal managed buffer,
-// so the caller can free memory of 'trans' at any time.
+// a wrapper for register_translation that converts the input string
+// to utf-8 and expands 'list' syntax.
 void
 keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans)
 {
-  keysym_t *key = new keysym_t;
   wchar_t *wc = rxvt_mbstowcs (trans);
   char *translation = rxvt_wcstoutf8 (wc);
   free (wc);

+  if (strncmp (translation, "list", 4) == 0 && translation [4]
+      && strlen (translation) < STRING_MAX)
+    {
+      char *prefix = translation + 4;
+      char *middle = strchr  (prefix + 1, translation [4]);
+      char *suffix = strrchr (prefix + 1, translation [4]);
+
+      if (suffix && middle && suffix > middle + 1)
+        {
+          int range = suffix - middle - 1;
+          int prefix_len = middle - prefix - 1;
+          char buf[STRING_MAX];
+
+          memcpy (buf, prefix + 1, prefix_len);
+          strcpy (buf + prefix_len + 1, suffix + 1);
+
+          for (int i = 0; i < range; i++)
+            {
+              buf [prefix_len] = middle [i + 1];
+              register_translation (keysym + i, state, strdup (buf));
+            }
+
+          free (translation);
+          return;
+        }
+      else
+        rxvt_warn ("cannot parse list-type keysym '%s', processing as normal keysym.\n", translation);
+    }
+
+  register_translation (keysym, state, translation);
+}
+
+void
+keyboard_manager::register_translation (KeySym keysym, unsigned int state, char *translation)
+{
+  keysym_t *key = new keysym_t;
+
   if (key && translation)
     {
       key->keysym = keysym;
diff --git a/src/keyboard.h b/src/keyboard.h
index c24c55104043e260358a3407ca57cdad24499a6d..
index ..869c6ab689ad4c597e21e237aa815462bd089dd6 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -71,6 +71,7 @@ public:

   void clear ();
   void register_user_translation (KeySym keysym, unsigned int state, const char *trans);
+  void register_translation (KeySym keysym, unsigned int state, char *translation);
   void register_done ();        // call this to make newly registered keymaps take effect
   bool dispatch (rxvt_term *term, KeySym keysym, unsigned int state);

-----END OF PAGE-----