Avoid unnecessary use of timers for resize_pty

This commit is contained in:
Kovid Goyal 2017-09-12 13:35:02 +05:30
parent 367ffb602c
commit c1cb4df9d2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 18 additions and 17 deletions

View File

@ -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)

View File

@ -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

View File

@ -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()

View File

@ -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