Allow only a single OS window close confirmation per OS window

This commit is contained in:
Kovid Goyal 2020-05-18 13:56:19 +05:30
parent 3d2cb37af0
commit 1cf0a8b78e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 18 additions and 9 deletions

View File

@ -27,9 +27,9 @@ from .constants import (
appname, config_dir, is_macos, kitty_exe, supports_primary_selection appname, config_dir, is_macos, kitty_exe, supports_primary_selection
) )
from .fast_data_types import ( from .fast_data_types import (
ChildMonitor, background_opacity_of, change_background_opacity, NO_CLOSE_REQUESTED, ChildMonitor, background_opacity_of,
change_os_window_state, cocoa_set_menubar_title, create_os_window, change_background_opacity, change_os_window_state, cocoa_set_menubar_title,
current_os_window, destroy_global_data, focus_os_window, create_os_window, current_os_window, destroy_global_data, focus_os_window,
get_clipboard_string, global_font_size, mark_os_window_for_close, get_clipboard_string, global_font_size, mark_os_window_for_close,
os_window_font_size, patch_global_colors, safe_pipe, set_background_image, os_window_font_size, patch_global_colors, safe_pipe, set_background_image,
set_boss, set_clipboard_string, set_in_sequence_mode, thread_write, 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: def handle_close_os_window_confirmation(self, os_window_id: int, data: Dict[str, Any], *a: Any) -> None:
if data['response'] == 'y': if data['response'] == 'y':
mark_os_window_for_close(os_window_id) 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: 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 self.cached_values['window-size'] = viewport_width, viewport_height

View File

@ -869,12 +869,15 @@ process_pending_closes(ChildMonitor *self) {
has_open_windows = true; has_open_windows = true;
break; break;
case CONFIRMABLE_CLOSE_REQUESTED: 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); call_boss(confirm_os_window_close, "K", os_window->id);
if (os_window->close_request == IMPERATIVE_CLOSE_REQUESTED) { if (os_window->close_request == IMPERATIVE_CLOSE_REQUESTED) {
close_os_window(self, os_window); close_os_window(self, os_window);
} else has_open_windows = true; } else has_open_windows = true;
break; break;
case CLOSE_BEING_CONFIRMED:
has_open_windows = true;
break;
case IMPERATIVE_CLOSE_REQUESTED: case IMPERATIVE_CLOSE_REQUESTED:
close_os_window(self, os_window); close_os_window(self, os_window);
break; break;

View File

@ -10,6 +10,8 @@ from kitty.options_stub import Options
# Constants {{{ # Constants {{{
KITTY_VCS_REV: str KITTY_VCS_REV: str
NO_CLOSE_REQUESTED: int
IMPERATIVE_CLOSE_REQUESTED: int
ERROR_PREFIX: str ERROR_PREFIX: str
GLSL_VERSION: int GLSL_VERSION: int
GLFW_IBEAM_CURSOR: int GLFW_IBEAM_CURSOR: int
@ -706,7 +708,7 @@ def cocoa_get_lang() -> Optional[str]:
pass 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 pass

View File

@ -152,12 +152,12 @@ blank_os_window(OSWindow *w) {
static void static void
window_close_callback(GLFWwindow* window) { window_close_callback(GLFWwindow* window) {
if (!set_callback_window(window)) return; if (!set_callback_window(window)) return;
global_state.has_pending_closes = true; if (global_state.callback_os_window->close_request == NO_CLOSE_REQUESTED) {
if (global_state.callback_os_window->close_request < CONFIRMABLE_CLOSE_REQUESTED) {
global_state.callback_os_window->close_request = CONFIRMABLE_CLOSE_REQUESTED; global_state.callback_os_window->close_request = CONFIRMABLE_CLOSE_REQUESTED;
global_state.has_pending_closes = true;
request_tick_callback();
} }
glfwSetWindowShouldClose(window, false); glfwSetWindowShouldClose(window, false);
request_tick_callback();
global_state.callback_os_window = NULL; global_state.callback_os_window = NULL;
} }

View File

@ -1190,6 +1190,8 @@ init_state(PyObject *module) {
if (PyStructSequence_InitType2(&RegionType, &region_desc) != 0) return false; if (PyStructSequence_InitType2(&RegionType, &region_desc) != 0) return false;
Py_INCREF((PyObject *) &RegionType); Py_INCREF((PyObject *) &RegionType);
PyModule_AddObject(module, "Region", (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) { if (Py_AtExit(finalize) != 0) {
PyErr_SetString(PyExc_RuntimeError, "Failed to register the state at exit handler"); PyErr_SetString(PyExc_RuntimeError, "Failed to register the state at exit handler");
return false; return false;

View File

@ -139,7 +139,7 @@ typedef struct {
} OSWindowGeometry; } OSWindowGeometry;
enum RENDER_STATE { RENDER_FRAME_NOT_REQUESTED, RENDER_FRAME_REQUESTED, RENDER_FRAME_READY }; 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 { typedef struct {
monotonic_t last_resize_event_at; monotonic_t last_resize_event_at;