mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
config: support quick terminal position
This commit is contained in:
@ -553,7 +553,10 @@ class AppDelegate: NSObject,
|
|||||||
|
|
||||||
@IBAction func toggleQuickTerminal(_ sender: Any) {
|
@IBAction func toggleQuickTerminal(_ sender: Any) {
|
||||||
if quickController == nil {
|
if quickController == nil {
|
||||||
quickController = QuickTerminalController(ghostty, baseConfig: nil)
|
quickController = QuickTerminalController(
|
||||||
|
ghostty,
|
||||||
|
position: ghostty.config.quickTerminalPosition
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let quickController = self.quickController else { return }
|
guard let quickController = self.quickController else { return }
|
||||||
|
@ -1,19 +1,30 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
enum QuickTerminalPosition {
|
enum QuickTerminalPosition : String {
|
||||||
case top
|
case top
|
||||||
|
case bottom
|
||||||
|
case left
|
||||||
|
case right
|
||||||
|
|
||||||
/// Set the loaded state for a window.
|
/// Set the loaded state for a window.
|
||||||
func setLoaded(_ window: NSWindow) {
|
func setLoaded(_ window: NSWindow) {
|
||||||
guard let screen = window.screen ?? NSScreen.main else { return }
|
guard let screen = window.screen ?? NSScreen.main else { return }
|
||||||
switch (self) {
|
switch (self) {
|
||||||
case .top:
|
case .top, .bottom:
|
||||||
window.setFrame(.init(
|
window.setFrame(.init(
|
||||||
origin: window.frame.origin,
|
origin: window.frame.origin,
|
||||||
size: .init(
|
size: .init(
|
||||||
width: screen.frame.width,
|
width: screen.frame.width,
|
||||||
height: screen.frame.height / 4)
|
height: screen.frame.height / 4)
|
||||||
), display: false)
|
), display: false)
|
||||||
|
|
||||||
|
case .left, .right:
|
||||||
|
window.setFrame(.init(
|
||||||
|
origin: window.frame.origin,
|
||||||
|
size: .init(
|
||||||
|
width: screen.frame.width / 4,
|
||||||
|
height: screen.frame.height)
|
||||||
|
), display: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,15 +34,10 @@ enum QuickTerminalPosition {
|
|||||||
window.alphaValue = 0
|
window.alphaValue = 0
|
||||||
|
|
||||||
// Position depends
|
// Position depends
|
||||||
switch (self) {
|
window.setFrame(.init(
|
||||||
case .top:
|
origin: initialOrigin(for: window, on: screen),
|
||||||
window.setFrame(.init(
|
size: window.frame.size
|
||||||
origin: initialOrigin(for: window, on: screen),
|
), display: false)
|
||||||
size: .init(
|
|
||||||
width: screen.frame.width,
|
|
||||||
height: window.frame.height)
|
|
||||||
), display: false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the final state for a window in this position.
|
/// Set the final state for a window in this position.
|
||||||
@ -40,21 +46,21 @@ enum QuickTerminalPosition {
|
|||||||
window.alphaValue = 1
|
window.alphaValue = 1
|
||||||
|
|
||||||
// Position depends
|
// Position depends
|
||||||
switch (self) {
|
window.setFrame(.init(
|
||||||
case .top:
|
origin: finalOrigin(for: window, on: screen),
|
||||||
window.setFrame(.init(
|
size: window.frame.size
|
||||||
origin: finalOrigin(for: window, on: screen),
|
), display: true)
|
||||||
size: window.frame.size
|
|
||||||
), display: true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restrict the frame size during resizing.
|
/// Restrict the frame size during resizing.
|
||||||
func restrictFrameSize(_ size: NSSize, on screen: NSScreen) -> NSSize {
|
func restrictFrameSize(_ size: NSSize, on screen: NSScreen) -> NSSize {
|
||||||
var finalSize = size
|
var finalSize = size
|
||||||
switch (self) {
|
switch (self) {
|
||||||
case .top:
|
case .top, .bottom:
|
||||||
finalSize.width = screen.frame.width
|
finalSize.width = screen.frame.width
|
||||||
|
|
||||||
|
case .left, .right:
|
||||||
|
finalSize.height = screen.frame.height
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalSize
|
return finalSize
|
||||||
@ -65,6 +71,15 @@ enum QuickTerminalPosition {
|
|||||||
switch (self) {
|
switch (self) {
|
||||||
case .top:
|
case .top:
|
||||||
return .init(x: 0, y: screen.frame.maxY)
|
return .init(x: 0, y: screen.frame.maxY)
|
||||||
|
|
||||||
|
case .bottom:
|
||||||
|
return .init(x: 0, y: -window.frame.height)
|
||||||
|
|
||||||
|
case .left:
|
||||||
|
return .init(x: -window.frame.width, y: 0)
|
||||||
|
|
||||||
|
case .right:
|
||||||
|
return .init(x: screen.frame.maxX, y: 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +88,15 @@ enum QuickTerminalPosition {
|
|||||||
switch (self) {
|
switch (self) {
|
||||||
case .top:
|
case .top:
|
||||||
return .init(x: window.frame.origin.x, y: screen.visibleFrame.maxY - window.frame.height)
|
return .init(x: window.frame.origin.x, y: screen.visibleFrame.maxY - window.frame.height)
|
||||||
|
|
||||||
|
case .bottom:
|
||||||
|
return .init(x: window.frame.origin.x, y: 0)
|
||||||
|
|
||||||
|
case .left:
|
||||||
|
return .init(x: 0, y: window.frame.origin.y)
|
||||||
|
|
||||||
|
case .right:
|
||||||
|
return .init(x: screen.visibleFrame.maxX - window.frame.width, y: window.frame.origin.y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,6 +332,16 @@ extension Ghostty {
|
|||||||
return Color(newColor)
|
return Color(newColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var quickTerminalPosition: QuickTerminalPosition {
|
||||||
|
guard let config = self.config else { return .top }
|
||||||
|
var v: UnsafePointer<Int8>? = nil
|
||||||
|
let key = "quick-terminal-position"
|
||||||
|
guard ghostty_config_get(config, &v, key, UInt(key.count)) else { return .top }
|
||||||
|
guard let ptr = v else { return .top }
|
||||||
|
let str = String(cString: ptr)
|
||||||
|
return QuickTerminalPosition(rawValue: str) ?? .top
|
||||||
|
}
|
||||||
|
|
||||||
var resizeOverlay: ResizeOverlay {
|
var resizeOverlay: ResizeOverlay {
|
||||||
guard let config = self.config else { return .after_first }
|
guard let config = self.config else { return .after_first }
|
||||||
var v: UnsafePointer<Int8>? = nil
|
var v: UnsafePointer<Int8>? = nil
|
||||||
|
@ -1220,6 +1220,13 @@ keybind: Keybinds = .{},
|
|||||||
/// window is ever created. Only implemented on Linux.
|
/// window is ever created. Only implemented on Linux.
|
||||||
@"initial-window": bool = true,
|
@"initial-window": bool = true,
|
||||||
|
|
||||||
|
/// The position of the "quick" terminal window. To learn more about the
|
||||||
|
/// quick terminal, see the documentation for the `toggle_quick_terminal`
|
||||||
|
/// binding action.
|
||||||
|
///
|
||||||
|
/// Changing this configuration requires restarting Ghostty completely.
|
||||||
|
@"quick-terminal-position": QuickTerminalPosition = .top,
|
||||||
|
|
||||||
/// Whether to enable shell integration auto-injection or not. Shell integration
|
/// Whether to enable shell integration auto-injection or not. Shell integration
|
||||||
/// greatly enhances the terminal experience by enabling a number of features:
|
/// greatly enhances the terminal experience by enabling a number of features:
|
||||||
///
|
///
|
||||||
@ -4401,6 +4408,14 @@ pub const ResizeOverlayPosition = enum {
|
|||||||
@"bottom-right",
|
@"bottom-right",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// See quick-terminal-position
|
||||||
|
pub const QuickTerminalPosition = enum {
|
||||||
|
top,
|
||||||
|
bottom,
|
||||||
|
left,
|
||||||
|
right,
|
||||||
|
};
|
||||||
|
|
||||||
/// See grapheme-width-method
|
/// See grapheme-width-method
|
||||||
pub const GraphemeWidthMethod = enum {
|
pub const GraphemeWidthMethod = enum {
|
||||||
legacy,
|
legacy,
|
||||||
|
@ -402,10 +402,6 @@ pub const Action = union(enum) {
|
|||||||
///
|
///
|
||||||
crash: CrashThread,
|
crash: CrashThread,
|
||||||
|
|
||||||
pub const QuickTerminalPosition = enum {
|
|
||||||
top,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const CrashThread = enum {
|
pub const CrashThread = enum {
|
||||||
main,
|
main,
|
||||||
io,
|
io,
|
||||||
|
Reference in New Issue
Block a user