Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
seflerZ committed Apr 17, 2024
1 parent ce007f1 commit c46d89e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 74 deletions.
5 changes: 4 additions & 1 deletion sesman/chansrv/chansrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <config_ac.h>
#endif

#ifdef XRDP_IBUS
#include "input.h"
#endif

#include "arch.h"
#include "os_calls.h"
#include "string_calls.h"
Expand All @@ -40,7 +44,6 @@
#include "chansrv_config.h"
#include "xrdp_sockets.h"
#include "audin.h"
#include "input.h"

#include "ms-rdpbcgr.h"

Expand Down
76 changes: 32 additions & 44 deletions sesman/chansrv/input_ibus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand All @@ -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"))
Expand All @@ -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;
}

Expand All @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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))
{
break;
}

sleep(1);
}

if (retry == 0)
if (!ibus_bus_get_global_engine(bus))
{
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;
}

Expand Down
64 changes: 36 additions & 28 deletions xrdp/xrdp_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,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 *
Expand Down Expand Up @@ -147,8 +150,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);
Expand Down Expand Up @@ -661,7 +666,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)
Expand All @@ -672,12 +677,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);
}

Expand All @@ -696,10 +701,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 */
Expand Down Expand Up @@ -2146,26 +2172,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
Expand Down Expand Up @@ -3033,21 +3039,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;
}
Expand Down
2 changes: 1 addition & 1 deletion xrdp/xrdp_wm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c46d89e

Please sign in to comment.