diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 98c83604b..83c02dd31 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -824,6 +824,7 @@ close_all_windows() { static inline bool process_pending_closes(ChildMonitor *self) { + global_state.has_pending_closes = false; bool has_open_windows = false; for (size_t w = global_state.num_os_windows; w > 0; w--) { OSWindow *os_window = global_state.os_windows + w - 1; @@ -906,7 +907,8 @@ process_global_state(void *data) { #endif } report_reaped_pids(); - bool has_open_windows = process_pending_closes(self); + bool has_open_windows = true; + if (global_state.has_pending_closes) has_open_windows = process_pending_closes(self); if (has_open_windows) { if (maximum_wait >= 0) { if (maximum_wait == 0) request_tick_callback(); diff --git a/kitty/glfw.c b/kitty/glfw.c index 36bdc3c1b..e27fc2457 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -109,6 +109,7 @@ blank_os_window(OSWindow *w) { static void window_close_callback(GLFWwindow* window) { if (!set_callback_window(window)) return; + global_state.has_pending_closes = true; request_tick_callback(); global_state.callback_os_window = NULL; } @@ -713,8 +714,10 @@ application_quit_requested() { void request_application_quit() { - if (application_quit_canary) + if (application_quit_canary) { + global_state.has_pending_closes = true; glfwSetWindowShouldClose(application_quit_canary, true); + } } #endif @@ -913,6 +916,7 @@ wakeup_main_loop() { void mark_os_window_for_close(OSWindow* w, bool yes) { + global_state.has_pending_closes = true; glfwSetWindowShouldClose(w->handle, yes); } @@ -988,26 +992,6 @@ set_primary_selection(PyObject UNUSED *self, PyObject *args) { Py_RETURN_NONE; } -static PyObject* -os_window_should_close(PyObject UNUSED *self, PyObject *args) { - int q = -1001; - id_type os_window_id; - if (!PyArg_ParseTuple(args, "K|i", &os_window_id, &q)) return NULL; - for (size_t i = 0; i < global_state.num_os_windows; i++) { - OSWindow *w = global_state.os_windows + i; - if (w->id == os_window_id) { - if (q == -1001) { - if (should_os_window_close(w)) Py_RETURN_TRUE; - Py_RETURN_FALSE; - } - glfwSetWindowShouldClose(w->handle, q ? GLFW_TRUE : GLFW_FALSE); - Py_RETURN_NONE; - } - } - PyErr_SetString(PyExc_ValueError, "no such OSWindow"); - return NULL; -} - static PyObject* os_window_swap_buffers(PyObject UNUSED *self, PyObject *args) { id_type os_window_id; @@ -1167,7 +1151,6 @@ static PyMethodDef module_methods[] = { METHODB(toggle_fullscreen, METH_NOARGS), METHODB(change_os_window_state, METH_VARARGS), METHODB(glfw_window_hint, METH_VARARGS), - METHODB(os_window_should_close, METH_VARARGS), METHODB(os_window_swap_buffers, METH_VARARGS), METHODB(get_primary_selection, METH_NOARGS), METHODB(x11_display, METH_NOARGS), diff --git a/kitty/state.h b/kitty/state.h index 569397128..84862ec07 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -151,7 +151,7 @@ typedef struct { bool is_wayland; bool has_render_frames; bool debug_gl, debug_font_fallback; - bool has_pending_resizes; + bool has_pending_resizes, has_pending_closes; bool in_sequence_mode; bool tab_bar_hidden; double font_sz_in_pts;