1 |
/* |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
User interface services - X keyboard mapping |
User interface services - X keyboard mapping |
4 |
|
|
5 |
Copyright (C) Matthew Chapman 1999-2002 |
Copyright (C) Matthew Chapman 1999-2002 |
6 |
|
Copyright (C) Peter Astrand <peter@cendio.se> 2003 |
7 |
|
|
8 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
9 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
42 |
extern int keylayout; |
extern int keylayout; |
43 |
extern int g_win_button_size; |
extern int g_win_button_size; |
44 |
extern BOOL g_enable_compose; |
extern BOOL g_enable_compose; |
45 |
|
extern BOOL g_use_rdp5; |
46 |
|
|
47 |
static BOOL keymap_loaded; |
static BOOL keymap_loaded; |
48 |
static key_translation keymap[KEYMAP_SIZE]; |
static key_translation keymap[KEYMAP_SIZE]; |
242 |
XDisplayKeycodes(g_display, &min_keycode, (int *) &max_keycode); |
XDisplayKeycodes(g_display, &min_keycode, (int *) &max_keycode); |
243 |
} |
} |
244 |
|
|
245 |
|
static void |
246 |
|
send_winkey(uint32 ev_time, BOOL pressed, BOOL leftkey) |
247 |
|
{ |
248 |
|
uint8 winkey; |
249 |
|
|
250 |
|
if (leftkey) |
251 |
|
winkey = SCANCODE_CHAR_LWIN; |
252 |
|
else |
253 |
|
winkey = SCANCODE_CHAR_RWIN; |
254 |
|
|
255 |
|
if (pressed) |
256 |
|
{ |
257 |
|
if (g_use_rdp5) |
258 |
|
{ |
259 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, winkey); |
260 |
|
} |
261 |
|
else |
262 |
|
{ |
263 |
|
/* RDP4 doesn't support winkey. Fake with Ctrl-Esc */ |
264 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL); |
265 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC); |
266 |
|
} |
267 |
|
} |
268 |
|
else |
269 |
|
{ |
270 |
|
/* key released */ |
271 |
|
if (g_use_rdp5) |
272 |
|
{ |
273 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, winkey); |
274 |
|
} |
275 |
|
else |
276 |
|
{ |
277 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC); |
278 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
279 |
|
} |
280 |
|
} |
281 |
|
} |
282 |
|
|
283 |
/* Handles, for example, multi-scancode keypresses (which is not |
/* Handles, for example, multi-scancode keypresses (which is not |
284 |
possible via keymap-files) */ |
possible via keymap-files) */ |
285 |
BOOL |
BOOL |
340 |
case XK_Meta_L: /* Windows keys */ |
case XK_Meta_L: /* Windows keys */ |
341 |
case XK_Super_L: |
case XK_Super_L: |
342 |
case XK_Hyper_L: |
case XK_Hyper_L: |
343 |
|
send_winkey(ev_time, pressed, True); |
344 |
|
return True; |
345 |
|
|
346 |
case XK_Meta_R: |
case XK_Meta_R: |
347 |
case XK_Super_R: |
case XK_Super_R: |
348 |
case XK_Hyper_R: |
case XK_Hyper_R: |
349 |
if (pressed) |
send_winkey(ev_time, pressed, False); |
|
{ |
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL); |
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC); |
|
|
} |
|
|
else |
|
|
{ |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
|
|
} |
|
350 |
return True; |
return True; |
351 |
|
|
352 |
case XK_space: |
case XK_space: |
450 |
return ksname; |
return ksname; |
451 |
} |
} |
452 |
|
|
453 |
|
static BOOL |
454 |
|
is_modifier(uint8 scancode) |
455 |
|
{ |
456 |
|
switch (scancode) |
457 |
|
{ |
458 |
|
case SCANCODE_CHAR_LSHIFT: |
459 |
|
case SCANCODE_CHAR_RSHIFT: |
460 |
|
case SCANCODE_CHAR_LCTRL: |
461 |
|
case SCANCODE_CHAR_RCTRL: |
462 |
|
case SCANCODE_CHAR_LALT: |
463 |
|
case SCANCODE_CHAR_RALT: |
464 |
|
case SCANCODE_CHAR_LWIN: |
465 |
|
case SCANCODE_CHAR_RWIN: |
466 |
|
case SCANCODE_CHAR_NUMLOCK: |
467 |
|
return True; |
468 |
|
default: |
469 |
|
break; |
470 |
|
} |
471 |
|
return False; |
472 |
|
} |
473 |
|
|
474 |
void |
void |
475 |
save_remote_modifiers() |
save_remote_modifiers(uint8 scancode) |
476 |
{ |
{ |
477 |
|
if (is_modifier(scancode)) |
478 |
|
return; |
479 |
|
|
480 |
saved_remote_modifier_state = remote_modifier_state; |
saved_remote_modifier_state = remote_modifier_state; |
481 |
} |
} |
482 |
|
|
483 |
void |
void |
484 |
restore_remote_modifiers(uint32 ev_time) |
restore_remote_modifiers(uint32 ev_time, uint8 scancode) |
485 |
{ |
{ |
486 |
key_translation dummy; |
key_translation dummy; |
487 |
|
|
488 |
|
if (is_modifier(scancode)) |
489 |
|
return; |
490 |
|
|
491 |
dummy.scancode = 0; |
dummy.scancode = 0; |
492 |
dummy.modifiers = saved_remote_modifier_state; |
dummy.modifiers = saved_remote_modifier_state; |
493 |
ensure_remote_modifiers(ev_time, dummy); |
ensure_remote_modifiers(ev_time, dummy); |
497 |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
498 |
{ |
{ |
499 |
/* If this key is a modifier, do nothing */ |
/* If this key is a modifier, do nothing */ |
500 |
switch (tr.scancode) |
if (is_modifier(tr.scancode)) |
501 |
{ |
return; |
|
case SCANCODE_CHAR_LSHIFT: |
|
|
case SCANCODE_CHAR_RSHIFT: |
|
|
case SCANCODE_CHAR_LCTRL: |
|
|
case SCANCODE_CHAR_RCTRL: |
|
|
case SCANCODE_CHAR_LALT: |
|
|
case SCANCODE_CHAR_RALT: |
|
|
case SCANCODE_CHAR_LWIN: |
|
|
case SCANCODE_CHAR_RWIN: |
|
|
case SCANCODE_CHAR_NUMLOCK: |
|
|
return; |
|
|
default: |
|
|
break; |
|
|
} |
|
502 |
|
|
503 |
/* NumLock */ |
/* NumLock */ |
504 |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |