35 |
extern Display *display; |
extern Display *display; |
36 |
extern char keymapname[16]; |
extern char keymapname[16]; |
37 |
extern int keylayout; |
extern int keylayout; |
38 |
|
extern BOOL enable_compose; |
39 |
|
|
40 |
static key_translation keymap[KEYMAP_SIZE]; |
static key_translation keymap[KEYMAP_SIZE]; |
41 |
static unsigned int min_keycode; |
static int min_keycode; |
42 |
static uint16 remote_modifier_state = 0; |
static uint16 remote_modifier_state = 0; |
43 |
|
|
44 |
static void |
static void |
53 |
return; |
return; |
54 |
} |
} |
55 |
|
|
56 |
DEBUG_KBD("Adding translation, keysym=0x%x, scancode=0x%x, " |
DEBUG_KBD(("Adding translation, keysym=0x%x, scancode=0x%x, " |
57 |
"modifiers=0x%x\n", (unsigned int) keysym, scancode, |
"modifiers=0x%x\n", (unsigned int) keysym, scancode, modifiers)); |
|
modifiers); |
|
58 |
|
|
59 |
keymap[keysym & KEYMAP_MASK].scancode = scancode; |
keymap[keysym & KEYMAP_MASK].scancode = scancode; |
60 |
keymap[keysym & KEYMAP_MASK].modifiers = modifiers; |
keymap[keysym & KEYMAP_MASK].modifiers = modifiers; |
116 |
if (strncmp(line, "map ", 4) == 0) |
if (strncmp(line, "map ", 4) == 0) |
117 |
{ |
{ |
118 |
keylayout = strtol(line + 4, NULL, 16); |
keylayout = strtol(line + 4, NULL, 16); |
119 |
DEBUG_KBD("Keylayout 0x%x\n", keylayout); |
DEBUG_KBD(("Keylayout 0x%x\n", keylayout)); |
120 |
|
continue; |
121 |
|
} |
122 |
|
|
123 |
|
/* compose */ |
124 |
|
if (strncmp(line, "enable_compose", 15) == 0) |
125 |
|
{ |
126 |
|
DEBUG_KBD(("Enabling compose handling\n")); |
127 |
|
enable_compose = True; |
128 |
continue; |
continue; |
129 |
} |
} |
130 |
|
|
139 |
p = strchr(line, ' '); |
p = strchr(line, ' '); |
140 |
if (p == NULL) |
if (p == NULL) |
141 |
{ |
{ |
142 |
error("Bad line %d in keymap %s\n", line_num, |
error("Bad line %d in keymap %s\n", line_num, mapname); |
|
mapname); |
|
143 |
continue; |
continue; |
144 |
} |
} |
145 |
else |
else |
170 |
MASK_ADD_BITS(modifiers, MapNumLockMask); |
MASK_ADD_BITS(modifiers, MapNumLockMask); |
171 |
} |
} |
172 |
|
|
173 |
|
if (strstr(line_rest, "localstate")) |
174 |
|
{ |
175 |
|
MASK_ADD_BITS(modifiers, MapLocalStateMask); |
176 |
|
} |
177 |
|
|
178 |
add_to_keymap(keyname, scancode, modifiers, mapname); |
add_to_keymap(keyname, scancode, modifiers, mapname); |
179 |
|
|
180 |
if (strstr(line_rest, "addupper")) |
if (strstr(line_rest, "addupper")) |
218 |
xkeymap_init2(void) |
xkeymap_init2(void) |
219 |
{ |
{ |
220 |
unsigned int max_keycode; |
unsigned int max_keycode; |
221 |
XDisplayKeycodes(display, &min_keycode, &max_keycode); |
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
222 |
} |
} |
223 |
|
|
224 |
|
|
225 |
key_translation |
key_translation |
226 |
xkeymap_translate_key(KeySym keysym, unsigned int keycode) |
xkeymap_translate_key(KeySym keysym, unsigned int keycode, unsigned int state) |
227 |
{ |
{ |
228 |
key_translation tr = { 0, 0 }; |
key_translation tr = { 0, 0 }; |
229 |
|
|
230 |
tr = keymap[keysym & KEYMAP_MASK]; |
tr = keymap[keysym & KEYMAP_MASK]; |
231 |
|
|
232 |
|
if (tr.modifiers & MapLocalStateMask) |
233 |
|
{ |
234 |
|
/* The modifiers to send for this key should be obtained |
235 |
|
from the local state. Currently, only shift is implemented. */ |
236 |
|
if (state & ShiftMask) |
237 |
|
{ |
238 |
|
tr.modifiers = MapLeftShiftMask; |
239 |
|
} |
240 |
|
} |
241 |
|
|
242 |
if (tr.scancode != 0) |
if (tr.scancode != 0) |
243 |
{ |
{ |
244 |
DEBUG_KBD |
DEBUG_KBD |
245 |
("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
(("Found key translation, scancode=0x%x, modifiers=0x%x\n", |
246 |
tr.scancode, tr.modifiers); |
tr.scancode, tr.modifiers)); |
247 |
return tr; |
return tr; |
248 |
} |
} |
249 |
|
|
250 |
printf("No translation for (keysym 0x%lx, %s)\n", keysym, |
fprintf(stderr, "No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); |
|
get_ksname(keysym)); |
|
251 |
|
|
252 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
253 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
254 |
{ |
{ |
255 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
256 |
printf("Sending guessed scancode 0x%x\n", tr.scancode); |
fprintf(stderr, "Sending guessed scancode 0x%x\n", tr.scancode); |
257 |
} |
} |
258 |
else |
else |
259 |
{ |
{ |
260 |
printf("No good guess for keycode 0x%x found\n", keycode); |
fprintf(stderr, "No good guess for keycode 0x%x found\n", keycode); |
261 |
} |
} |
262 |
|
|
263 |
return tr; |
return tr; |
274 |
return MOUSE_FLAG_BUTTON3; |
return MOUSE_FLAG_BUTTON3; |
275 |
case Button3: /* right */ |
case Button3: /* right */ |
276 |
return MOUSE_FLAG_BUTTON2; |
return MOUSE_FLAG_BUTTON2; |
277 |
|
case Button4: /* wheel up */ |
278 |
|
return MOUSE_FLAG_BUTTON4; |
279 |
|
case Button5: /* wheel down */ |
280 |
|
return MOUSE_FLAG_BUTTON5; |
281 |
} |
} |
282 |
|
|
283 |
return 0; |
return 0; |
341 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask)) |
342 |
{ |
{ |
343 |
/* Needs this modifier. Send down. */ |
/* Needs this modifier. Send down. */ |
344 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_LSHIFT); |
|
SCANCODE_CHAR_LSHIFT); |
|
345 |
} |
} |
346 |
else |
else |
347 |
{ |
{ |
348 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up. */ |
349 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LSHIFT); |
|
SCANCODE_CHAR_LSHIFT); |
|
350 |
} |
} |
351 |
} |
} |
352 |
|
|
358 |
if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapAltGrMask)) |
359 |
{ |
{ |
360 |
/* Needs this modifier. Send down. */ |
/* Needs this modifier. Send down. */ |
361 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_RALT); |
|
SCANCODE_CHAR_RALT); |
|
362 |
} |
} |
363 |
else |
else |
364 |
{ |
{ |
365 |
/* Should not use this modifier. Send up. */ |
/* Should not use this modifier. Send up. */ |
366 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_RALT); |
|
SCANCODE_CHAR_RALT); |
|
367 |
} |
} |
368 |
} |
} |
369 |
|
|
372 |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
373 |
{ |
{ |
374 |
/* The remote modifier state is not correct */ |
/* The remote modifier state is not correct */ |
375 |
DEBUG_KBD("Remote NumLock state is incorrect. Toggling\n"); |
DEBUG_KBD(("Remote NumLock state is incorrect. Toggling\n")); |
376 |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
377 |
{ |
{ |
378 |
/* Needs this modifier. Toggle */ |
/* Needs this modifier. Toggle */ |
379 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_NUMLOCK); |
380 |
SCANCODE_CHAR_NUMLOCK); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_NUMLOCK); |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
|
|
SCANCODE_CHAR_NUMLOCK); |
|
381 |
} |
} |
382 |
else |
else |
383 |
{ |
{ |
384 |
/* Should not use this modifier. Toggle */ |
/* Should not use this modifier. Toggle */ |
385 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_scancode(ev_time, RDP_KEYPRESS, SCANCODE_CHAR_NUMLOCK); |
386 |
SCANCODE_CHAR_NUMLOCK); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_NUMLOCK); |
|
rdp_send_scancode(ev_time, RDP_KEYRELEASE, |
|
|
SCANCODE_CHAR_NUMLOCK); |
|
387 |
} |
} |
388 |
} |
} |
389 |
|
|
393 |
static void |
static void |
394 |
update_modifier_state(uint16 modifiers, BOOL pressed) |
update_modifier_state(uint16 modifiers, BOOL pressed) |
395 |
{ |
{ |
396 |
|
#ifdef WITH_DEBUG_KBD |
397 |
|
uint16 old_modifier_state; |
398 |
|
|
399 |
|
old_modifier_state = remote_modifier_state; |
400 |
|
#endif |
401 |
|
|
|
DEBUG_KBD("Before updating modifier_state:0x%x, pressed=0x%x\n", |
|
|
remote_modifier_state, pressed); |
|
402 |
switch (modifiers) |
switch (modifiers) |
403 |
{ |
{ |
404 |
case SCANCODE_CHAR_LSHIFT: |
case SCANCODE_CHAR_LSHIFT: |
405 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftShiftMask, pressed); |
|
MapLeftShiftMask, pressed); |
|
406 |
break; |
break; |
407 |
case SCANCODE_CHAR_RSHIFT: |
case SCANCODE_CHAR_RSHIFT: |
408 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightShiftMask, pressed); |
|
MapRightShiftMask, pressed); |
|
409 |
break; |
break; |
410 |
case SCANCODE_CHAR_LCTRL: |
case SCANCODE_CHAR_LCTRL: |
411 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftCtrlMask, pressed); |
|
MapLeftCtrlMask, pressed); |
|
412 |
break; |
break; |
413 |
case SCANCODE_CHAR_RCTRL: |
case SCANCODE_CHAR_RCTRL: |
414 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightCtrlMask, pressed); |
|
MapRightCtrlMask, pressed); |
|
415 |
break; |
break; |
416 |
case SCANCODE_CHAR_LALT: |
case SCANCODE_CHAR_LALT: |
417 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftAltMask, pressed); |
|
pressed); |
|
418 |
break; |
break; |
419 |
case SCANCODE_CHAR_RALT: |
case SCANCODE_CHAR_RALT: |
420 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightAltMask, pressed); |
|
MapRightAltMask, pressed); |
|
421 |
break; |
break; |
422 |
case SCANCODE_CHAR_LWIN: |
case SCANCODE_CHAR_LWIN: |
423 |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask, |
MASK_CHANGE_BIT(remote_modifier_state, MapLeftWinMask, pressed); |
|
pressed); |
|
424 |
break; |
break; |
425 |
case SCANCODE_CHAR_RWIN: |
case SCANCODE_CHAR_RWIN: |
426 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, MapRightWinMask, pressed); |
|
MapRightWinMask, pressed); |
|
427 |
break; |
break; |
428 |
case SCANCODE_CHAR_NUMLOCK: |
case SCANCODE_CHAR_NUMLOCK: |
429 |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
/* KeyReleases for NumLocks are sent immediately. Toggle the |
433 |
BOOL newNumLockState; |
BOOL newNumLockState; |
434 |
newNumLockState = |
newNumLockState = |
435 |
(MASK_HAS_BITS |
(MASK_HAS_BITS |
436 |
(remote_modifier_state, |
(remote_modifier_state, MapNumLockMask) == False); |
|
MapNumLockMask) == False); |
|
437 |
MASK_CHANGE_BIT(remote_modifier_state, |
MASK_CHANGE_BIT(remote_modifier_state, |
438 |
MapNumLockMask, |
MapNumLockMask, newNumLockState); |
|
newNumLockState); |
|
439 |
} |
} |
440 |
break; |
break; |
441 |
} |
} |
442 |
DEBUG_KBD("After updating modifier_state:0x%x\n", |
|
443 |
remote_modifier_state); |
#ifdef WITH_DEBUG_KBD |
444 |
|
if (old_modifier_state != remote_modifier_state) |
445 |
|
{ |
446 |
|
DEBUG_KBD(("Before updating modifier_state:0x%x, pressed=0x%x\n", |
447 |
|
old_modifier_state, pressed)); |
448 |
|
DEBUG_KBD(("After updating modifier_state:0x%x\n", remote_modifier_state)); |
449 |
|
} |
450 |
|
#endif |
451 |
|
|
452 |
} |
} |
453 |
|
|
459 |
|
|
460 |
if (scancode & SCANCODE_EXTENDED) |
if (scancode & SCANCODE_EXTENDED) |
461 |
{ |
{ |
462 |
DEBUG_KBD("Sending extended scancode=0x%x, flags=0x%x\n", |
DEBUG_KBD(("Sending extended scancode=0x%x, flags=0x%x\n", |
463 |
scancode & ~SCANCODE_EXTENDED, flags); |
scancode & ~SCANCODE_EXTENDED, flags)); |
464 |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT, |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags | KBD_FLAG_EXT, |
465 |
scancode & ~SCANCODE_EXTENDED, 0); |
scancode & ~SCANCODE_EXTENDED, 0); |
466 |
} |
} |
467 |
else |
else |
468 |
{ |
{ |
469 |
DEBUG_KBD("Sending scancode=0x%x, flags=0x%x\n", scancode, |
DEBUG_KBD(("Sending scancode=0x%x, flags=0x%x\n", scancode, flags)); |
|
flags); |
|
470 |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
rdp_send_input(time, RDP_INPUT_SCANCODE, flags, scancode, 0); |
471 |
} |
} |
472 |
} |
} |