diff --git a/docs/intro.dox b/docs/intro.dox index 5cbd7eb0..449c8be0 100644 --- a/docs/intro.dox +++ b/docs/intro.dox @@ -143,6 +143,14 @@ __GLFW_X11_XCB_VULKAN_SURFACE__ specifies whether to prefer the the `VK_KHR_xlib_surface` extension. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This is ignored on other platforms. +@anchor GLFW_X11_ONTHESPOT_hint +__GLFW_X11_ONTHESPOT__ specifies whether to use on-the-spot input method style. +On X11 platform, over-the-spot style is used if this hint is `GLFW_FALSE`, +which is the default value. You can set `GLFW_TRUE` to use on-the-spot style +as with other platforms. However, on-the-spot style on X11 is unstable, so +it is recommended not to use this hint in normal cases. Possible values are +`GLFW_TRUE` and `GLFW_FALSE`. This is ignored on other platforms. Please see +@ref preedit for more information about IME support. @subsubsection init_hints_values Supported and default values @@ -154,6 +162,7 @@ Initialization hint | Default value | Supported v @ref GLFW_COCOA_CHDIR_RESOURCES | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` @ref GLFW_COCOA_MENUBAR | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` @ref GLFW_X11_XCB_VULKAN_SURFACE | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` +@ref GLFW_X11_ONTHESPOT | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE` @subsection platform Runtime platform selection diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 0f208a68..6fb925cd 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1287,6 +1287,11 @@ extern "C" { * X11 specific [init hint](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint). */ #define GLFW_X11_XCB_VULKAN_SURFACE 0x00052001 +/*! @brief X11 specific init hint. + * + * X11 specific [init hint](@ref GLFW_X11_ONTHESPOT_hint). + */ +#define GLFW_X11_ONTHESPOT 0x00052002 /*! @} */ /*! @addtogroup init diff --git a/src/init.c b/src/init.c index d07a492e..1d250dbb 100644 --- a/src/init.c +++ b/src/init.c @@ -61,6 +61,7 @@ static _GLFWinitconfig _glfwInitHints = }, { GLFW_TRUE, // X11 XCB Vulkan surface + GLFW_FALSE // X11 on-the-spot IM-style }, }; @@ -479,7 +480,10 @@ GLFWAPI void glfwInitHint(int hint, int value) case GLFW_X11_XCB_VULKAN_SURFACE: _glfwInitHints.x11.xcbVulkanSurface = value; return; - } + case GLFW_X11_ONTHESPOT: + _glfwInitHints.x11.onTheSpotIMStyle = value; + return; + } _glfwInputError(GLFW_INVALID_ENUM, "Invalid init hint 0x%08X", hint); diff --git a/src/internal.h b/src/internal.h index 56d6386b..f5d5043a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -385,6 +385,7 @@ struct _GLFWinitconfig } ns; struct { GLFWbool xcbVulkanSurface; + GLFWbool onTheSpotIMStyle; } x11; }; diff --git a/src/x11_init.c b/src/x11_init.c index a5e3af02..dcf5e658 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -440,14 +440,14 @@ static GLFWbool hasUsableInputMethodStyle(void) { GLFWbool found = GLFW_FALSE; XIMStyles* styles = NULL; - const char* imStyle = getenv("IM_STYLE"); if (XGetIMValues(_glfw.x11.im, XNQueryInputStyle, &styles, NULL) != NULL) return GLFW_FALSE; - _glfw.x11.imStyle = STYLE_OVERTHESPOT; - if (imStyle && strcmp(imStyle, "on-the-spot") == 0) + if (_glfw.hints.init.x11.onTheSpotIMStyle) _glfw.x11.imStyle = STYLE_ONTHESPOT; + else + _glfw.x11.imStyle = STYLE_OVERTHESPOT; for (unsigned int i = 0; i < styles->count_styles; i++) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 22219513..f28a53b6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,7 +32,7 @@ add_executable(cursor cursor.c ${GLAD_GL}) add_executable(empty WIN32 MACOSX_BUNDLE empty.c ${TINYCTHREAD} ${GLAD_GL}) add_executable(gamma WIN32 MACOSX_BUNDLE gamma.c ${GLAD_GL}) add_executable(icon WIN32 MACOSX_BUNDLE icon.c ${GLAD_GL}) -add_executable(input_text WIN32 MACOSX_BUNDLE input_text.c ${GLAD_GL}) +add_executable(input_text WIN32 MACOSX_BUNDLE input_text.c ${GETOPT} ${GLAD_GL}) add_executable(inputlag WIN32 MACOSX_BUNDLE inputlag.c ${GETOPT} ${GLAD_GL}) add_executable(joysticks WIN32 MACOSX_BUNDLE joysticks.c ${GLAD_GL}) add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GLAD_GL}) diff --git a/tests/input_text.c b/tests/input_text.c index 92af0b26..685a8282 100644 --- a/tests/input_text.c +++ b/tests/input_text.c @@ -70,6 +70,8 @@ #include #include +#include "getopt.h" + #if defined(FONTCONFIG_ENABLED) #include #endif @@ -103,6 +105,14 @@ static int currentIMEStatus = GLFW_FALSE; #define MAX_PREDIT_LEN 128 static char preeditBuf[MAX_PREDIT_LEN] = ""; +void usage(void) +{ + printf("Usage: input_text [-h] [-s]\n"); + printf("Options:\n"); + printf(" -s Use on-the-spot sytle on X11. This is ignored on other platforms.\n"); + printf(" -h Show this help\n"); +} + static size_t encode_utf8(char* s, unsigned int ch) { size_t count = 0; @@ -556,6 +566,21 @@ int main(int argc, char** argv) char boxBuffer[MAX_BUFFER_LEN] = "Input text here.\nここに入力してください。"; int boxLen = strlen(boxBuffer); int isAutoUpdatingPreeditPosEnabled = GLFW_TRUE; + int ch; + + while ((ch = getopt(argc, argv, "hs")) != -1) + { + switch (ch) + { + case 'h': + usage(); + exit(EXIT_SUCCESS); + + case 's': + glfwInitHint(GLFW_X11_ONTHESPOT, GLFW_TRUE); + break; + } + } if (!glfwInit()) exit(EXIT_FAILURE);