From 5bc569c4dde5ceab10cba7ee992d052e7154d92c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 20 Aug 2021 17:13:42 +0530 Subject: [PATCH] Allow specifying whether to count windows at prompts or not for confirm_clsoe --- kitty/boss.py | 15 +++++++++------ kitty/options/definition.py | 8 +++++--- kitty/options/parse.py | 2 +- kitty/tabs.py | 7 +++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index eb05a003a..5f9c52eec 100755 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -541,8 +541,9 @@ class Boss: self.confirm_tab_close(tab) def confirm_tab_close(self, tab: Tab) -> None: - num = tab.number_of_windows_with_running_programs - needs_confirmation = get_options().confirm_os_window_close > 0 and num >= get_options().confirm_os_window_close + x = get_options().confirm_os_window_close + num = tab.number_of_windows_with_running_programs if x < 0 else len(tab) + needs_confirmation = x != 0 and num >= abs(x) if not needs_confirmation: self.close_tab_no_confirm(tab) return @@ -930,8 +931,9 @@ class Boss: def confirm_os_window_close(self, os_window_id: int) -> None: tm = self.os_window_map.get(os_window_id) - num = 0 if tm is None else tm.number_of_windows_with_running_programs - needs_confirmation = tm is not None and get_options().confirm_os_window_close > 0 and num >= get_options().confirm_os_window_close + q = get_options().confirm_os_window_close + num = 0 if tm is None else (tm.number_of_windows_with_running_programs if q < 0 else tm.number_of_windows) + needs_confirmation = tm is not None and q != 0 and num >= abs(q) if not needs_confirmation: mark_os_window_for_close(os_window_id) return @@ -967,9 +969,10 @@ class Boss: def quit(self, *args: Any) -> None: tm = self.active_tab num = 0 + x = get_options().confirm_os_window_close for q in self.os_window_map.values(): - num += q.number_of_windows_with_running_programs - needs_confirmation = tm is not None and get_options().confirm_os_window_close > 0 and num >= get_options().confirm_os_window_close + num += q.number_of_windows_with_running_programs if x < 0 else q.number_of_windows + needs_confirmation = tm is not None and x != 0 and num >= abs(x) if not needs_confirmation: set_application_quit_request(IMPERATIVE_CLOSE_REQUESTED) return diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 2d855904f..e75d45d04 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -859,13 +859,15 @@ does not currently work on Wayland. ) opt('confirm_os_window_close', '0', - option_type='positive_int', + option_type='int', long_text=''' Ask for confirmation when closing an OS window or a tab that has at least this number of kitty windows in it. A value of zero disables confirmation. This confirmation also applies to requests to quit the entire application (all OS -windows, via the quit action). Note that if you have :ref:`shell_integration` -enabled, a window that is sitting at a shell prompt is not counted. +windows, via the quit action). Negative values are converted to positive ones, +however, with :ref:`shell_integration` enabled, using negative values means +windows sitting at a shell prompt are not counted, only windows where some command is +currently running. ''' ) egr() # }}} diff --git a/kitty/options/parse.py b/kitty/options/parse.py index 759a0552f..405060529 100644 --- a/kitty/options/parse.py +++ b/kitty/options/parse.py @@ -880,7 +880,7 @@ class Parser: ans['command_on_bell'] = to_cmdline(val) def confirm_os_window_close(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: - ans['confirm_os_window_close'] = positive_int(val) + ans['confirm_os_window_close'] = int(val) def copy_on_select(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['copy_on_select'] = copy_on_select(val) diff --git a/kitty/tabs.py b/kitty/tabs.py index 10faf3b88..c41bda70c 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -814,6 +814,13 @@ class TabManager: # {{{ count += tab.number_of_windows_with_running_programs return count + @property + def number_of_windows(self) -> int: + count = 0 + for tab in self: + count += len(tab) + return count + def tab_for_id(self, tab_id: int) -> Optional[Tab]: for t in self.tabs: if t.id == tab_id: