macOS: Fix IME position incorrect after moving OS window

This commit is contained in:
Kovid Goyal 2021-11-12 08:51:03 +05:30
parent 81babd29e7
commit 4ab5d97e9b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 18 additions and 2 deletions

View File

@ -169,6 +169,21 @@ blank_os_window(OSWindow *w) {
blank_canvas(w->is_semi_transparent ? w->background_opacity : 1.0f, color);
}
static void
window_pos_callback(GLFWwindow* window, int x UNUSED, int y UNUSED) {
if (!set_callback_window(window)) return;
#ifdef __APPLE__
// Apple needs IME position to be accurate before the next key event
OSWindow *osw = global_state.callback_os_window;
if (osw->is_focused && is_window_ready_for_callbacks()) {
Tab *tab = osw->tabs + osw->active_tab;
Window *w = tab->windows + tab->active_window;
if (w->render_data.screen) update_ime_position(w, w->render_data.screen);
}
#endif
global_state.callback_os_window = NULL;
}
static void
window_close_callback(GLFWwindow* window) {
if (!set_callback_window(window)) return;
@ -815,7 +830,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) {
if (logo.pixels && logo.width && logo.height) glfwSetWindowIcon(glfw_window, 1, &logo);
glfwSetCursor(glfw_window, standard_cursor);
update_os_window_viewport(w, false);
// missing pos callback
glfwSetWindowPosCallback(glfw_window, window_pos_callback);
// missing size callback
glfwSetWindowCloseCallback(glfw_window, window_close_callback);
glfwSetWindowRefreshCallback(glfw_window, refresh_callback);

View File

@ -79,7 +79,7 @@ active_window(void) {
return NULL;
}
static void
void
update_ime_position(Window* w, Screen *screen) {
unsigned int cell_width = global_state.callback_os_window->fonts_data->cell_width, cell_height = global_state.callback_os_window->fonts_data->cell_height;
unsigned int left = w->geometry.left, top = w->geometry.top;

View File

@ -322,3 +322,4 @@ void get_platform_dependent_config_values(void *glfw_window);
bool draw_window_title(OSWindow *window, const char *text, color_type fg, color_type bg, uint8_t *output_buf, size_t width, size_t height);
uint8_t* draw_single_ascii_char(const char ch, size_t *result_width, size_t *result_height);
bool is_os_window_fullscreen(OSWindow *);
void update_ime_position(Window* w, Screen *screen);