From 42f85aa29e11d9c2c1cf424fd40913415e046c3c Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 8 Oct 2016 11:30:07 -0700 Subject: [PATCH] Fixed building and using fcitx IME support on Linux --- docs/README-linux.md | 3 +- src/core/linux/SDL_fcitx.c | 2 +- src/core/linux/SDL_ime.c | 56 +++++++++++++++++++----------------- src/video/x11/SDL_x11video.c | 11 +++++++ 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/docs/README-linux.md b/docs/README-linux.md index f676727e1..30c5efcf9 100644 --- a/docs/README-linux.md +++ b/docs/README-linux.md @@ -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. diff --git a/src/core/linux/SDL_fcitx.c b/src/core/linux/SDL_fcitx.c index 20be9f0d6..05361fff2 100644 --- a/src/core/linux/SDL_fcitx.c +++ b/src/core/linux/SDL_fcitx.c @@ -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) diff --git a/src/core/linux/SDL_ime.c b/src/core/linux/SDL_ime.c index ac959ea60..e33fa7d4b 100644 --- a/src/core/linux/SDL_ime.c +++ b/src/core/linux/SDL_ime.c @@ -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 diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 66a1c2679..724b5fb38 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -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); @@ -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"; }