Skip to content

Commit

Permalink
Remove invalidation of window titlebar
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Aug 11, 2023
1 parent 630f148 commit 32f23d4
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 46 deletions.
28 changes: 0 additions & 28 deletions CotEditor/Sources/DocumentWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
//

import AppKit
import Combine

final class DocumentWindow: NSWindow {

Expand Down Expand Up @@ -59,11 +58,6 @@ final class DocumentWindow: NSWindow {
}


// MARK: Private Properties

private var appearanceObserver: AnyCancellable?



// MARK: -
// MARK: Window Methods
Expand Down Expand Up @@ -98,17 +92,6 @@ final class DocumentWindow: NSWindow {

didSet {
self.didChangeValue(for: \.isOpaque)

guard isOpaque != oldValue else { return }

self.invalidateTitlebarOpacity()

if isOpaque {
self.appearanceObserver = nil
} else if self.appearanceObserver == nil {
self.appearanceObserver = self.publisher(for: \.effectiveAppearance)
.sink { [weak self] _ in self?.invalidateTitlebarOpacity() }
}
}
}

Expand Down Expand Up @@ -172,17 +155,6 @@ final class DocumentWindow: NSWindow {
self.invalidateRestorableState()
}
}


/// Make sure window title bar (incl. toolbar) is opaque.
private func invalidateTitlebarOpacity() {

guard let titlebarView = self.standardWindowButton(.closeButton)?.superview else { return }

// dirty manipulation to avoid the title bar being dyed in the window background color (2016-01).
titlebarView.wantsLayer = !self.isOpaque
titlebarView.layer?.backgroundColor = self.isOpaque ? nil : NSColor.windowBackgroundColor.cgColor(for: self.effectiveAppearance)
}
}


Expand Down
2 changes: 1 addition & 1 deletion CotEditor/Sources/HoleContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class HoleContentView: NSView {

super.viewWillMove(toWindow: newWindow)

self.windowOpacityObserver = newWindow?.publisher(for: \.isOpaque)
self.windowOpacityObserver = newWindow?.publisher(for: \.isOpaque, options: .initial)
.sink { [unowned self] isOpaque in
self.holeViewObserver = if isOpaque {
nil
Expand Down
17 changes: 0 additions & 17 deletions CotEditor/Sources/NSColor+NamedColors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ extension NSColor {

extension NSColor {

/// Return CGColor of the receiver by converting system color correctly for the specific appearance.
///
/// - Parameter appearance: The appearance to get the corresponding system color.
/// - Returns: A CGColor instance.
func cgColor(for appearance: NSAppearance) -> CGColor {

guard NSAppearance.currentDrawing() != appearance else { return self.cgColor }

var cgColor: CGColor = .clear
appearance.performAsCurrentDrawingAppearance {
cgColor = self.cgColor
}

return cgColor
}


/// Create desired number of well distributed colors from the receiver.
///
/// - Parameter number: The required number of colors.
Expand Down

0 comments on commit 32f23d4

Please sign in to comment.