Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass always config option to confirm-close-surface #3703

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 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,28 @@ 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 (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;
// Based on the 'confirm_close_surface' configuration, decide whether to prompt for confirmation.
return switch (self.config.confirm_close_surface) {
// Always prompt for confirmation before closing the surface, regardless of the terminal state.
.always => true,

// We have to talk to the terminal.
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
return !self.io.terminal.cursorIsAtPrompt();
// Prompt for confirmation only when a process is running.
.when_process_running => blk: {
// We have to talk to the terminal.
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
break :blk !self.io.terminal.cursorIsAtPrompt();
},

//Never prompt for confirmation; allow the surface to close immediately.
.never => false,
};
}

/// 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
19 changes: 16 additions & 3 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1304,9 +1304,15 @@ keybind: Keybinds = .{},
/// This configuration can only be set via CLI arguments.
@"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,
/// Confirms that a surface should be closed before closing it.
///
/// Valid values:
/// - always: Always prompt for confirmation when closing.
/// - when_process_running: Prompt when a process is running (default).
/// - never: Never prompt for confirmation.
///
/// The default value is `when_process_running`.
@"confirm-close-surface": ConfirmCloseSurface = .when_process_running,

/// Whether or not to quit after the last surface is closed.
///
Expand Down Expand Up @@ -5331,6 +5337,13 @@ pub const AutoUpdate = enum {
download,
};

/// See confirm-close-surface
pub const ConfirmCloseSurface = enum {
always,
when_process_running,
never,
};

/// See theme
pub const Theme = struct {
light: []const u8,
Expand Down