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")) |
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 |
|
xwin_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 |
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 |
|
|
293 |
|
/* The modifiers to send for this key should be |
294 |
|
obtained from the local state. Currently, only |
295 |
|
shift is implemented. */ |
296 |
|
if (state & ShiftMask) |
297 |
|
{ |
298 |
|
tr.modifiers = MapLeftShiftMask; |
299 |
|
} |
300 |
|
|
301 |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
302 |
} |
} |
303 |
else |
else |
341 |
return ksname; |
return ksname; |
342 |
} |
} |
343 |
|
|
|
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; |
|
|
} |
|
344 |
|
|
345 |
void |
void |
346 |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
376 |
{ |
{ |
377 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up. */ |
378 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
379 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
380 |
} |
} |
381 |
} |
} |
382 |
|
|
402 |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
403 |
{ |
{ |
404 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
405 |
DEBUG_KBD(("Remote NumLock state is incorrect. Toggling\n")); |
uint16 new_remote_state = 0; |
406 |
|
|
407 |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
408 |
{ |
{ |
409 |
/* Needs this modifier. Toggle */ |
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
410 |
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); |
|
411 |
} |
} |
412 |
else |
else |
413 |
{ |
{ |
414 |
/* 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); |
|
415 |
} |
} |
416 |
|
|
417 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
418 |
|
update_modifier_state(SCANCODE_CHAR_NUMLOCK, True); |
419 |
} |
} |
420 |
|
} |
421 |
|
|
422 |
|
|
423 |
|
void |
424 |
|
reset_modifier_keys() |
425 |
|
{ |
426 |
|
/* reset keys */ |
427 |
|
uint32 ev_time; |
428 |
|
ev_time = time(NULL); |
429 |
|
|
430 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftShiftMask) && !get_key_state(XK_Shift_L)) |
431 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
432 |
|
|
433 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightShiftMask) && !get_key_state(XK_Shift_R)) |
434 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RSHIFT); |
435 |
|
|
436 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftCtrlMask) && !get_key_state(XK_Control_L)) |
437 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
438 |
|
|
439 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightCtrlMask) && !get_key_state(XK_Control_R)) |
440 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RCTRL); |
441 |
|
|
442 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapLeftAltMask) && !get_key_state(XK_Alt_L)) |
443 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LALT); |
444 |
|
|
445 |
|
if (MASK_HAS_BITS(remote_modifier_state, MapRightAltMask) && |
446 |
|
!get_key_state(XK_Alt_R) && !get_key_state(XK_Mode_switch)) |
447 |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
448 |
} |
} |
449 |
|
|
450 |
|
|
451 |
static void |
static void |
452 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint16 modifiers, BOOL pressed) |
453 |
{ |
{ |
454 |
|
#ifdef WITH_DEBUG_KBD |
455 |
|
uint16 old_modifier_state; |
456 |
|
|
457 |
|
old_modifier_state = remote_modifier_state; |
458 |
|
#endif |
459 |
|
|
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
|
|
remote_modifier_state, pressed)); |
|
460 |
switch (modifiers) |
switch (modifiers) |
461 |
{ |
{ |
462 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
497 |
} |
} |
498 |
break; |
break; |
499 |
} |
} |
500 |
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
|
501 |
|
#ifdef WITH_DEBUG_KBD |
502 |
|
if (old_modifier_state != remote_modifier_state) |
503 |
|
{ |
504 |
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
505 |
|
old_modifier_state, pressed)); |
506 |
|
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
507 |
|
} |
508 |
|
#endif |
509 |
|
|
510 |
} |
} |
511 |
|
|