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> |
31 |
#include "rdesktop.h" |
#include "rdesktop.h" |
32 |
#include "scancodes.h" |
#include "scancodes.h" |
33 |
|
|
34 |
#define KEYMAP_SIZE 4096 |
#define KEYMAP_SIZE 0xffff+1 |
35 |
#define KEYMAP_MASK (KEYMAP_SIZE - 1) |
#define KEYMAP_MASK 0xffff |
36 |
#define KEYMAP_MAX_LINE_LENGTH 80 |
#define KEYMAP_MAX_LINE_LENGTH 80 |
37 |
|
|
38 |
extern Display *display; |
extern Display *display; |
39 |
extern char keymapname[16]; |
extern char keymapname[16]; |
40 |
extern int keylayout; |
extern int keylayout; |
41 |
extern BOOL enable_compose; |
extern int 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]; |
56 |
keysym = XStringToKeysym(keyname); |
keysym = XStringToKeysym(keyname); |
57 |
if (keysym == NoSymbol) |
if (keysym == NoSymbol) |
58 |
{ |
{ |
59 |
error("Bad keysym %s in keymap %s\n", keyname, mapname); |
DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring)\n", keyname, mapname)); |
60 |
return; |
return; |
61 |
} |
} |
62 |
|
|
140 |
if (strncmp(line, "enable_compose", 15) == 0) |
if (strncmp(line, "enable_compose", 15) == 0) |
141 |
{ |
{ |
142 |
DEBUG_KBD(("Enabling compose handling\n")); |
DEBUG_KBD(("Enabling compose handling\n")); |
143 |
enable_compose = True; |
g_enable_compose = True; |
144 |
continue; |
continue; |
145 |
} |
} |
146 |
|
|
203 |
/* Automatically add uppercase key, with same modifiers |
/* Automatically add uppercase key, with same modifiers |
204 |
plus shift */ |
plus shift */ |
205 |
for (p = keyname; *p; p++) |
for (p = keyname; *p; p++) |
206 |
*p = toupper(*p); |
*p = toupper((int) *p); |
207 |
MASK_ADD_BITS(modifiers, MapLeftShiftMask); |
MASK_ADD_BITS(modifiers, MapLeftShiftMask); |
208 |
add_to_keymap(keyname, scancode, modifiers, mapname); |
add_to_keymap(keyname, scancode, modifiers, mapname); |
209 |
} |
} |
225 |
mapname_ptr = keymapname; |
mapname_ptr = keymapname; |
226 |
while (*mapname_ptr) |
while (*mapname_ptr) |
227 |
{ |
{ |
228 |
*mapname_ptr = tolower(*mapname_ptr); |
*mapname_ptr = tolower((int) *mapname_ptr); |
229 |
mapname_ptr++; |
mapname_ptr++; |
230 |
} |
} |
231 |
|
|
245 |
{ |
{ |
246 |
switch (keysym) |
switch (keysym) |
247 |
{ |
{ |
248 |
case XK_Break: |
case XK_Return: |
|
case XK_Pause: |
|
249 |
if ((get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R)) |
if ((get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R)) |
250 |
&& (get_key_state(state, XK_Control_L) |
&& (get_key_state(state, XK_Control_L) |
251 |
|| get_key_state(state, XK_Control_R))) |
|| get_key_state(state, XK_Control_R))) |
252 |
{ |
{ |
253 |
/* Ctrl-Alt-Break: toggle full screen */ |
/* Ctrl-Alt-Enter: toggle full screen */ |
254 |
if (pressed) |
if (pressed) |
255 |
xwin_toggle_fullscreen(); |
xwin_toggle_fullscreen(); |
256 |
|
return True; |
257 |
|
} |
258 |
|
break; |
259 |
|
|
260 |
|
case XK_Break: |
261 |
|
/* Send Break sequence E0 46 E0 C6 */ |
262 |
|
if (pressed) |
263 |
|
{ |
264 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
265 |
|
(SCANCODE_EXTENDED | 0x46)); |
266 |
|
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
267 |
|
(SCANCODE_EXTENDED | 0xc6)); |
268 |
} |
} |
269 |
else if (keysym == XK_Break) |
/* No release sequence */ |
270 |
|
return True; |
271 |
|
|
272 |
|
case XK_Pause: |
273 |
|
/* According to MS Keyboard Scan Code |
274 |
|
Specification, pressing Pause should result |
275 |
|
in E1 1D 45 E1 9D C5. I'm not exactly sure |
276 |
|
of how this is supposed to be sent via |
277 |
|
RDP. The code below seems to work, but with |
278 |
|
the side effect that Left Ctrl stays |
279 |
|
down. Therefore, we release it when Pause |
280 |
|
is released. */ |
281 |
|
if (pressed) |
282 |
{ |
{ |
283 |
/* Send Break sequence E0 46 E0 C6 */ |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); |
284 |
if (pressed) |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x1d, 0); |
285 |
{ |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x45, 0); |
286 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xe1, 0); |
287 |
(SCANCODE_EXTENDED | 0x46)); |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0x9d, 0); |
288 |
rdp_send_scancode(ev_time, RDP_KEYPRESS, |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, 0xc5, 0); |
|
(SCANCODE_EXTENDED | 0xc6)); |
|
|
} |
|
|
/* No break sequence */ |
|
289 |
} |
} |
290 |
else /* XK_Pause */ |
else |
291 |
{ |
{ |
292 |
/* According to MS Keyboard Scan Code |
/* Release Left Ctrl */ |
293 |
Specification, pressing Pause should result |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, |
294 |
in E1 1D 45 E1 9D C5. I'm not exactly sure |
0x1d, 0); |
|
of how this is supposed to be sent via |
|
|
RDP. The code below seems to work, but with |
|
|
the side effect that Left Ctrl stays |
|
|
down. Therefore, we release it when Pause |
|
|
is released. */ |
|
|
if (pressed) |
|
|
{ |
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, |
|
|
0xe1, 0); |
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, |
|
|
0x1d, 0); |
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, |
|
|
0x45, 0); |
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, |
|
|
0xe1, 0); |
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, |
|
|
0x9d, 0); |
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYPRESS, |
|
|
0xc5, 0); |
|
|
} |
|
|
else |
|
|
{ |
|
|
/* Release Left Ctrl */ |
|
|
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, |
|
|
0x1d, 0); |
|
|
} |
|
295 |
} |
} |
296 |
return True; |
return True; |
297 |
|
|
312 |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
rdp_send_scancode(ev_time, RDP_KEYRELEASE, SCANCODE_CHAR_LCTRL); |
313 |
} |
} |
314 |
return True; |
return True; |
315 |
|
|
316 |
|
case XK_space: |
317 |
|
/* Prevent access to the Windows system menu in single app mode */ |
318 |
|
if (win_button_size |
319 |
|
&& (get_key_state(state, XK_Alt_L) || get_key_state(state, XK_Alt_R))) |
320 |
|
return True; |
321 |
|
|
322 |
} |
} |
323 |
return False; |
return False; |
324 |
} |
} |
356 |
} |
} |
357 |
|
|
358 |
if (keymap_loaded) |
if (keymap_loaded) |
359 |
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)); |
360 |
|
|
361 |
/* not in keymap, try to interpret the raw scancode */ |
/* not in keymap, try to interpret the raw scancode */ |
362 |
if ((keycode >= min_keycode) && (keycode <= 0x60)) |
if (((int) keycode >= min_keycode) && (keycode <= 0x60)) |
363 |
{ |
{ |
364 |
tr.scancode = keycode - min_keycode; |
tr.scancode = keycode - min_keycode; |
365 |
|
|
435 |
break; |
break; |
436 |
} |
} |
437 |
|
|
438 |
|
/* NumLock */ |
439 |
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask) |
440 |
|
!= MASK_HAS_BITS(remote_modifier_state, MapNumLockMask)) |
441 |
|
{ |
442 |
|
/* The remote modifier state is not correct */ |
443 |
|
uint16 new_remote_state; |
444 |
|
|
445 |
|
if (MASK_HAS_BITS(tr.modifiers, MapNumLockMask)) |
446 |
|
{ |
447 |
|
DEBUG_KBD(("Remote NumLock state is incorrect, activating NumLock.\n")); |
448 |
|
new_remote_state = KBD_FLAG_NUMLOCK; |
449 |
|
remote_modifier_state = MapNumLockMask; |
450 |
|
} |
451 |
|
else |
452 |
|
{ |
453 |
|
DEBUG_KBD(("Remote NumLock state is incorrect, deactivating NumLock.\n")); |
454 |
|
new_remote_state = 0; |
455 |
|
remote_modifier_state = 0; |
456 |
|
} |
457 |
|
|
458 |
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
459 |
|
} |
460 |
|
|
461 |
/* 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. */ |
462 |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
if (MASK_HAS_BITS(tr.modifiers, MapShiftMask) |
463 |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
!= MASK_HAS_BITS(remote_modifier_state, MapShiftMask)) |
502 |
} |
} |
503 |
} |
} |
504 |
|
|
|
/* 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; |
|
|
|
|
|
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")); |
|
|
} |
|
505 |
|
|
|
rdp_send_input(0, RDP_INPUT_SYNCHRONIZE, 0, new_remote_state, 0); |
|
|
update_modifier_state(SCANCODE_CHAR_NUMLOCK, True); |
|
|
} |
|
506 |
} |
} |
507 |
|
|
508 |
|
|