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: 3 additions & 1 deletion OpenTable/Views/Editor/NativeTabBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ final class NativeTabBarView: NSView {

override func viewDidChangeEffectiveAppearance() {
super.viewDidChangeEffectiveAppearance()
layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
effectiveAppearance.performAsCurrentDrawingAppearance {
self.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
}
// Re-render tab items to update colors
for snapshot in tabSnapshots {
tabViews[snapshot.id]?.update(
Expand Down
59 changes: 47 additions & 12 deletions OpenTable/Views/Editor/NativeTabItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class NativeTabItemView: NSView {
private var tabType: TabType
private var isSelected: Bool = false
private var isHovered: Bool = false
private var isWindowKey: Bool = true

// MARK: - Callbacks

Expand Down Expand Up @@ -191,6 +192,43 @@ final class NativeTabItemView: NSView {
statusIconLeadingConstraint?.isActive = true
}

// MARK: - Window Key State

override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()

NotificationCenter.default.removeObserver(
self, name: NSWindow.didBecomeKeyNotification, object: nil
)
NotificationCenter.default.removeObserver(
self, name: NSWindow.didResignKeyNotification, object: nil
)

guard let window = window else { return }
isWindowKey = window.isKeyWindow

NotificationCenter.default.addObserver(
self, selector: #selector(windowKeyStateChanged),
name: NSWindow.didBecomeKeyNotification, object: window
)
NotificationCenter.default.addObserver(
self, selector: #selector(windowKeyStateChanged),
name: NSWindow.didResignKeyNotification, object: window
)

updateAppearance()
}

@objc private func windowKeyStateChanged(_ notification: Notification) {
isWindowKey = window?.isKeyWindow ?? true
updateAppearance()
}

override func viewDidChangeEffectiveAppearance() {
super.viewDidChangeEffectiveAppearance()
updateAppearance()
}

// MARK: - Drag Source

private func setupDragSource() {
Expand Down Expand Up @@ -239,18 +277,15 @@ final class NativeTabItemView: NSView {
closeButton.isHidden = !isHovered || isPinned

// Background
if isSelected {
layer?.backgroundColor = NSColor.controlBackgroundColor.cgColor
layer?.borderColor = NSColor.separatorColor.cgColor
layer?.borderWidth = 0.5
} else if isHovered {
layer?.backgroundColor = NSColor.controlBackgroundColor.withAlphaComponent(0.5).cgColor
layer?.borderColor = nil
layer?.borderWidth = 0
} else {
layer?.backgroundColor = nil
layer?.borderColor = nil
layer?.borderWidth = 0
effectiveAppearance.performAsCurrentDrawingAppearance {
if self.isSelected {
self.layer?.backgroundColor = NSColor.controlAccentColor
.withAlphaComponent(0.15).cgColor
} else if self.isHovered {
self.layer?.backgroundColor = NSColor.quaternaryLabelColor.cgColor
} else {
self.layer?.backgroundColor = nil
}
}
}

Expand Down