summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog11
-rw-r--r--src/actions.c49
-rw-r--r--src/events.c12
-rw-r--r--src/input.c49
-rw-r--r--src/input.h1
5 files changed, 91 insertions, 31 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e3898f0..e1477f4 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2000-12-03 shawn <sabetts@diggin.lamenet.tmp>
+
+ * 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.
+
2000-12-01 shawn <sabetts@diggin.lamenet.tmp>
* list.c (find_window_by_name): added check to make sure the
diff --git a/src/actions.c b/src/actions.c
index 09e5bd2..323f519 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -3,34 +3,35 @@
#include <unistd.h>
#include <sys/wait.h>
+#include <X11/keysym.h>
#include "ratpoison.h"
/* Initialization of the key structure */
-rp_action key_actions[] = { {KEY_PREFIX, 0, 0, generate_prefix},
- {'c', -1, "xterm", spawn},
- {'e', -1, "emacs", spawn},
- {'p', -1, 0, prev_window},
- {'n', -1, 0, next_window},
- {';', ShiftMask, 0, execute_command},
- {KEY_PREFIX, -1, 0, last_window},
- {'w', -1, 0, toggle_bar},
- {'k', ShiftMask, 0, kill_window},
- {'k', 0, 0, delete_window},
- {'\'', -1, 0, goto_win_by_name},
- {'a', -1, 0, rename_current_window},
- {'g', ControlMask, 0, abort_keypress},
- {'0', -1, 0, goto_window_0},
- {'1', -1, 0, goto_window_1},
- {'2', -1, 0, goto_window_2},
- {'3', -1, 0, goto_window_3},
- {'4', -1, 0, goto_window_4},
- {'5', -1, 0, goto_window_5},
- {'6', -1, 0, goto_window_6},
- {'7', -1, 0, goto_window_7},
- {'8', -1, 0, goto_window_8},
- {'9', -1, 0, goto_window_9},
- { 0, 0, 0, 0 } };
+rp_action key_actions[] = { {KEY_PREFIX, 0, 0, generate_prefix},
+ {XK_c, -1, "xterm", spawn},
+ {XK_e, -1, "emacs", spawn},
+ {XK_p, -1, 0, prev_window},
+ {XK_n, -1, 0, next_window},
+ {XK_colon, 0, 0, execute_command},
+ {KEY_PREFIX, -1, 0, last_window},
+ {XK_w, -1, 0, toggle_bar},
+ {XK_K, 0, 0, kill_window},
+ {XK_k, 0, 0, delete_window},
+ {XK_quoteright, -1, 0, goto_win_by_name},
+ {XK_a, -1, 0, rename_current_window},
+ {XK_g, ControlMask, 0, abort_keypress},
+ {XK_0, -1, 0, goto_window_0},
+ {XK_1, -1, 0, goto_window_1},
+ {XK_2, -1, 0, goto_window_2},
+ {XK_3, -1, 0, goto_window_3},
+ {XK_4, -1, 0, goto_window_4},
+ {XK_5, -1, 0, goto_window_5},
+ {XK_6, -1, 0, goto_window_6},
+ {XK_7, -1, 0, goto_window_7},
+ {XK_8, -1, 0, goto_window_8},
+ {XK_9, -1, 0, goto_window_9},
+ { 0, 0, 0, 0 } };
void
prev_window (void *data)
diff --git a/src/events.c b/src/events.c
index 5c35717..bf9c78b 100644
--- a/src/events.c
+++ b/src/events.c
@@ -243,7 +243,8 @@ handle_key (screen_info *s)
int revert;
Window fwin;
XEvent ev;
- int keysym, mod;
+ KeySym keysym;
+ int mod;
PRINT_DEBUG ("handling key.\n");
@@ -256,9 +257,10 @@ handle_key (screen_info *s)
do
{
XMaskEvent (dpy, KeyPressMask, &ev);
- keysym = XLookupKeysym((XKeyEvent *) &ev, 0);
mod = ev.xkey.state;
+ cook_keycode (ev.xkey.keycode, &keysym, &mod);
+
for (i = key_actions; i->key != 0; i++)
{
if (keysym == i->key)
@@ -402,6 +404,12 @@ delegate_event (XEvent *ev)
case KeyPress:
PRINT_DEBUG ("KeyPress %d %d\n", ev->xkey.keycode, ev->xkey.state);
+ {
+ KeySym thesym;
+ char buf[512];
+ XLookupString (&ev->xkey, buf, 512, &thesym, NULL);
+ PRINT_DEBUG ("key string: '%s' %ld\n", buf, thesym);
+ }
key_press (ev);
break;
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++;
diff --git a/src/input.h b/src/input.h
index 9d49bbf..b00414d 100644
--- a/src/input.h
+++ b/src/input.h
@@ -1 +1,2 @@
+void cook_keycode (KeyCode keycode, KeySym *keysym, int *mod);
void get_input (screen_info *s, char *prompt, char *str, int len);