diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 45734e747..afed53938 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -1295,11 +1295,11 @@ - (void)unmarkText [[markedText mutableString] setString:@""]; } -void _glfwPlatformUpdateIMEState(_GLFWwindow *w, int which, int a, int b, int c, int d) { +void _glfwPlatformUpdateIMEState(_GLFWwindow *w, GLFWIMEUpdateState which, int a, int b, int c, int d) { [w->ns.view updateIMEStateFor: which left:(CGFloat)a top:(CGFloat)b cellWidth:(CGFloat)c cellHeight:(CGFloat)d]; } -- (void)updateIMEStateFor:(int)which +- (void)updateIMEStateFor:(GLFWIMEUpdateState)which left:(CGFloat)left top:(CGFloat)top cellWidth:(CGFloat)cellWidth diff --git a/glfw/glfw3.h b/glfw/glfw3.h index cbfa60830..18518e85a 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -1179,17 +1179,24 @@ typedef struct GLFWwindow GLFWwindow; * @ingroup input */ typedef struct GLFWcursor GLFWcursor; + typedef enum { GLFW_RELEASE = 0, GLFW_PRESS = 1, GLFW_REPEAT = 2 } GLFWKeyAction; + typedef enum { GLFW_IME_NONE, GLFW_IME_PREEDIT_CHANGED, GLFW_IME_COMMIT_TEXT } GLFWIMEState; +typedef enum { + GLFW_IME_UPDATE_FOCUS = 1, + GLFW_IME_UPDATE_CURSOR_POSITION = 2 +} GLFWIMEUpdateState; + typedef struct GLFWkeyevent { // The [keyboard key](@ref keys) that was pressed or released. @@ -4538,16 +4545,16 @@ GLFWAPI GLFWkeyboardfun glfwSetKeyboardCallback(GLFWwindow* window, GLFWkeyboard * Used to notify the IME system of changes in state such as focus gained/lost * and text cursor position. * - * @param which: What data to notify. 1 means focus and 2 means cursor position. - * @param a, b, c, d: Interpreted based on the value of which. When which is 1 - * a is interpreted as a boolean indicating focus gained/lost. When which is 2 + * @param which: What data to notify. + * @param a, b, c, d: Interpreted based on the value of which. When which is GLFW_IME_UPDATE_FOCUS + * a is interpreted as a boolean indicating focus gained/lost. When which is GLFW_IME_UPDATE_CURSOR_POSITION * a, b, c, d are the cursor x, y, width and height values (in the window co-ordinate * system). * * @ingroup input * @since Added in version 4.0 */ -GLFWAPI void glfwUpdateIMEState(GLFWwindow* window, int which, int a, int b, int c, int d); +GLFWAPI void glfwUpdateIMEState(GLFWwindow* window, GLFWIMEUpdateState which, int a, int b, int c, int d); /*! @brief Sets the mouse button callback. diff --git a/glfw/input.c b/glfw/input.c index c6a7569e6..7ba7922df 100644 --- a/glfw/input.c +++ b/glfw/input.c @@ -1010,7 +1010,7 @@ GLFWAPI GLFWkeyboardfun glfwSetKeyboardCallback(GLFWwindow* handle, GLFWkeyboard return cbfun; } -GLFWAPI void glfwUpdateIMEState(GLFWwindow* handle, int which, int a, int b, int c, int d) { +GLFWAPI void glfwUpdateIMEState(GLFWwindow* handle, GLFWIMEUpdateState which, int a, int b, int c, int d) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); diff --git a/glfw/internal.h b/glfw/internal.h index 58edb4ce9..88076bed1 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -728,7 +728,7 @@ void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, bool enabled); void _glfwPlatformSetWindowFloating(_GLFWwindow* window, bool enabled); void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, bool enabled); void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity); -void _glfwPlatformUpdateIMEState(_GLFWwindow *w, int which, int a, int b, int c, int d); +void _glfwPlatformUpdateIMEState(_GLFWwindow *w, GLFWIMEUpdateState which, int a, int b, int c, int d); void _glfwPlatformPollEvents(void); void _glfwPlatformWaitEvents(void); diff --git a/glfw/wl_window.c b/glfw/wl_window.c index c3b897602..b3eb96a59 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -2105,7 +2105,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, } void -_glfwPlatformUpdateIMEState(_GLFWwindow *w, int which, int a, int b, int c, int d) { +_glfwPlatformUpdateIMEState(_GLFWwindow *w, GLFWIMEUpdateState which, int a, int b, int c, int d) { glfw_xkb_update_ime_state(w, &_glfw.wl.xkb, which, a, b, c, d); } diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 1389e171a..e7d6149df 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -3085,7 +3085,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, } void -_glfwPlatformUpdateIMEState(_GLFWwindow *w, int which, int a, int b, int c, int d) { +_glfwPlatformUpdateIMEState(_GLFWwindow *w, GLFWIMEUpdateState which, int a, int b, int c, int d) { glfw_xkb_update_ime_state(w, &_glfw.x11.xkb, which, a, b, c, d); } diff --git a/glfw/xkb_glfw.c b/glfw/xkb_glfw.c index 314f10eb0..47b16d5a0 100644 --- a/glfw/xkb_glfw.c +++ b/glfw/xkb_glfw.c @@ -555,13 +555,13 @@ format_xkb_mods(_GLFWXKBData *xkb, const char* name, xkb_mod_mask_t mods) { } void -glfw_xkb_update_ime_state(_GLFWwindow *w, _GLFWXKBData *xkb, int which, int a, int b, int c, int d) { +glfw_xkb_update_ime_state(_GLFWwindow *w, _GLFWXKBData *xkb, GLFWIMEUpdateState which, int a, int b, int c, int d) { int x = 0, y = 0; switch(which) { - case 1: + case GLFW_IME_UPDATE_FOCUS: glfw_ibus_set_focused(&xkb->ibus, a ? true : false); break; - case 2: + case GLFW_IME_UPDATE_CURSOR_POSITION: _glfwPlatformGetWindowPos(w, &x, &y); x += a; y += b; glfw_ibus_set_cursor_geometry(&xkb->ibus, x, y, c, d); diff --git a/glfw/xkb_glfw.h b/glfw/xkb_glfw.h index 39b74c851..68d7ccd18 100644 --- a/glfw/xkb_glfw.h +++ b/glfw/xkb_glfw.h @@ -92,5 +92,5 @@ const char* glfw_xkb_keysym_name(xkb_keysym_t sym); xkb_keysym_t glfw_xkb_sym_for_key(uint32_t key); void glfw_xkb_handle_key_event(_GLFWwindow *window, _GLFWXKBData *xkb, xkb_keycode_t keycode, int action); int glfw_xkb_keysym_from_name(const char *name, bool case_sensitive); -void glfw_xkb_update_ime_state(_GLFWwindow *w, _GLFWXKBData *xkb, int which, int a, int b, int c, int d); +void glfw_xkb_update_ime_state(_GLFWwindow *w, _GLFWXKBData *xkb, GLFWIMEUpdateState which, int a, int b, int c, int d); void glfw_xkb_key_from_ime(_GLFWIBUSKeyEvent *ev, bool handled_by_ime, bool failed); diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index bcb40a0bc..a5856b1ec 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -917,17 +917,24 @@ typedef struct GLFWwindow GLFWwindow; * @ingroup input */ typedef struct GLFWcursor GLFWcursor; + typedef enum { GLFW_RELEASE = 0, GLFW_PRESS = 1, GLFW_REPEAT = 2 } GLFWKeyAction; + typedef enum { GLFW_IME_NONE, GLFW_IME_PREEDIT_CHANGED, GLFW_IME_COMMIT_TEXT } GLFWIMEState; +typedef enum { + GLFW_IME_UPDATE_FOCUS = 1, + GLFW_IME_UPDATE_CURSOR_POSITION = 2 +} GLFWIMEUpdateState; + typedef struct GLFWkeyevent { // The [keyboard key](@ref keys) that was pressed or released. @@ -1925,7 +1932,7 @@ typedef GLFWkeyboardfun (*glfwSetKeyboardCallback_func)(GLFWwindow*, GLFWkeyboar GFW_EXTERN glfwSetKeyboardCallback_func glfwSetKeyboardCallback_impl; #define glfwSetKeyboardCallback glfwSetKeyboardCallback_impl -typedef void (*glfwUpdateIMEState_func)(GLFWwindow*, int, int, int, int, int); +typedef void (*glfwUpdateIMEState_func)(GLFWwindow*, GLFWIMEUpdateState, int, int, int, int); GFW_EXTERN glfwUpdateIMEState_func glfwUpdateIMEState_impl; #define glfwUpdateIMEState glfwUpdateIMEState_impl