[cairo-commit] xsvg/src xsvg.c,1.31,1.32
Keith Packard
commit at pdx.freedesktop.org
Wed Jan 25 20:07:24 PST 2006
Committed by: keithp
Update of /cvs/cairo/xsvg/src
In directory gabe:/tmp/cvs-serv14244/src
Modified Files:
xsvg.c
Log Message:
2006-01-26 Keith Packard <keithp at keithp.com>
* configure.in:
* src/xsvg.c: (win_init), (win_handle_key_press):
Use keysyms for matching instead of keycodes.
Allows for multiple keys with same keysym.
Index: xsvg.c
===================================================================
RCS file: /cvs/cairo/xsvg/src/xsvg.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- xsvg.c 1 Jun 2005 20:47:46 -0000 1.31
+++ xsvg.c 26 Jan 2006 04:07:22 -0000 1.32
@@ -42,6 +42,7 @@
#include "args.h"
#include <X11/Xatom.h>
#include <X11/Xutil.h>
+#include <X11/keysym.h>
/* XXX: The cursor code doesn't seem to be working, (and someone
* couldn't get it to compile on Solaris), so I'm just disabling it
@@ -105,7 +106,7 @@
{
char *key;
int is_alias;
- KeyCode keycode;
+ KeySym keysym;
key_callback_t callback;
} key_binding_t;
@@ -192,7 +193,7 @@
};
static key_binding_t key_binding[] = {
- /* Keysym, Alias, Keycode, callback */
+ /* Name, Alias, Keysym, callback */
{ "X", 0, 0, x_flip_cb },
{ "Y", 0, 0, y_flip_cb },
{ "Q", 0, 0, quit_cb },
@@ -556,11 +557,7 @@
if (keysym == NoSymbol)
fprintf(stderr, "ERROR: No keysym for \"%s\"\n", key_binding[i].key);
else
- {
- key_binding[i].keycode = XKeysymToKeycode(dpy, keysym);
- if (!key_binding[i].keycode)
- fprintf(stderr, "ERROR: No key for \"%s\"\n", key_binding[i].key);
- }
+ key_binding[i].keysym = keysym;
}
surface = cairo_xlib_surface_create (dpy,
@@ -654,10 +651,17 @@
win_handle_key_press(win_t *win, XKeyEvent *kev)
{
unsigned int i;
+ char buffer[64];
+ KeySym keysym;
- for (i=0; i < ARRAY_SIZE(key_binding); i++)
- if (key_binding[i].keycode == kev->keycode)
+ XLookupString (kev, buffer, sizeof (buffer), &keysym, NULL);
+ if (XK_a <= keysym && keysym <= XK_z)
+ keysym += XK_A - XK_a;
+
+ for (i=0; i < ARRAY_SIZE(key_binding); i++) {
+ if (keysym == key_binding[i].keysym)
return (key_binding[i].callback)(win);
+ }
return 0;
}
More information about the cairo-commit
mailing list