ratpoison-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RP] [PATCH] Add topkmap set variable to allow runtime top keymap switch


From: Tim Cooijmans
Subject: [RP] [PATCH] Add topkmap set variable to allow runtime top keymap switching
Date: Mon, 15 May 2006 22:19:09 +0200
User-agent: Thunderbird 1.5.0.2 (X11/20060501)

Attached patch adds a set variable called 'topkmap' so you can switch top keymaps at runtime. For instance, if you would run ``set topkmap root'', you would no longer need to type the prefix key before a command keystroke.

Have fun,

Tim
diff -ur ratpoison/src/actions.c ratpoison-modified/src/actions.c
--- ratpoison/src/actions.c     2006-04-29 17:34:15.000000000 +0200
+++ ratpoison-modified/src/actions.c    2006-05-15 21:51:11.000000000 +0200
@@ -63,6 +63,7 @@
 static cmdret * set_framesels (struct cmdarg **args);
 static cmdret * set_maxundos (struct cmdarg **args);
 static cmdret * set_infofmt (struct cmdarg **args);
+static cmdret * set_topkmap (struct cmdarg **args);
 
 LIST_HEAD(set_vars);
 
@@ -115,6 +116,7 @@
   add_set_var ("winliststyle", set_winliststyle, 1, "", arg_STRING);
   add_set_var ("framesels", set_framesels, 1, "", arg_STRING);
   add_set_var ("infofmt", set_infofmt, 1, "", arg_REST);
+  add_set_var ("topkmap", set_topkmap, 1, "", arg_STRING);
 }
 
 /* rp_keymaps is ratpoison's list of keymaps. */
@@ -646,7 +648,7 @@
   map = keymap_new (ROOT_KEYMAP);
   list_add (&map->node, &rp_keymaps);
 
-  top = keymap_new (TOP_KEYMAP);
+  top = keymap_new (defaults.top_kmap);
   list_add (&top->node, &rp_keymaps);
 
   /* Initialive the alias list. */
@@ -974,7 +976,7 @@
 
   /* If we're updating the top level map, we'll need to update the
      keys grabbed. */
-  if (map == find_keymap (TOP_KEYMAP))
+  if (map == find_keymap (defaults.top_kmap))
     ungrab_keys_all_wins ();
 
   /* If no comand is specified, then unbind the key. */
@@ -982,7 +984,7 @@
     ret = cmdret_new (RET_FAILURE, "undefinekey: key '%s' is not bound", 
ARG_STRING(1));
 
   /* Update the grabbed keys. */
-  if (map == find_keymap (TOP_KEYMAP))
+  if (map == find_keymap (defaults.top_kmap))
     grab_keys_all_wins ();
   XSync (dpy, False);
 
@@ -1007,7 +1009,7 @@
 
   /* If we're updating the top level map, we'll need to update the
      keys grabbed. */
-  if (map == find_keymap (TOP_KEYMAP))
+  if (map == find_keymap (defaults.top_kmap))
     ungrab_keys_all_wins ();
 
   if ((key_action = find_keybinding (key->sym, key->state, map)))
@@ -1016,7 +1018,7 @@
     add_keybinding (key->sym, key->state, ARG_STRING(2), map);
 
   /* Update the grabbed keys. */
-  if (map == find_keymap (TOP_KEYMAP))
+  if (map == find_keymap (defaults.top_kmap))
     grab_keys_all_wins ();
   XSync (dpy, False);
 
@@ -2655,7 +2657,7 @@
   rp_action *action;
   rp_keymap *map, *top;
 
-  top = find_keymap (TOP_KEYMAP);
+  top = find_keymap (defaults.top_kmap);
   map = find_keymap (ROOT_KEYMAP);
   key = ARG(0,key);
 
@@ -3608,6 +3610,26 @@
 }
 
 static cmdret *
+set_topkmap (struct cmdarg **args)
+{
+  if (args[0] == NULL)
+    return cmdret_new (RET_SUCCESS, "%s", defaults.top_kmap);
+
+  if (!find_keymap (ARG_STRING(0)))
+    return cmdret_new(RET_FAILURE, "Unknown keymap %s", ARG_STRING(0));
+
+  ungrab_keys_all_wins();
+
+  free (defaults.top_kmap);
+  defaults.top_kmap = xstrdup (ARG_STRING(0));
+
+  grab_keys_all_wins();
+  XSync(dpy, False);
+
+  return cmdret_new (RET_SUCCESS, NULL);
+}
+
+static cmdret *
 set_winfmt (struct cmdarg **args)
 {
   if (args[0] == NULL)
@@ -4785,7 +4807,7 @@
 {
    rp_keymap *map, *top, *root;
 
-  top = find_keymap (TOP_KEYMAP);
+  top = find_keymap (defaults.top_kmap);
   root = find_keymap (ROOT_KEYMAP);
 
   map = ARG(0,keymap);
diff -ur ratpoison/src/data.h ratpoison-modified/src/data.h
--- ratpoison/src/data.h        2006-04-20 04:10:02.000000000 +0200
+++ ratpoison-modified/src/data.h       2006-05-15 00:43:54.000000000 +0200
@@ -249,6 +249,9 @@
 
   /* How many frame sets to remember when undoing. */
   int maxundos;
+
+  /* The name of the top level keymap */
+  char *top_kmap;
 };
 
 /* Information about a child process. */
diff -ur ratpoison/src/events.c ratpoison-modified/src/events.c
--- ratpoison/src/events.c      2006-04-20 04:16:09.000000000 +0200
+++ ratpoison-modified/src/events.c     2006-05-15 01:04:07.000000000 +0200
@@ -383,11 +383,11 @@
 handle_key (KeySym ks, unsigned int mod, rp_screen *s)
 {
   rp_action *key_action;
-  rp_keymap *map = find_keymap (TOP_KEYMAP);
+  rp_keymap *map = find_keymap (defaults.top_kmap);
 
   if (map == NULL)
     {
-      PRINT_ERROR (("Unable to find " TOP_KEYMAP " keymap\n"));
+      PRINT_ERROR (("Unable to find top level keymap\n"));
       return;
     }
 
diff -ur ratpoison/src/main.c ratpoison-modified/src/main.c
--- ratpoison/src/main.c        2006-04-22 00:56:00.000000000 +0200
+++ ratpoison-modified/src/main.c       2006-05-15 00:53:14.000000000 +0200
@@ -465,6 +465,8 @@
 static void
 init_defaults ()
 {
+  defaults.top_kmap = xstrdup(TOP_KEYMAP);
+
   defaults.win_gravity     = NorthWestGravity;
   defaults.trans_gravity   = CenterGravity;
   defaults.maxsize_gravity = CenterGravity;
diff -ur ratpoison/src/manage.c ratpoison-modified/src/manage.c
--- ratpoison/src/manage.c      2006-04-20 04:10:02.000000000 +0200
+++ ratpoison-modified/src/manage.c     2006-05-15 01:04:48.000000000 +0200
@@ -110,12 +110,12 @@
   XGrabKey(dpy, AnyKey, AnyModifier, w, True,
            GrabModeAsync, GrabModeAsync);
 #else
-  rp_keymap *map = find_keymap (TOP_KEYMAP);
+  rp_keymap *map = find_keymap (defaults.top_kmap);
   int i;
 
   if (map == NULL)
     {
-      PRINT_ERROR (("Unable to find " TOP_KEYMAP " keymap\n"));
+      PRINT_ERROR (("Unable to find top level keymap\n"));
       return;
     }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]