From 2f8d3ba9da68c120a5a4f156a0da06c135b9e862 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Sat, 10 Dec 2016 00:11:28 -0800 Subject: [PATCH] add unicode support --- common/xrdp_constants.h | 1 + libxrdp/xrdp_caps.c | 3 +- libxrdp/xrdp_fastpath.c | 30 ++++++++++++---- xrdp/xrdp_wm.c | 77 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 7 deletions(-) diff --git a/common/xrdp_constants.h b/common/xrdp_constants.h index 7dcb3064..795264a5 100644 --- a/common/xrdp_constants.h +++ b/common/xrdp_constants.h @@ -160,6 +160,7 @@ #define RDP_INPUT_CODEPOINT 1 #define RDP_INPUT_VIRTKEY 2 #define RDP_INPUT_SCANCODE 4 +#define RDP_INPUT_UNICODE 5 #define RDP_INPUT_MOUSE 0x8001 #define RDP_INPUT_MOUSEX 0x8002 diff --git a/libxrdp/xrdp_caps.c b/libxrdp/xrdp_caps.c index 8d5250d5..bb1cd619 100644 --- a/libxrdp/xrdp_caps.c +++ b/libxrdp/xrdp_caps.c @@ -872,9 +872,10 @@ xrdp_caps_send_demand_active(struct xrdp_rdp *self) /* INPUT_FLAG_SCANCODES 0x0001 INPUT_FLAG_MOUSEX 0x0004 + INPUT_FLAG_UNICODE 0x0010 INPUT_FLAG_FASTPATH_INPUT 0x0008 INPUT_FLAG_FASTPATH_INPUT2 0x0020 */ - flags = 0x0001 | 0x0004; + flags = 0x0001 | 0x0004 | 0x0010; if (self->client_info.use_fast_path & 2) { /* 0x0008 INPUT_FLAG_FASTPATH_INPUT */ diff --git a/libxrdp/xrdp_fastpath.c b/libxrdp/xrdp_fastpath.c index 008c8289..daa08373 100644 --- a/libxrdp/xrdp_fastpath.c +++ b/libxrdp/xrdp_fastpath.c @@ -265,12 +265,30 @@ static int APP_CC xrdp_fastpath_process_EVENT_UNICODE(struct xrdp_fastpath *self, int eventFlags, struct stream *s) { - if (!s_check_rem(s, 2)) - { - return 1; - } - in_uint8s(s, 2); - return 0; + int flags; + int code; + + flags = 0; + if (!s_check_rem(s, 2)) + { + return 1; + } + in_uint16_le(s, code); /* keyCode (1 byte) */ + if (eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE) + { + flags |= KBD_FLAG_UP; + } + else + { + flags |= KBD_FLAG_DOWN; + } + if (eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED) + { + flags |= KBD_FLAG_EXT; + } + xrdp_fastpath_session_callback(self, RDP_INPUT_UNICODE, + code, 0, flags, 0); + return 0; } /*****************************************************************************/ diff --git a/xrdp/xrdp_wm.c b/xrdp/xrdp_wm.c index 4917c3aa..26d488ec 100644 --- a/xrdp/xrdp_wm.c +++ b/xrdp/xrdp_wm.c @@ -1525,6 +1525,80 @@ xrdp_wm_key_sync(struct xrdp_wm *self, int device_flags, int key_flags) return 0; } +/*****************************************************************************/ +int APP_CC +xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, int unicode) +{ + int index; + + for (index = 8; index < 256; index++) + { + if (unicode == self->keymap.keys_noshift[index].chr) + { + xrdp_wm_key(self, device_flags, index - 8); + return 0; + } + } + + for (index = 8; index < 256; index++) + { + if (unicode == self->keymap.keys_shift[index].chr) + { + if (device_flags & KBD_FLAG_UP) + { + xrdp_wm_key(self, device_flags, index - 8); + xrdp_wm_key(self, KBD_FLAG_UP, 42); + } + else + { + xrdp_wm_key(self, KBD_FLAG_DOWN, 42); + xrdp_wm_key(self, device_flags, index - 8); + } + return 0; + } + } + + for (index = 8; index < 256; index++) + { + if (unicode == self->keymap.keys_altgr[index].chr) + { + if (device_flags & KBD_FLAG_UP) + { + xrdp_wm_key(self, device_flags, index - 8); + xrdp_wm_key(self, KBD_FLAG_UP | KBD_FLAG_EXT, 56); + } + else + { + xrdp_wm_key(self, KBD_FLAG_DOWN | KBD_FLAG_EXT, 56); + xrdp_wm_key(self, device_flags, index - 8); + } + return 0; + } + } + + for (index = 8; index < 256; index++) + { + if (unicode == self->keymap.keys_shiftaltgr[index].chr) + { + if (device_flags & KBD_FLAG_UP) + { + xrdp_wm_key(self, device_flags, index - 8); + xrdp_wm_key(self, KBD_FLAG_UP | KBD_FLAG_EXT, 56); + xrdp_wm_key(self, KBD_FLAG_UP, 42); + } + else + { + xrdp_wm_key(self, KBD_FLAG_DOWN, 42); + xrdp_wm_key(self, KBD_FLAG_DOWN | KBD_FLAG_EXT, 56); + xrdp_wm_key(self, device_flags, index - 8); + } + return 0; + } + } + + return 0; +} + /*****************************************************************************/ int APP_CC xrdp_wm_pu(struct xrdp_wm *self, struct xrdp_bitmap *control) @@ -1721,6 +1795,9 @@ callback(long id, int msg, long param1, long param2, long param3, long param4) case 4: /* RDP_INPUT_SCANCODE */ rv = xrdp_wm_key(wm, param3, param1); break; + case 5: /* RDP_INPUT_UNICODE */ + rv = xrdp_wm_key_unicode(wm, param3, param1); + break; case 0x8001: /* RDP_INPUT_MOUSE */ rv = xrdp_wm_process_input_mouse(wm, param3, param1, param2); break;