From d18e1c879bcc68a4c4db68f4cebaa16193b26bdd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 22 Sep 2024 21:35:07 -0700 Subject: [PATCH] macos: restrict resizing based on sliding terminal position --- .../SlideTerminal/SlideTerminalController.swift | 7 ++++++- .../SlideTerminal/SlideTerminalPosition.swift | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift b/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift index c117ae0f1..12f785843 100644 --- a/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift +++ b/macos/Sources/Features/SlideTerminal/SlideTerminalController.swift @@ -10,7 +10,7 @@ class SlideTerminalController: NSWindowController, NSWindowDelegate, TerminalVie /// The app instance that this terminal view will represent. let ghostty: Ghostty.App - /// The position fo the slide terminal. + /// The position for the slide terminal. let position: SlideTerminalPosition /// The surface tree for this window. @@ -65,6 +65,11 @@ class SlideTerminalController: NSWindowController, NSWindowDelegate, TerminalVie slideOut() } + func windowWillResize(_ sender: NSWindow, to frameSize: NSSize) -> NSSize { + guard let screen = NSScreen.main else { return frameSize } + return position.restrictFrameSize(frameSize, on: screen) + } + //MARK: TerminalViewDelegate func cellSizeDidChange(to: NSSize) { diff --git a/macos/Sources/Features/SlideTerminal/SlideTerminalPosition.swift b/macos/Sources/Features/SlideTerminal/SlideTerminalPosition.swift index 3ef7d7dcc..72f8d9483 100644 --- a/macos/Sources/Features/SlideTerminal/SlideTerminalPosition.swift +++ b/macos/Sources/Features/SlideTerminal/SlideTerminalPosition.swift @@ -35,6 +35,17 @@ enum SlideTerminalPosition { } } + /// Restrict the frame size during resizing. + func restrictFrameSize(_ size: NSSize, on screen: NSScreen) -> NSSize { + var finalSize = size + switch (self) { + case .top: + finalSize.width = screen.frame.width + } + + return finalSize + } + /// The initial point origin for this position. func initialOrigin(for window: NSWindow, on screen: NSScreen) -> CGPoint { switch (self) {