diff --git a/kitty/child.py b/kitty/child.py index 4e115fa83..32d429f28 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -10,6 +10,7 @@ import signal from threading import Thread from .constants import terminfo_dir +import kitty.fast_data_types as fast_data_types def remove_cloexec(fd): @@ -33,6 +34,7 @@ class Child: self.forked = True master, slave = os.openpty() # Note that master and slave are in blocking mode remove_cloexec(slave) + self.set_iutf8(fd=master) stdin, self.stdin = self.stdin, None if stdin is not None: stdin_read_fd, stdin_write_fd = os.pipe() @@ -79,6 +81,16 @@ class Child: if self.child_fd is not None: fcntl.ioctl(self.child_fd, termios.TIOCSWINSZ, struct.pack('4H', h, w, ww, wh)) + def set_iutf8(self, on=True, fd=None): + fd = fd or self.child_fd + if fd is not None and hasattr(fast_data_types, 'IUTF8'): + attrs = termios.tcgetattr(fd) + if on: + attrs[0] |= fast_data_types.IUTF8 + else: + attrs[0] &= ~fast_data_types.IUTF8 + termios.tcsetattr(fd, termios.TCSANOW, attrs) + def hangup(self): if self.pid is not None: pid, self.pid = self.pid, None diff --git a/kitty/data-types.c b/kitty/data-types.c index cf36f728e..7ffbc2a69 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -56,6 +56,8 @@ static struct PyModuleDef module = { .m_methods = module_methods }; +#include + PyMODINIT_FUNC PyInit_fast_data_types(void) { PyObject *m; @@ -105,6 +107,9 @@ PyInit_fast_data_types(void) { PyModule_AddIntMacro(m, NORMAL_PROTOCOL); PyModule_AddIntMacro(m, URXVT_PROTOCOL); PyModule_AddIntMacro(m, UTF8_PROTOCOL); +#ifdef IUTF8 + PyModule_AddIntMacro(m, IUTF8); +#endif } return m; diff --git a/kitty/screen.c b/kitty/screen.c index 41a61d93c..ce56172cb 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -860,6 +860,9 @@ void screen_erase_characters(Screen *self, unsigned int count) { void screen_use_latin1(Screen *self, bool on) { self->use_latin1 = on; self->utf8_state = 0; self->utf8_codepoint = 0; + PyObject_CallMethod(self->callbacks, "use_utf8", "O", on ? Py_False : Py_True); + if (PyErr_Occurred()) PyErr_Print(); + PyErr_Clear(); } void diff --git a/kitty/window.py b/kitty/window.py index c49d9c8bb..1b6f2b9a1 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -120,6 +120,9 @@ class Window: self.start_visual_bell_at = monotonic() glfw_post_empty_event() + def use_utf8(self, on): + self.child.set_iutf8(on) + def update_screen(self): self.char_grid.update_cell_data() glfw_post_empty_event()