[PATCH] more correct cmd_help()
[email protected] (Jérémie Courrèges -Anglas)
| Newsgroups | gmane.comp.window-managers.ratpoison.devel |
|---|---|
| Message-ID | <[email protected]> |
* 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?
Matt: are you happy with this way of handling "Command key"?
---
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 (i<map->actions_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;
}
--
1.8.1.2
--
Jérémie Courrèges-Anglas
GPG Key Fingerprint: 61DB D9A0 00A4 67CF 2A90 8961 6191 8FBF 06A1 1494
_______________________________________________
Ratpoison-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/ratpoison-devel
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (OpenBSD) iQIcBAEBCgAGBQJRHo9gAAoJEGGRj78GoRSUpN4P/2YTXaUvzeNZgf8un16HLmvE yw2wmj2Pqw9GflhIbL1F7LNyQulkDTP0lOwyazkUxbfnzzNLn1fq6VQFXPp+Relk EhtBGEZbDGyIL2kVQcm/HZj/Tt4oTYYFzWk0HFfRYVRXQMVVBI4er0e4weic1SWd vGg3wf4/5YqpRZQB4Uw89edCrh123MNywxJDN3p1WlJ+HrxNAd/sIJr4K8+RD1Oj t3LrWfeY7qFRVllMWAafjVX8hLTGlfPAZP0g40rDtcEr+Yqqz41+0eEhi772WYW6 JdRAKJHNKCYvbc/Bz0afE9SayV1tULeyhMlZcZRC/Qdr71z6PzD/lQQdWICXHRqT yzp6t/cp4yRh+f2SX1hSzLimzjV7j3c1DNiL+uFuvMvrA17Y9DinyIXBoH09B3Xk VxsXSLXUnYD562wulKHGl/FxehKwXjYvI49RLrqRNKJfrm7ErmiKSZB1EOn9IXa9 xgO9Ck4GLj6aqVSuOGxbl8rcfZH6dBLs977ziAgmArIWaGqHWwOyII8PGiLmIdid 7OoKS6TEaQYFR+o4CDgkoicDBnyne6hmjuFq+NGXyFUhL7wTbE0/ICOwIS+ngA+k k0qBIfHagbTqMa7YQiUfTmJp2EM2CmBPDpi5DataVmgxmAdQF3dsbo2lykQhyiWH WkcwtIWJEdbmPEQ9Dg9d =H9zb -----END PGP SIGNATURE-----