diff options
author | sabetts <sabetts> | 2003-01-26 03:08:26 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2003-01-26 03:08:26 +0000 |
commit | bf9397240778d2b75d531e76ddda9c7942371757 (patch) | |
tree | 20d59389b9a5304b4729de601ccdbebdac7b4f3c | |
parent | 61c6312c8b6d84509c38836cb38ee3fc59045198 (diff) | |
download | ratpoison-bf9397240778d2b75d531e76ddda9c7942371757.zip |
(cmd_help): Print key binding when called
non-interactively.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/actions.c | 224 |
2 files changed, 131 insertions, 98 deletions
@@ -1,3 +1,8 @@ +2003-01-25 Shawn Betts <sabetts@sfu.ca> + + * src/actions.c (cmd_help): Print key binding when called + non-interactively. + 2002-12-11 Shawn <sabetts@sfu.ca> * configure.in (AC_CHECK_FUNCS): Add check for putenv, remove diff --git a/src/actions.c b/src/actions.c index b46b16c..cabe3ca 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1456,114 +1456,142 @@ cmd_license (int interactive, void *data) char * cmd_help (int interactive, void *data) { - screen_info *s = current_screen(); - XEvent ev; - Window fwin; /* Window currently in focus */ - int revert; - 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 */ - char *keysym_name; - - XMapRaised (dpy, s->help_window); - - XGetInputFocus (dpy, &fwin, &revert); - XSetInputFocus (dpy, s->help_window, RevertToPointerRoot, CurrentTime); - - XDrawString (dpy, s->help_window, s->normal_gc, - 10, y + defaults.font->max_bounds.ascent, - "ratpoison key bindings", strlen ("ratpoison key bindings")); + if (interactive) + { + screen_info *s = current_screen(); + XEvent ev; + Window fwin; /* Window currently in focus */ + int revert; + 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 */ + char *keysym_name; + + XMapRaised (dpy, s->help_window); + + XGetInputFocus (dpy, &fwin, &revert); + XSetInputFocus (dpy, s->help_window, RevertToPointerRoot, CurrentTime); + + XDrawString (dpy, s->help_window, s->normal_gc, + 10, y + defaults.font->max_bounds.ascent, + "ratpoison key bindings", strlen ("ratpoison key bindings")); + + y += FONT_HEIGHT (defaults.font) * 2; + + XDrawString (dpy, s->help_window, s->normal_gc, + 10, y + defaults.font->max_bounds.ascent, + "Command key: ", strlen ("Command key: ")); + + keysym_name = keysym_to_string (prefix_key.sym, prefix_key.state); + XDrawString (dpy, s->help_window, s->normal_gc, + 10 + XTextWidth (defaults.font, "Command key: ", strlen ("Command key: ")), + y + defaults.font->max_bounds.ascent, + keysym_name, strlen (keysym_name)); + free (keysym_name); - y += FONT_HEIGHT (defaults.font) * 2; + y += FONT_HEIGHT (defaults.font) * 2; + + i = 0; + old_i = 0; + while (i<key_actions_last || drawing_keys) + { + if (drawing_keys) + { + keysym_name = keysym_to_string (key_actions[i].key, key_actions[i].state); + + XDrawString (dpy, s->help_window, s->normal_gc, + x, y + defaults.font->max_bounds.ascent, + 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)); + + free (keysym_name); + } + else + { + 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)); + } + } + + y += FONT_HEIGHT (defaults.font); + /* Make sure the next line fits entirely within the window. */ + if (y + FONT_HEIGHT (defaults.font) >= s->root_attr.height) + { + if (drawing_keys) + { + x += max_width + 10; + drawing_keys = 0; + i = old_i; + } + else + { + x += max_width + 20; + drawing_keys = 1; + i++; + old_i = i; + } + + max_width = 0; + y = FONT_HEIGHT (defaults.font) * 4; + } + else + { + i++; + if (i >= key_actions_last && drawing_keys) + { + x += max_width + 10; + drawing_keys = 0; + y = FONT_HEIGHT (defaults.font) * 4; + i = old_i; + max_width = 0; + } + } + } - XDrawString (dpy, s->help_window, s->normal_gc, - 10, y + defaults.font->max_bounds.ascent, - "Command key: ", strlen ("Command key: ")); + XMaskEvent (dpy, KeyPressMask, &ev); + XUnmapWindow (dpy, s->help_window); + XSetInputFocus (dpy, fwin, revert, CurrentTime); - keysym_name = keysym_to_string (prefix_key.sym, prefix_key.state); - XDrawString (dpy, s->help_window, s->normal_gc, - 10 + XTextWidth (defaults.font, "Command key: ", strlen ("Command key: ")), - y + defaults.font->max_bounds.ascent, - keysym_name, strlen (keysym_name)); - free (keysym_name); + /* The help window overlaps the bar, so redraw it. */ + if (current_screen()->bar_is_raised) + show_last_message(); - y += FONT_HEIGHT (defaults.font) * 2; - - i = 0; - old_i = 0; - while (i<key_actions_last || drawing_keys) + return NULL; + } + else { - if (drawing_keys) - { - keysym_name = keysym_to_string (key_actions[i].key, key_actions[i].state); - - XDrawString (dpy, s->help_window, s->normal_gc, - x, y + defaults.font->max_bounds.ascent, - keysym_name, strlen (keysym_name)); + struct sbuf *help_list; + char *keysym_name; + char *tmp; + int i; - if (XTextWidth (defaults.font, keysym_name, strlen (keysym_name)) > max_width) - max_width = XTextWidth (defaults.font, keysym_name, strlen (keysym_name)); + help_list = sbuf_new (0); - free (keysym_name); - } - else - { - 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)); - } - } + for (i = 0; i < key_actions_last; i++) + { + keysym_name = keysym_to_string (key_actions[i].key, key_actions[i].state); + sbuf_concat (help_list, keysym_name); + free (keysym_name); + sbuf_concat (help_list, " "); + sbuf_concat (help_list, key_actions[i].data); + if (i < key_actions_last - 1) + sbuf_concat (help_list, "\n"); + } - y += FONT_HEIGHT (defaults.font); - /* Make sure the next line fits entirely within the window. */ - if (y + FONT_HEIGHT (defaults.font) >= s->root_attr.height) - { - if (drawing_keys) - { - x += max_width + 10; - drawing_keys = 0; - i = old_i; - } - else - { - x += max_width + 20; - drawing_keys = 1; - i++; - old_i = i; - } + tmp = sbuf_get (help_list); + free (help_list); - max_width = 0; - y = FONT_HEIGHT (defaults.font) * 4; - } - else - { - i++; - if (i >= key_actions_last && drawing_keys) - { - x += max_width + 10; - drawing_keys = 0; - y = FONT_HEIGHT (defaults.font) * 4; - i = old_i; - max_width = 0; - } - } + return tmp; } - - XMaskEvent (dpy, KeyPressMask, &ev); - XUnmapWindow (dpy, s->help_window); - XSetInputFocus (dpy, fwin, revert, CurrentTime); - - /* The help window overlaps the bar, so redraw it. */ - if (current_screen()->bar_is_raised) - show_last_message(); - - return NULL; } char * |