summaryrefslogtreecommitdiff
path: root/src/input.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2000-12-09 11:34:43 +0000
committersabetts <sabetts>2000-12-09 11:34:43 +0000
commit1a8458cd5a3252f9d2141de13ef67a30b215476c (patch)
tree4d4b0b7c70c141f83c66c2adff651cb5b8c9d49e /src/input.c
parent7ee9190d0849e8df707611b63b42e976bbd8d827 (diff)
downloadratpoison-1a8458cd5a3252f9d2141de13ef67a30b215476c.zip
* input.c (cook_keycode): properly handle LockMask
* input.h: added prototype for keysym_to_string * input.c (keysym_to_string): added * bar.c (show_bar): update_window_names(s) is called whether the bar is raised or not. * conf.h: Added BAR_Y_PADDING BAR_X_PADDING * list.c (goto_window_name): return success or failure * list.h: updated prototype for goto_window_name * events.c (handle_key): Added a message indicating an unbound key. * bar.c (display_msg_in_bar): added (update_window_names): uses BAR_X_PADDING instead of `5' (update_window_names): Updated BAR_PADDING to BAR_Y_PADDING * input.c (cook_keycode): mod is now an usigned int (read_key): Ignores modifier keys. Now returns keysym and modifiers. (get_input): Updated BAR_PADDING to BAR_Y_PADDING and BAR_X_PADDING. * events.c (handle_key): uses read_key instead of XMaskEvent to read a key. * actions.c (goto_window_number): window list is displayed on failure. (bye): added (switch_to): added (execute_command): no longer seg faults when no windows exist.
Diffstat (limited to 'src/input.c')
-rw-r--r--src/input.c127
1 files changed, 95 insertions, 32 deletions
diff --git a/src/input.c b/src/input.c
index 60e3932..c9a276a 100644
--- a/src/input.c
+++ b/src/input.c
@@ -9,51 +9,102 @@
#include "ratpoison.h"
+/* Return the name of the keysym. caller must free returned pointer */
+char *
+keysym_to_string (KeySym keysym, unsigned int modifier)
+{
+ const unsigned int mod_table[] = {ControlMask,
+ Mod1Mask,
+ Mod2Mask,
+ Mod3Mask,
+ Mod4Mask,
+ Mod5Mask};
+ const unsigned char str_table[] = "CM2345";
+
+ unsigned char *name;
+ int pos, i;
+
+ name = malloc (15);
+ if (name == NULL)
+ {
+ PRINT_ERROR ("Out of memory!\n");
+ exit (EXIT_FAILURE);
+ }
+
+ for (pos = 0, i = 0; i < 6; i++)
+ {
+ if (modifier & mod_table[i])
+ {
+ name[pos] = str_table[i];
+ name[pos+1] = '-';
+ pos += 2;
+ }
+ }
+
+ name[pos] = keysym;
+ name[pos+1] = '\0';
+
+ return name;
+}
+
/* 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)
+cook_keycode (KeyCode keycode, KeySym *keysym, unsigned int *mod)
{
KeySym normal, shifted;
- if (*mod & ShiftMask)
- {
- normal = XKeycodeToKeysym(dpy, keycode, 0);
- shifted = XKeycodeToKeysym(dpy, keycode, 1);
+ 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 */
+ /* FIXME: eew, this looks gross. */
+ if (*mod & (ShiftMask | LockMask))
+ {
+ /* 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
+ else if (*mod & ShiftMask)
+ {
+ *keysym = shifted;
+ *mod &= ~(ShiftMask | LockMask);
+ }
+ else if (normal >= XK_a
+ && normal <= XK_z
+ && *mod & LockMask)
{
*keysym = shifted;
- *mod &= ~ShiftMask;
+ }
+ /* But if the shifted code is defined, we use it and remove the
+ shift mask */
+ else
+ {
+ *keysym = normal;
}
}
else
{
- *keysym = XKeycodeToKeysym(dpy, keycode, 0);
+ *keysym = normal;
}
- PRINT_DEBUG ("cooked keysym: %ld '%c' mask: %d\n", *keysym, *keysym, *mod);
+ PRINT_DEBUG ("cooked keysym: %ld '%c' mask: %d\n",
+ *keysym, (char)*keysym, *mod);
}
-static KeySym
-read_key ()
+void
+read_key (KeySym *keysym, unsigned int *modifiers)
{
- KeySym keysym;
- int mod;
XEvent ev;
- XMaskEvent (dpy, KeyPressMask, &ev);
- mod = ev.xkey.state;
- cook_keycode (ev.xkey.keycode, &keysym, &mod);
-
- return keysym;
+ do
+ {
+ XMaskEvent (dpy, KeyPressMask, &ev);
+ *modifiers = ev.xkey.state;
+ cook_keycode (ev.xkey.keycode, keysym, modifiers);
+ } while (IsModifierKey (*keysym));
}
/* pass in a pointer a string and how much room we have, and fill it
@@ -63,6 +114,7 @@ get_input (screen_info *s, char *prompt, char *str, int len)
{
int cur_len; /* Current length of the string. */
KeySym ch;
+ unsigned int modifier;
int revert;
Window fwin;
int prompt_width = XTextWidth (s->font, prompt, strlen (prompt));
@@ -73,38 +125,49 @@ get_input (screen_info *s, char *prompt, char *str, int len)
XMapWindow (dpy, s->input_window);
XMoveResizeWindow (dpy, s->input_window,
- bar_x (s, width), bar_y (s), width, (FONT_HEIGHT (s->font) + BAR_PADDING * 2));
+ bar_x (s, width), bar_y (s), width,
+ (FONT_HEIGHT (s->font) + BAR_Y_PADDING * 2));
XClearWindow (dpy, s->input_window);
XRaiseWindow (dpy, s->input_window);
/* draw the window prompt. */
- XDrawString (dpy, s->input_window, s->bold_gc, 5,
- BAR_PADDING + s->font->max_bounds.ascent, prompt, strlen (prompt));
+ XDrawString (dpy, s->input_window, s->bold_gc, BAR_X_PADDING,
+ BAR_Y_PADDING + s->font->max_bounds.ascent, prompt,
+ strlen (prompt));
XGetInputFocus (dpy, &fwin, &revert);
XSetInputFocus (dpy, s->input_window, RevertToPointerRoot, CurrentTime);
+ /* XSync (dpy, False); */
cur_len = 0;
- while ((ch = read_key ()) != XK_Return)
+
+ read_key (&ch, &modifier);
+ while (ch != XK_Return)
{
- PRINT_DEBUG ("key %d\n", ch);
+ PRINT_DEBUG ("key %ld\n", ch);
if (ch == XK_BackSpace)
{
if (cur_len > 0) cur_len--;
XClearWindow (dpy, s->input_window);
- XDrawString (dpy, s->input_window, s->bold_gc, 5,
- BAR_PADDING + s->font->max_bounds.ascent, prompt, strlen (prompt));
- XDrawString (dpy, s->input_window, s->bold_gc, 5 + prompt_width,
- BAR_PADDING + s->font->max_bounds.ascent, str, cur_len);
+ XDrawString (dpy, s->input_window, s->bold_gc, BAR_X_PADDING,
+ BAR_Y_PADDING + s->font->max_bounds.ascent, prompt,
+ strlen (prompt));
+ XDrawString (dpy, s->input_window, s->bold_gc,
+ BAR_X_PADDING + prompt_width,
+ BAR_Y_PADDING + s->font->max_bounds.ascent, str,
+ cur_len);
}
- else if (!IsModifierKey (ch))
+ else
{
str[cur_len] = ch;
if (cur_len < len - 1) cur_len++;
- XDrawString (dpy, s->input_window, s->bold_gc, 5 + prompt_width,
- BAR_PADDING + s->font->max_bounds.ascent, str, cur_len);
+ XDrawString (dpy, s->input_window, s->bold_gc,
+ BAR_X_PADDING + prompt_width,
+ BAR_Y_PADDING + s->font->max_bounds.ascent, str, cur_len);
}
+
+ read_key (&ch, &modifier);
}
str[cur_len] = 0;