Skip to content

Commit

Permalink
It works now
Browse files Browse the repository at this point in the history
  • Loading branch information
seflerZ committed Apr 17, 2024
1 parent cdec850 commit ce007f1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 12 deletions.
2 changes: 2 additions & 0 deletions sesman/chansrv/input_ibus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 3 additions & 4 deletions xrdp/xrdp_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
71 changes: 63 additions & 8 deletions xrdp/xrdp_wm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down

0 comments on commit ce007f1

Please sign in to comment.