It works now

This commit is contained in:
seflerZ 2024-04-17 12:02:20 +08:00 committed by sefler
parent bea72150fb
commit d4e2e0a093
3 changed files with 69 additions and 13 deletions

View File

@ -222,6 +222,8 @@ xrdp_input_unicode_init()
return 0; return 0;
} }
sleep(5);
LOG(LOG_LEVEL_INFO, "xrdp_ibus_init: Initializing the iBus engine"); LOG(LOG_LEVEL_INFO, "xrdp_ibus_init: Initializing the iBus engine");
ibus_init(); ibus_init();
bus = ibus_bus_new(); bus = ibus_bus_new();

View File

@ -2159,7 +2159,7 @@ int xrdp_mm_send_unicode_to_chansrv(struct xrdp_mm *self,
} }
out_uint32_le(s, 0); /* version */ out_uint32_le(s, 0); /* version */
out_uint32_le(s, 24); /* size */ 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, 16); /* size */
out_uint32_le(s, key_down); out_uint32_le(s, key_down);
out_uint32_le(s, unicode); out_uint32_le(s, unicode);
@ -3034,17 +3034,16 @@ xrdp_mm_chansrv_connect(struct xrdp_mm *self, const char *port)
"connect successful"); "connect successful");
} }
/* if client supports unicode input, initialize the input method */ /* if client supports unicode input, initialize the input method */
if (1) if (1)
{ {
LOG(LOG_LEVEL_INFO, "xrdp_mm_chansrv_connect: chansrv " 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) if (xrdp_mm_send_unicode_setup(self, self->chan_trans) != 0)
{ {
LOG(LOG_LEVEL_ERROR, "xrdp_mm_chansrv_connect: error in " LOG(LOG_LEVEL_ERROR, "xrdp_mm_chansrv_connect: error in "
"xrdp_mm_send_unicode_setup"); "xrdp_mm_send_unicode_setup");
/* disable unicode input */ /* disable unicode input */
// self->wm->client_info->unicode_input = 0; // self->wm->client_info->unicode_input = 0;

View File

@ -1676,14 +1676,64 @@ xrdp_wm_key_sync(struct xrdp_wm *self, int device_flags, int key_flags)
} }
/*****************************************************************************/ /*****************************************************************************/
static int /**
xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t unicode) * 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 c16)
{
char32_t c32 = get_unicode_character(self, device_flags, c16);
if (c32 == 0)
{
return 0;
}
int index; int index;
for (index = XR_MIN_KEY_CODE; index < XR_MAX_KEY_CODE; 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); xrdp_wm_key(self, device_flags, index - XR_MIN_KEY_CODE);
return 0; 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++) 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) 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++) 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) 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++) 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) 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 #ifdef XRDP_IBUS
// Forward unicode to chansrv to input method like iBus if (self->mm->chan_trans != NULL &&
xrdp_mm_send_unicode_to_chansrv(self->mm, !(device_flags & KBD_FLAG_UP), unicode); 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 #endif
return 0; return 0;