Fixed building and using fcitx IME support on Linux
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
diff --git a/docs/README-linux.md b/docs/README-linux.md
index f676727..30c5efc 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 20be9f0..05361ff 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 ac959ea..e33fa7d 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 66a1c26..724b5fb 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";
}