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 |
{ |
{ |
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")) |
228 |
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
229 |
} |
} |
230 |
|
|
231 |
|
/* Handles, for example, multi-scancode keypresses (which is not |
232 |
|
possible via keymap-files) */ |
233 |
|
BOOL |
234 |
|
handle_special_keys(KeySym keysym, uint32 ev_time, BOOL pressed) |
235 |
|
{ |
236 |
|
switch (keysym) |
237 |
|
{ |
238 |
|
case XK_Break: /* toggle full screen */ |
239 |
|
if (pressed && (get_key_state(XK_Alt_L) || get_key_state(XK_Alt_R))) |
240 |
|
{ |
241 |
|
toggle_fullscreen(); |
242 |
|
return True; |
243 |
|
} |
244 |
|
break; |
245 |
|
|
246 |
|
case XK_Meta_L: /* Windows keys */ |
247 |
|
case XK_Super_L: |
248 |
|
case XK_Hyper_L: |
249 |
|
case XK_Meta_R: |
250 |
|
case XK_Super_R: |
251 |
|
case XK_Hyper_R: |
252 |
|
if (pressed) |
253 |
|
{ |
254 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LCTRL); |
255 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_ESC); |
256 |
|
} |
257 |
|
else |
258 |
|
{ |
259 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_ESC); |
260 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
261 |
|
} |
262 |
|
return True; |
263 |
|
break; |
264 |
|
} |
265 |
|
return False; |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
key_translation |
key_translation |
270 |
xkeymap_translate_key(KeySym keysym, unsigned int keycode, unsigned int state) |
xkeymap_translate_key(KeySym keysym, unsigned int keycode, unsigned int state) |
273 |
|
|
274 |
tr = keymap[keysym & KEYMAP_MASK]; |
tr = keymap[keysym & KEYMAP_MASK]; |
275 |
|
|
276 |
|
if (tr.modifiers & MapInhibitMask) |
277 |
|
{ |
278 |
|
DEBUG_KBD(("Inhibiting key\n")); |
279 |
|
tr.scancode = 0; |
280 |
|
return tr; |
281 |
|
} |
282 |
|
|
283 |
if (tr.modifiers & MapLocalStateMask) |
if (tr.modifiers & MapLocalStateMask) |
284 |
{ |
{ |
285 |
/* The modifiers to send for this key should be obtained |
/* The modifiers to send for this key should be obtained |
298 |
return tr; |
return tr; |
299 |
} |
} |
300 |
|
|
301 |
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)); |
302 |
|
|
303 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
304 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
305 |
{ |
{ |
306 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
307 |
printf("Sending guessed scancode 0x%x\n", tr.scancode); |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
308 |
} |
} |
309 |
else |
else |
310 |
{ |
{ |
311 |
printf("No good guess for keycode 0x%x found\n", keycode); |
fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); |
312 |
} |
} |
313 |
|
|
314 |
return tr; |
return tr; |
347 |
return ksname; |
return ksname; |
348 |
} |
} |
349 |
|
|
|
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; |
|
|
} |
|
350 |
|
|
351 |
void |
void |
352 |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
407 |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
408 |
{ |
{ |
409 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
410 |
DEBUG_KBD(("Remote NumLock state is incorrect. Toggling\n")); |
uint16 new_remote_state = 0; |
411 |
|
|
412 |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
413 |
{ |
{ |
414 |
/* Needs this modifier. Toggle */ |
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
415 |
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); |
|
416 |
} |
} |
417 |
else |
else |
418 |
{ |
{ |
419 |
/* 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); |
|
420 |
} |
} |
|
} |
|
421 |
|
|
422 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
423 |
|
update_modifier_state(SCANCODE_CHAR_NUMLOCK, True); |
424 |
|
} |
425 |
} |
} |
426 |
|
|
427 |
|
|
428 |
static void |
static void |
429 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint16 modifiers, BOOL pressed) |
430 |
{ |
{ |
431 |
|
#ifdef WITH_DEBUG_KBD |
432 |
|
uint16 old_modifier_state; |
433 |
|
|
434 |
|
old_modifier_state = remote_modifier_state; |
435 |
|
#endif |
436 |
|
|
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
|
|
remote_modifier_state, pressed)); |
|
437 |
switch (modifiers) |
switch (modifiers) |
438 |
{ |
{ |
439 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
474 |
} |
} |
475 |
break; |
break; |
476 |
} |
} |
477 |
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
|
478 |
|
#ifdef WITH_DEBUG_KBD |
479 |
|
if (old_modifier_state != remote_modifier_state) |
480 |
|
{ |
481 |
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
482 |
|
old_modifier_state, pressed)); |
483 |
|
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
484 |
|
} |
485 |
|
#endif |
486 |
|
|
487 |
} |
} |
488 |
|
|
501 |
} |
} |
502 |
else |
else |
503 |
{ |
{ |
504 |
DEBUG_KBD(("Sending scancode=0x%x, flags=0x%x\n", scancode, flags); |
DEBUG_KBD(("Sending scancode=0x%x, flags=0x%x\n", scancode, flags)); |
505 |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0)); |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
506 |
} |
} |
507 |
} |
} |