Use an enum for updateimestate as well

This commit is contained in:
Kovid Goyal 2021-03-23 10:52:11 +05:30
parent 84dcf8fd27
commit a981b46ec9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
9 changed files with 29 additions and 15 deletions

View File

@ -1295,11 +1295,11 @@ is_ascii_control_char(char x) {
[[markedText mutableString] setString:@""]; [[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]; [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 left:(CGFloat)left
top:(CGFloat)top top:(CGFloat)top
cellWidth:(CGFloat)cellWidth cellWidth:(CGFloat)cellWidth

15
glfw/glfw3.h vendored
View File

@ -1179,17 +1179,24 @@ typedef struct GLFWwindow GLFWwindow;
* @ingroup input * @ingroup input
*/ */
typedef struct GLFWcursor GLFWcursor; typedef struct GLFWcursor GLFWcursor;
typedef enum { typedef enum {
GLFW_RELEASE = 0, GLFW_RELEASE = 0,
GLFW_PRESS = 1, GLFW_PRESS = 1,
GLFW_REPEAT = 2 GLFW_REPEAT = 2
} GLFWKeyAction; } GLFWKeyAction;
typedef enum { typedef enum {
GLFW_IME_NONE, GLFW_IME_NONE,
GLFW_IME_PREEDIT_CHANGED, GLFW_IME_PREEDIT_CHANGED,
GLFW_IME_COMMIT_TEXT GLFW_IME_COMMIT_TEXT
} GLFWIMEState; } GLFWIMEState;
typedef enum {
GLFW_IME_UPDATE_FOCUS = 1,
GLFW_IME_UPDATE_CURSOR_POSITION = 2
} GLFWIMEUpdateState;
typedef struct GLFWkeyevent typedef struct GLFWkeyevent
{ {
// The [keyboard key](@ref keys) that was pressed or released. // 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 * Used to notify the IME system of changes in state such as focus gained/lost
* and text cursor position. * and text cursor position.
* *
* @param which: What data to notify. 1 means focus and 2 means cursor position. * @param which: What data to notify.
* @param a, b, c, d: Interpreted based on the value of which. When which is 1 * @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 2 * 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 * a, b, c, d are the cursor x, y, width and height values (in the window co-ordinate
* system). * system).
* *
* @ingroup input * @ingroup input
* @since Added in version 4.0 * @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. /*! @brief Sets the mouse button callback.

2
glfw/input.c vendored
View File

@ -1010,7 +1010,7 @@ GLFWAPI GLFWkeyboardfun glfwSetKeyboardCallback(GLFWwindow* handle, GLFWkeyboard
return cbfun; 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; _GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL); assert(window != NULL);

2
glfw/internal.h vendored
View File

@ -728,7 +728,7 @@ void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, bool enabled);
void _glfwPlatformSetWindowFloating(_GLFWwindow* window, bool enabled); void _glfwPlatformSetWindowFloating(_GLFWwindow* window, bool enabled);
void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, bool enabled); void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, bool enabled);
void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity); 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 _glfwPlatformPollEvents(void);
void _glfwPlatformWaitEvents(void); void _glfwPlatformWaitEvents(void);

2
glfw/wl_window.c vendored
View File

@ -2105,7 +2105,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
} }
void 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); glfw_xkb_update_ime_state(w, &_glfw.wl.xkb, which, a, b, c, d);
} }

2
glfw/x11_window.c vendored
View File

@ -3085,7 +3085,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
} }
void 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); glfw_xkb_update_ime_state(w, &_glfw.x11.xkb, which, a, b, c, d);
} }

6
glfw/xkb_glfw.c vendored
View File

@ -555,13 +555,13 @@ format_xkb_mods(_GLFWXKBData *xkb, const char* name, xkb_mod_mask_t mods) {
} }
void 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; int x = 0, y = 0;
switch(which) { switch(which) {
case 1: case GLFW_IME_UPDATE_FOCUS:
glfw_ibus_set_focused(&xkb->ibus, a ? true : false); glfw_ibus_set_focused(&xkb->ibus, a ? true : false);
break; break;
case 2: case GLFW_IME_UPDATE_CURSOR_POSITION:
_glfwPlatformGetWindowPos(w, &x, &y); _glfwPlatformGetWindowPos(w, &x, &y);
x += a; y += b; x += a; y += b;
glfw_ibus_set_cursor_geometry(&xkb->ibus, x, y, c, d); glfw_ibus_set_cursor_geometry(&xkb->ibus, x, y, c, d);

2
glfw/xkb_glfw.h vendored
View File

@ -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); 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); 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); 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); void glfw_xkb_key_from_ime(_GLFWIBUSKeyEvent *ev, bool handled_by_ime, bool failed);

9
kitty/glfw-wrapper.h generated
View File

@ -917,17 +917,24 @@ typedef struct GLFWwindow GLFWwindow;
* @ingroup input * @ingroup input
*/ */
typedef struct GLFWcursor GLFWcursor; typedef struct GLFWcursor GLFWcursor;
typedef enum { typedef enum {
GLFW_RELEASE = 0, GLFW_RELEASE = 0,
GLFW_PRESS = 1, GLFW_PRESS = 1,
GLFW_REPEAT = 2 GLFW_REPEAT = 2
} GLFWKeyAction; } GLFWKeyAction;
typedef enum { typedef enum {
GLFW_IME_NONE, GLFW_IME_NONE,
GLFW_IME_PREEDIT_CHANGED, GLFW_IME_PREEDIT_CHANGED,
GLFW_IME_COMMIT_TEXT GLFW_IME_COMMIT_TEXT
} GLFWIMEState; } GLFWIMEState;
typedef enum {
GLFW_IME_UPDATE_FOCUS = 1,
GLFW_IME_UPDATE_CURSOR_POSITION = 2
} GLFWIMEUpdateState;
typedef struct GLFWkeyevent typedef struct GLFWkeyevent
{ {
// The [keyboard key](@ref keys) that was pressed or released. // 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; GFW_EXTERN glfwSetKeyboardCallback_func glfwSetKeyboardCallback_impl;
#define glfwSetKeyboardCallback 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; GFW_EXTERN glfwUpdateIMEState_func glfwUpdateIMEState_impl;
#define glfwUpdateIMEState glfwUpdateIMEState_impl #define glfwUpdateIMEState glfwUpdateIMEState_impl