Skip to content

Commit

Permalink
confirm-close-surface option can be set to always to always require c…
Browse files Browse the repository at this point in the history
…onfirmation

Fixes #3648
The confirm-close-surface configuration can now be set to always
ensuring a confirmation dialog is shown before closing a surface, even
if shell integration indicates no running processes.
  • Loading branch information
ErfanTech committed Dec 28, 2024
1 parent 6cbd69d commit 4bd0779
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
29 changes: 19 additions & 10 deletions src/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ const DerivedConfig = struct {
clipboard_paste_protection: bool,
clipboard_paste_bracketed_safe: bool,
copy_on_select: configpkg.CopyOnSelect,
confirm_close_surface: bool,
confirm_close_surface: configpkg.ConfirmCloseSurface,
cursor_click_to_move: bool,
desktop_notifications: bool,
font: font.SharedGridSet.DerivedConfig,
Expand Down Expand Up @@ -784,18 +784,27 @@ pub fn deactivateInspector(self: *Surface) void {
/// True if the surface requires confirmation to quit. This should be called
/// by apprt to determine if the surface should confirm before quitting.
pub fn needsConfirmQuit(self: *Surface) bool {
// If the child has exited then our process is certainly not alive.
// If the child has exited, then our process is certainly not alive.
// We check this first to avoid the locking overhead below.
if (self.child_exited) return false;

// If we are configured to not hold open surfaces explicitly, just
// always say there is nothing alive.
if (!self.config.confirm_close_surface) return false;

// We have to talk to the terminal.
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
return !self.io.terminal.cursorIsAtPrompt();
// Check the configuration for confirming close behavior.
switch (self.config.confirm_close_surface) {
.false => {
// No confirmation needed.
return false;
},
.true => {
// Proceed with the standard check.
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
return !self.io.terminal.cursorIsAtPrompt();
},
.always => {
// Always confirm, regardless of terminal state.
return true;
},
}
}

/// Called from the app thread to handle mailbox messages to our specific
Expand Down
1 change: 1 addition & 0 deletions src/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub const formatEntry = formatter.formatEntry;

// Field types
pub const ClipboardAccess = Config.ClipboardAccess;
pub const ConfirmCloseSurface = Config.ConfirmCloseSurface;
pub const CopyOnSelect = Config.CopyOnSelect;
pub const CustomShaderAnimation = Config.CustomShaderAnimation;
pub const FontSyntheticStyle = Config.FontSyntheticStyle;
Expand Down
16 changes: 14 additions & 2 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1305,8 +1305,11 @@ keybind: Keybinds = .{},
@"config-default-files": bool = true,

/// Confirms that a surface should be closed before closing it. This defaults to
/// true. If set to false, surfaces will close without any confirmation.
@"confirm-close-surface": bool = true,
/// `true`. If set to `false`, surfaces will close without any confirmation.
///
/// This can also be set to `always`, which will always confirm closing a
/// surface, even if shell integration says a process isn't running.
@"confirm-close-surface": ConfirmCloseSurface = .true,

/// Whether or not to quit after the last surface is closed.
///
Expand Down Expand Up @@ -3636,6 +3639,15 @@ const Replay = struct {
}
};

/// Valid values for confirm-close-surface
/// c_int because it needs to be extern compatible
/// If this is changed, you must also update ghostty.h
pub const ConfirmCloseSurface = enum(c_int) {
false,
true,
always,
};

/// Valid values for custom-shader-animation
/// c_int because it needs to be extern compatible
/// If this is changed, you must also update ghostty.h
Expand Down

0 comments on commit 4bd0779

Please sign in to comment.