Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions GhosttyTabs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
D0B1001CA1B2C3D4E5F60001 /* PaneDropRoutingSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B1001DA1B2C3D4E5F60001 /* PaneDropRoutingSupport.swift */; };
D0B1001EA1B2C3D4E5F60001 /* BrowserPaneDropTargetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B1001FA1B2C3D4E5F60001 /* BrowserPaneDropTargetView.swift */; };
D0B10016A1B2C3D4E5F60001 /* FilePreviewTextEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B10017A1B2C3D4E5F60001 /* FilePreviewTextEditor.swift */; };
A5001450A5001450A5001450 /* FilePreviewNativeBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001451A5001451A5001451 /* FilePreviewNativeBackground.swift */; };
D0B10018A1B2C3D4E5F60001 /* FileDropOverlayViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B10019A1B2C3D4E5F60001 /* FileDropOverlayViewTests.swift */; };
D7AB34300000000000000001 /* SidebarDropPlanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7AB34300000000000000002 /* SidebarDropPlanner.swift */; };
D7AB34300000000000000003 /* SidebarBonsplitTabWorkspaceDropOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7AB34300000000000000004 /* SidebarBonsplitTabWorkspaceDropOverlay.swift */; };
Expand Down Expand Up @@ -684,6 +685,7 @@
D0B1001DA1B2C3D4E5F60001 /* PaneDropRoutingSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaneDropRoutingSupport.swift; sourceTree = "<group>"; };
D0B1001FA1B2C3D4E5F60001 /* BrowserPaneDropTargetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserPaneDropTargetView.swift; sourceTree = "<group>"; };
D0B10017A1B2C3D4E5F60001 /* FilePreviewTextEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/FilePreviewTextEditor.swift; sourceTree = "<group>"; };
A5001451A5001451A5001451 /* FilePreviewNativeBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Panels/FilePreviewNativeBackground.swift; sourceTree = "<group>"; };
A5001016 /* GhosttyKit.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = GhosttyKit.xcframework; sourceTree = "<group>"; };
A5001017 /* ghostty.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ghostty.h; sourceTree = "<group>"; };
A5001018 /* cmux-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "cmux-Bridging-Header.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1306,6 +1308,7 @@
A50014F1 /* MarkdownViewerAssets.swift */,
A5001423 /* FilePreviewPanel.swift */,
D0B10017A1B2C3D4E5F60001 /* FilePreviewTextEditor.swift */,
A5001451A5001451A5001451 /* FilePreviewNativeBackground.swift */,
A5001442A5001442A5001442 /* FilePreviewModeSupport.swift */,
A5001444A5001444A5001444 /* FilePreviewWorkspaceOpenSupport.swift */,
A5001446A5001446A5001446 /* FilePreviewMagnifyingPDFView.swift */,
Expand Down Expand Up @@ -1985,6 +1988,7 @@
A50014F3 /* MarkdownViewerAssets.swift in Sources */,
A5001422 /* FilePreviewPanel.swift in Sources */,
D0B10016A1B2C3D4E5F60001 /* FilePreviewTextEditor.swift in Sources */,
A5001450A5001450A5001450 /* FilePreviewNativeBackground.swift in Sources */,
A5001443A5001443A5001443 /* FilePreviewModeSupport.swift in Sources */,
A5001445A5001445A5001445 /* FilePreviewWorkspaceOpenSupport.swift in Sources */,
A5001447A5001447A5001447 /* FilePreviewMagnifyingPDFView.swift in Sources */,
Expand Down
65 changes: 65 additions & 0 deletions Sources/Panels/FilePreviewNativeBackground.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import AppKit

enum FilePreviewNativeBackground {
static func resolvedColor(backgroundColor: NSColor, drawsBackground: Bool) -> NSColor {
drawsBackground ? backgroundColor : .clear
}

static func applyRootLayer(
to view: NSView,
backgroundColor: NSColor,
drawsBackground: Bool
) {
let resolvedBackgroundColor = resolvedColor(
backgroundColor: backgroundColor,
drawsBackground: drawsBackground
)
view.wantsLayer = true
view.layer?.backgroundColor = resolvedBackgroundColor.cgColor
view.layer?.isOpaque = drawsBackground && resolvedBackgroundColor.alphaComponent >= 0.999
}

static func applyScrollBackgrounds(
in view: NSView,
backgroundColor: NSColor,
drawsBackground: Bool
) {
let resolvedBackgroundColor = resolvedColor(
backgroundColor: backgroundColor,
drawsBackground: drawsBackground
)
if let scrollView = view as? NSScrollView {
scrollView.drawsBackground = drawsBackground
scrollView.backgroundColor = resolvedBackgroundColor
}
if let clipView = view as? NSClipView {
clipView.drawsBackground = drawsBackground
clipView.backgroundColor = resolvedBackgroundColor
}
for subview in view.subviews {
applyScrollBackgrounds(
in: subview,
backgroundColor: backgroundColor,
drawsBackground: drawsBackground
)
}
}

static func scrollBackgroundHostIdentifiers(in view: NSView) -> Set<ObjectIdentifier> {
var identifiers = Set<ObjectIdentifier>()
collectScrollBackgroundHostIdentifiers(in: view, into: &identifiers)
return identifiers
}

private static func collectScrollBackgroundHostIdentifiers(
in view: NSView,
into identifiers: inout Set<ObjectIdentifier>
) {
if view is NSScrollView || view is NSClipView {
identifiers.insert(ObjectIdentifier(view))
}
for subview in view.subviews {
collectScrollBackgroundHostIdentifiers(in: subview, into: &identifiers)
}
}
}
Loading
Loading