Skip to content

Commit

Permalink
Do not count background processes by default for confirm_os_window_close
Browse files Browse the repository at this point in the history
Fixes #8358
  • Loading branch information
kovidgoyal committed Mar 9, 2025
1 parent 812fe46 commit 370723b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ consumption to do the same tasks.
Detailed list of changes
-------------------------------------

0.40.1 [future]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- Do not count background processes by default for :opt:`confirm_os_window_close` (:iss:`8358`)

0.40.0 [2025-03-08]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
9 changes: 5 additions & 4 deletions kitty/boss.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,15 @@ def close_window(self) -> None:
def close_windows_with_confirmation_msg(self, windows: Iterable[Window], active_window: Window | None) -> tuple[str, int]:
num_running_programs = 0
num_background_programs = 0
count_background = get_options().confirm_os_window_close[1]
running_program = background_program = ''
windows = sorted(windows, key=lambda w: 0 if w is active_window else 1)
with cached_process_data():
for window in windows:
if window.has_running_program:
num_running_programs += 1
running_program = running_program or (window.child.foreground_cmdline or [''])[0]
elif bp := window.child.background_processes:
elif count_background and (bp := window.child.background_processes):
num_background_programs += len(bp)
for q in bp:
background_program = background_program or (q['cmdline'] or [''])[0]
Expand Down Expand Up @@ -1141,7 +1142,7 @@ def on_popup_overlay_removal(wid: int, boss: Boss) -> None:

def confirm_tab_close(self, tab: Tab) -> None:
msg, num_active_windows = self.close_windows_with_confirmation_msg(tab, tab.active_window)
x = get_options().confirm_os_window_close
x = get_options().confirm_os_window_close[0]
num = num_active_windows if x < 0 else len(tab)
needs_confirmation = x != 0 and num >= abs(x)
if not needs_confirmation:
Expand Down Expand Up @@ -1777,7 +1778,7 @@ def confirm_os_window_close(self, os_window_id: int) -> None:
for tab in tm:
windows += list(tab)
msg, num_active_windows = self.close_windows_with_confirmation_msg(windows, active_window)
q = get_options().confirm_os_window_close
q = get_options().confirm_os_window_close[0]
num = num_active_windows if q < 0 else len(windows)
needs_confirmation = tm is not None and q != 0 and num >= abs(q)
if not needs_confirmation:
Expand Down Expand Up @@ -1820,7 +1821,7 @@ def quit(self, *args: Any) -> None:
windows += list(qt)
active_window = self.active_window
msg, num_active_windows = self.close_windows_with_confirmation_msg(windows, active_window)
x = get_options().confirm_os_window_close
x = get_options().confirm_os_window_close[0]
num = num_active_windows if x < 0 else len(windows)
needs_confirmation = x != 0 and num >= abs(x)
if not needs_confirmation:
Expand Down
13 changes: 6 additions & 7 deletions kitty/options/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,9 +1236,7 @@
'''
)

opt('confirm_os_window_close', '-1',
option_type='int',
long_text='''
opt('confirm_os_window_close', '-1', option_type='confirm_close', long_text='''
Ask for confirmation when closing an OS window or a tab with at least this
number of kitty windows in it by window manager (e.g. clicking the window close
button or pressing the operating system shortcut to close windows) or by the
Expand All @@ -1247,10 +1245,11 @@
:ac:`quit` action). Negative values are converted to positive ones, however,
with :opt:`shell_integration` enabled, using negative values means windows
sitting at a shell prompt are not counted, only windows where some command is
currently running or is running in the background. Note that if you want confirmation
when closing individual windows, you can map the :ac:`close_window_with_confirmation` action.
'''
)
currently running. You can also have backgrounded jobs prevent closing,
by adding :code:`count-background` ot the setting, for example: :code:`-1 count-background`.

This comment was marked as resolved.

Copy link
@00-kat

00-kat Mar 9, 2025

There's a typo here: otto.

Note that if you want confirmation when closing individual windows,
you can map the :ac:`close_window_with_confirmation` action.
''')
egr() # }}}


Expand Down
4 changes: 2 additions & 2 deletions kitty/options/parse.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kitty/options/types.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions kitty/options/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,13 @@ def shell_integration(x: str) -> frozenset[str]:
return q


def confirm_close(x: str) -> tuple[int, bool]:
parts = x.split(maxsplit=1)
num = int(parts[0])
allow_background = len(parts) > 1 and parts[1] == 'count-background'
return num, allow_background


def underline_exclusion(x: str) -> tuple[float, Literal['', 'px', 'pt']]:
try:
return float(x), ''
Expand Down

0 comments on commit 370723b

Please sign in to comment.