Use draw rect to do the "plus darker" blending

This is a lot simpler and doesn't require adding Obj-C into the mix.
This commit is contained in:
Pete Schaffner
2024-02-08 16:38:07 +01:00
parent 33a8368a68
commit 8831c601a4
5 changed files with 17 additions and 49 deletions

View File

@ -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 = "<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>"; };
C1F26EB02B743B7700404083 /* Ghostty-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Ghostty-Bridging-Header.h"; sourceTree = "<group>"; };
C1F26EB12B743B7700404083 /* PlusDarkerBlendingModeLayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PlusDarkerBlendingModeLayer.m; sourceTree = "<group>"; };
C1F26EB32B743C9300404083 /* PlusDarkerBlendingModeLayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlusDarkerBlendingModeLayer.h; sourceTree = "<group>"; };
/* 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 = "<group>";
@ -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;

View File

@ -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"

View File

@ -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()
}
}
}

View File

@ -1,4 +0,0 @@
#import <QuartzCore/QuartzCore.h>
@interface PlusDarkerBlendingModeLayer: CALayer
@end

View File

@ -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