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 |
Copyright (C) Matthew Chapman 1999-2001 |
|
5 |
|
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 |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
GNU General Public License for more details. |
GNU General Public License for more details. |
17 |
|
|
18 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
19 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
20 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 |
*/ |
*/ |
22 |
|
|
23 |
|
#ifdef RDP2VNC |
24 |
|
#include "vnc/x11stubs.h" |
25 |
|
#else |
26 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
27 |
#include <X11/keysym.h> |
#include <X11/keysym.h> |
28 |
#include <stdio.h> |
#endif |
29 |
#include <stdlib.h> |
|
|
#include <string.h> |
|
30 |
#include <ctype.h> |
#include <ctype.h> |
31 |
#include <limits.h> |
#include <limits.h> |
32 |
|
#include <time.h> |
33 |
#include "rdesktop.h" |
#include "rdesktop.h" |
34 |
#include "scancodes.h" |
#include "scancodes.h" |
35 |
|
|
36 |
#define KEYMAP_SIZE 4096 |
#define KEYMAP_SIZE 0xffff+1 |
37 |
#define KEYMAP_MASK (KEYMAP_SIZE - 1) |
#define KEYMAP_MASK 0xffff |
38 |
#define KEYMAP_MAX_LINE_LENGTH 80 |
#define KEYMAP_MAX_LINE_LENGTH 80 |
39 |
|
|
40 |
extern Display *display; |
extern Display *g_display; |
41 |
extern char keymapname[16]; |
extern char keymapname[16]; |
42 |
extern int keylayout; |
extern int keylayout; |
43 |
extern BOOL enable_compose; |
extern int g_win_button_size; |
44 |
|
extern BOOL g_enable_compose; |
45 |
|
extern BOOL g_use_rdp5; |
46 |
|
|
47 |
|
static BOOL keymap_loaded; |
48 |
static key_translation keymap[KEYMAP_SIZE]; |
static key_translation keymap[KEYMAP_SIZE]; |
49 |
static int min_keycode; |
static int min_keycode; |
50 |
static uint16 remote_modifier_state = 0; |
static uint16 remote_modifier_state = 0; |
51 |
|
static uint16 saved_remote_modifier_state = 0; |
52 |
|
|
53 |
|
static void update_modifier_state(uint8 scancode, BOOL pressed); |
54 |
|
|
55 |
static void |
static void |
56 |
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) |
add_to_keymap(char *keyname, uint8 scancode, uint16 modifiers, char *mapname) |
60 |
keysym = XStringToKeysym(keyname); |
keysym = XStringToKeysym(keyname); |
61 |
if (keysym == NoSymbol) |
if (keysym == NoSymbol) |
62 |
{ |
{ |
63 |
error("Bad keysym %s in keymap %s\n", keyname, mapname); |
DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring)\n", keyname, mapname)); |
64 |
return; |
return; |
65 |
} |
} |
66 |
|
|
78 |
xkeymap_read(char *mapname) |
xkeymap_read(char *mapname) |
79 |
{ |
{ |
80 |
FILE *fp; |
FILE *fp; |
81 |
char line[KEYMAP_MAX_LINE_LENGTH], path[PATH_MAX]; |
char line[KEYMAP_MAX_LINE_LENGTH]; |
82 |
|
char path[PATH_MAX], inplace_path[PATH_MAX]; |
83 |
unsigned int line_num = 0; |
unsigned int line_num = 0; |
84 |
unsigned int line_length = 0; |
unsigned int line_length = 0; |
85 |
char *keyname, *p; |
char *keyname, *p; |
94 |
fp = fopen(path, "r"); |
fp = fopen(path, "r"); |
95 |
if (fp == NULL) |
if (fp == NULL) |
96 |
{ |
{ |
97 |
error("Failed to open keymap %s\n", path); |
/* in case we are running from the source tree */ |
98 |
return False; |
strcpy(inplace_path, "keymaps/"); |
99 |
|
strncat(inplace_path, mapname, sizeof(inplace_path) - sizeof("keymaps/")); |
100 |
|
|
101 |
|
fp = fopen(inplace_path, "r"); |
102 |
|
if (fp == NULL) |
103 |
|
{ |
104 |
|
error("Failed to open keymap %s\n", path); |
105 |
|
return False; |
106 |
|
} |
107 |
} |
} |
108 |
|
|
109 |
/* FIXME: More tolerant on white space */ |
/* FIXME: More tolerant on white space */ |
144 |
if (strncmp(line, "enable_compose", 15) == 0) |
if (strncmp(line, "enable_compose", 15) == 0) |
145 |
{ |
{ |
146 |
DEBUG_KBD(("Enabling compose handling\n")); |
DEBUG_KBD(("Enabling compose handling\n")); |
147 |
enable_compose = True; |
g_enable_compose = True; |
148 |
continue; |
continue; |
149 |
} |
} |
150 |
|
|
195 |
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
196 |
} |
} |
197 |
|
|
198 |
|
if (strstr(line_rest, "inhibit")) |
199 |
|
{ |
200 |
|
MASK_ADD_BITS(modifiers, MapInhibitMask); |
201 |
|
} |
202 |
|
|
203 |
add_to_keymap(keyname, scancode, modifiers, mapname); |
add_to_keymap(keyname, scancode, modifiers, mapname); |
204 |
|
|
205 |
if (strstr(line_rest, "addupper")) |
if (strstr(line_rest, "addupper")) |
207 |
/* Automatically add uppercase key, with same modifiers |
/* Automatically add uppercase key, with same modifiers |
208 |
plus shift */ |
plus shift */ |
209 |
for (p = keyname; *p; p++) |
for (p = keyname; *p; p++) |
210 |
*p = toupper(*p); |
*p = toupper((int) *p); |
211 |
MASK_ADD_BITS(modifiers, MapLeftShiftMask); |
MASK_ADD_BITS(modifiers, MapLeftShiftMask); |
212 |
add_to_keymap(keyname, scancode, modifiers, mapname); |
add_to_keymap(keyname, scancode, modifiers, mapname); |
213 |
} |
} |
220 |
|
|
221 |
/* Before connecting and creating UI */ |
/* Before connecting and creating UI */ |
222 |
void |
void |
223 |
xkeymap_init1(void) |
xkeymap_init(void) |
224 |
{ |
{ |
225 |
int i; |
unsigned int max_keycode; |
226 |
|
char *mapname_ptr; |
227 |
|
|
228 |
/* Zeroing keymap */ |
/* Make keymapname lowercase */ |
229 |
for (i = 0; i < KEYMAP_SIZE; i++) |
mapname_ptr = keymapname; |
230 |
|
while (*mapname_ptr) |
231 |
{ |
{ |
232 |
keymap[i].scancode = 0; |
*mapname_ptr = tolower((int) *mapname_ptr); |
233 |
keymap[i].modifiers = 0; |
mapname_ptr++; |
234 |
} |
} |
235 |
|
|
236 |
if (strcmp(keymapname, "none")) |
if (strcmp(keymapname, "none")) |
237 |
{ |
{ |
238 |
xkeymap_read(keymapname); |
if (xkeymap_read(keymapname)) |
239 |
|
keymap_loaded = True; |
240 |
} |
} |
241 |
|
|
242 |
|
XDisplayKeycodes(g_display, &min_keycode, (int *) &max_keycode); |
243 |
} |
} |
244 |
|
|
245 |
/* After connecting and creating UI */ |
static void |
246 |
void |
send_winkey(uint32 ev_time, BOOL pressed, BOOL leftkey) |
|
xkeymap_init2(void) |
|
247 |
{ |
{ |
248 |
unsigned int max_keycode; |
uint8 winkey; |
249 |
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
|
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 |
284 |
|
possible via keymap-files) */ |
285 |
|
BOOL |
286 |
|
handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, BOOL pressed) |
287 |
|
{ |
288 |
|
switch (keysym) |
289 |
|
{ |
290 |
|
case XK_Return: |
291 |
|
if ((get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R)) |
292 |
|
&& (get_key_state(state, XK_Control_L) |
293 |
|
|| get_key_state(state, XK_Control_R))) |
294 |
|
{ |
295 |
|
/* Ctrl-Alt-Enter: toggle full screen */ |
296 |
|
if (pressed) |
297 |
|
xwin_toggle_fullscreen(); |
298 |
|
return True; |
299 |
|
} |
300 |
|
break; |
301 |
|
|
302 |
|
case XK_Break: |
303 |
|
/* Send Break sequence E0 46 E0 C6 */ |
304 |
|
if (pressed) |
305 |
|
{ |
306 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
307 |
|
(SCANCODE_EXTENDED | 0x46)); |
308 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
309 |
|
(SCANCODE_EXTENDED | 0xc6)); |
310 |
|
} |
311 |
|
/* No release sequence */ |
312 |
|
return True; |
313 |
|
|
314 |
|
case XK_Pause: |
315 |
|
/* According to MS Keyboard Scan Code |
316 |
|
Specification, pressing Pause should result |
317 |
|
in E1 1D 45 E1 9D C5. I'm not exactly sure |
318 |
|
of how this is supposed to be sent via |
319 |
|
RDP. The code below seems to work, but with |
320 |
|
the side effect that Left Ctrl stays |
321 |
|
down. Therefore, we release it when Pause |
322 |
|
is released. */ |
323 |
|
if (pressed) |
324 |
|
{ |
325 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); |
326 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0); |
327 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x45, 0); |
328 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); |
329 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x9d, 0); |
330 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xc5, 0); |
331 |
|
} |
332 |
|
else |
333 |
|
{ |
334 |
|
/* Release Left Ctrl */ |
335 |
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, |
336 |
|
0x1d, 0); |
337 |
|
} |
338 |
|
return True; |
339 |
|
|
340 |
|
case XK_Meta_L: /* Windows keys */ |
341 |
|
case XK_Super_L: |
342 |
|
case XK_Hyper_L: |
343 |
|
send_winkey(ev_time, pressed, True); |
344 |
|
return True; |
345 |
|
|
346 |
|
case XK_Meta_R: |
347 |
|
case XK_Super_R: |
348 |
|
case XK_Hyper_R: |
349 |
|
send_winkey(ev_time, pressed, False); |
350 |
|
return True; |
351 |
|
|
352 |
|
case XK_space: |
353 |
|
/* Prevent access to the Windows system menu in single app mode */ |
354 |
|
if (g_win_button_size |
355 |
|
&& (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R))) |
356 |
|
return True; |
357 |
|
|
358 |
|
} |
359 |
|
return False; |
360 |
} |
} |
361 |
|
|
362 |
|
|
363 |
key_translation |
key_translation |
364 |
xkeymap_translate_key(KeySym keysym, unsigned int keycode, unsigned int state) |
xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state) |
365 |
{ |
{ |
366 |
key_translation tr = { 0, 0 }; |
key_translation tr = { 0, 0 }; |
367 |
|
|
368 |
tr = keymap[keysym & KEYMAP_MASK]; |
tr = keymap[keysym & KEYMAP_MASK]; |
369 |
|
|
370 |
|
if (tr.modifiers & MapInhibitMask) |
371 |
|
{ |
372 |
|
DEBUG_KBD(("Inhibiting key\n")); |
373 |
|
tr.scancode = 0; |
374 |
|
return tr; |
375 |
|
} |
376 |
|
|
377 |
if (tr.modifiers & MapLocalStateMask) |
if (tr.modifiers & MapLocalStateMask) |
378 |
{ |
{ |
379 |
/* The modifiers to send for this key should be obtained |
/* The modifiers to send for this key should be obtained |
386 |
|
|
387 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
388 |
{ |
{ |
389 |
DEBUG_KBD |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
390 |
(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
tr.scancode, tr.modifiers)); |
|
tr.scancode, tr.modifiers)); |
|
391 |
return tr; |
return tr; |
392 |
} |
} |
393 |
|
|
394 |
fprintf(stderr, "No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); |
if (keymap_loaded) |
395 |
|
warning("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); |
396 |
|
|
397 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
398 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if (((int) keycode >= min_keycode) && (keycode <= 0x60)) |
399 |
{ |
{ |
400 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
401 |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
|
402 |
|
/* The modifiers to send for this key should be |
403 |
|
obtained from the local state. Currently, only |
404 |
|
shift is implemented. */ |
405 |
|
if (state & ShiftMask) |
406 |
|
{ |
407 |
|
tr.modifiers = MapLeftShiftMask; |
408 |
|
} |
409 |
|
|
410 |
|
DEBUG_KBD(("Sending guessed scancode 0x%x\n", tr.scancode)); |
411 |
} |
} |
412 |
else |
else |
413 |
{ |
{ |
414 |
fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); |
DEBUG_KBD(("No good guess for keycode 0x%x found\n", keycode)); |
415 |
} |
} |
416 |
|
|
417 |
return tr; |
return tr; |
438 |
} |
} |
439 |
|
|
440 |
char * |
char * |
441 |
get_ksname(KeySym keysym) |
get_ksname(uint32 keysym) |
442 |
{ |
{ |
443 |
char *ksname = NULL; |
char *ksname = NULL; |
444 |
|
|
450 |
return ksname; |
return ksname; |
451 |
} |
} |
452 |
|
|
453 |
BOOL |
static BOOL |
454 |
inhibit_key(KeySym keysym) |
is_modifier(uint8 scancode) |
455 |
{ |
{ |
456 |
switch (keysym) |
switch (scancode) |
457 |
{ |
{ |
458 |
case XK_Caps_Lock: |
case SCANCODE_CHAR_LSHIFT: |
459 |
return True; |
case SCANCODE_CHAR_RSHIFT: |
460 |
break; |
case SCANCODE_CHAR_LCTRL: |
461 |
case XK_Multi_key: |
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; |
return True; |
|
break; |
|
468 |
default: |
default: |
469 |
break; |
break; |
470 |
} |
} |
472 |
} |
} |
473 |
|
|
474 |
void |
void |
475 |
|
save_remote_modifiers(uint8 scancode) |
476 |
|
{ |
477 |
|
if (is_modifier(scancode)) |
478 |
|
return; |
479 |
|
|
480 |
|
saved_remote_modifier_state = remote_modifier_state; |
481 |
|
} |
482 |
|
|
483 |
|
void |
484 |
|
restore_remote_modifiers(uint32 ev_time, uint8 scancode) |
485 |
|
{ |
486 |
|
key_translation dummy; |
487 |
|
|
488 |
|
if (is_modifier(scancode)) |
489 |
|
return; |
490 |
|
|
491 |
|
dummy.scancode = 0; |
492 |
|
dummy.modifiers = saved_remote_modifier_state; |
493 |
|
ensure_remote_modifiers(ev_time, dummy); |
494 |
|
} |
495 |
|
|
496 |
|
void |
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; |
502 |
|
|
503 |
|
/* NumLock */ |
504 |
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
505 |
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
506 |
{ |
{ |
507 |
case SCANCODE_CHAR_LSHIFT: |
/* The remote modifier state is not correct */ |
508 |
case SCANCODE_CHAR_RSHIFT: |
uint16 new_remote_state; |
509 |
case SCANCODE_CHAR_LCTRL: |
|
510 |
case SCANCODE_CHAR_RCTRL: |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
511 |
case SCANCODE_CHAR_LALT: |
{ |
512 |
case SCANCODE_CHAR_RALT: |
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
513 |
case SCANCODE_CHAR_LWIN: |
new_remote_state = KBD_FLAG_NUMLOCK; |
514 |
case SCANCODE_CHAR_RWIN: |
remote_modifier_state = MapNumLockMask; |
515 |
case SCANCODE_CHAR_NUMLOCK: |
} |
516 |
return; |
else |
517 |
default: |
{ |
518 |
break; |
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
519 |
|
new_remote_state = 0; |
520 |
|
remote_modifier_state = 0; |
521 |
|
} |
522 |
|
|
523 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
524 |
} |
} |
525 |
|
|
526 |
/* Shift */ |
/* Shift. Left shift and right shift are treated as equal; either is fine. */ |
527 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
528 |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
529 |
{ |
{ |
530 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
531 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapLeftShiftMask)) |
532 |
{ |
{ |
533 |
/* Needs this modifier. Send down. */ |
/* Needs left shift. Send down. */ |
534 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
535 |
} |
} |
536 |
|
else if (MASK_HAS_BITS(tr.modifiers, MapRightShiftMask)) |
537 |
|
{ |
538 |
|
/* Needs right shift. Send down. */ |
539 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RSHIFT); |
540 |
|
} |
541 |
else |
else |
542 |
{ |
{ |
543 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up for shift currently pressed. */ |
544 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask)) |
545 |
|
/* Left shift is down */ |
546 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
547 |
|
else |
548 |
|
/* Right shift is down */ |
549 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
550 |
} |
} |
551 |
} |
} |
552 |
|
|
567 |
} |
} |
568 |
} |
} |
569 |
|
|
|
/* NumLock */ |
|
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
|
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
|
|
{ |
|
|
/* The remote modifier state is not correct */ |
|
|
DEBUG_KBD(("Remote NumLock state is incorrect. Toggling\n")); |
|
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
|
|
{ |
|
|
/* Needs this modifier. Toggle */ |
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_NUMLOCK); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_NUMLOCK); |
|
|
} |
|
|
else |
|
|
{ |
|
|
/* Should not use this modifier. Toggle */ |
|
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_NUMLOCK); |
|
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_NUMLOCK); |
|
|
} |
|
|
} |
|
570 |
|
|
571 |
} |
} |
572 |
|
|
573 |
|
|
574 |
|
void |
575 |
|
reset_modifier_keys(unsigned int state) |
576 |
|
{ |
577 |
|
/* reset keys */ |
578 |
|
uint32 ev_time; |
579 |
|
ev_time = time(NULL); |
580 |
|
|
581 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) |
582 |
|
&& !get_key_state(state, XK_Shift_L)) |
583 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
584 |
|
|
585 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) |
586 |
|
&& !get_key_state(state, XK_Shift_R)) |
587 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
588 |
|
|
589 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) |
590 |
|
&& !get_key_state(state, XK_Control_L)) |
591 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
592 |
|
|
593 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) |
594 |
|
&& !get_key_state(state, XK_Control_R)) |
595 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
596 |
|
|
597 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(state, XK_Alt_L)) |
598 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
599 |
|
|
600 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
601 |
|
!get_key_state(state, XK_Alt_R) && !get_key_state(state, XK_Mode_switch)) |
602 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
603 |
|
} |
604 |
|
|
605 |
|
|
606 |
static void |
static void |
607 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint8 scancode, BOOL pressed) |
608 |
{ |
{ |
609 |
|
#ifdef WITH_DEBUG_KBD |
610 |
|
uint16 old_modifier_state; |
611 |
|
|
612 |
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
old_modifier_state = remote_modifier_state; |
613 |
remote_modifier_state, pressed)); |
#endif |
614 |
switch (modifiers) |
|
615 |
|
switch (scancode) |
616 |
{ |
{ |
617 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
618 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed); |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed); |
652 |
} |
} |
653 |
break; |
break; |
654 |
} |
} |
655 |
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
|
656 |
|
#ifdef WITH_DEBUG_KBD |
657 |
|
if (old_modifier_state != remote_modifier_state) |
658 |
|
{ |
659 |
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
660 |
|
old_modifier_state, pressed)); |
661 |
|
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
662 |
|
} |
663 |
|
#endif |
664 |
|
|
665 |
} |
} |
666 |
|
|
667 |
/* Send keyboard input */ |
/* Send keyboard input */ |
668 |
void |
void |
669 |
rdp_send_scancode(uint32 time, uint16 flags, uint16 scancode) |
rdp_send_scancode(uint32 time, uint16 flags, uint8 scancode) |
670 |
{ |
{ |
671 |
update_modifier_state(scancode, !(flags & RDP_KEYRELEASE)); |
update_modifier_state(scancode, !(flags & RDP_KEYRELEASE)); |
672 |
|
|