Skip to content

Commit

Permalink
Fixed building and using fcitx IME support on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 8, 2016
1 parent 27d4f09 commit 42f85aa
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
3 changes: 2 additions & 1 deletion docs/README-linux.md
Expand Up @@ -19,7 +19,8 @@ sudo apt-get install build-essential mercurial make cmake autoconf automake \
libtool libasound2-dev libpulse-dev libaudio-dev libx11-dev libxext-dev \
libxrandr-dev libxcursor-dev libxi-dev libxinerama-dev libxxf86vm-dev \
libxss-dev libgl1-mesa-dev libesd0-dev libdbus-1-dev libudev-dev \
libgles1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libibus-1.0-dev
libgles1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libibus-1.0-dev \
fcitx-libs-dev

Ubuntu 16.04 can also add "libwayland-dev libxkbcommon-dev wayland-protocols"
to that command line for Wayland support.
Expand Down
2 changes: 1 addition & 1 deletion src/core/linux/SDL_fcitx.c
Expand Up @@ -62,7 +62,7 @@ static int
GetDisplayNumber()
{
const char *display = SDL_getenv("DISPLAY");
const char *p = NULL;;
const char *p = NULL;
int number = 0;

if (display == NULL)
Expand Down
56 changes: 30 additions & 26 deletions src/core/linux/SDL_ime.c
Expand Up @@ -43,40 +43,44 @@ static void
InitIME()
{
static SDL_bool inited = SDL_FALSE;
const char *im_module = NULL;
const char *im_module;
const char *xmodifiers = SDL_getenv("XMODIFIERS");

if (inited == SDL_TRUE)
return ;
return;

inited = SDL_TRUE;
// TODO:
// better move every ime implenment to a shared library

// default to IBus
#ifdef HAVE_IBUS_IBUS_H
SDL_IME_Init_Real = SDL_IBus_Init;
SDL_IME_Quit_Real = SDL_IBus_Quit;
SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
SDL_IME_Reset_Real = SDL_IBus_Reset;
SDL_IME_ProcessKeyEvent_Real = SDL_IBus_ProcessKeyEvent;
SDL_IME_UpdateTextRect_Real = SDL_IBus_UpdateTextRect;
SDL_IME_PumpEvents_Real = SDL_IBus_PumpEvents;
#endif

im_module = SDL_getenv("SDL_IM_MODULE");
if (im_module) {
if (SDL_strcmp(im_module, "fcitx") == 0) {
xmodifiers = SDL_getenv("XMODIFIERS");

/* See if fcitx IME support is being requested */
#ifdef HAVE_FCITX_FRONTEND_H
SDL_IME_Init_Real = SDL_Fcitx_Init;
SDL_IME_Quit_Real = SDL_Fcitx_Quit;
SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
SDL_IME_Reset_Real = SDL_Fcitx_Reset;
SDL_IME_ProcessKeyEvent_Real = SDL_Fcitx_ProcessKeyEvent;
SDL_IME_UpdateTextRect_Real = SDL_Fcitx_UpdateTextRect;
SDL_IME_PumpEvents_Real = SDL_Fcitx_PumpEvents;
#endif
}
if (!SDL_IME_Init_Real &&
((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
(!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
SDL_IME_Init_Real = SDL_Fcitx_Init;
SDL_IME_Quit_Real = SDL_Fcitx_Quit;
SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
SDL_IME_Reset_Real = SDL_Fcitx_Reset;
SDL_IME_ProcessKeyEvent_Real = SDL_Fcitx_ProcessKeyEvent;
SDL_IME_UpdateTextRect_Real = SDL_Fcitx_UpdateTextRect;
SDL_IME_PumpEvents_Real = SDL_Fcitx_PumpEvents;
}
#endif /* HAVE_FCITX_FRONTEND_H */

/* default to IBus */
#ifdef HAVE_IBUS_IBUS_H
if (!SDL_IME_Init_Real) {
SDL_IME_Init_Real = SDL_IBus_Init;
SDL_IME_Quit_Real = SDL_IBus_Quit;
SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
SDL_IME_Reset_Real = SDL_IBus_Reset;
SDL_IME_ProcessKeyEvent_Real = SDL_IBus_ProcessKeyEvent;
SDL_IME_UpdateTextRect_Real = SDL_IBus_UpdateTextRect;
SDL_IME_PumpEvents_Real = SDL_IBus_PumpEvents;
}
#endif /* HAVE_IBUS_IBUS_H */
}

SDL_bool
Expand Down
11 changes: 11 additions & 0 deletions src/video/x11/SDL_x11video.c
Expand Up @@ -397,6 +397,7 @@ X11_VideoInit(_THIS)
char *prev_xmods = X11_XSetLocaleModifiers(NULL);
const char *new_xmods = "";
const char *env_xmods = SDL_getenv("XMODIFIERS");
SDL_bool has_dbus_ime_support = SDL_FALSE;

if (prev_xmods) {
prev_xmods = SDL_strdup(prev_xmods);
Expand All @@ -406,7 +407,17 @@ X11_VideoInit(_THIS)
when it is used via XIM which causes issues. Prevent this by forcing
@im=none if XMODIFIERS contains @im=ibus. IBus can still be used via
the DBus implementation, which also has support for pre-editing. */
#ifdef HAVE_IBUS_IBUS_H
if (env_xmods && SDL_strstr(env_xmods, "@im=ibus") != NULL) {
has_dbus_ime_support = SDL_TRUE;
}
#endif
#ifdef HAVE_FCITX_FRONTEND_H
if (env_xmods && SDL_strstr(env_xmods, "@im=fcitx") != NULL) {
has_dbus_ime_support = SDL_TRUE;
}
#endif
if (has_dbus_ime_support) {
new_xmods = "@im=none";
}

Expand Down

0 comments on commit 42f85aa

Please sign in to comment.