diff options
author | sabetts <sabetts> | 2000-12-04 00:06:12 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2000-12-04 00:06:12 +0000 |
commit | 3b8d3d379b2778cfdbc2c1e1c6c448303311e20f (patch) | |
tree | 3022f113a89ec8aaef4781458b31fbff649bfac1 /src/input.c | |
parent | 5ec1978cf5d9917e1ea6dda6f9169aedef7351a0 (diff) | |
download | ratpoison-3b8d3d379b2778cfdbc2c1e1c6c448303311e20f.zip |
* 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.
Diffstat (limited to 'src/input.c')
-rw-r--r-- | src/input.c | 49 |
1 files changed, 44 insertions, 5 deletions
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 <X11/keysym.h> #include <stdlib.h> #include <stdio.h> +#include <X11/Xlib.h> +#include <X11/keysym.h> +#include <X11/Xutil.h> #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++; |