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=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; |
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 |
} |
} |
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 |
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")) |
202 |
|
|
203 |
/* Before connecting and creating UI */ |
/* Before connecting and creating UI */ |
204 |
void |
void |
205 |
xkeymap_init1(void) |
xkeymap_init(void) |
206 |
{ |
{ |
207 |
|
unsigned int max_keycode; |
208 |
int i; |
int i; |
209 |
|
|
|
/* Zeroing keymap */ |
|
|
for (i = 0; i < KEYMAP_SIZE; i++) |
|
|
{ |
|
|
keymap[i].scancode = 0; |
|
|
keymap[i].modifiers = 0; |
|
|
} |
|
|
|
|
210 |
if (strcmp(keymapname, "none")) |
if (strcmp(keymapname, "none")) |
|
{ |
|
211 |
xkeymap_read(keymapname); |
xkeymap_read(keymapname); |
|
} |
|
212 |
|
|
213 |
|
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
214 |
} |
} |
215 |
|
|
216 |
/* After connecting and creating UI */ |
/* Handles, for example, multi-scancode keypresses (which is not |
217 |
void |
possible via keymap-files) */ |
218 |
xkeymap_init2(void) |
BOOL |
219 |
|
handle_special_keys(KeySym keysym, uint32 ev_time, BOOL pressed) |
220 |
{ |
{ |
221 |
unsigned int max_keycode; |
switch (keysym) |
222 |
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
{ |
223 |
|
case XK_Break: /* toggle full screen */ |
224 |
|
if (pressed && (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R))) |
225 |
|
{ |
226 |
|
toggle_fullscreen(); |
227 |
|
return True; |
228 |
|
} |
229 |
|
break; |
230 |
|
|
231 |
|
case XK_Meta_L: /* Windows keys */ |
232 |
|
case XK_Super_L: |
233 |
|
case XK_Hyper_L: |
234 |
|
case XK_Meta_R: |
235 |
|
case XK_Super_R: |
236 |
|
case XK_Hyper_R: |
237 |
|
if (pressed) |
238 |
|
{ |
239 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL); |
240 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC); |
241 |
|
} |
242 |
|
else |
243 |
|
{ |
244 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC); |
245 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
246 |
|
} |
247 |
|
return True; |
248 |
|
break; |
249 |
|
} |
250 |
|
return False; |
251 |
} |
} |
252 |
|
|
253 |
|
|
258 |
|
|
259 |
tr = keymap[keysym & KEYMAP_MASK]; |
tr = keymap[keysym & KEYMAP_MASK]; |
260 |
|
|
261 |
|
if (tr.modifiers & MapInhibitMask) |
262 |
|
{ |
263 |
|
DEBUG_KBD(("Inhibiting key\n")); |
264 |
|
tr.scancode = 0; |
265 |
|
return tr; |
266 |
|
} |
267 |
|
|
268 |
if (tr.modifiers & MapLocalStateMask) |
if (tr.modifiers & MapLocalStateMask) |
269 |
{ |
{ |
270 |
/* The modifiers to send for this key should be obtained |
/* The modifiers to send for this key should be obtained |
278 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
279 |
{ |
{ |
280 |
DEBUG_KBD |
DEBUG_KBD |
281 |
("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
282 |
tr.scancode, tr.modifiers); |
tr.scancode, tr.modifiers)); |
283 |
return tr; |
return tr; |
284 |
} |
} |
285 |
|
|
286 |
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)); |
|
287 |
|
|
288 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
289 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
290 |
{ |
{ |
291 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
292 |
printf("Sending guessed scancode 0x%x\n", tr.scancode); |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
293 |
} |
} |
294 |
else |
else |
295 |
{ |
{ |
296 |
printf("No good guess for keycode 0x%x found\n", keycode); |
fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); |
297 |
} |
} |
298 |
|
|
299 |
return tr; |
return tr; |
332 |
return ksname; |
return ksname; |
333 |
} |
} |
334 |
|
|
|
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; |
|
|
} |
|
335 |
|
|
336 |
void |
void |
337 |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
361 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
362 |
{ |
{ |
363 |
/* Needs this modifier. Send down. */ |
/* Needs this modifier. Send down. */ |
364 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
|
SCANCODE_CHAR_LSHIFT); |
|
365 |
} |
} |
366 |
else |
else |
367 |
{ |
{ |
368 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up. */ |
369 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
|
SCANCODE_CHAR_LSHIFT); |
|
370 |
} |
} |
371 |
} |
} |
372 |
|
|
378 |
if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)) |
379 |
{ |
{ |
380 |
/* Needs this modifier. Send down. */ |
/* Needs this modifier. Send down. */ |
381 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RALT); |
|
SCANCODE_CHAR_RALT); |
|
382 |
} |
} |
383 |
else |
else |
384 |
{ |
{ |
385 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up. */ |
386 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
|
SCANCODE_CHAR_RALT); |
|
387 |
} |
} |
388 |
} |
} |
389 |
|
|
392 |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
393 |
{ |
{ |
394 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
395 |
DEBUG_KBD("Remote NumLock state is incorrect. Toggling\n"); |
uint16 new_remote_state = 0; |
396 |
|
|
397 |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
398 |
{ |
{ |
399 |
/* Needs this modifier. Toggle */ |
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
400 |
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); |
|
401 |
} |
} |
402 |
else |
else |
403 |
{ |
{ |
404 |
/* 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); |
|
405 |
} |
} |
|
} |
|
406 |
|
|
407 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
408 |
|
update_modifier_state(SCANCODE_CHAR_NUMLOCK, True); |
409 |
|
} |
410 |
} |
} |
411 |
|
|
412 |
|
|
413 |
static void |
static void |
414 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint16 modifiers, BOOL pressed) |
415 |
{ |
{ |
416 |
|
#ifdef WITH_DEBUG_KBD |
417 |
|
uint16 old_modifier_state; |
418 |
|
|
419 |
|
old_modifier_state = remote_modifier_state; |
420 |
|
#endif |
421 |
|
|
|
DEBUG_KBD("Before updating modifier_state:0x%x, pressed=0x%x\n", |
|
|
remote_modifier_state, pressed); |
|
422 |
switch (modifiers) |
switch (modifiers) |
423 |
{ |
{ |
424 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
425 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed); |
|
MapLeftShiftMask, pressed); |
|
426 |
break; |
break; |
427 |
case SCANCODE_CHAR_RSHIFT: |
case SCANCODE_CHAR_RSHIFT: |
428 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightShiftMask, pressed); |
|
MapRightShiftMask, pressed); |
|
429 |
break; |
break; |
430 |
case SCANCODE_CHAR_LCTRL: |
case SCANCODE_CHAR_LCTRL: |
431 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftCtrlMask, pressed); |
|
MapLeftCtrlMask, pressed); |
|
432 |
break; |
break; |
433 |
case SCANCODE_CHAR_RCTRL: |
case SCANCODE_CHAR_RCTRL: |
434 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightCtrlMask, pressed); |
|
MapRightCtrlMask, pressed); |
|
435 |
break; |
break; |
436 |
case SCANCODE_CHAR_LALT: |
case SCANCODE_CHAR_LALT: |
437 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask, pressed); |
|
pressed); |
|
438 |
break; |
break; |
439 |
case SCANCODE_CHAR_RALT: |
case SCANCODE_CHAR_RALT: |
440 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightAltMask, pressed); |
|
MapRightAltMask, pressed); |
|
441 |
break; |
break; |
442 |
case SCANCODE_CHAR_LWIN: |
case SCANCODE_CHAR_LWIN: |
443 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask, pressed); |
|
pressed); |
|
444 |
break; |
break; |
445 |
case SCANCODE_CHAR_RWIN: |
case SCANCODE_CHAR_RWIN: |
446 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightWinMask, pressed); |
|
MapRightWinMask, pressed); |
|
447 |
break; |
break; |
448 |
case SCANCODE_CHAR_NUMLOCK: |
case SCANCODE_CHAR_NUMLOCK: |
449 |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
453 |
BOOL newNumLockState; |
BOOL newNumLockState; |
454 |
newNumLockState = |
newNumLockState = |
455 |
(MASK_HAS_BITS |
(MASK_HAS_BITS |
456 |
(remote_modifier_state, |
(remote_modifier_state, MapNumLockMask) == False); |
|
MapNumLockMask) == False); |
|
457 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, |
458 |
MapNumLockMask, |
MapNumLockMask, newNumLockState); |
|
newNumLockState); |
|
459 |
} |
} |
460 |
break; |
break; |
461 |
} |
} |
462 |
DEBUG_KBD("After updating modifier_state:0x%x\n", |
|
463 |
remote_modifier_state); |
#ifdef WITH_DEBUG_KBD |
464 |
|
if (old_modifier_state != remote_modifier_state) |
465 |
|
{ |
466 |
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
467 |
|
old_modifier_state, pressed)); |
468 |
|
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
469 |
|
} |
470 |
|
#endif |
471 |
|
|
472 |
} |
} |
473 |
|
|
479 |
|
|
480 |
if (scancode & SCANCODE_EXTENDED) |
if (scancode & SCANCODE_EXTENDED) |
481 |
{ |
{ |
482 |
DEBUG_KBD("Sending extended scancode=0x%x, flags=0x%x\n", |
DEBUG_KBD(("Sending extended scancode=0x%x, flags=0x%x\n", |
483 |
scancode & ~SCANCODE_EXTENDED, flags); |
scancode & ~SCANCODE_EXTENDED, flags)); |
484 |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT, |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT, |
485 |
scancode & ~SCANCODE_EXTENDED, 0); |
scancode & ~SCANCODE_EXTENDED, 0); |
486 |
} |
} |
487 |
else |
else |
488 |
{ |
{ |
489 |
DEBUG_KBD("Sending scancode=0x%x, flags=0x%x\n", scancode, |
DEBUG_KBD(("Sending scancode=0x%x, flags=0x%x\n", scancode, flags)); |
|
flags); |
|
490 |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
491 |
} |
} |
492 |
} |
} |