From b13ac575e6c07298225bf4cf3efebe75ea9b9042 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 27 Dec 2025 12:51:26 -0800 Subject: [PATCH] macos: move grab handle to separate file --- .../Surface View/SurfaceGrabHandle.swift | 40 +++++++++++++++++++ .../Ghostty/Surface View/SurfaceView.swift | 37 ----------------- 2 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 macos/Sources/Ghostty/Surface View/SurfaceGrabHandle.swift diff --git a/macos/Sources/Ghostty/Surface View/SurfaceGrabHandle.swift b/macos/Sources/Ghostty/Surface View/SurfaceGrabHandle.swift new file mode 100644 index 000000000..6e99bc281 --- /dev/null +++ b/macos/Sources/Ghostty/Surface View/SurfaceGrabHandle.swift @@ -0,0 +1,40 @@ +import SwiftUI + +extension Ghostty { + /// A grab handle overlay at the top of the surface for dragging the window. + /// Only appears when hovering in the top region of the surface. + struct SurfaceGrabHandle: View { + private let handleHeight: CGFloat = 10 + + let surfaceView: SurfaceView + + @State private var isHovering: Bool = false + @State private var isDragging: Bool = false + + var body: some View { + VStack(spacing: 0) { + Rectangle() + .fill(Color.white.opacity(isHovering || isDragging ? 0.15 : 0)) + .frame(height: handleHeight) + .overlay(alignment: .center) { + if isHovering || isDragging { + Capsule() + .fill(Color.white.opacity(0.4)) + .frame(width: 40, height: 4) + } + } + .contentShape(Rectangle()) + .onHover { hovering in + withAnimation(.easeInOut(duration: 0.15)) { + isHovering = hovering + } + } + .backport.pointerStyle(isHovering ? .grabIdle : nil) + + Spacer() + } + .frame(maxWidth: .infinity, maxHeight: .infinity) + .draggable(surfaceView) + } + } +} diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView.swift b/macos/Sources/Ghostty/Surface View/SurfaceView.swift index 140266ec5..872b89d30 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView.swift @@ -956,43 +956,6 @@ extension Ghostty { } #endif - /// A grab handle overlay at the top of the surface for dragging the window. - /// Only appears when hovering in the top region of the surface. - struct SurfaceGrabHandle: View { - private let handleHeight: CGFloat = 10 - - let surfaceView: SurfaceView - - @State private var isHovering: Bool = false - @State private var isDragging: Bool = false - - var body: some View { - VStack(spacing: 0) { - Rectangle() - .fill(Color.white.opacity(isHovering || isDragging ? 0.15 : 0)) - .frame(height: handleHeight) - .overlay(alignment: .center) { - if isHovering || isDragging { - Capsule() - .fill(Color.white.opacity(0.4)) - .frame(width: 40, height: 4) - } - } - .contentShape(Rectangle()) - .onHover { hovering in - withAnimation(.easeInOut(duration: 0.15)) { - isHovering = hovering - } - } - .backport.pointerStyle(isHovering ? .grabIdle : nil) - - Spacer() - } - .frame(maxWidth: .infinity, maxHeight: .infinity) - .draggable(surfaceView) - } - } - /// Visual overlay that shows a border around the edges when the bell rings with border feature enabled. struct BellBorderOverlay: View { let bell: Bool