12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
GNU General Public License for more details. |
15 |
|
|
16 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
17 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
*/ |
20 |
|
|
21 |
|
#ifdef RDP2VNC |
22 |
|
#include "vnc/x11stubs.h" |
23 |
|
#else |
24 |
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
25 |
#define XK_MISCELLANY |
#include <X11/keysym.h> |
26 |
#include <X11/keysymdef.h> |
#endif |
27 |
|
|
28 |
#include <ctype.h> |
#include <ctype.h> |
29 |
#include <limits.h> |
#include <limits.h> |
30 |
#include <time.h> |
#include <time.h> |
35 |
#define KEYMAP_MASK 0xffff |
#define KEYMAP_MASK 0xffff |
36 |
#define KEYMAP_MAX_LINE_LENGTH 80 |
#define KEYMAP_MAX_LINE_LENGTH 80 |
37 |
|
|
38 |
extern Display *display; |
extern Display *g_display; |
39 |
extern char keymapname[16]; |
extern char keymapname[16]; |
40 |
extern int keylayout; |
extern int keylayout; |
41 |
extern BOOL enable_compose; |
extern int g_win_button_size; |
42 |
|
extern BOOL g_enable_compose; |
43 |
|
|
44 |
static BOOL keymap_loaded; |
static BOOL keymap_loaded; |
45 |
static key_translation keymap[KEYMAP_SIZE]; |
static key_translation keymap[KEYMAP_SIZE]; |
46 |
static int min_keycode; |
static int min_keycode; |
47 |
static uint16 remote_modifier_state = 0; |
static uint16 remote_modifier_state = 0; |
48 |
|
static uint16 saved_remote_modifier_state = 0; |
49 |
|
|
50 |
static void update_modifier_state(uint8 scancode, BOOL pressed); |
static void update_modifier_state(uint8 scancode, BOOL pressed); |
51 |
|
|
57 |
keysym = XStringToKeysym(keyname); |
keysym = XStringToKeysym(keyname); |
58 |
if (keysym == NoSymbol) |
if (keysym == NoSymbol) |
59 |
{ |
{ |
60 |
error("Bad keysym %s in keymap %s\n", keyname, mapname); |
DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring)\n", keyname, mapname)); |
61 |
return; |
return; |
62 |
} |
} |
63 |
|
|
141 |
if (strncmp(line, "enable_compose", 15) == 0) |
if (strncmp(line, "enable_compose", 15) == 0) |
142 |
{ |
{ |
143 |
DEBUG_KBD(("Enabling compose handling\n")); |
DEBUG_KBD(("Enabling compose handling\n")); |
144 |
enable_compose = True; |
g_enable_compose = True; |
145 |
continue; |
continue; |
146 |
} |
} |
147 |
|
|
204 |
/* Automatically add uppercase key, with same modifiers |
/* Automatically add uppercase key, with same modifiers |
205 |
plus shift */ |
plus shift */ |
206 |
for (p = keyname; *p; p++) |
for (p = keyname; *p; p++) |
207 |
*p = toupper(*p); |
*p = toupper((int) *p); |
208 |
MASK_ADD_BITS(modifiers, MapLeftShiftMask); |
MASK_ADD_BITS(modifiers, MapLeftShiftMask); |
209 |
add_to_keymap(keyname, scancode, modifiers, mapname); |
add_to_keymap(keyname, scancode, modifiers, mapname); |
210 |
} |
} |
226 |
mapname_ptr = keymapname; |
mapname_ptr = keymapname; |
227 |
while (*mapname_ptr) |
while (*mapname_ptr) |
228 |
{ |
{ |
229 |
*mapname_ptr = tolower(*mapname_ptr); |
*mapname_ptr = tolower((int) *mapname_ptr); |
230 |
mapname_ptr++; |
mapname_ptr++; |
231 |
} |
} |
232 |
|
|
236 |
keymap_loaded = True; |
keymap_loaded = True; |
237 |
} |
} |
238 |
|
|
239 |
XDisplayKeycodes(display, &min_keycode, (int *) &max_keycode); |
XDisplayKeycodes(g_display, &min_keycode, (int *) &max_keycode); |
240 |
} |
} |
241 |
|
|
242 |
/* Handles, for example, multi-scancode keypresses (which is not |
/* Handles, for example, multi-scancode keypresses (which is not |
313 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
314 |
} |
} |
315 |
return True; |
return True; |
316 |
|
|
317 |
|
case XK_space: |
318 |
|
/* Prevent access to the Windows system menu in single app mode */ |
319 |
|
if (g_win_button_size |
320 |
|
&& (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R))) |
321 |
|
return True; |
322 |
|
|
323 |
} |
} |
324 |
return False; |
return False; |
325 |
} |
} |
357 |
} |
} |
358 |
|
|
359 |
if (keymap_loaded) |
if (keymap_loaded) |
360 |
error("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); |
warning("No translation for (keysym 0x%lx, %s)\n", keysym, get_ksname(keysym)); |
361 |
|
|
362 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
363 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if (((int) keycode >= min_keycode) && (keycode <= 0x60)) |
364 |
{ |
{ |
365 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
366 |
|
|
415 |
return ksname; |
return ksname; |
416 |
} |
} |
417 |
|
|
418 |
|
void |
419 |
|
save_remote_modifiers() |
420 |
|
{ |
421 |
|
saved_remote_modifier_state = remote_modifier_state; |
422 |
|
} |
423 |
|
|
424 |
|
void |
425 |
|
restore_remote_modifiers(uint32 ev_time) |
426 |
|
{ |
427 |
|
key_translation dummy; |
428 |
|
|
429 |
|
dummy.scancode = 0; |
430 |
|
dummy.modifiers = saved_remote_modifier_state; |
431 |
|
ensure_remote_modifiers(ev_time, dummy); |
432 |
|
} |
433 |
|
|
434 |
void |
void |
435 |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
ensure_remote_modifiers(uint32 ev_time, key_translation tr) |
451 |
break; |
break; |
452 |
} |
} |
453 |
|
|
454 |
|
/* NumLock */ |
455 |
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
456 |
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
457 |
|
{ |
458 |
|
/* The remote modifier state is not correct */ |
459 |
|
uint16 new_remote_state; |
460 |
|
|
461 |
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
462 |
|
{ |
463 |
|
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
464 |
|
new_remote_state = KBD_FLAG_NUMLOCK; |
465 |
|
remote_modifier_state = MapNumLockMask; |
466 |
|
} |
467 |
|
else |
468 |
|
{ |
469 |
|
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
470 |
|
new_remote_state = 0; |
471 |
|
remote_modifier_state = 0; |
472 |
|
} |
473 |
|
|
474 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
475 |
|
} |
476 |
|
|
477 |
/* Shift. Left shift and right shift are treated as equal; either is fine. */ |
/* Shift. Left shift and right shift are treated as equal; either is fine. */ |
478 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
479 |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
518 |
} |
} |
519 |
} |
} |
520 |
|
|
|
/* NumLock */ |
|
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
|
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
|
|
{ |
|
|
/* The remote modifier state is not correct */ |
|
|
uint16 new_remote_state = 0; |
|
521 |
|
|
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
|
|
{ |
|
|
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
|
|
new_remote_state |= KBD_FLAG_NUMLOCK; |
|
|
} |
|
|
else |
|
|
{ |
|
|
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
|
|
} |
|
|
|
|
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
|
|
update_modifier_state(SCANCODE_CHAR_NUMLOCK, True); |
|
|
} |
|
522 |
} |
} |
523 |
|
|
524 |
|
|