mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Add extensions to help finding private subviews
This commit is contained in:
@ -68,6 +68,7 @@
|
|||||||
AEF9CE242B6AD07A0017E195 /* TerminalToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEF9CE232B6AD07A0017E195 /* TerminalToolbar.swift */; };
|
AEF9CE242B6AD07A0017E195 /* TerminalToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEF9CE232B6AD07A0017E195 /* TerminalToolbar.swift */; };
|
||||||
C159E81D2B66A06B00FDFE9C /* OSColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */; };
|
C159E81D2B66A06B00FDFE9C /* OSColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */; };
|
||||||
C159E89D2B69A2EF00FDFE9C /* OSColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */; };
|
C159E89D2B69A2EF00FDFE9C /* OSColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */; };
|
||||||
|
C1F26EA72B738B9900404083 /* NSView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1F26EA62B738B9900404083 /* NSView+Extension.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
@ -128,6 +129,7 @@
|
|||||||
A5FEB2FF2ABB69450068369E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
A5FEB2FF2ABB69450068369E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
||||||
AEF9CE232B6AD07A0017E195 /* TerminalToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalToolbar.swift; sourceTree = "<group>"; };
|
AEF9CE232B6AD07A0017E195 /* TerminalToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalToolbar.swift; sourceTree = "<group>"; };
|
||||||
C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OSColor+Extension.swift"; sourceTree = "<group>"; };
|
C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OSColor+Extension.swift"; sourceTree = "<group>"; };
|
||||||
|
C1F26EA62B738B9900404083 /* NSView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSView+Extension.swift"; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -193,6 +195,7 @@
|
|||||||
A59630962AEE163600D64628 /* HostingWindow.swift */,
|
A59630962AEE163600D64628 /* HostingWindow.swift */,
|
||||||
A59FB5D02AE0DEA7009128F3 /* MetalView.swift */,
|
A59FB5D02AE0DEA7009128F3 /* MetalView.swift */,
|
||||||
C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */,
|
C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */,
|
||||||
|
C1F26EA62B738B9900404083 /* NSView+Extension.swift */,
|
||||||
A5CEAFDA29B8005900646FDA /* SplitView */,
|
A5CEAFDA29B8005900646FDA /* SplitView */,
|
||||||
);
|
);
|
||||||
path = Helpers;
|
path = Helpers;
|
||||||
@ -468,6 +471,7 @@
|
|||||||
A59FB5CF2AE0DB50009128F3 /* InspectorView.swift in Sources */,
|
A59FB5CF2AE0DB50009128F3 /* InspectorView.swift in Sources */,
|
||||||
A5D0AF3D2B37804400D21823 /* CodableBridge.swift in Sources */,
|
A5D0AF3D2B37804400D21823 /* CodableBridge.swift in Sources */,
|
||||||
A5D0AF3B2B36A1DE00D21823 /* TerminalRestorable.swift in Sources */,
|
A5D0AF3B2B36A1DE00D21823 /* TerminalRestorable.swift in Sources */,
|
||||||
|
C1F26EA72B738B9900404083 /* NSView+Extension.swift in Sources */,
|
||||||
A596309C2AEE1C9E00D64628 /* TerminalController.swift in Sources */,
|
A596309C2AEE1C9E00D64628 /* TerminalController.swift in Sources */,
|
||||||
A56D58892ACDE6CA00508D2C /* ServiceProvider.swift in Sources */,
|
A56D58892ACDE6CA00508D2C /* ServiceProvider.swift in Sources */,
|
||||||
A51BFC222B2FB6B400E92F16 /* AboutView.swift in Sources */,
|
A51BFC222B2FB6B400E92F16 /* AboutView.swift in Sources */,
|
||||||
|
@ -70,9 +70,9 @@ class TerminalWindow: NSWindow {
|
|||||||
func setTitlebarBackground(_ color: CGColor) {
|
func setTitlebarBackground(_ color: CGColor) {
|
||||||
storedTitlebarBackgroundColor = color
|
storedTitlebarBackgroundColor = color
|
||||||
|
|
||||||
guard let titlebarContainer = contentView?.superview?.subviews.first(where: {
|
guard let titlebarContainer = contentView?.superview?.firstSubview(withClassName: "NSTitlebarContainerView") else {
|
||||||
$0.className == "NSTitlebarContainerView"
|
return
|
||||||
}) else { return }
|
}
|
||||||
|
|
||||||
titlebarContainer.wantsLayer = true
|
titlebarContainer.wantsLayer = true
|
||||||
titlebarContainer.layer?.backgroundColor = color
|
titlebarContainer.layer?.backgroundColor = color
|
||||||
@ -134,9 +134,10 @@ class TerminalWindow: NSWindow {
|
|||||||
guard let accessoryClipView = accessoryView.superview else { return }
|
guard let accessoryClipView = accessoryView.superview else { return }
|
||||||
guard let titlebarView = accessoryClipView.superview else { return }
|
guard let titlebarView = accessoryClipView.superview else { return }
|
||||||
guard titlebarView.className == "NSTitlebarView" else { return }
|
guard titlebarView.className == "NSTitlebarView" else { return }
|
||||||
guard let toolbarView = titlebarView.subviews.first(where: {
|
|
||||||
$0.className == "NSToolbarView"
|
guard let toolbarView = titlebarView.firstSubview(withClassName: "NSToolbarView") else {
|
||||||
}) else { return }
|
return
|
||||||
|
}
|
||||||
|
|
||||||
addWindowButtonsBackdrop(titlebarView: titlebarView, toolbarView: toolbarView)
|
addWindowButtonsBackdrop(titlebarView: titlebarView, toolbarView: toolbarView)
|
||||||
guard let windowButtonsBackdrop = windowButtonsBackdrop else { return }
|
guard let windowButtonsBackdrop = windowButtonsBackdrop else { return }
|
||||||
|
29
macos/Sources/Helpers/NSView+Extension.swift
Normal file
29
macos/Sources/Helpers/NSView+Extension.swift
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import AppKit
|
||||||
|
|
||||||
|
extension NSView {
|
||||||
|
func firstSubview(withClassName name: String) -> NSView? {
|
||||||
|
for subview in subviews {
|
||||||
|
if String(describing: type(of: subview)) == name {
|
||||||
|
return subview
|
||||||
|
} else if let found = subview.firstSubview(withClassName: name) {
|
||||||
|
return found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func subviews(withClassName name: String) -> [NSView] {
|
||||||
|
var result = [NSView]()
|
||||||
|
|
||||||
|
for subview in subviews {
|
||||||
|
if String(describing: type(of: subview)) == name {
|
||||||
|
result.append(subview)
|
||||||
|
}
|
||||||
|
|
||||||
|
result += subview.subviews(withClassName: name)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user