From ce007f152f7429b23088e682a433a308d75b7984 Mon Sep 17 00:00:00 2001 From: seflerZ Date: Wed, 17 Apr 2024 12:02:20 +0800 Subject: [PATCH] It works now --- sesman/chansrv/input_ibus.c | 2 ++ xrdp/xrdp_mm.c | 7 ++-- xrdp/xrdp_wm.c | 71 ++++++++++++++++++++++++++++++++----- 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/sesman/chansrv/input_ibus.c b/sesman/chansrv/input_ibus.c index 003cd58a3..b2b4deba6 100644 --- a/sesman/chansrv/input_ibus.c +++ b/sesman/chansrv/input_ibus.c @@ -222,6 +222,8 @@ xrdp_input_unicode_init() return 0; } + sleep(5); + LOG(LOG_LEVEL_INFO, "xrdp_ibus_init: Initializing the iBus engine"); ibus_init(); bus = ibus_bus_new(); diff --git a/xrdp/xrdp_mm.c b/xrdp/xrdp_mm.c index 7e182bc9b..27b4e01d0 100644 --- a/xrdp/xrdp_mm.c +++ b/xrdp/xrdp_mm.c @@ -2158,7 +2158,7 @@ int xrdp_mm_send_unicode_to_chansrv(struct xrdp_mm *self, } out_uint32_le(s, 0); /* version */ out_uint32_le(s, 24); /* size */ - out_uint32_le(s, 21); /* msg id */ + out_uint32_le(s, 23); /* msg id */ out_uint32_le(s, 16); /* size */ out_uint32_le(s, key_down); out_uint32_le(s, unicode); @@ -3033,17 +3033,16 @@ xrdp_mm_chansrv_connect(struct xrdp_mm *self, const char *port) "connect successful"); } - /* if client supports unicode input, initialize the input method */ if (1) { LOG(LOG_LEVEL_INFO, "xrdp_mm_chansrv_connect: chansrv " - "client support unicode input, init the input method"); + "client support unicode input, init the input method"); if (xrdp_mm_send_unicode_setup(self, self->chan_trans) != 0) { LOG(LOG_LEVEL_ERROR, "xrdp_mm_chansrv_connect: error in " - "xrdp_mm_send_unicode_setup"); + "xrdp_mm_send_unicode_setup"); /* disable unicode input */ // self->wm->client_info->unicode_input = 0; diff --git a/xrdp/xrdp_wm.c b/xrdp/xrdp_wm.c index 7be9f0867..151de59ad 100644 --- a/xrdp/xrdp_wm.c +++ b/xrdp/xrdp_wm.c @@ -1675,15 +1675,65 @@ xrdp_wm_key_sync(struct xrdp_wm *self, int device_flags, int key_flags) return 0; } +/*****************************************************************************/ +/** + * Takes a stream of UTF-16 characters and maps then to Unicode characters + */ +static char32_t +get_unicode_character(struct xrdp_wm *self, int device_flags, char16_t c16) +{ + char32_t c32 = 0; + int *high_ptr; + + if (device_flags & KBD_FLAG_UP) + { + high_ptr = &self->last_high_surrogate_key_up; + } + else + { + high_ptr = &self->last_high_surrogate_key_down; + } + + if (IS_HIGH_SURROGATE(c16)) + { + // Record high surrogate for next time + *high_ptr = c16; + } + else if (IS_LOW_SURROGATE(c16)) + { + // If last character was a high surrogate, we can use it + if (*high_ptr != 0) + { + c32 = C32_FROM_SURROGATE_PAIR(c16, *high_ptr); + *high_ptr = 0; + } + } + else + { + // Character maps straight across + c32 = c16; + *high_ptr = 0; + } + + return c32; +} + /*****************************************************************************/ static int -xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t unicode) +xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t c16) { + char32_t c32 = get_unicode_character(self, device_flags, c16); + + if (c32 == 0) + { + return 0; + } + int index; - + for (index = XR_MIN_KEY_CODE; index < XR_MAX_KEY_CODE; index++) { - if (unicode == self->keymap.keys_noshift[index].chr) + if (c32 == self->keymap.keys_noshift[index].chr) { xrdp_wm_key(self, device_flags, index - XR_MIN_KEY_CODE); return 0; @@ -1692,7 +1742,7 @@ xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t unicode) for (index = XR_MIN_KEY_CODE; index < XR_MAX_KEY_CODE; index++) { - if (unicode == self->keymap.keys_shift[index].chr) + if (c32 == self->keymap.keys_shift[index].chr) { if (device_flags & KBD_FLAG_UP) { @@ -1710,7 +1760,7 @@ xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t unicode) for (index = XR_MIN_KEY_CODE; index < XR_MAX_KEY_CODE; index++) { - if (unicode == self->keymap.keys_altgr[index].chr) + if (c32 == self->keymap.keys_altgr[index].chr) { if (device_flags & KBD_FLAG_UP) { @@ -1730,7 +1780,7 @@ xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t unicode) for (index = XR_MIN_KEY_CODE; index < XR_MAX_KEY_CODE; index++) { - if (unicode == self->keymap.keys_shiftaltgr[index].chr) + if (c32 == self->keymap.keys_shiftaltgr[index].chr) { if (device_flags & KBD_FLAG_UP) { @@ -1750,8 +1800,13 @@ xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t unicode) } #ifdef XRDP_IBUS - // Forward unicode to chansrv to input method like iBus - xrdp_mm_send_unicode_to_chansrv(self->mm, !(device_flags & KBD_FLAG_UP), unicode); + if (self->mm->chan_trans != NULL && + self->mm->chan_trans->status == TRANS_STATUS_UP) + { + xrdp_mm_send_unicode_to_chansrv(self->mm, + !(device_flags & KBD_FLAG_UP), c32); + return 0; + } #endif return 0;