35 |
extern Display *display; |
extern Display *display; |
36 |
extern char keymapname[16]; |
extern char keymapname[16]; |
37 |
extern int keylayout; |
extern int keylayout; |
38 |
|
extern BOOL enable_compose; |
39 |
|
|
40 |
static key_translation keymap[KEYMAP_SIZE]; |
static key_translation keymap[KEYMAP_SIZE]; |
41 |
static unsigned int min_keycode; |
static int min_keycode; |
42 |
static uint16 remote_modifier_state = 0; |
static uint16 remote_modifier_state = 0; |
43 |
|
|
44 |
|
static void update_modifier_state(uint16 modifiers, BOOL pressed); |
45 |
|
|
46 |
static void |
static void |
47 |
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) |
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) |
48 |
{ |
{ |
55 |
return; |
return; |
56 |
} |
} |
57 |
|
|
58 |
DEBUG_KBD("Adding translation, keysym=0x%x, scancode=0x%x, " |
DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, " |
59 |
"modifiers=0x%x\n", (unsigned int) keysym, scancode, |
"modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers)); |
|
modifiers); |
|
60 |
|
|
61 |
keymap[keysym & KEYMAP_MASK].scancode = scancode; |
keymap[keysym & KEYMAP_MASK].scancode = scancode; |
62 |
keymap[keysym & KEYMAP_MASK].modifiers = modifiers; |
keymap[keysym & KEYMAP_MASK].modifiers = modifiers; |
118 |
if (strncmp(line, "map ", 4) == 0) |
if (strncmp(line, "map ", 4) == 0) |
119 |
{ |
{ |
120 |
keylayout = strtol(line + 4, NULL, 16); |
keylayout = strtol(line + 4, NULL, 16); |
121 |
DEBUG_KBD("Keylayout 0x%x\n", keylayout); |
DEBUG_KBD(("Keylayout 0x%x\n", keylayout)); |
122 |
|
continue; |
123 |
|
} |
124 |
|
|
125 |
|
/* compose */ |
126 |
|
if (strncmp(line, "enable_compose", 15) == 0) |
127 |
|
{ |
128 |
|
DEBUG_KBD(("Enabling compose handling\n")); |
129 |
|
enable_compose = True; |
130 |
continue; |
continue; |
131 |
} |
} |
132 |
|
|
141 |
p = strchr(line, ' '); |
p = strchr(line, ' '); |
142 |
if (p == NULL) |
if (p == NULL) |
143 |
{ |
{ |
144 |
error("Bad line %d in keymap %s\n", line_num, |
error("Bad line %d in keymap %s\n", line_num, mapname); |
|
mapname); |
|
145 |
continue; |
continue; |
146 |
} |
} |
147 |
else |
else |
172 |
MASK_ADD_BITS(modifiers, MapNumLockMask); |
MASK_ADD_BITS(modifiers, MapNumLockMask); |
173 |
} |
} |
174 |
|
|
175 |
|
if (strstr(line_rest, "localstate")) |
176 |
|
{ |
177 |
|
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
178 |
|
} |
179 |
|
|
180 |
|
if (strstr(line_rest, "inhibit")) |
181 |
|
{ |
182 |
|
MASK_ADD_BITS(modifiers, MapInhibitMask); |
183 |
|
} |
184 |
|
|
185 |
add_to_keymap(keyname, scancode, modifiers, mapname); |
add_to_keymap(keyname, scancode, modifiers, mapname); |
186 |
|
|
187 |
if (strstr(line_rest, "addupper")) |
if (strstr(line_rest, "addupper")) |
225 |
xkeymap_init2(void) |
xkeymap_init2(void) |
226 |
{ |
{ |
227 |
unsigned int max_keycode; |
unsigned int max_keycode; |
228 |
XDisplayKeycodes(display, &min_keycode, &max_keycode); |
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
229 |
} |
} |
230 |
|
|
231 |
|
|
232 |
key_translation |
key_translation |
233 |
xkeymap_translate_key(KeySym keysym, unsigned int keycode) |
xkeymap_translate_key(KeySym keysym, unsigned int keycode, unsigned int state) |
234 |
{ |
{ |
235 |
key_translation tr = { 0, 0 }; |
key_translation tr = { 0, 0 }; |
236 |
|
|
237 |
tr = keymap[keysym & KEYMAP_MASK]; |
tr = keymap[keysym & KEYMAP_MASK]; |
238 |
|
|
239 |
|
if (tr.modifiers & MapInhibitMask) |
240 |
|
{ |
241 |
|
DEBUG_KBD(("Inhibiting key\n")); |
242 |
|
tr.scancode = 0; |
243 |
|
return tr; |
244 |
|
} |
245 |
|
|
246 |
|
if (tr.modifiers & MapLocalStateMask) |
247 |
|
{ |
248 |
|
/* The modifiers to send for this key should be obtained |
249 |
|
from the local state. Currently, only shift is implemented. */ |
250 |
|
if (state & ShiftMask) |
251 |
|
{ |
252 |
|
tr.modifiers = MapLeftShiftMask; |
253 |
|
} |
254 |
|
} |
255 |
|
|
256 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
257 |
{ |
{ |
258 |
DEBUG_KBD |
DEBUG_KBD |
259 |
("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
260 |
tr.scancode, tr.modifiers); |
tr.scancode, tr.modifiers)); |
261 |
return tr; |
return tr; |
262 |
} |
} |
263 |
|
|
264 |
printf("No translation for (keysym 0x%lx, %s)\n", keysym, |
fprintf(stderr, "No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); |
|
get_ksname(keysym)); |
|
265 |
|
|
266 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
267 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
268 |
{ |
{ |
269 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
270 |
printf("Sending guessed scancode 0x%x\n", tr.scancode); |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
271 |
} |
} |
272 |
else |
else |
273 |
{ |
{ |
274 |
printf("No good guess for keycode 0x%x found\n", keycode); |
fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); |
275 |
} |
} |
276 |
|
|
277 |
return tr; |
return tr; |
310 |
return ksname; |
return ksname; |
311 |
} |
} |
312 |
|
|
|
BOOL |
|
|
inhibit_key(KeySym keysym) |
|
|
{ |
|
|
switch (keysym) |
|
|
{ |
|
|
case XK_Caps_Lock: |
|
|
return True; |
|
|
break; |
|
|
case XK_Multi_key: |
|
|
return True; |
|
|
break; |
|
|
default: |
|
|
break; |
|
|
} |
|
|
return False; |
|
|
} |
|
313 |
|
|
314 |
void |
void |
315 |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
339 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
340 |
{ |
{ |
341 |
/* Needs this modifier. Send down. */ |
/* Needs this modifier. Send down. */ |
342 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
|
SCANCODE_CHAR_LSHIFT); |
|
343 |
} |
} |
344 |
else |
else |
345 |
{ |
{ |
346 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up. */ |
347 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
|
SCANCODE_CHAR_LSHIFT); |
|
348 |
} |
} |
349 |
} |
} |
350 |
|
|
356 |
if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)) |
357 |
{ |
{ |
358 |
/* Needs this modifier. Send down. */ |
/* Needs this modifier. Send down. */ |
359 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RALT); |
|
SCANCODE_CHAR_RALT); |
|
360 |
} |
} |
361 |
else |
else |
362 |
{ |
{ |
363 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up. */ |
364 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
|
SCANCODE_CHAR_RALT); |
|
365 |
} |
} |
366 |
} |
} |
367 |
|
|
370 |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
371 |
{ |
{ |
372 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
373 |
DEBUG_KBD("Remote NumLock state is incorrect. Toggling\n"); |
uint16 new_remote_state = 0; |
374 |
|
|
375 |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
376 |
{ |
{ |
377 |
/* Needs this modifier. Toggle */ |
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
378 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
new_remote_state |= KBD_FLAG_NUMLOCK; |
|
SCANCODE_CHAR_NUMLOCK); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
|
|
SCANCODE_CHAR_NUMLOCK); |
|
379 |
} |
} |
380 |
else |
else |
381 |
{ |
{ |
382 |
/* Should not use this modifier. Toggle */ |
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
|
|
SCANCODE_CHAR_NUMLOCK); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
|
|
SCANCODE_CHAR_NUMLOCK); |
|
383 |
} |
} |
|
} |
|
384 |
|
|
385 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
386 |
|
update_modifier_state(SCANCODE_CHAR_NUMLOCK, True); |
387 |
|
} |
388 |
} |
} |
389 |
|
|
390 |
|
|
391 |
static void |
static void |
392 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint16 modifiers, BOOL pressed) |
393 |
{ |
{ |
394 |
|
#ifdef WITH_DEBUG_KBD |
395 |
|
uint16 old_modifier_state; |
396 |
|
|
397 |
|
old_modifier_state = remote_modifier_state; |
398 |
|
#endif |
399 |
|
|
|
DEBUG_KBD("Before updating modifier_state:0x%x, pressed=0x%x\n", |
|
|
remote_modifier_state, pressed); |
|
400 |
switch (modifiers) |
switch (modifiers) |
401 |
{ |
{ |
402 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
403 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed); |
|
MapLeftShiftMask, pressed); |
|
404 |
break; |
break; |
405 |
case SCANCODE_CHAR_RSHIFT: |
case SCANCODE_CHAR_RSHIFT: |
406 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightShiftMask, pressed); |
|
MapRightShiftMask, pressed); |
|
407 |
break; |
break; |
408 |
case SCANCODE_CHAR_LCTRL: |
case SCANCODE_CHAR_LCTRL: |
409 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftCtrlMask, pressed); |
|
MapLeftCtrlMask, pressed); |
|
410 |
break; |
break; |
411 |
case SCANCODE_CHAR_RCTRL: |
case SCANCODE_CHAR_RCTRL: |
412 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightCtrlMask, pressed); |
|
MapRightCtrlMask, pressed); |
|
413 |
break; |
break; |
414 |
case SCANCODE_CHAR_LALT: |
case SCANCODE_CHAR_LALT: |
415 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask, pressed); |
|
pressed); |
|
416 |
break; |
break; |
417 |
case SCANCODE_CHAR_RALT: |
case SCANCODE_CHAR_RALT: |
418 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightAltMask, pressed); |
|
MapRightAltMask, pressed); |
|
419 |
break; |
break; |
420 |
case SCANCODE_CHAR_LWIN: |
case SCANCODE_CHAR_LWIN: |
421 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask, pressed); |
|
pressed); |
|
422 |
break; |
break; |
423 |
case SCANCODE_CHAR_RWIN: |
case SCANCODE_CHAR_RWIN: |
424 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightWinMask, pressed); |
|
MapRightWinMask, pressed); |
|
425 |
break; |
break; |
426 |
case SCANCODE_CHAR_NUMLOCK: |
case SCANCODE_CHAR_NUMLOCK: |
427 |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
431 |
BOOL newNumLockState; |
BOOL newNumLockState; |
432 |
newNumLockState = |
newNumLockState = |
433 |
(MASK_HAS_BITS |
(MASK_HAS_BITS |
434 |
(remote_modifier_state, |
(remote_modifier_state, MapNumLockMask) == False); |
|
MapNumLockMask) == False); |
|
435 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, |
436 |
MapNumLockMask, |
MapNumLockMask, newNumLockState); |
|
newNumLockState); |
|
437 |
} |
} |
438 |
break; |
break; |
439 |
} |
} |
440 |
DEBUG_KBD("After updating modifier_state:0x%x\n", |
|
441 |
remote_modifier_state); |
#ifdef WITH_DEBUG_KBD |
442 |
|
if (old_modifier_state != remote_modifier_state) |
443 |
|
{ |
444 |
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
445 |
|
old_modifier_state, pressed)); |
446 |
|
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
447 |
|
} |
448 |
|
#endif |
449 |
|
|
450 |
} |
} |
451 |
|
|
457 |
|
|
458 |
if (scancode & SCANCODE_EXTENDED) |
if (scancode & SCANCODE_EXTENDED) |
459 |
{ |
{ |
460 |
DEBUG_KBD("Sending extended scancode=0x%x, flags=0x%x\n", |
DEBUG_KBD(("Sending extended scancode=0x%x, flags=0x%x\n", |
461 |
scancode & ~SCANCODE_EXTENDED, flags); |
scancode & ~SCANCODE_EXTENDED, flags)); |
462 |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT, |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT, |
463 |
scancode & ~SCANCODE_EXTENDED, 0); |
scancode & ~SCANCODE_EXTENDED, 0); |
464 |
} |
} |
465 |
else |
else |
466 |
{ |
{ |
467 |
DEBUG_KBD("Sending scancode=0x%x, flags=0x%x\n", scancode, |
DEBUG_KBD(("Sending scancode=0x%x, flags=0x%x\n", scancode, flags)); |
|
flags); |
|
468 |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
469 |
} |
} |
470 |
} |
} |