From 90e44d3ff2182749da8d7d255bef15fd99c18eee Mon Sep 17 00:00:00 2001 From: der richter Date: Fri, 29 Mar 2019 20:39:42 +0100 Subject: cocoa-cb: add support for custom colored title bar --- video/out/cocoa-cb/title_bar.swift | 16 ++++++++++++++++ video/out/cocoa_cb_common.swift | 4 ++++ 2 files changed, 20 insertions(+) (limited to 'video/out') diff --git a/video/out/cocoa-cb/title_bar.swift b/video/out/cocoa-cb/title_bar.swift index e9109d4a2b..8a7bf30f02 100644 --- a/video/out/cocoa-cb/title_bar.swift +++ b/video/out/cocoa-cb/title_bar.swift @@ -62,12 +62,14 @@ class TitleBar: NSVisualEffectView { autoresizingMask = [.viewWidthSizable, .viewMinYMargin] systemBar.alphaValue = 0 state = .followsWindowActiveState + wantsLayer = true window.contentView!.addSubview(self, positioned: .above, relativeTo: nil) window.titlebarAppearsTransparent = true window.styleMask.insert(.fullSizeContentView) set(appearance: Int(mpv.macOpts!.macos_title_bar_appearance)) set(material: Int(mpv.macOpts!.macos_title_bar_material)) + set(color: mpv.macOpts!.macos_title_bar_color) } // catch these events so they are not propagated to the underlying view @@ -108,6 +110,20 @@ class TitleBar: NSVisualEffectView { } } + func set(color: Any) { + if color is String { + layer?.backgroundColor = NSColor(hex: color as! String).cgColor + } else { + let col = color as! m_color + let red = CGFloat(col.r)/255 + let green = CGFloat(col.g)/255 + let blue = CGFloat(col.b)/255 + let alpha = CGFloat(col.a)/255 + layer?.backgroundColor = NSColor(calibratedRed: red, green: green, + blue: blue, alpha: alpha).cgColor + } + } + func show() { if (!cocoaCB.window.border && !cocoaCB.window.isInFullscreen) { return } let loc = cocoaCB.view.convert(cocoaCB.window.mouseLocationOutsideOfEventStream, from: nil) diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift index a3fabd0324..f545e72a3d 100644 --- a/video/out/cocoa_cb_common.swift +++ b/video/out/cocoa_cb_common.swift @@ -521,6 +521,10 @@ class CocoaCB: NSObject { if let data = MPVHelper.mpvStringArrayToString(property.data) { titleBar.set(material: data) } + case "macos-title-bar-color": + if let data = MPVHelper.mpvStringArrayToString(property.data) { + titleBar.set(color: data) + } default: break } -- cgit v1.2.3