forked from ghostty-org/ghostty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduce `quick-terminal-size` option which allows to define the size of the quick terminal. It also fixes an issue where the quick terminal position was not properly updated when reloading the configuration. Resolves ghostty-org#2384
- Loading branch information
Showing
8 changed files
with
386 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
macos/Sources/Features/QuickTerminal/QuickTerminalSize.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import Cocoa | ||
import GhosttyKit | ||
|
||
class QuickTerminalSize { | ||
enum Size { | ||
case percent(value: Double) | ||
case pixel(value: UInt) | ||
|
||
init?(c_dimension: ghostty_config_quick_terminal_dimension_s) { | ||
switch(c_dimension.unit) { | ||
case GHOSTTY_QUICK_TERMINAL_PIXEL_UNIT: | ||
self = .pixel(value: UInt(c_dimension.value)) | ||
case GHOSTTY_QUICK_TERMINAL_PERCENTAGE_UNIT: | ||
self = .percent(value: Double(c_dimension.value) / 100.0) | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
func apply(value: CGFloat) -> CGFloat { | ||
switch(self) { | ||
case .pixel(let fixed_size): | ||
return CGFloat(fixed_size); | ||
case .percent(let pct): | ||
return value * pct; | ||
} | ||
} | ||
} | ||
|
||
var mainDimension: Size; | ||
var secondDimension: Size; | ||
|
||
init() { | ||
self.mainDimension = Size.percent(value: 0.25) | ||
self.secondDimension = Size.percent(value: 0.25) | ||
} | ||
|
||
init(config: ghostty_config_quick_terminal_size_s) { | ||
switch (config.len) { | ||
case 1: | ||
self.mainDimension = Size(c_dimension: config.dimensions[0]) ?? Size.percent(value: 0.25) | ||
self.secondDimension = Size.percent(value: 0.25) | ||
case 2: | ||
self.mainDimension = Size(c_dimension: config.dimensions[0]) ?? Size.percent(value: 0.25) | ||
self.secondDimension = Size(c_dimension: config.dimensions[1]) ?? Size.percent(value: 0.25) | ||
default: | ||
self.mainDimension = Size.percent(value: 0.25) | ||
self.secondDimension = Size.percent(value: 0.25) | ||
} | ||
} | ||
|
||
/// Set the window size. | ||
func apply(_ window: NSWindow, _ position: QuickTerminalPosition) { | ||
guard let screen = window.screen ?? NSScreen.main else { return } | ||
switch (position) { | ||
case .top, .bottom: | ||
window.setFrame(.init( | ||
origin: window.frame.origin, | ||
size: .init( | ||
width: screen.frame.width, | ||
height: self.mainDimension.apply(value: screen.frame.height)) | ||
), display: false) | ||
|
||
case .left, .right: | ||
window.setFrame(.init( | ||
origin: window.frame.origin, | ||
size: .init( | ||
width: self.mainDimension.apply(value: screen.frame.width), | ||
height: screen.frame.height) | ||
), display: false) | ||
|
||
case .center: | ||
window.setFrame(.init( | ||
origin: window.frame.origin, | ||
size: .init( | ||
width: self.mainDimension.apply(value: screen.frame.width), | ||
height: self.secondDimension.apply(value: screen.frame.height)) | ||
), display: false) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.