2001-09-13 Gergely Nagy
* src/actions.c (find_command_by_keydesc): initialize our counter to zero (resolve_command_from_keydesc): new function (cmd_help): use it * src/conf.h (MAX_SYMBIND_DEPTH): new constant diff -urd ratpoison.orig/src/actions.c ratpoison/src/actions.c --- ratpoison.orig/src/actions.c Thu Sep 13 11:24:20 2001 +++ ratpoison/src/actions.c Thu Sep 13 16:20:51 2001 @@ -143,7 +143,7 @@ static char * find_command_by_keydesc (char *desc) { - int i; + int i = 0; char *keysym_name; while (i < key_actions_last) @@ -161,6 +161,23 @@ return NULL; } +static char * +resolve_command_from_keydesc (char *desc, int depth) +{ + char *cmd, *command; + + command = find_command_by_keydesc (desc); + if (!command) + return NULL; + + /* is it a symbind? */ + if (strncmp (command, "symbind", 7) || depth > MAX_SYMBIND_DEPTH) + /* it is not */ + return command; + + cmd = resolve_command_from_keydesc (&command[8], depth + 1); + return (cmd != NULL) ? cmd : command; +} static void add_keybinding (KeySym keysym, int state, char *cmd) @@ -1233,46 +1250,24 @@ keysym_name, strlen (keysym_name)); if (XTextWidth (defaults.font, keysym_name, strlen (keysym_name)) > max_width) - { - max_width = XTextWidth (defaults.font, keysym_name, strlen (keysym_name)); - } + max_width = XTextWidth (defaults.font, keysym_name, strlen (keysym_name)); free (keysym_name); } else { - char *cmd = NULL; - if (!strncmp (key_actions[i].data, "symbind", 7)) - { - char *data2, *key; - data2 = strdup (key_actions[i].data); - key = strtok (data2, " "); - key = strtok (NULL, "\0"); - - cmd = find_command_by_keydesc (key); - - if (cmd) - { - XDrawString (dpy, s->help_window, s->normal_gc, x, - y + defaults.font->max_bounds.ascent, cmd, - strlen (cmd)); - if (XTextWidth (defaults.font, cmd, strlen (cmd)) > max_width) - { - max_width = XTextWidth (defaults.font, cmd, strlen (cmd)); - } - } - } - if (cmd == NULL) - { - XDrawString (dpy, s->help_window, s->normal_gc, - x, y + defaults.font->max_bounds.ascent, - key_actions[i].data, strlen (key_actions[i].data)); - - if (XTextWidth (defaults.font, key_actions[i].data, strlen (key_actions[i].data)) > max_width) - { - max_width = XTextWidth (defaults.font, key_actions[i].data, strlen (key_actions[i].data)); - } - } + char *cmd; + cmd = resolve_command_from_keydesc ( + keysym_to_string (key_actions[i].key, + key_actions[i].state), 0); + if (cmd) + { + XDrawString (dpy, s->help_window, s->normal_gc, x, + y + defaults.font->max_bounds.ascent, cmd, + strlen (cmd)); + if (XTextWidth (defaults.font, cmd, strlen (cmd)) > max_width) + max_width = XTextWidth (defaults.font, cmd, strlen (cmd)); + } } y += FONT_HEIGHT (defaults.font); diff -urd ratpoison.orig/src/conf.h ratpoison/src/conf.h --- ratpoison.orig/src/conf.h Mon Sep 10 20:43:30 2001 +++ ratpoison/src/conf.h Thu Sep 13 16:08:43 2001 @@ -47,4 +47,7 @@ mostly for use with hand-helds. */ #define UNMANAGED_WINDOW_LIST "xapm","xclock","xscribble" +/* The maximum depth of a symbind */ +#define MAX_SYMBIND_DEPTH 16 + #endif /* !_ _RATPOISON_CONF_H */