From c1cb4df9d2dcd8605e19fab2e30cbee93bea66a9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 12 Sep 2017 13:35:02 +0530 Subject: [PATCH] Avoid unnecessary use of timers for resize_pty --- kitty/boss.py | 6 ++---- kitty/child-monitor.c | 24 ++++++++++++++---------- kitty/tabs.py | 1 + kitty/window.py | 4 +--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 0415577a3..9ec62c466 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -137,12 +137,10 @@ class Boss: self.window_id_map[window.id] = window wakeup() - def retry_resize_pty(self, window_id): - # In case the child has not yet been added in the child monitor + def resize_pty(self, window_id): w = self.window_id_map.get(window_id) if w is not None: - if not self.child_monitor.resize_pty(window_id, *w.current_pty_size): - return 0.002 # re-add this timer + self.child_monitor.resize_pty(window_id, *w.current_pty_size) def on_child_death(self, window_id): w = self.window_id_map.pop(window_id, None) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 4e6982223..b52886035 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -366,20 +366,24 @@ resize_pty(ChildMonitor *self, PyObject *args) { #define resize_pty_doc "Resize the pty associated with the specified child" unsigned long window_id; struct winsize dim; - PyObject *found = Py_False; + int fd = -1; if (!PyArg_ParseTuple(args, "kHHHH", &window_id, &dim.ws_row, &dim.ws_col, &dim.ws_xpixel, &dim.ws_ypixel)) return NULL; children_mutex(lock); - for (size_t i = 0; i < self->count; i++) { - if (children[i].id == window_id) { - found = Py_True; - if (!pty_resize(children[i].fd, &dim)) PyErr_SetFromErrno(PyExc_OSError); - break; - } - } +#define FIND(queue, count) { \ + for (size_t i = 0; i < count; i++) { \ + if (queue[i].id == window_id) { \ + fd = queue[i].fd; \ + break; \ + } \ + }} + FIND(children, self->count); + if (fd == -1) FIND(add_queue, add_queue_count); + if (fd != -1) { + if (!pty_resize(fd, &dim)) PyErr_SetFromErrno(PyExc_OSError); + } else fprintf(stderr, "Failed to send resize signal to child with id: %lu (children count: %u) (add queue: %lu)\n", window_id, self->count, add_queue_count); children_mutex(unlock); if (PyErr_Occurred()) return NULL; - Py_INCREF(found); - return found; + Py_RETURN_NONE; } bool diff --git a/kitty/tabs.py b/kitty/tabs.py index 6c5a7e65f..4481f1f28 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -119,6 +119,7 @@ class Tab: window = Window(self, child, self.opts, self.args) if override_title is not None: window.title = window.override_title = override_title + # Must add child before laying out so that resize_pty succeeds get_boss().add_child(window) self.active_window_idx = self.current_layout.add_window(self.windows, window, self.active_window_idx) self.relayout_borders() diff --git a/kitty/window.py b/kitty/window.py index 7d3acb53b..7607c1b05 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -86,9 +86,7 @@ class Window: max(0, new_geometry.right - new_geometry.left), max(0, new_geometry.bottom - new_geometry.top)) self.char_grid.resize(new_geometry) self.needs_layout = False - timeout = boss.retry_resize_pty(self.id) - if timeout is not None: - boss.ui_timers.add(timeout, boss.retry_resize_pty, self.id) + boss.resize_pty(self.id) else: self.char_grid.update_position(new_geometry) self.geometry = new_geometry