From 3b8d3d379b2778cfdbc2c1e1c6c448303311e20f Mon Sep 17 00:00:00 2001 From: sabetts Date: Mon, 4 Dec 2000 00:06:12 +0000 Subject: * input.h (cook_keycode): added prototype * actions.c: key_actions now uses the #define'd keysyms from X11/keysym.h * events.c (handle_key): calls cook_keycode() before processing the keysym. * input.c (read_key): calls cook_keycode() before returning the keysym (cook_keycode): added. --- src/input.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'src/input.c') diff --git a/src/input.c b/src/input.c index 222e3e6..60e3932 100644 --- a/src/input.c +++ b/src/input.c @@ -1,20 +1,59 @@ /* for reading kdb input from the user. Currently only used to read in the name of a window to jump to. */ -#include #include #include +#include +#include +#include #include "ratpoison.h" +/* Cooks a keycode + modifier into a keysym + modifier. This should be + used anytime meaningful key information is to be extracted from a + KeyPress or KeyRelease event. */ +void +cook_keycode (KeyCode keycode, KeySym *keysym, int *mod) +{ + KeySym normal, shifted; -static int + if (*mod & ShiftMask) + { + normal = XKeycodeToKeysym(dpy, keycode, 0); + shifted = XKeycodeToKeysym(dpy, keycode, 1); + + /* if the shifted code is not defined, then we use the normal keysym and keep the shift mask */ + if (shifted == NoSymbol) + { + *keysym = normal; + } + /* But if the shifted code is defined, we use it and remove the shift mask */ + else + { + *keysym = shifted; + *mod &= ~ShiftMask; + } + } + else + { + *keysym = XKeycodeToKeysym(dpy, keycode, 0); + } + + PRINT_DEBUG ("cooked keysym: %ld '%c' mask: %d\n", *keysym, *keysym, *mod); +} + +static KeySym read_key () { + KeySym keysym; + int mod; XEvent ev; XMaskEvent (dpy, KeyPressMask, &ev); - return XLookupKeysym ((XKeyEvent *)&ev, 0); + mod = ev.xkey.state; + cook_keycode (ev.xkey.keycode, &keysym, &mod); + + return keysym; } /* pass in a pointer a string and how much room we have, and fill it @@ -23,7 +62,7 @@ void get_input (screen_info *s, char *prompt, char *str, int len) { int cur_len; /* Current length of the string. */ - int ch; + KeySym ch; int revert; Window fwin; int prompt_width = XTextWidth (s->font, prompt, strlen (prompt)); @@ -58,7 +97,7 @@ get_input (screen_info *s, char *prompt, char *str, int len) XDrawString (dpy, s->input_window, s->bold_gc, 5 + prompt_width, BAR_PADDING + s->font->max_bounds.ascent, str, cur_len); } - else if (ch >= ' ') + else if (!IsModifierKey (ch)) { str[cur_len] = ch; if (cur_len < len - 1) cur_len++; -- cgit v1.2.3