Use a struct for IME update events

Allows for easier extension in the future
This commit is contained in:
Kovid Goyal 2021-03-23 16:05:22 +05:30
parent a981b46ec9
commit 34d06fa3e9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
11 changed files with 45 additions and 26 deletions

View File

@ -1295,8 +1295,8 @@ is_ascii_control_char(char x) {
[[markedText mutableString] setString:@""]; [[markedText mutableString] setString:@""];
} }
void _glfwPlatformUpdateIMEState(_GLFWwindow *w, GLFWIMEUpdateState which, int a, int b, int c, int d) { void _glfwPlatformUpdateIMEState(_GLFWwindow *w, const GLFWIMEUpdateEvent *ev) {
[w->ns.view updateIMEStateFor: which left:(CGFloat)a top:(CGFloat)b cellWidth:(CGFloat)c cellHeight:(CGFloat)d]; [w->ns.view updateIMEStateFor: which left:(CGFloat)ev->cursor.left top:(CGFloat)ev->cursor.top cellWidth:(CGFloat)ev->cursor.width cellHeight:(CGFloat)ev->cursor.height];
} }
- (void)updateIMEStateFor:(GLFWIMEUpdateState)which - (void)updateIMEStateFor:(GLFWIMEUpdateState)which

20
glfw/glfw3.h vendored
View File

