mirror of
https://github.com/mpv-player/mpv
synced 2024-11-14 22:48:35 +01:00
cocoa-cb: add support for custom colored title bar
This commit is contained in:
parent
837e5058ff
commit
90e44d3ff2
@ -4905,6 +4905,12 @@ The following video options are currently all specific to ``--vo=gpu`` and
|
||||
:ultraDark: The standard macOS ultraDark material.
|
||||
(macOS 10.11+ deprecated in macOS 10.14+)
|
||||
|
||||
``--macos-title-bar-color=<color>``
|
||||
Sets the color of the title bar (default: completely transparent). Is
|
||||
influenced by ``--macos-title-bar-appearance`` and
|
||||
``--macos-title-bar-material``.
|
||||
See ``--sub-color`` for color syntax.
|
||||
|
||||
``--macos-fs-animation-duration=<default|0-1000>``
|
||||
Sets the fullscreen resize animation duration in ms (default: default).
|
||||
The default value is slightly less than the system's animation duration
|
||||
|
@ -59,6 +59,7 @@ class MPVHelper: NSObject {
|
||||
mpv_observe_property(mpvHandle, 0, "macos-title-bar-style", MPV_FORMAT_STRING)
|
||||
mpv_observe_property(mpvHandle, 0, "macos-title-bar-appearance", MPV_FORMAT_STRING)
|
||||
mpv_observe_property(mpvHandle, 0, "macos-title-bar-material", MPV_FORMAT_STRING)
|
||||
mpv_observe_property(mpvHandle, 0, "macos-title-bar-color", MPV_FORMAT_STRING)
|
||||
}
|
||||
|
||||
func initRender() {
|
||||
|
@ -56,3 +56,16 @@ extension NSScreen {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension NSColor {
|
||||
|
||||
convenience init(hex: String) {
|
||||
let int = Int(hex.dropFirst(), radix: 16)
|
||||
let alpha = CGFloat((int! >> 24) & 0x000000FF)/255
|
||||
let red = CGFloat((int! >> 16) & 0x000000FF)/255
|
||||
let green = CGFloat((int! >> 8) & 0x000000FF)/255
|
||||
let blue = CGFloat((int!) & 0x000000FF)/255
|
||||
|
||||
self.init(calibratedRed: red, green: green, blue: blue, alpha: alpha)
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,13 @@
|
||||
#define MPV_MACOSX_APPLICATION
|
||||
|
||||
#include "osdep/macosx_menubar.h"
|
||||
#include "options/m_option.h"
|
||||
|
||||
struct macos_opts {
|
||||
int macos_title_bar_style;
|
||||
int macos_title_bar_appearance;
|
||||
int macos_title_bar_material;
|
||||
struct m_color macos_title_bar_color;
|
||||
int macos_fs_animation_duration;
|
||||
int cocoa_cb_sw_renderer;
|
||||
};
|
||||
|
@ -57,6 +57,7 @@ const struct m_sub_options macos_conf = {
|
||||
{"underWindowBackground", 12}, {"underPageBackground", 13},
|
||||
{"dark", 14}, {"light", 15}, {"mediumLight", 16},
|
||||
{"ultraDark", 17})),
|
||||
OPT_COLOR("macos-title-bar-color", macos_title_bar_color, 0),
|
||||
OPT_CHOICE_OR_INT("macos-fs-animation-duration",
|
||||
macos_fs_animation_duration, 0, 0, 1000,
|
||||
({"default", -1})),
|
||||
@ -68,6 +69,7 @@ const struct m_sub_options macos_conf = {
|
||||
},
|
||||
.size = sizeof(struct macos_opts),
|
||||
.defaults = &(const struct macos_opts){
|
||||
.macos_title_bar_color = {0, 0, 0, 0},
|
||||
.macos_fs_animation_duration = -1,
|
||||
.cocoa_cb_sw_renderer = -1,
|
||||
},
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user