mirror of
https://github.com/glfw/glfw.git
synced 2025-06-14 11:42:16 +00:00
X11: Use GLFW_X11_ONTHESPOT of glfwInitHint to change on-the-spot
GLFW has the function `glfwInitHint` for setting initialization parameters. So use this instead of environmental variable.
This commit is contained in:
parent
cacb1e8222
commit
dc953898cc
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -385,6 +385,7 @@ struct _GLFWinitconfig
|
||||
} ns;
|
||||
struct {
|
||||
GLFWbool xcbVulkanSurface;
|
||||
GLFWbool onTheSpotIMStyle;
|
||||
} x11;
|
||||
};
|
||||
|
||||
|
@ -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++)
|
||||
{
|
||||
|
@ -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})
|
||||
|
@ -70,6 +70,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
#if defined(FONTCONFIG_ENABLED)
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#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);
|
||||
|
Loading…
Reference in New Issue
Block a user