@ -1195,7 +1195,17 @@ typedef enum {
typedef enum { typedef enum {
GLFW_IME_UPDATE_FOCUS = 1, GLFW_IME_UPDATE_FOCUS = 1,
GLFW_IME_UPDATE_CURSOR_POSITION = 2 GLFW_IME_UPDATE_CURSOR_POSITION = 2
} GLFWIMEUpdateState; } GLFWIMEUpdateType;
typedef struct GLFWIMEUpdateEvent {
GLFWIMEUpdateType type;
const char *before_text, *at_text, *after_text;
bool focused;
struct {
int left, top, width, height;
} cursor;
} GLFWIMEUpdateEvent;
typedef struct GLFWkeyevent typedef struct GLFWkeyevent
{ {
@ -4545,16 +4555,12 @@ 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. * @param ev: 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 * @ingroup input
* @since Added in version 4.0 * @since Added in version 4.0
*/ */
GLFWAPI void glfwUpdateIMEState(GLFWwindow* window, GLFWIMEUpdateState which, int a, int b, int c, int d); GLFWAPI void glfwUpdateIMEState(GLFWwindow* window, const GLFWIMEUpdateEvent *ev);
/*! @brief Sets the mouse button callback. /*! @brief Sets the mouse button callback.

4
glfw/input.c vendored
View File

@ -1010,13 +1010,13 @@ GLFWAPI GLFWkeyboardfun glfwSetKeyboardCallback(GLFWwindow* handle, GLFWkeyboard
return cbfun; return cbfun;
} }
GLFWAPI void glfwUpdateIMEState(GLFWwindow* handle, GLFWIMEUpdateState which, int a, int b, int c, int d) { GLFWAPI void glfwUpdateIMEState(GLFWwindow* handle, const GLFWIMEUpdateEvent *ev) {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL); assert(window != NULL);
_GLFW_REQUIRE_INIT(); _GLFW_REQUIRE_INIT();
#if defined(_GLFW_X11) || defined(_GLFW_WAYLAND) || defined(_GLFW_COCOA) #if defined(_GLFW_X11) || defined(_GLFW_WAYLAND) || defined(_GLFW_COCOA)
_glfwPlatformUpdateIMEState(window, which, a, b, c, d); _glfwPlatformUpdateIMEState(window, ev);
#else #else
(void)window; (void)which; (void)a; (void)b; (void)c; (void)d; (void)window; (void)which; (void)a; (void)b; (void)c; (void)d;
#endif #endif

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, GLFWIMEUpdateState which, int a, int b, int c, int d); void _glfwPlatformUpdateIMEState(_GLFWwindow *w, const GLFWIMEUpdateEvent *ev);
void _glfwPlatformPollEvents(void); void _glfwPlatformPollEvents(void);
void _glfwPlatformWaitEvents(void); void _glfwPlatformWaitEvents(void);

4
glfw/wl_window.c vendored
View File

@ -2105,8 +2105,8 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
} }
void void
_glfwPlatformUpdateIMEState(_GLFWwindow *w, GLFWIMEUpdateState which, int a, int b, int c, int d) { _glfwPlatformUpdateIMEState(_GLFWwindow *w, const GLFWIMEUpdateEvent *ev) {
glfw_xkb_update_ime_state(w, &_glfw.wl.xkb, which, a, b, c, d); glfw_xkb_update_ime_state(w, &_glfw.wl.xkb, ev);
} }
static void static void

4
glfw/x11_window.c vendored
View File

@ -3085,8 +3085,8 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
} }
void void
_glfwPlatformUpdateIMEState(_GLFWwindow *w, GLFWIMEUpdateState which, int a, int b, int c, int d) { _glfwPlatformUpdateIMEState(_GLFWwindow *w, const GLFWIMEUpdateEvent *ev) {
glfw_xkb_update_ime_state(w, &_glfw.x11.xkb, which, a, b, c, d); glfw_xkb_update_ime_state(w, &_glfw.x11.xkb, ev);
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////

10
glfw/xkb_glfw.c vendored
View File

@ -555,16 +555,16 @@ format_xkb_mods(_GLFWXKBData *xkb, const char* name, xkb_mod_mask_t mods) {
} }
void void
glfw_xkb_update_ime_state(_GLFWwindow *w, _GLFWXKBData *xkb, GLFWIMEUpdateState which, int a, int b, int c, int d) { glfw_xkb_update_ime_state(_GLFWwindow *w, _GLFWXKBData *xkb, const GLFWIMEUpdateEvent *ev) {
int x = 0, y = 0; int x = 0, y = 0;
switch(which) { switch(ev->type) {
case GLFW_IME_UPDATE_FOCUS: case GLFW_IME_UPDATE_FOCUS:
glfw_ibus_set_focused(&xkb->ibus, a ? true : false); glfw_ibus_set_focused(&xkb->ibus, ev->focused);
break; break;
case GLFW_IME_UPDATE_CURSOR_POSITION: case GLFW_IME_UPDATE_CURSOR_POSITION:
_glfwPlatformGetWindowPos(w, &x, &y); _glfwPlatformGetWindowPos(w, &x, &y);
x += a; y += b; x += ev->cursor.left; y += ev->cursor.top;
glfw_ibus_set_cursor_geometry(&xkb->ibus, x, y, c, d); glfw_ibus_set_cursor_geometry(&xkb->ibus, x, y, ev->cursor.width, ev->cursor.height);
break; break;
} }
} }

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, GLFWIMEUpdateState which, int a, int b, int c, int d); void glfw_xkb_update_ime_state(_GLFWwindow *w, _GLFWXKBData *xkb, const GLFWIMEUpdateEvent *ev);
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);

14
kitty/glfw-wrapper.h generated
View File

@ -933,7 +933,17 @@ typedef enum {
typedef enum { typedef enum {
GLFW_IME_UPDATE_FOCUS = 1, GLFW_IME_UPDATE_FOCUS = 1,
GLFW_IME_UPDATE_CURSOR_POSITION = 2 GLFW_IME_UPDATE_CURSOR_POSITION = 2
} GLFWIMEUpdateState; } GLFWIMEUpdateType;
typedef struct GLFWIMEUpdateEvent {
GLFWIMEUpdateType type;
const char *before_text, *at_text, *after_text;
bool focused;
struct {
int left, top, width, height;
} cursor;
} GLFWIMEUpdateEvent;
typedef struct GLFWkeyevent typedef struct GLFWkeyevent
{ {
@ -1932,7 +1942,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*, GLFWIMEUpdateState, int, int, int, int); typedef void (*glfwUpdateIMEState_func)(GLFWwindow*, const GLFWIMEUpdateEvent*);
GFW_EXTERN glfwUpdateIMEState_func glfwUpdateIMEState_impl; GFW_EXTERN glfwUpdateIMEState_func glfwUpdateIMEState_impl;
#define glfwUpdateIMEState glfwUpdateIMEState_impl #define glfwUpdateIMEState glfwUpdateIMEState_impl

View File

@ -343,7 +343,8 @@ window_focus_callback(GLFWwindow *w, int focused) {
global_state.callback_os_window->cursor_blink_zero_time = now; global_state.callback_os_window->cursor_blink_zero_time = now;
if (is_window_ready_for_callbacks()) { if (is_window_ready_for_callbacks()) {
WINDOW_CALLBACK(on_focus, "O", focused ? Py_True : Py_False); WINDOW_CALLBACK(on_focus, "O", focused ? Py_True : Py_False);
glfwUpdateIMEState(global_state.callback_os_window->handle, 1, focused, 0, 0, 0); GLFWIMEUpdateEvent ev = { .type = GLFW_IME_UPDATE_FOCUS, .focused = focused };
glfwUpdateIMEState(global_state.callback_os_window->handle, &ev);
} }
request_tick_callback(); request_tick_callback();
global_state.callback_os_window = NULL; global_state.callback_os_window = NULL;

View File

@ -85,7 +85,9 @@ update_ime_position(OSWindow *os_window, Window* w, Screen *screen) {
unsigned int left = w->geometry.left, top = w->geometry.top; unsigned int left = w->geometry.left, top = w->geometry.top;
left += screen->cursor->x * cell_width; left += screen->cursor->x * cell_width;
top += screen->cursor->y * cell_height; top += screen->cursor->y * cell_height;
glfwUpdateIMEState(global_state.callback_os_window->handle, 2, left, top, cell_width, cell_height); GLFWIMEUpdateEvent ev = { .type = GLFW_IME_UPDATE_CURSOR_POSITION };
ev.cursor.left = left; ev.cursor.top = top; ev.cursor.width = cell_width; ev.cursor.height = cell_height;
glfwUpdateIMEState(global_state.callback_os_window->handle, &ev);
} }
void void