diff --git a/kitty/boss.py b/kitty/boss.py index 99ef36bf1..95fd4cf34 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -27,9 +27,9 @@ from .constants import ( appname, config_dir, is_macos, kitty_exe, supports_primary_selection ) from .fast_data_types import ( - ChildMonitor, background_opacity_of, change_background_opacity, - change_os_window_state, cocoa_set_menubar_title, create_os_window, - current_os_window, destroy_global_data, focus_os_window, + NO_CLOSE_REQUESTED, ChildMonitor, background_opacity_of, + change_background_opacity, change_os_window_state, cocoa_set_menubar_title, + create_os_window, current_os_window, destroy_global_data, focus_os_window, get_clipboard_string, global_font_size, mark_os_window_for_close, os_window_font_size, patch_global_colors, safe_pipe, set_background_image, set_boss, set_clipboard_string, set_in_sequence_mode, thread_write, @@ -745,6 +745,8 @@ class Boss: def handle_close_os_window_confirmation(self, os_window_id: int, data: Dict[str, Any], *a: Any) -> None: if data['response'] == 'y': mark_os_window_for_close(os_window_id) + else: + mark_os_window_for_close(os_window_id, NO_CLOSE_REQUESTED) def on_os_window_closed(self, os_window_id: int, viewport_width: int, viewport_height: int) -> None: self.cached_values['window-size'] = viewport_width, viewport_height diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 6c89d3bb2..a66ab2163 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -869,12 +869,15 @@ process_pending_closes(ChildMonitor *self) { has_open_windows = true; break; case CONFIRMABLE_CLOSE_REQUESTED: - os_window->close_request = NO_CLOSE_REQUESTED; + os_window->close_request = CLOSE_BEING_CONFIRMED; call_boss(confirm_os_window_close, "K", os_window->id); if (os_window->close_request == IMPERATIVE_CLOSE_REQUESTED) { close_os_window(self, os_window); } else has_open_windows = true; break; + case CLOSE_BEING_CONFIRMED: + has_open_windows = true; + break; case IMPERATIVE_CLOSE_REQUESTED: close_os_window(self, os_window); break; diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 1b129d7a2..f7457aa3a 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -10,6 +10,8 @@ from kitty.options_stub import Options # Constants {{{ KITTY_VCS_REV: str +NO_CLOSE_REQUESTED: int +IMPERATIVE_CLOSE_REQUESTED: int ERROR_PREFIX: str GLSL_VERSION: int GLFW_IBEAM_CURSOR: int @@ -706,7 +708,7 @@ def cocoa_get_lang() -> Optional[str]: pass -def mark_os_window_for_close(os_window_id: int, yes: bool = True) -> bool: +def mark_os_window_for_close(os_window_id: int, cr_type: int = 2) -> bool: pass diff --git a/kitty/glfw.c b/kitty/glfw.c index 6345b2535..9f4d14842 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -152,12 +152,12 @@ blank_os_window(OSWindow *w) { static void window_close_callback(GLFWwindow* window) { if (!set_callback_window(window)) return; - global_state.has_pending_closes = true; - if (global_state.callback_os_window->close_request < CONFIRMABLE_CLOSE_REQUESTED) { + if (global_state.callback_os_window->close_request == NO_CLOSE_REQUESTED) { global_state.callback_os_window->close_request = CONFIRMABLE_CLOSE_REQUESTED; + global_state.has_pending_closes = true; + request_tick_callback(); } glfwSetWindowShouldClose(window, false); - request_tick_callback(); global_state.callback_os_window = NULL; } diff --git a/kitty/state.c b/kitty/state.c index 1f3e90a11..5581f801d 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -1190,6 +1190,8 @@ init_state(PyObject *module) { if (PyStructSequence_InitType2(&RegionType, ®ion_desc) != 0) return false; Py_INCREF((PyObject *) &RegionType); PyModule_AddObject(module, "Region", (PyObject *) &RegionType); + PyModule_AddIntConstant(module, "IMPERATIVE_CLOSE_REQUESTED", IMPERATIVE_CLOSE_REQUESTED); + PyModule_AddIntConstant(module, "NO_CLOSE_REQUESTED", NO_CLOSE_REQUESTED); if (Py_AtExit(finalize) != 0) { PyErr_SetString(PyExc_RuntimeError, "Failed to register the state at exit handler"); return false; diff --git a/kitty/state.h b/kitty/state.h index 5a6fac4bf..74e9aa7f1 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -139,7 +139,7 @@ typedef struct { } OSWindowGeometry; enum RENDER_STATE { RENDER_FRAME_NOT_REQUESTED, RENDER_FRAME_REQUESTED, RENDER_FRAME_READY }; -typedef enum { NO_CLOSE_REQUESTED, CONFIRMABLE_CLOSE_REQUESTED, IMPERATIVE_CLOSE_REQUESTED } CloseRequest; +typedef enum { NO_CLOSE_REQUESTED, CONFIRMABLE_CLOSE_REQUESTED, CLOSE_BEING_CONFIRMED, IMPERATIVE_CLOSE_REQUESTED } CloseRequest; typedef struct { monotonic_t last_resize_event_at;