|
|
|
|
@ -38,7 +38,7 @@ |
|
|
|
|
***********************************************************************/ |
|
|
|
|
typedef struct _Key_t |
|
|
|
|
{ |
|
|
|
|
KeySym key; |
|
|
|
|
KeyCode key; |
|
|
|
|
struct _Key_t *next; |
|
|
|
|
} Key_t; |
|
|
|
|
|
|
|
|
|
@ -78,7 +78,7 @@ void intercept (XPointer user_data, XRecordInterceptData *data); |
|
|
|
|
|
|
|
|
|
KeyMap_t *parse_mapping (Display *ctrl_conn, char *mapping, Bool debug); |
|
|
|
|
|
|
|
|
|
Key_t *key_add_key (Key_t *keys, KeySym key); |
|
|
|
|
Key_t *key_add_key (Key_t *keys, KeyCode key); |
|
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
|
* Main function |
|
|
|
|
@ -235,7 +235,7 @@ void *sig_handler (void *user_data) |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Key_t *key_add_key (Key_t *keys, KeySym key) |
|
|
|
|
Key_t *key_add_key (Key_t *keys, KeyCode key) |
|
|
|
|
{ |
|
|
|
|
Key_t *rval = keys; |
|
|
|
|
|
|
|
|
|
@ -289,32 +289,20 @@ void handle_key (XCape_t *self, KeyMap_t *key, |
|
|
|
|
|
|
|
|
|
if (!self->timeout_valid || timercmp (&timev, &self->timeout, <)) |
|
|
|
|
{ |
|
|
|
|
/* Generate key press for each key in keymap */ |
|
|
|
|
for (k = key->to_keys; k != NULL; k = k->next) |
|
|
|
|
{ |
|
|
|
|
if (self->debug) |
|
|
|
|
{ |
|
|
|
|
fprintf (stdout, "Generating \"%s\" ( keysym 0x%x, " |
|
|
|
|
"key code %d)\n", |
|
|
|
|
XKeysymToString (k->key), |
|
|
|
|
(unsigned) k->key, |
|
|
|
|
(unsigned) XKeysymToKeycode (self->ctrl_conn, k->key)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* This and the XTestFakeKeyEvent call below need to be
|
|
|
|
|
replaced with calls to XSendEvent so that the real |
|
|
|
|
KeySym can be used instead of the key code.*/ |
|
|
|
|
if (self->debug) fprintf (stdout, "Generating %s!\n", |
|
|
|
|
XKeysymToString (XkbKeycodeToKeysym (self->ctrl_conn, |
|
|
|
|
k->key, 0, 0))); |
|
|
|
|
|
|
|
|
|
XTestFakeKeyEvent (self->ctrl_conn, |
|
|
|
|
XKeysymToKeycode (self->ctrl_conn, k->key), True, 0); |
|
|
|
|
k->key, True, 0); |
|
|
|
|
self->generated = key_add_key (self->generated, k->key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Generate key release for each key in keymap */ |
|
|
|
|
for (k = key->to_keys; k != NULL; k = k->next) |
|
|
|
|
{ |
|
|
|
|
XTestFakeKeyEvent (self->ctrl_conn, |
|
|
|
|
XKeysymToKeycode (self->ctrl_conn, k->key), False, 0); |
|
|
|
|
k->key, False, 0); |
|
|
|
|
self->generated = key_add_key (self->generated, k->key); |
|
|
|
|
} |
|
|
|
|
XFlush (self->ctrl_conn); |
|
|
|
|
@ -339,13 +327,7 @@ void intercept (XPointer user_data, XRecordInterceptData *data) |
|
|
|
|
|
|
|
|
|
for (g = self->generated; g != NULL; g = g->next) |
|
|
|
|
{ |
|
|
|
|
/* TODO: This is a bug! By comparing key codes we are ignoring
|
|
|
|
|
the shift level and group, so non-generated events may be |
|
|
|
|
ignored! Unfortunately I don't (yet) understand the |
|
|
|
|
XRecordInterceptData data structure well enough to extract the |
|
|
|
|
real keysym from the data. |
|
|
|
|
*/ |
|
|
|
|
if (XKeysymToKeycode (self->ctrl_conn, g->key) == key_code) |
|
|
|
|
if (g->key == key_code) |
|
|
|
|
{ |
|
|
|
|
if (self->debug) fprintf (stdout, |
|
|
|
|
"Ignoring generated event.\n"); |
|
|
|
|
@ -404,7 +386,7 @@ KeyMap_t *parse_token (Display *dpy, char *token, Bool debug) |
|
|
|
|
KeyMap_t *km = NULL; |
|
|
|
|
KeySym ks; |
|
|
|
|
char *from, *to, *key; |
|
|
|
|
KeySym tosym; // keysym (to)
|
|
|
|
|
KeyCode code; // keycode (to)
|
|
|
|
|
long fromcode; // keycode (from)
|
|
|
|
|
|
|
|
|
|
to = token; |
|
|
|
|
@ -474,23 +456,22 @@ KeyMap_t *parse_token (Display *dpy, char *token, Bool debug) |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tosym = ks; |
|
|
|
|
if (XKeysymToKeycode (dpy, ks) == 0) |
|
|
|
|
code = XKeysymToKeycode (dpy, ks); |
|
|
|
|
if (code == 0) |
|
|
|
|
{ |
|
|
|
|
fprintf (stderr, "WARNING: No keycode found for keysym " |
|
|
|
|
"%s (0x%x) in mapping %s. Ignoring this " |
|
|
|
|
"mapping.\n", key, (unsigned int)ks, token); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
km->to_keys = key_add_key (km->to_keys, tosym); |
|
|
|
|
km->to_keys = key_add_key (km->to_keys, code); |
|
|
|
|
|
|
|
|
|
if (debug) |
|
|
|
|
{ |
|
|
|
|
fprintf(stderr, "to \"%s\" (keysym 0x%x, key code %d)\n", |
|
|
|
|
key, |
|
|
|
|
(unsigned) XStringToKeysym (key), |
|
|
|
|
(unsigned) tosym); |
|
|
|
|
(unsigned) code); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|