19 |
*/ |
*/ |
20 |
|
|
21 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
22 |
#include <X11/keysym.h> |
#define XK_MISCELLANY |
23 |
#include <stdio.h> |
#include <X11/keysymdef.h> |
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
24 |
#include <ctype.h> |
#include <ctype.h> |
25 |
#include <limits.h> |
#include <limits.h> |
26 |
|
#include <time.h> |
27 |
#include "rdesktop.h" |
#include "rdesktop.h" |
28 |
#include "scancodes.h" |
#include "scancodes.h" |
29 |
|
|
204 |
xkeymap_init(void) |
xkeymap_init(void) |
205 |
{ |
{ |
206 |
unsigned int max_keycode; |
unsigned int max_keycode; |
|
int i; |
|
207 |
|
|
208 |
if (strcmp(keymapname, "none")) |
if (strcmp(keymapname, "none")) |
209 |
xkeymap_read(keymapname); |
xkeymap_read(keymapname); |
214 |
/* Handles, for example, multi-scancode keypresses (which is not |
/* Handles, for example, multi-scancode keypresses (which is not |
215 |
possible via keymap-files) */ |
possible via keymap-files) */ |
216 |
BOOL |
BOOL |
217 |
handle_special_keys(KeySym keysym, uint32 ev_time, BOOL pressed) |
handle_special_keys(uint32 keysym, uint32 ev_time, BOOL pressed) |
218 |
{ |
{ |
219 |
switch (keysym) |
switch (keysym) |
220 |
{ |
{ |
221 |
case XK_Break: /* toggle full screen */ |
case XK_Break: /* toggle full screen */ |
222 |
if (pressed && (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R))) |
if (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R)) |
223 |
{ |
{ |
224 |
toggle_fullscreen(); |
if (pressed) |
225 |
|
xwin_toggle_fullscreen(); |
226 |
return True; |
return True; |
227 |
} |
} |
228 |
break; |
break; |
251 |
|
|
252 |
|
|
253 |
key_translation |
key_translation |
254 |
xkeymap_translate_key(KeySym keysym, unsigned int keycode, unsigned int state) |
xkeymap_translate_key(uint32 keysym, unsigned int keycode, unsigned int state) |
255 |
{ |
{ |
256 |
key_translation tr = { 0, 0 }; |
key_translation tr = { 0, 0 }; |
257 |
|
|
276 |
|
|
277 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
278 |
{ |
{ |
279 |
DEBUG_KBD |
DEBUG_KBD(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
|
(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
|
280 |
tr.scancode, tr.modifiers)); |
tr.scancode, tr.modifiers)); |
281 |
return tr; |
return tr; |
282 |
} |
} |
283 |
|
|
284 |
fprintf(stderr, "No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); |
DEBUG_KBD(("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym))); |
285 |
|
|
286 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
287 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
288 |
{ |
{ |
289 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
290 |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
|
291 |
|
/* The modifiers to send for this key should be |
292 |
|
obtained from the local state. Currently, only |
293 |
|
shift is implemented. */ |
294 |
|
if (state & ShiftMask) |
295 |
|
{ |
296 |
|
tr.modifiers = MapLeftShiftMask; |
297 |
|
} |
298 |
|
|
299 |
|
DEBUG_KBD(("Sending guessed scancode 0x%x\n", tr.scancode)); |
300 |
} |
} |
301 |
else |
else |
302 |
{ |
{ |
303 |
fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); |
DEBUG_KBD(("No good guess for keycode 0x%x found\n", keycode)); |
304 |
} |
} |
305 |
|
|
306 |
return tr; |
return tr; |
327 |
} |
} |
328 |
|
|
329 |
char * |
char * |
330 |
get_ksname(KeySym keysym) |
get_ksname(uint32 keysym) |
331 |
{ |
{ |
332 |
char *ksname = NULL; |
char *ksname = NULL; |
333 |
|
|
360 |
break; |
break; |
361 |
} |
} |
362 |
|
|
363 |
/* Shift */ |
/* Shift. Left shift and right shift are treated as equal; either is fine. */ |
364 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
365 |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
366 |
{ |
{ |
367 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
368 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapLeftShiftMask)) |
369 |
{ |
{ |
370 |
/* Needs this modifier. Send down. */ |
/* Needs left shift. Send down. */ |
371 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
372 |
} |
} |
373 |
|
else if (MASK_HAS_BITS(tr.modifiers, MapRightShiftMask)) |
374 |
|
{ |
375 |
|
/* Needs right shift. Send down. */ |
376 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RSHIFT); |
377 |
|
} |
378 |
else |
else |
379 |
{ |
{ |
380 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up for shift currently pressed. */ |
381 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask)) |
382 |
|
/* Left shift is down */ |
383 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
384 |
|
else |
385 |
|
/* Right shift is down */ |
386 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
387 |
} |
} |
388 |
} |
} |
389 |
|
|
427 |
} |
} |
428 |
|
|
429 |
|
|
430 |
|
void |
431 |
|
reset_modifier_keys(void) |
432 |
|
{ |
433 |
|
/* reset keys */ |
434 |
|
uint32 ev_time; |
435 |
|
ev_time = time(NULL); |
436 |
|
|
437 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_state(XK_Shift_L)) |
438 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
439 |
|
|
440 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) && !get_key_state(XK_Shift_R)) |
441 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
442 |
|
|
443 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) && !get_key_state(XK_Control_L)) |
444 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
445 |
|
|
446 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) && !get_key_state(XK_Control_R)) |
447 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
448 |
|
|
449 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(XK_Alt_L)) |
450 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
451 |
|
|
452 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
453 |
|
!get_key_state(XK_Alt_R) && !get_key_state(XK_Mode_switch)) |
454 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
455 |
|
} |
456 |
|
|
457 |
|
|
458 |
static void |
static void |
459 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint16 modifiers, BOOL pressed) |
460 |
{ |
{ |