From 8831c601a4c803c58b4b255791e4ba3cdc0cbc15 Mon Sep 17 00:00:00 2001 From: Pete Schaffner Date: Thu, 8 Feb 2024 16:38:07 +0100 Subject: [PATCH] Use draw rect to do the "plus darker" blending This is a lot simpler and doesn't require adding Obj-C into the mix. --- macos/Ghostty.xcodeproj/project.pbxproj | 11 ------ .../App/macOS/Ghostty-Bridging-Header.h | 5 --- .../Features/Terminal/TerminalWindow.swift | 37 +++++++++---------- .../Helpers/PlusDarkerBlendingModeLayer.h | 4 -- .../Helpers/PlusDarkerBlendingModeLayer.m | 9 ----- 5 files changed, 17 insertions(+), 49 deletions(-) delete mode 100644 macos/Sources/App/macOS/Ghostty-Bridging-Header.h delete mode 100644 macos/Sources/Helpers/PlusDarkerBlendingModeLayer.h delete mode 100644 macos/Sources/Helpers/PlusDarkerBlendingModeLayer.m diff --git a/macos/Ghostty.xcodeproj/project.pbxproj b/macos/Ghostty.xcodeproj/project.pbxproj index 286fe5c87..b7e0134c8 100644 --- a/macos/Ghostty.xcodeproj/project.pbxproj +++ b/macos/Ghostty.xcodeproj/project.pbxproj @@ -69,7 +69,6 @@ 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 */; }; C1F26EA72B738B9900404083 /* NSView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1F26EA62B738B9900404083 /* NSView+Extension.swift */; }; - C1F26EB22B743B7700404083 /* PlusDarkerBlendingModeLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = C1F26EB12B743B7700404083 /* PlusDarkerBlendingModeLayer.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -131,9 +130,6 @@ AEF9CE232B6AD07A0017E195 /* TerminalToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalToolbar.swift; sourceTree = ""; }; C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OSColor+Extension.swift"; sourceTree = ""; }; C1F26EA62B738B9900404083 /* NSView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSView+Extension.swift"; sourceTree = ""; }; - C1F26EB02B743B7700404083 /* Ghostty-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Ghostty-Bridging-Header.h"; sourceTree = ""; }; - C1F26EB12B743B7700404083 /* PlusDarkerBlendingModeLayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PlusDarkerBlendingModeLayer.m; sourceTree = ""; }; - C1F26EB32B743C9300404083 /* PlusDarkerBlendingModeLayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlusDarkerBlendingModeLayer.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -200,8 +196,6 @@ A59FB5D02AE0DEA7009128F3 /* MetalView.swift */, C159E81C2B66A06B00FDFE9C /* OSColor+Extension.swift */, C1F26EA62B738B9900404083 /* NSView+Extension.swift */, - C1F26EB32B743C9300404083 /* PlusDarkerBlendingModeLayer.h */, - C1F26EB12B743B7700404083 /* PlusDarkerBlendingModeLayer.m */, A5CEAFDA29B8005900646FDA /* SplitView */, ); path = Helpers; @@ -241,7 +235,6 @@ A5FEB2FF2ABB69450068369E /* main.swift */, A53426342A7DA53D00EBB7A2 /* AppDelegate.swift */, 857F63802A5E64F200CA4815 /* MainMenu.xib */, - C1F26EB02B743B7700404083 /* Ghostty-Bridging-Header.h */, ); path = macOS; sourceTree = ""; @@ -504,7 +497,6 @@ A55685E029A03A9F004303CE /* AppError.swift in Sources */, A535B9DA299C569B0017E2E4 /* ErrorView.swift in Sources */, A51BFC202B2FB64F00E92F16 /* AboutController.swift in Sources */, - C1F26EB22B743B7700404083 /* PlusDarkerBlendingModeLayer.m in Sources */, A5CEAFFF29C2410700646FDA /* Backport.swift in Sources */, A5E112952AF73E8A00C6E0C2 /* ClipboardConfirmationController.swift in Sources */, 8503D7C72A549C66006CFF3D /* FullScreenHandler.swift in Sources */, @@ -622,7 +614,6 @@ PRODUCT_BUNDLE_IDENTIFIER = com.mitchellh.ghostty; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_OBJC_BRIDGING_HEADER = "Sources/App/macOS/Ghostty-Bridging-Header.h"; SWIFT_VERSION = 5.0; }; name = ReleaseLocal; @@ -772,7 +763,6 @@ PRODUCT_BUNDLE_IDENTIFIER = com.mitchellh.ghostty; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_OBJC_BRIDGING_HEADER = "Sources/App/macOS/Ghostty-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; }; @@ -811,7 +801,6 @@ PRODUCT_BUNDLE_IDENTIFIER = com.mitchellh.ghostty; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_OBJC_BRIDGING_HEADER = "Sources/App/macOS/Ghostty-Bridging-Header.h"; SWIFT_VERSION = 5.0; }; name = Release; diff --git a/macos/Sources/App/macOS/Ghostty-Bridging-Header.h b/macos/Sources/App/macOS/Ghostty-Bridging-Header.h deleted file mode 100644 index 44aaa3ff6..000000000 --- a/macos/Sources/App/macOS/Ghostty-Bridging-Header.h +++ /dev/null @@ -1,5 +0,0 @@ -// -// Use this file to import your target's public headers that you would like to expose to Swift. -// - -#import "PlusDarkerBlendingModeLayer.h" diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift index c0b90afbd..de0749f27 100644 --- a/macos/Sources/Features/Terminal/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -301,20 +301,12 @@ fileprivate class WindowDragView: NSView { // A view that matches the color of selected and unselected tabs in the adjacent tab bar. fileprivate class WindowButtonsBackdropView: NSView { - private let overlayLayer = PlusDarkerBlendingModeLayer() - private let backgroundColor: CGColor + private let backgroundColor: NSColor private let isLightTheme: Bool var isHighlighted: Bool = true { didSet { - if isLightTheme { - overlayLayer.isHidden = isHighlighted - layer?.backgroundColor = backgroundColor - } else { - overlayLayer.isHidden = true - layer?.backgroundColor = isHighlighted ? backgroundColor : CGColor(genericGrayGamma2_2Gray: 0.0, alpha: 0.45) - } - + setNeedsDisplay(self.bounds) } } @@ -323,20 +315,25 @@ fileprivate class WindowButtonsBackdropView: NSView { } init(backgroundColor: CGColor) { - self.backgroundColor = backgroundColor + self.backgroundColor = NSColor(cgColor: backgroundColor)! self.isLightTheme = NSColor(cgColor: backgroundColor)!.isLightColor super.init(frame: .zero) + } + override func draw(_ dirtyRect: NSRect) { + if isLightTheme { + backgroundColor.setFill() + bounds.fill() - wantsLayer = true - - overlayLayer.frame = layer!.bounds - overlayLayer.autoresizingMask = [.layerWidthSizable, .layerHeightSizable] - overlayLayer.backgroundColor = CGColor(genericGrayGamma2_2Gray: 0.95, alpha: 1) - - layer?.addSublayer(overlayLayer) - - isHighlighted = true + if !isHighlighted { + let overlayColor = NSColor(cgColor: CGColor(genericGrayGamma2_2Gray: 0.95, alpha: 1))! + overlayColor.setFill() + bounds.fill(using: .plusDarker) + } + } else { + (isHighlighted ? backgroundColor : NSColor(cgColor: CGColor(genericGrayGamma2_2Gray: 0.0, alpha: 0.45))!).setFill() + bounds.fill() + } } } diff --git a/macos/Sources/Helpers/PlusDarkerBlendingModeLayer.h b/macos/Sources/Helpers/PlusDarkerBlendingModeLayer.h deleted file mode 100644 index e3d0c5f8e..000000000 --- a/macos/Sources/Helpers/PlusDarkerBlendingModeLayer.h +++ /dev/null @@ -1,4 +0,0 @@ -#import - -@interface PlusDarkerBlendingModeLayer: CALayer -@end diff --git a/macos/Sources/Helpers/PlusDarkerBlendingModeLayer.m b/macos/Sources/Helpers/PlusDarkerBlendingModeLayer.m deleted file mode 100644 index 2ec6933e5..000000000 --- a/macos/Sources/Helpers/PlusDarkerBlendingModeLayer.m +++ /dev/null @@ -1,9 +0,0 @@ -#import "PlusDarkerBlendingModeLayer.h" - -@implementation PlusDarkerBlendingModeLayer - -// A private compositing filter ("plus darker") that is used in titlebar -// tab bars to create the effect of recessed, unselected tabs. -- (id)compositingFilter { return @"plusD"; } - -@end