mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-19 15:04:50 +02:00
Avoid unnecessary use of timers for resize_pty
This commit is contained in:
@@ -137,12 +137,10 @@ class Boss:
|
|||||||
self.window_id_map[window.id] = window
|
self.window_id_map[window.id] = window
|
||||||
wakeup()
|
wakeup()
|
||||||
|
|
||||||
def retry_resize_pty(self, window_id):
|
def resize_pty(self, window_id):
|
||||||
# In case the child has not yet been added in the child monitor
|
|
||||||
w = self.window_id_map.get(window_id)
|
w = self.window_id_map.get(window_id)
|
||||||
if w is not None:
|
if w is not None:
|
||||||
if not self.child_monitor.resize_pty(window_id, *w.current_pty_size):
|
self.child_monitor.resize_pty(window_id, *w.current_pty_size)
|
||||||
return 0.002 # re-add this timer
|
|
||||||
|
|
||||||
def on_child_death(self, window_id):
|
def on_child_death(self, window_id):
|
||||||
w = self.window_id_map.pop(window_id, None)
|
w = self.window_id_map.pop(window_id, None)
|
||||||
|
|||||||
@@ -366,20 +366,24 @@ resize_pty(ChildMonitor *self, PyObject *args) {
|
|||||||
#define resize_pty_doc "Resize the pty associated with the specified child"
|
#define resize_pty_doc "Resize the pty associated with the specified child"
|
||||||
unsigned long window_id;
|
unsigned long window_id;
|
||||||
struct winsize dim;
|
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;
|
if (!PyArg_ParseTuple(args, "kHHHH", &window_id, &dim.ws_row, &dim.ws_col, &dim.ws_xpixel, &dim.ws_ypixel)) return NULL;
|
||||||
children_mutex(lock);
|
children_mutex(lock);
|
||||||
for (size_t i = 0; i < self->count; i++) {
|
#define FIND(queue, count) { \
|
||||||
if (children[i].id == window_id) {
|
for (size_t i = 0; i < count; i++) { \
|
||||||
found = Py_True;
|
if (queue[i].id == window_id) { \
|
||||||
if (!pty_resize(children[i].fd, &dim)) PyErr_SetFromErrno(PyExc_OSError);
|
fd = queue[i].fd; \
|
||||||
break;
|
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);
|
children_mutex(unlock);
|
||||||
if (PyErr_Occurred()) return NULL;
|
if (PyErr_Occurred()) return NULL;
|
||||||
Py_INCREF(found);
|
Py_RETURN_NONE;
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ class Tab:
|
|||||||
window = Window(self, child, self.opts, self.args)
|
window = Window(self, child, self.opts, self.args)
|
||||||
if override_title is not None:
|
if override_title is not None:
|
||||||
window.title = window.override_title = override_title
|
window.title = window.override_title = override_title
|
||||||
|
# Must add child before laying out so that resize_pty succeeds
|
||||||
get_boss().add_child(window)
|
get_boss().add_child(window)
|
||||||
self.active_window_idx = self.current_layout.add_window(self.windows, window, self.active_window_idx)
|
self.active_window_idx = self.current_layout.add_window(self.windows, window, self.active_window_idx)
|
||||||
self.relayout_borders()
|
self.relayout_borders()
|
||||||
|
|||||||
@@ -86,9 +86,7 @@ class Window:
|
|||||||
max(0, new_geometry.right - new_geometry.left), max(0, new_geometry.bottom - new_geometry.top))
|
max(0, new_geometry.right - new_geometry.left), max(0, new_geometry.bottom - new_geometry.top))
|
||||||
self.char_grid.resize(new_geometry)
|
self.char_grid.resize(new_geometry)
|
||||||
self.needs_layout = False
|
self.needs_layout = False
|
||||||
timeout = boss.retry_resize_pty(self.id)
|
boss.resize_pty(self.id)
|
||||||
if timeout is not None:
|
|
||||||
boss.ui_timers.add(timeout, boss.retry_resize_pty, self.id)
|
|
||||||
else:
|
else:
|
||||||
self.char_grid.update_position(new_geometry)
|
self.char_grid.update_position(new_geometry)
|
||||||
self.geometry = new_geometry
|
self.geometry = new_geometry
|
||||||
|
|||||||
Reference in New Issue
Block a user