From 20b90c1098cb3809c9faa68b035668e1ee1f339d Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:35:58 +0000 Subject: [PATCH] Initial support for ibus input from chansrv --- configure.ac | 12 ++++++++++++ sesman/chansrv/Makefile.am | 5 +++++ sesman/chansrv/chansrv.c | 30 ++++++++++++++++++++++++++++++ xrdp/Makefile.am | 4 ++++ xrdp/xrdp.h | 4 ++++ xrdp/xrdp_mm.c | 20 ++++++++++++++++++++ xrdp/xrdp_wm.c | 12 ++++++++++++ 7 files changed, 87 insertions(+) diff --git a/configure.ac b/configure.ac index 11b2b85e..a6ba833a 100644 --- a/configure.ac +++ b/configure.ac @@ -164,6 +164,10 @@ AC_ARG_ENABLE(mp3lame, AS_HELP_STRING([--enable-mp3lame], [Build lame mp3(audio codec) (default: no)]), [], [enable_mp3lame=no]) AM_CONDITIONAL(XRDP_MP3LAME, [test x$enable_mp3lame = xyes]) +AC_ARG_ENABLE(ibus, AS_HELP_STRING([--enable-ibus], + [Allow unicode input via IBus) (default: no)]), + [], [enable_ibus=no]) +AM_CONDITIONAL(XRDP_IBUS, [test x$enable_ibus = xyes]) AC_ARG_ENABLE(pixman, AS_HELP_STRING([--enable-pixman], [Use pixman library (default: no)]), [], [enable_pixman=no]) @@ -472,6 +476,13 @@ then [AC_MSG_ERROR([please install libmp3lame-dev or lamemp3-devel])]) fi +# checking for ibus includes +if test "x$enable_ibus" = "xyes" +then + PKG_CHECK_MODULES([IBUS], [ibus-1.0 >= 1.5], [], + [AC_MSG_ERROR([please install libibus-1.0-dev or ibus-devel])]) +fi + AS_IF( [test "x$enable_pixman" = "xyes"] , [PKG_CHECK_MODULES(PIXMAN, pixman-1 >= 0.1.0)] ) # checking for TurboJPEG @@ -646,6 +657,7 @@ echo " fuse $enable_fuse" echo " ipv6 $enable_ipv6" echo " ipv6only $enable_ipv6only" echo " vsock $enable_vsock" +echo " ibus $enable_ibus" echo " auth mechanism $auth_mech" echo " rdpsndaudin $enable_rdpsndaudin" echo " utmp support $enable_utmp" diff --git a/sesman/chansrv/Makefile.am b/sesman/chansrv/Makefile.am index 959cdb52..9916ba00 100644 --- a/sesman/chansrv/Makefile.am +++ b/sesman/chansrv/Makefile.am @@ -38,6 +38,11 @@ if XRDP_RDPSNDAUDIN AM_CPPFLAGS += -DXRDP_RDPSNDAUDIN endif +if XRDP_IBUS +AM_CPPFLAGS += -DXRDP_IBUS $(IBUS_CFLAGS) +CHANSRV_EXTRA_LIBS += $(IBUS_LIBS) +endif + AM_CFLAGS = $(X_CFLAGS) sbin_PROGRAMS = \ diff --git a/sesman/chansrv/chansrv.c b/sesman/chansrv/chansrv.c index d3a32165..f97de07c 100644 --- a/sesman/chansrv/chansrv.c +++ b/sesman/chansrv/chansrv.c @@ -823,6 +823,31 @@ chansrv_drdynvc_send_data(int chan_id, const char *data, int data_bytes) return 0; } +/*****************************************************************************/ +#ifdef XRDP_IBUS +static int +process_message_unicode_key_press(struct stream *s) +{ + int rv = 0; + int key_down; + char32_t unicode_char; + + LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_unicode_keypress:"); + if (!s_check_rem(s, 8)) + { + rv = 1; + } + else + { + in_uint32_le(s, key_down); + in_uint32_le(s, unicode_char); + LOG(LOG_LEVEL_INFO, "Unicode char 0x%08x received down=%d", + unicode_char, key_down); + } + return rv; +} +#endif // XRDP_IBUS + /*****************************************************************************/ /* returns error */ static int @@ -875,6 +900,11 @@ process_message(void) case 19: /* drdynvc data */ rv = process_message_drdynvc_data(s); break; +#ifdef XRDP_IBUS + case 21: /* Unicode key press */ + rv = process_message_unicode_key_press(s); + break; +#endif default: LOG_DEVEL(LOG_LEVEL_ERROR, "process_message: unknown msg %d", id); break; diff --git a/xrdp/Makefile.am b/xrdp/Makefile.am index 69658a2b..845091ba 100644 --- a/xrdp/Makefile.am +++ b/xrdp/Makefile.am @@ -38,6 +38,10 @@ AM_CPPFLAGS += -I$(top_srcdir)/libpainter/include XRDP_EXTRA_LIBS += $(top_builddir)/libpainter/src/.libs/libpainter.a endif +if XRDP_IBUS +AM_CPPFLAGS += -DXRDP_IBUS +endif + sbin_PROGRAMS = \ xrdp diff --git a/xrdp/xrdp.h b/xrdp/xrdp.h index b2a8ae97..77af4665 100644 --- a/xrdp/xrdp.h +++ b/xrdp/xrdp.h @@ -483,6 +483,10 @@ xrdp_mm_suppress_output(struct xrdp_mm *self, int suppress, int left, int top, int right, int bottom); int xrdp_mm_up_and_running(struct xrdp_mm *self); +int +xrdp_mm_send_unicode_to_chansrv(struct xrdp_mm *self, + int key_down, + char32_t unicode); struct xrdp_mm * xrdp_mm_create(struct xrdp_wm *owner); void diff --git a/xrdp/xrdp_mm.c b/xrdp/xrdp_mm.c index 034d63a9..124ff4aa 100644 --- a/xrdp/xrdp_mm.c +++ b/xrdp/xrdp_mm.c @@ -2103,6 +2103,26 @@ xrdp_mm_up_and_running(struct xrdp_mm *self) return 0; } +/******************************************************************************/ +int +xrdp_mm_send_unicode_to_chansrv(struct xrdp_mm *self, + int key_down, + char32_t unicode) +{ + struct stream *s = trans_get_out_s(self->chan_trans, 8192); + if (s == NULL) + { + return 1; + } + out_uint32_le(s, 0); /* version */ + out_uint32_le(s, 8 + 4 + 4 + 4); + out_uint32_le(s, 21); /* msg id */ + out_uint32_le(s, key_down); + out_uint32_le(s, unicode); + s_mark_end(s); + return trans_write_copy(self->chan_trans); +} + /*****************************************************************************/ /* open response from client going to channel server */ static int diff --git a/xrdp/xrdp_wm.c b/xrdp/xrdp_wm.c index e77fdabd..7c64c662 100644 --- a/xrdp/xrdp_wm.c +++ b/xrdp/xrdp_wm.c @@ -1678,6 +1678,18 @@ 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) { +#ifdef XRDP_IBUS + // Test code for ibus Unicode forwarding + 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) == 0, + unicode); + return 0; + } +#endif + int index; for (index = XR_MIN_KEY_CODE; index < XR_MAX_KEY_CODE; index++)