Fixed building and using fcitx IME support on Linux

This commit is contained in:
Sam Lantinga 2016-10-08 11:30:07 -07:00
parent 27d4f09929
commit 42f85aa29e
4 changed files with 44 additions and 28 deletions

View File

@ -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 \ libtool libasound2-dev libpulse-dev libaudio-dev libx11-dev libxext-dev \
libxrandr-dev libxcursor-dev libxi-dev libxinerama-dev libxxf86vm-dev \ libxrandr-dev libxcursor-dev libxi-dev libxinerama-dev libxxf86vm-dev \
libxss-dev libgl1-mesa-dev libesd0-dev libdbus-1-dev libudev-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" Ubuntu 16.04 can also add "libwayland-dev libxkbcommon-dev wayland-protocols"
to that command line for Wayland support. to that command line for Wayland support.

View File

@ -62,7 +62,7 @@ static int
GetDisplayNumber() GetDisplayNumber()
{ {
const char *display = SDL_getenv("DISPLAY"); const char *display = SDL_getenv("DISPLAY");
const char *p = NULL;; const char *p = NULL;
int number = 0; int number = 0;
if (display == NULL) if (display == NULL)

View File

@ -43,40 +43,44 @@ static void
InitIME() InitIME()
{ {
static SDL_bool inited = SDL_FALSE; 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) if (inited == SDL_TRUE)
return ; return;
inited = SDL_TRUE; 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"); im_module = SDL_getenv("SDL_IM_MODULE");
if (im_module) { xmodifiers = SDL_getenv("XMODIFIERS");
if (SDL_strcmp(im_module, "fcitx") == 0) {
/* See if fcitx IME support is being requested */
#ifdef HAVE_FCITX_FRONTEND_H #ifdef HAVE_FCITX_FRONTEND_H
SDL_IME_Init_Real = SDL_Fcitx_Init; if (!SDL_IME_Init_Real &&
SDL_IME_Quit_Real = SDL_Fcitx_Quit; ((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus; (!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
SDL_IME_Reset_Real = SDL_Fcitx_Reset; SDL_IME_Init_Real = SDL_Fcitx_Init;
SDL_IME_ProcessKeyEvent_Real = SDL_Fcitx_ProcessKeyEvent; SDL_IME_Quit_Real = SDL_Fcitx_Quit;
SDL_IME_UpdateTextRect_Real = SDL_Fcitx_UpdateTextRect; SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
SDL_IME_PumpEvents_Real = SDL_Fcitx_PumpEvents; SDL_IME_Reset_Real = SDL_Fcitx_Reset;
#endif 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 SDL_bool

View File

@ -397,6 +397,7 @@ X11_VideoInit(_THIS)
char *prev_xmods = X11_XSetLocaleModifiers(NULL); char *prev_xmods = X11_XSetLocaleModifiers(NULL);
const char *new_xmods = ""; const char *new_xmods = "";
const char *env_xmods = SDL_getenv("XMODIFIERS"); const char *env_xmods = SDL_getenv("XMODIFIERS");
SDL_bool has_dbus_ime_support = SDL_FALSE;
if (prev_xmods) { if (prev_xmods) {
prev_xmods = SDL_strdup(prev_xmods); prev_xmods = SDL_strdup(prev_xmods);
@ -406,7 +407,17 @@ X11_VideoInit(_THIS)
when it is used via XIM which causes issues. Prevent this by forcing 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 @im=none if XMODIFIERS contains @im=ibus. IBus can still be used via
the DBus implementation, which also has support for pre-editing. */ 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) { 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"; new_xmods = "@im=none";
} }