41 |
static 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); |
"modifiers=0x%x\n", (unsigned int) keysym, scancode, 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; |
continue; |
123 |
} |
} |
124 |
|
|
125 |
/* compose */ |
/* compose */ |
126 |
if (strncmp(line, "enable_compose", 15) == 0) |
if (strncmp(line, "enable_compose", 15) == 0) |
127 |
{ |
{ |
128 |
DEBUG_KBD("Enabling compose handling\n"); |
DEBUG_KBD(("Enabling compose handling\n")); |
129 |
enable_compose = True; |
enable_compose = True; |
130 |
continue; |
continue; |
131 |
} |
} |
177 |
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
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")) |
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) |
if (tr.modifiers & MapLocalStateMask) |
247 |
{ |
{ |
248 |
/* The modifiers to send for this key should be obtained |
/* The modifiers to send for this key should be obtained |
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, get_ksname(keysym)); |
fprintf(stderr, "No translation for (keysym 0x%lx, %s)\n", 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) |
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, SCANCODE_CHAR_NUMLOCK); |
new_remote_state |= KBD_FLAG_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: |
437 |
} |
} |
438 |
break; |
break; |
439 |
} |
} |
440 |
DEBUG_KBD("After updating modifier_state:0x%x\n", remote_modifier_state); |
|
441 |
|
#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, flags); |
DEBUG_KBD(("Sending scancode=0x%x, flags=0x%x\n", scancode, flags)); |
468 |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
469 |
} |
} |
470 |
} |
} |