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

macos: add configuration support for quick-terminal-size #2385

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
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class QuickTerminalController: BaseTerminalController {
syncAppearance()

// Setup our initial size based on our configured position
position.setLoaded(window)
position.setLoaded(window, size: ghostty.config.quickTerminalSize)

// Setup our content
window.contentView = NSHostingView(rootView: TerminalView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ enum QuickTerminalPosition : String {
case right

/// Set the loaded state for a window.
func setLoaded(_ window: NSWindow) {
func setLoaded(_ window: NSWindow, size: Double) {
guard let screen = window.screen ?? NSScreen.main else { return }
switch (self) {
case .top, .bottom:
window.setFrame(.init(
origin: window.frame.origin,
size: .init(
width: screen.frame.width,
height: screen.frame.height / 4)
height: screen.frame.height * CGFloat(size))
), display: false)

case .left, .right:
window.setFrame(.init(
origin: window.frame.origin,
size: .init(
width: screen.frame.width / 4,
width: screen.frame.width / CGFloat(size),
height: screen.frame.height)
), display: false)
}
Expand Down
8 changes: 8 additions & 0 deletions macos/Sources/Ghostty/Ghostty.Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ extension Ghostty {
let str = String(cString: ptr)
return QuickTerminalScreen(fromGhosttyConfig: str) ?? .main
}

var quickTerminalSize: Double {
guard let config = self.config else { return 0.25 }
var v: Double = 0.25
let key = "quick-terminal-size"
_ = ghostty_config_get(config, &v, key, UInt(key.count))
return v
}
#endif

var resizeOverlay: ResizeOverlay {
Expand Down
18 changes: 18 additions & 0 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,21 @@ keybind: Keybinds = .{},
/// by the operating system.
@"quick-terminal-screen": QuickTerminalScreen = .main,

/// This size of the quick terminal screen based on the quick-terminal-position.
///
/// This value should be a floating-point number between 0 and 1,
/// where 1 means it occupies the entire screen.
///
/// The default value is 0.25, meaning the quick terminal will occupy 25%
/// of the screen's dimension. When quick-terminal-position is set to `left` or `right`,
/// the dimension is the screen's width. When quick-terminal-position is set to `top` or `bottom`,
/// the dimension is the screen's height.
///
/// Examples:
/// * Setting to 0.5 will make the quick terminal occupy 50% of the screen.
/// * Setting to 1 will make it occupy 100% of the screen.
@"quick-terminal-size": f64 = 0.25,

/// Whether to enable shell integration auto-injection or not. Shell integration
/// greatly enhances the terminal experience by enabling a number of features:
///
Expand Down Expand Up @@ -2654,6 +2669,9 @@ pub fn finalize(self: *Config) !void {
if (self.@"window-width" > 0) self.@"window-width" = @max(10, self.@"window-width");
if (self.@"window-height" > 0) self.@"window-height" = @max(4, self.@"window-height");

// Clamp quick terminal size
if (self.@"quick-window-size" > 0) self.@"quick-window-size" = @min(0.25, @max(1, self.@"quick-window-size"));

// If URLs are disabled, cut off the first link. The first link is
// always the URL matcher.
if (!self.@"link-url") self.link.links.items = self.link.links.items[1..];
Expand Down