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 |
|
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 |
332 |
return ksname; |
return ksname; |
333 |
} |
} |
334 |
|
|
|
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; |
|
|
} |
|
335 |
|
|
336 |
void |
void |
337 |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
392 |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
393 |
{ |
{ |
394 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
395 |
DEBUG_KBD(("Remote NumLock state is incorrect. Toggling\n")); |
uint16 new_remote_state = 0; |
396 |
|
|
397 |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
398 |
{ |
{ |
399 |
/* Needs this modifier. Toggle */ |
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
400 |
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); |
|
401 |
} |
} |
402 |
else |
else |
403 |
{ |
{ |
404 |
/* 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); |
|
405 |
} |
} |
|
} |
|
406 |
|
|
407 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
408 |
|
update_modifier_state(SCANCODE_CHAR_NUMLOCK, True); |
409 |
|
} |
410 |
} |
} |
411 |
|
|
412 |
|
|
413 |
static void |
static void |
414 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint16 modifiers, BOOL pressed) |
415 |
{ |
{ |
416 |
|
#ifdef WITH_DEBUG_KBD |
417 |
|
uint16 old_modifier_state; |
418 |
|
|
419 |
|
old_modifier_state = remote_modifier_state; |
420 |
|
#endif |
421 |
|
|
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
|
|
remote_modifier_state, pressed)); |
|
422 |
switch (modifiers) |
switch (modifiers) |
423 |
{ |
{ |
424 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
459 |
} |
} |
460 |
break; |
break; |
461 |
} |
} |
462 |
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
|
463 |
|
#ifdef WITH_DEBUG_KBD |
464 |
|
if (old_modifier_state != remote_modifier_state) |
465 |
|
{ |
466 |
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
467 |
|
old_modifier_state, pressed)); |
468 |
|
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
469 |
|
} |
470 |
|
#endif |
471 |
|
|
472 |
} |
} |
473 |
|
|