From 1c4335fe092978b42eda6ccbb37854c95fb5f368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Courr=C3=A8ges-Anglas?= Date: Thu, 14 Feb 2013 22:39:10 +0100 Subject: more correct cmd_help() * only print the "Command key: ..." bits if we're dealing with the root kmap * don't read (and print) uninitialized data (foomap->actions[foomap->actions_last] shouldn't be accessed) It seems like keymap actions and other things like aliases use arrays because they were implemented before linkedlist.[ch] were introduced. Perhaps should we just switch them to more fool-proof linked lists? --- src/actions.c | 61 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/actions.c b/src/actions.c index 9227feb..4abfadf 100644 --- a/src/actions.c +++ b/src/actions.c @@ -3365,8 +3365,10 @@ cmd_help (int interactive, struct cmdarg **args) int i, old_i; int x = 10; int y = 0; - int max_width = 0; - int drawing_keys = 1; /* 1 if we are drawing keys 0 if we are drawing commands */ + int header_offset; + int width, max_width = 0; + /* 1 if we are drawing keys, 0 if we are drawing commands */ + int drawing_keys = 1; char *keysym_name; /* Switch to the default colormap. */ @@ -3382,34 +3384,40 @@ cmd_help (int interactive, struct cmdarg **args) y += FONT_HEIGHT (s) * 2; - rp_draw_string (s, s->help_window, STYLE_NORMAL, - 10, y + FONT_ASCENT(s), - "Command key: ", -1); - - - keysym_name = keysym_to_string (prefix_key.sym, prefix_key.state); - rp_draw_string (s, s->help_window, STYLE_NORMAL, - 10 + rp_text_width (s, "Command key: ", -1), - y + FONT_ASCENT(s), - keysym_name, -1); - free (keysym_name); + /* Only print the "Command key" for the root keymap */ + if (map == find_keymap (ROOT_KEYMAP)) + { + rp_draw_string (s, s->help_window, STYLE_NORMAL, + 10, y + FONT_ASCENT(s), + "Command key: ", -1); + + keysym_name = keysym_to_string (prefix_key.sym, prefix_key.state); + rp_draw_string (s, s->help_window, STYLE_NORMAL, + 10 + rp_text_width (s, "Command key: ", -1), + y + FONT_ASCENT(s), + keysym_name, -1); + free (keysym_name); + + y += FONT_HEIGHT (s) * 2; + } - y += FONT_HEIGHT (s) * 2; + header_offset = y; - i = 0; - old_i = 0; - while (iactions_last || drawing_keys) + i = old_i = 0; + while (i < map->actions_last && old_i < map->actions_last) { if (drawing_keys) { - keysym_name = keysym_to_string (map->actions[i].key, map->actions[i].state); + keysym_name = + keysym_to_string (map->actions[i].key, map->actions[i].state); rp_draw_string (s, s->help_window, STYLE_NORMAL, x, y + FONT_ASCENT(s), keysym_name, -1); - if (rp_text_width (s, keysym_name, -1) > max_width) - max_width = rp_text_width (s, keysym_name, -1); + width = rp_text_width (s, keysym_name, -1); + if (width > max_width) + max_width = width; free (keysym_name); } @@ -3419,10 +3427,9 @@ cmd_help (int interactive, struct cmdarg **args) x, y + FONT_ASCENT(s), map->actions[i].data, -1); - if (rp_text_width (s, map->actions[i].data, -1) > max_width) - { - max_width = rp_text_width (s, map->actions[i].data, -1); - } + width = rp_text_width (s, map->actions[i].data, -1); + if (width > max_width) + max_width = width; } y += FONT_HEIGHT (s); @@ -3444,16 +3451,16 @@ cmd_help (int interactive, struct cmdarg **args) } max_width = 0; - y = FONT_HEIGHT (s) * 4; + y = header_offset; } else { i++; - if (i >= map->actions_last && drawing_keys) + if (i == map->actions_last && drawing_keys) { x += max_width + 10; drawing_keys = 0; - y = FONT_HEIGHT (s) * 4; + y = header_offset; i = old_i; max_width = 0; } -- cgit v1.2.3