Cleanup previous PR
1) Fix a text_len leaking 2) No need to re-decode overlay_text 3) get_ime_cursor_position should not change the current global callback OS window
This commit is contained in:
parent
dba8d278cb
commit
5ce85292b7
@ -626,7 +626,7 @@ cursor_needs_render(Window *w) {
|
||||
static bool
|
||||
collect_cursor_info(CursorRenderInfo *ans, Window *w, monotonic_t now, OSWindow *os_window) {
|
||||
ScreenRenderData *rd = &w->render_data;
|
||||
Cursor *cursor;
|
||||
const Cursor *cursor;
|
||||
if (screen_is_overlay_active(rd->screen)) {
|
||||
// Do not force the cursor to be visible here for the sake of some programs that prefer it hidden
|
||||
cursor = &(rd->screen->overlay_line.original_line.cursor);
|
||||
|
||||
23
kitty/glfw.c
23
kitty/glfw.c
@ -187,17 +187,22 @@ update_os_window_references(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
set_callback_window(GLFWwindow *w) {
|
||||
global_state.callback_os_window = glfwGetWindowUserPointer(w);
|
||||
if (global_state.callback_os_window) return true;
|
||||
static OSWindow*
|
||||
os_window_for_glfw_window(GLFWwindow *w) {
|
||||
OSWindow *ans = glfwGetWindowUserPointer(w);
|
||||
if (ans != NULL) return ans;
|
||||
for (size_t i = 0; i < global_state.num_os_windows; i++) {
|
||||
if ((GLFWwindow*)(global_state.os_windows[i].handle) == w) {
|
||||
global_state.callback_os_window = global_state.os_windows + i;
|
||||
return true;
|
||||
return global_state.os_windows + i;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool
|
||||
set_callback_window(GLFWwindow *w) {
|
||||
global_state.callback_os_window = os_window_for_glfw_window(w);
|
||||
return global_state.callback_os_window != NULL;
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -511,9 +516,8 @@ void prepare_ime_position_update_event(OSWindow *osw, Window *w, Screen *screen,
|
||||
|
||||
static bool
|
||||
get_ime_cursor_position(GLFWwindow *glfw_window, GLFWIMEUpdateEvent *ev) {
|
||||
if (!set_callback_window(glfw_window)) return false;
|
||||
bool ans = false;
|
||||
OSWindow *osw = global_state.callback_os_window;
|
||||
OSWindow *osw = os_window_for_glfw_window(glfw_window);
|
||||
if (osw && osw->is_focused && is_window_ready_for_callbacks()) {
|
||||
Tab *tab = osw->tabs + osw->active_tab;
|
||||
Window *w = tab->windows + tab->active_window;
|
||||
@ -523,7 +527,6 @@ get_ime_cursor_position(GLFWwindow *glfw_window, GLFWIMEUpdateEvent *ev) {
|
||||
ans = true;
|
||||
}
|
||||
}
|
||||
global_state.callback_os_window = NULL;
|
||||
return ans;
|
||||
}
|
||||
|
||||
|
||||
@ -2732,7 +2732,7 @@ screen_update_overlay_text(Screen *self, const char *utf8_text) {
|
||||
if (!text) return;
|
||||
Py_XDECREF(self->overlay_line.overlay_text);
|
||||
// Calculate the total number of cells for initial overlay cursor position
|
||||
PyObject *text_len = wcswidth_std(NULL, text);
|
||||
DECREF_AFTER_FUNCTION PyObject *text_len = wcswidth_std(NULL, text);
|
||||
self->overlay_line.overlay_text = text;
|
||||
self->overlay_line.is_active = true;
|
||||
self->overlay_line.is_dirty = true;
|
||||
@ -2753,10 +2753,7 @@ screen_update_overlay_text(Screen *self, const char *utf8_text) {
|
||||
static void
|
||||
screen_draw_overlay_line(Screen *self) {
|
||||
if (!self->overlay_line.overlay_text) return;
|
||||
const char *utf8_text = PyUnicode_AsUTF8(self->overlay_line.overlay_text);
|
||||
if (!utf8_text || !utf8_text[0]) return;
|
||||
self->overlay_line.xnum = 0;
|
||||
uint32_t codepoint = 0; UTF8State state = UTF8_ACCEPT;
|
||||
bool orig_line_wrap_mode = self->modes.mDECAWM;
|
||||
bool orig_cursor_enable_mode = self->modes.mDECTCEM;
|
||||
bool orig_insert_replace_mode = self->modes.mIRM;
|
||||
@ -2770,16 +2767,13 @@ screen_draw_overlay_line(Screen *self) {
|
||||
self->cursor->y = self->overlay_line.ynum;
|
||||
self->overlay_line.xnum = 0;
|
||||
index_type before;
|
||||
while (*utf8_text) {
|
||||
switch(decode_utf8(&state, &codepoint, *(utf8_text++))) {
|
||||
case UTF8_ACCEPT:
|
||||
before = self->cursor->x;
|
||||
draw_codepoint(self, codepoint, false);
|
||||
self->overlay_line.xnum += self->cursor->x - before;
|
||||
break;
|
||||
case UTF8_REJECT:
|
||||
break;
|
||||
}
|
||||
const int kind = PyUnicode_KIND(self->overlay_line.overlay_text);
|
||||
const void *data = PyUnicode_DATA(self->overlay_line.overlay_text);
|
||||
const Py_ssize_t sz = PyUnicode_GET_LENGTH(self->overlay_line.overlay_text);
|
||||
for (Py_ssize_t pos = 0; pos < sz; pos++) {
|
||||
before = self->cursor->x;
|
||||
draw_codepoint(self, PyUnicode_READ(kind, data, pos), false);
|
||||
self->overlay_line.xnum += self->cursor->x - before;
|
||||
}
|
||||
self->overlay_line.cursor_x = self->cursor->x;
|
||||
self->cursor->reverse ^= true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user