Skip to content

Commit

Permalink
macos: add configuration support for quick-terminal-size
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Franco committed Oct 4, 2024
1 parent 0dbf979 commit c0df3b3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
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
15 changes: 15 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

0 comments on commit c0df3b3

Please sign in to comment.