From 1497e90f9535f9b850a9cf39b8db76cda64a9415 Mon Sep 17 00:00:00 2001 From: Damien Mehala Date: Tue, 24 Dec 2024 14:44:21 +0100 Subject: [PATCH 1/2] feat: add support for middle position in quick terminal This update introduces the ability to launch the quick terminal in the middle position. Resolves #2494 --- .../QuickTerminal/QuickTerminalPosition.swift | 19 +++++++++++++++++++ src/config/Config.zig | 1 + 2 files changed, 20 insertions(+) diff --git a/macos/Sources/Features/QuickTerminal/QuickTerminalPosition.swift b/macos/Sources/Features/QuickTerminal/QuickTerminalPosition.swift index 51b450700..8669af3de 100644 --- a/macos/Sources/Features/QuickTerminal/QuickTerminalPosition.swift +++ b/macos/Sources/Features/QuickTerminal/QuickTerminalPosition.swift @@ -5,6 +5,7 @@ enum QuickTerminalPosition : String { case bottom case left case right + case middle /// Set the loaded state for a window. func setLoaded(_ window: NSWindow) { @@ -25,6 +26,14 @@ enum QuickTerminalPosition : String { width: screen.frame.width / 4, height: screen.frame.height) ), display: false) + + case .middle: + window.setFrame(.init( + origin: window.frame.origin, + size: .init( + width: screen.frame.width / 2, + height: screen.frame.height / 3) + ), display: false) } } @@ -61,6 +70,10 @@ enum QuickTerminalPosition : String { case .left, .right: finalSize.height = screen.frame.height + + case .middle: + finalSize.width = screen.frame.width / 2 + finalSize.height = screen.frame.height / 3 } return finalSize @@ -80,6 +93,9 @@ enum QuickTerminalPosition : String { case .right: return .init(x: screen.frame.maxX, y: 0) + + case .middle: + return .init(x: (screen.visibleFrame.maxX - window.frame.width) / 2, y: screen.visibleFrame.maxY - window.frame.width) } } @@ -97,6 +113,9 @@ enum QuickTerminalPosition : String { case .right: return .init(x: screen.visibleFrame.maxX - window.frame.width, y: window.frame.origin.y) + + case .middle: + return .init(x: (screen.visibleFrame.maxX - window.frame.width) / 2, y: (screen.visibleFrame.maxY - window.frame.height) / 2) } } } diff --git a/src/config/Config.zig b/src/config/Config.zig index 4727da832..4c146bc1c 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -5257,6 +5257,7 @@ pub const QuickTerminalPosition = enum { bottom, left, right, + middle, }; /// See quick-terminal-screen From 44459e93d1ed6081071428fdbc2e0122bcfb86b3 Mon Sep 17 00:00:00 2001 From: Damien Mehala Date: Wed, 25 Dec 2024 00:07:12 +0100 Subject: [PATCH 2/2] code review --- .../Features/QuickTerminal/QuickTerminalPosition.swift | 10 +++++----- src/config/Config.zig | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/macos/Sources/Features/QuickTerminal/QuickTerminalPosition.swift b/macos/Sources/Features/QuickTerminal/QuickTerminalPosition.swift index 8669af3de..3d2a2a045 100644 --- a/macos/Sources/Features/QuickTerminal/QuickTerminalPosition.swift +++ b/macos/Sources/Features/QuickTerminal/QuickTerminalPosition.swift @@ -5,7 +5,7 @@ enum QuickTerminalPosition : String { case bottom case left case right - case middle + case center /// Set the loaded state for a window. func setLoaded(_ window: NSWindow) { @@ -27,7 +27,7 @@ enum QuickTerminalPosition : String { height: screen.frame.height) ), display: false) - case .middle: + case .center: window.setFrame(.init( origin: window.frame.origin, size: .init( @@ -71,7 +71,7 @@ enum QuickTerminalPosition : String { case .left, .right: finalSize.height = screen.frame.height - case .middle: + case .center: finalSize.width = screen.frame.width / 2 finalSize.height = screen.frame.height / 3 } @@ -94,7 +94,7 @@ enum QuickTerminalPosition : String { case .right: return .init(x: screen.frame.maxX, y: 0) - case .middle: + case .center: return .init(x: (screen.visibleFrame.maxX - window.frame.width) / 2, y: screen.visibleFrame.maxY - window.frame.width) } } @@ -114,7 +114,7 @@ enum QuickTerminalPosition : String { case .right: return .init(x: screen.visibleFrame.maxX - window.frame.width, y: window.frame.origin.y) - case .middle: + case .center: return .init(x: (screen.visibleFrame.maxX - window.frame.width) / 2, y: (screen.visibleFrame.maxY - window.frame.height) / 2) } } diff --git a/src/config/Config.zig b/src/config/Config.zig index 4c146bc1c..e82b4f97a 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1377,6 +1377,7 @@ keybind: Keybinds = .{}, /// * `bottom` - Terminal appears at the bottom of the screen. /// * `left` - Terminal appears at the left of the screen. /// * `right` - Terminal appears at the right of the screen. +/// * `center` - Terminal appears at the center of the screen. /// /// Changing this configuration requires restarting Ghostty completely. @"quick-terminal-position": QuickTerminalPosition = .top, @@ -5257,7 +5258,7 @@ pub const QuickTerminalPosition = enum { bottom, left, right, - middle, + center, }; /// See quick-terminal-screen