From 3b1cc551e40ee9bdd079e6b40c885dd69e6f3e05 Mon Sep 17 00:00:00 2001 From: seflerZ Date: Wed, 17 Apr 2024 13:56:52 +0800 Subject: [PATCH] format code --- sesman/chansrv/chansrv.c | 5 ++- sesman/chansrv/input_ibus.c | 76 ++++++++++++++++--------------------- xrdp/xrdp_mm.c | 64 +++++++++++++++++-------------- xrdp/xrdp_wm.c | 2 +- 4 files changed, 73 insertions(+), 74 deletions(-) diff --git a/sesman/chansrv/chansrv.c b/sesman/chansrv/chansrv.c index 8a4692ef..dc973d67 100644 --- a/sesman/chansrv/chansrv.c +++ b/sesman/chansrv/chansrv.c @@ -21,6 +21,10 @@ #include #endif +#ifdef XRDP_IBUS +#include "input.h" +#endif + #include "arch.h" #include "os_calls.h" #include "string_calls.h" @@ -40,7 +44,6 @@ #include "chansrv_config.h" #include "xrdp_sockets.h" #include "audin.h" -#include "input.h" #include "ms-rdpbcgr.h" diff --git a/sesman/chansrv/input_ibus.c b/sesman/chansrv/input_ibus.c index b2b4deba..5de3b81f 100644 --- a/sesman/chansrv/input_ibus.c +++ b/sesman/chansrv/input_ibus.c @@ -30,7 +30,7 @@ static IBusBus *bus; static IBusEngine *g_engine; -// This is the engine name enabled before unicode engine enabled +/* This is the engine name enabled before unicode engine enabled */ static const gchar *ori_name; static int id = 0; @@ -42,10 +42,10 @@ xrdp_input_enable() if (ori_name) { - // already enabled + /* already enabled */ return 0; } - + if (!bus) { LOG(LOG_LEVEL_ERROR, "xrdp_ibus_init: input method switched failed, ibus not connected"); @@ -58,8 +58,8 @@ xrdp_input_enable() { return 0; } - - // remember user's input method, will switch back when disconnect + + /* remember user's input method, will switch back when disconnect */ ori_name = name; if (!ibus_bus_set_global_engine(bus, "XrdpIme")) @@ -69,7 +69,7 @@ xrdp_input_enable() } LOG(LOG_LEVEL_INFO, "xrdp_ibus_init: input method switched sucessfully, old input name: %s", ori_name); - + return 0; } @@ -89,20 +89,20 @@ xrdp_input_send_unicode(uint32_t unicode) return 0; } -void +void xrdp_input_ibus_engine_enable(IBusEngine *engine) { LOG(LOG_LEVEL_INFO, "xrdp_ibus_engine_enable: IM enabled"); g_engine = engine; } -void +void xrdp_input_ibus_engine_disable(IBusEngine *engine) { LOG(LOG_LEVEL_INFO, "xrdp_ibus_engine_disable: IM disabled"); } -void +void xrdp_input_ibus_disconnect(IBusEngine *engine) { LOG(LOG_LEVEL_INFO, "xrdp_ibus_engine_disable: IM disabled"); @@ -115,14 +115,14 @@ gboolean engine_process_key_event_cb(IBusEngine *engine, guint keycode, guint state) { - // Pass the keyboard event to system + /* Pass the keyboard event to system */ return FALSE; } IBusEngine * xrdp_input_ibus_create_engine(IBusFactory *factory, - gchar *engine_name, - gpointer user_data) + gchar *engine_name, + gpointer user_data) { IBusEngine *engine; gchar *path = g_strdup_printf("/org/freedesktop/IBus/Engine/%i", 1); @@ -160,23 +160,23 @@ xrdp_input_main_loop() ibus_factory_add_engine(factory, "XrdpIme", IBUS_TYPE_ENGINE); - component = ibus_component_new("org.freedesktop.IBus.XrdpIme", // name - "Xrdp input method", // description - "1.1", // version - "MIT", // license - "seflerZ", // author - "fake_page", // homepage - "/exec/fake_path", // cmd - "xrdpime"); // text domain + component = ibus_component_new("org.freedesktop.IBus.XrdpIme", /* name */ + "Xrdp input method", /* description */ + "1.1", /* version */ + "MIT", /* license */ + "seflerZ", /* author */ + "default", /* homepage */ + "default", /* cmd */ + "xrdpime"); /* text domain */ desc = ibus_engine_desc_new("XrdpIme", - "unicode input method for xrdp", - "unicode input method for xrdp", - "unicode", - "MIT", - "seflerZ", - "fake_icon.png", - "default"); // layout + "unicode input method for xrdp", + "unicode input method for xrdp", + "unicode", + "MIT", + "seflerZ", + "default", /* icon */ + "default"); /* layout */ ibus_component_add_engine(component, desc); ibus_bus_register_component(bus, component); @@ -213,16 +213,15 @@ xrdp_input_unicode_destory() int xrdp_input_unicode_init() { - int retry = 10; - if (bus) { - // Already initialized, just re-enable it + /* Already initialized, just re-enable it */ xrdp_input_enable(); return 0; } - sleep(5); + /* Wait becasue ibus daemon may not be ready in first login. Do we have a flag to avoid busy waiting? */ + sleep(3); LOG(LOG_LEVEL_INFO, "xrdp_ibus_init: Initializing the iBus engine"); ibus_init(); @@ -239,20 +238,9 @@ xrdp_input_unicode_init() tc_thread_create(xrdp_input_main_loop, NULL); - // session may not be ready, repeat until input method enabled - while (retry--) + if (!ibus_bus_get_global_engine(bus)) { - if (ibus_bus_get_global_engine(bus)) - { - break; - } - - sleep(1); - } - - if (retry == 0) - { - LOG(LOG_LEVEL_ERROR, "xrdp_ibus_init: failed to connect to ibus"); + LOG(LOG_LEVEL_ERROR, "xrdp_ibus_init: failed to get origin global engine"); return 1; } diff --git a/xrdp/xrdp_mm.c b/xrdp/xrdp_mm.c index dd1916b6..cd0e8eab 100644 --- a/xrdp/xrdp_mm.c +++ b/xrdp/xrdp_mm.c @@ -42,8 +42,11 @@ static int xrdp_mm_chansrv_connect(struct xrdp_mm *self, const char *port); static void xrdp_mm_connect_sm(struct xrdp_mm *self); + +#ifdef XRDP_IBUS static int xrdp_mm_send_unicode_shutdown(struct xrdp_mm *self, struct trans *trans); +#endif /*****************************************************************************/ struct xrdp_mm * @@ -148,8 +151,10 @@ xrdp_mm_delete(struct xrdp_mm *self) return; } +#ifdef XRDP_IBUS /* shutdown input method */ xrdp_mm_send_unicode_shutdown(self, self->chan_trans); +#endif /* free any module stuff */ xrdp_mm_module_cleanup(self); @@ -662,7 +667,7 @@ xrdp_mm_trans_process_channel_data(struct xrdp_mm *self, struct stream *s) return rv; } - +#ifdef XRDP_IBUS /*****************************************************************************/ static int xrdp_mm_send_unicode_shutdown(struct xrdp_mm *self, struct trans *trans) @@ -673,12 +678,12 @@ xrdp_mm_send_unicode_shutdown(struct xrdp_mm *self, struct trans *trans) return 1; } - out_uint32_le(s, 0); /* version */ + out_uint32_le(s, 0); /* version */ out_uint32_le(s, 8 + 8); /* size */ - out_uint32_le(s, 25); /* msg id */ - out_uint32_le(s, 8); /* size */ + out_uint32_le(s, 25); /* msg id */ + out_uint32_le(s, 8); /* size */ s_mark_end(s); - + return trans_write_copy(self->chan_trans); } @@ -697,10 +702,31 @@ xrdp_mm_send_unicode_setup(struct xrdp_mm *self, struct trans *trans) out_uint32_le(s, 21); /* msg id */ out_uint32_le(s, 8); /* size */ s_mark_end(s); - + return trans_write_copy(self->chan_trans); } +/******************************************************************************/ +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, 24); /* size */ + out_uint32_le(s, 23); /* msg id */ + out_uint32_le(s, 16); /* size */ + out_uint32_le(s, key_down); + out_uint32_le(s, unicode); + s_mark_end(s); + return trans_write_copy(self->chan_trans); +} +#endif + /*****************************************************************************/ /* returns error process rail create window order */ @@ -2147,26 +2173,6 @@ 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, 24); /* size */ - out_uint32_le(s, 23); /* msg id */ - out_uint32_le(s, 16); /* size */ - 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 @@ -3034,21 +3040,23 @@ xrdp_mm_chansrv_connect(struct xrdp_mm *self, const char *port) "connect successful"); } +#ifdef XRDP_IBUS /* 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; } } +#endif return 0; } diff --git a/xrdp/xrdp_wm.c b/xrdp/xrdp_wm.c index 5954fbca..eebe0da4 100644 --- a/xrdp/xrdp_wm.c +++ b/xrdp/xrdp_wm.c @@ -1801,7 +1801,7 @@ xrdp_wm_key_unicode(struct xrdp_wm *self, int device_flags, char32_t c16) #ifdef XRDP_IBUS if (self->mm->chan_trans != NULL && - self->mm->chan_trans->status == TRANS_STATUS_UP) + self->mm->chan_trans->status == TRANS_STATUS_UP) { xrdp_mm_send_unicode_to_chansrv(self->mm, !(device_flags & KBD_FLAG_UP), c32);