mirror of https://github.com/mpv-player/mpv
cocoa-cb: refactor title bar styling
half of the materials we used were deprecated with macOS 10.14, broken and not supported by run time changes of the macOS theme. furthermore our styling names were completely inconsistent with the actually look since macOS 10.14, eg ultradark got a lot brighter and couldn't be considered ultradark anymore. i decided to drop the old option --macos-title-bar-style and rework the whole mechanism to allow more freedom. now materials and appearance can be set separately. even if apple changes the look or semantics in the future the new options can be easily adapted.
This commit is contained in:
parent
23f55569be
commit
837e5058ff
|
@ -76,6 +76,8 @@ Interface changes
|
|||
network streams should not freeze the player core (only playback in
|
||||
uncached regions), and differing behavior should be reported as a bug.
|
||||
If --demuxer-thread=no is used, there are no guarantees.
|
||||
- remove `--macos-title-bar-style`, replaced by `--macos-title-bar-material`
|
||||
and `--macos-title-bar-appearance`.
|
||||
--- mpv 0.29.0 ---
|
||||
- drop --opensles-sample-rate, as --audio-samplerate should be used if desired
|
||||
- drop deprecated --videotoolbox-format, --ff-aid, --ff-vid, --ff-sid,
|
||||
|
|
|
@ -4842,17 +4842,68 @@ The following video options are currently all specific to ``--vo=gpu`` and
|
|||
|
||||
OS X only.
|
||||
|
||||
``--macos-title-bar-style=<dark|ultradark|light|mediumlight|auto>``
|
||||
Sets the styling of the title bar (default: dark).
|
||||
OS X and cocoa-cb only
|
||||
``--macos-title-bar-appearance=<appearance>``
|
||||
Sets the appearance of the title bar (default: auto). Not all combinations
|
||||
of appearances and ``--macos-title-bar-material`` materials make sense or
|
||||
are unique. Appearances that are not supported by you current macOS version
|
||||
fall back to the default value.
|
||||
macOS and cocoa-cb only
|
||||
|
||||
:dark: Dark title bar with vibrancy, a subtle blurring effect that
|
||||
dynamically blends the background (Video) into the title bar.
|
||||
:ultradark: Darker title bar with vibrancy (like QuickTime Player).
|
||||
:light: Bright title bar with vibrancy.
|
||||
:mediumlight: Less bright title bar with vibrancy.
|
||||
:auto: Detects the system settings and sets the title bar styling
|
||||
appropriately, either ultradark or mediumlight.
|
||||
``<appearance>`` can be one of the following:
|
||||
|
||||
:auto: Detects the system settings and sets the title
|
||||
bar appearance appropriately. On macOS 10.14 it
|
||||
also detects run time changes.
|
||||
:aqua: The standard macOS Light appearance.
|
||||
:darkAqua: The standard macOS Dark appearance. (macOS 10.14+)
|
||||
:vibrantLight: Light vibrancy appearance with.
|
||||
:vibrantDark: Dark vibrancy appearance with.
|
||||
:aquaHighContrast: Light Accessibility appearance. (macOS 10.14+)
|
||||
:darkAquaHighContrast: Dark Accessibility appearance. (macOS 10.14+)
|
||||
:vibrantLightHighContrast: Light vibrancy Accessibility appearance.
|
||||
(macOS 10.14+)
|
||||
:vibrantDarkHighContrast: Dark vibrancy Accessibility appearance.
|
||||
(macOS 10.14+)
|
||||
|
||||
``--macos-title-bar-material=<material>``
|
||||
Sets the material of the title bar (default: titlebar). All deprecated
|
||||
materials should not be used on macOS 10.14+ because their functionality
|
||||
is not guaranteed. Not all combinations of materials and
|
||||
``--macos-title-bar-appearance`` appearances make sense or are unique.
|
||||
Materials that are not supported by you current macOS version fall back to
|
||||
the default value.
|
||||
macOS and cocoa-cb only
|
||||
|
||||
``<material>`` can be one of the following:
|
||||
|
||||
:titlebar: The standard macOS titel bar material.
|
||||
:selection: The standard macOS selection material.
|
||||
:menu: The standard macOS menu material. (macOS 10.11+)
|
||||
:popover: The standard macOS popover material. (macOS 10.11+)
|
||||
:sidebar: The standard macOS sidebar material. (macOS 10.11+)
|
||||
:headerView: The standard macOS header view material.
|
||||
(macOS 10.14+)
|
||||
:sheet: The standard macOS sheet material. (macOS 10.14+)
|
||||
:windowBackground: The standard macOS window background material.
|
||||
(macOS 10.14+)
|
||||
:hudWindow: The standard macOS hudWindow material. (macOS 10.14+)
|
||||
:fullScreen: The standard macOS full screen material.
|
||||
(macOS 10.14+)
|
||||
:toolTip: The standard macOS tool tip material. (macOS 10.14+)
|
||||
:contentBackground: The standard macOS content background material.
|
||||
(macOS 10.14+)
|
||||
:underWindowBackground: The standard macOS under window background material.
|
||||
(macOS 10.14+)
|
||||
:underPageBackground: The standard macOS under page background material.
|
||||
(deprecated in macOS 10.14+)
|
||||
:dark: The standard macOS dark material.
|
||||
(deprecated in macOS 10.14+)
|
||||
:light: The standard macOS light material.
|
||||
(macOS 10.14+)
|
||||
:mediumLight: The standard macOS mediumLight material.
|
||||
(macOS 10.11+, deprecated in macOS 10.14+)
|
||||
:ultraDark: The standard macOS ultraDark material.
|
||||
(macOS 10.11+ deprecated in macOS 10.14+)
|
||||
|
||||
``--macos-fs-animation-duration=<default|0-1000>``
|
||||
Sets the fullscreen resize animation duration in ms (default: default).
|
||||
|
|
|
@ -57,6 +57,8 @@ class MPVHelper: NSObject {
|
|||
mpv_observe_property(mpvHandle, 0, "border", MPV_FORMAT_FLAG)
|
||||
mpv_observe_property(mpvHandle, 0, "keepaspect-window", MPV_FORMAT_FLAG)
|
||||
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)
|
||||
}
|
||||
|
||||
func initRender() {
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
struct macos_opts {
|
||||
int macos_title_bar_style;
|
||||
int macos_title_bar_appearance;
|
||||
int macos_title_bar_material;
|
||||
int macos_fs_animation_duration;
|
||||
int cocoa_cb_sw_renderer;
|
||||
};
|
||||
|
|
|
@ -43,14 +43,27 @@
|
|||
#define OPT_BASE_STRUCT struct macos_opts
|
||||
const struct m_sub_options macos_conf = {
|
||||
.opts = (const struct m_option[]) {
|
||||
OPT_CHOICE("macos-title-bar-style", macos_title_bar_style, 0,
|
||||
({"dark", 0}, {"ultradark", 1}, {"light", 2},
|
||||
{"mediumlight", 3}, {"auto", 4})),
|
||||
OPT_CHOICE("macos-title-bar-appearance", macos_title_bar_appearance, 0,
|
||||
({"auto", 0}, {"aqua", 1}, {"darkAqua", 2},
|
||||
{"vibrantLight", 3}, {"vibrantDark", 4},
|
||||
{"aquaHighContrast", 5}, {"darkAquaHighContrast", 6},
|
||||
{"vibrantLightHighContrast", 7},
|
||||
{"vibrantDarkHighContrast", 8})),
|
||||
OPT_CHOICE("macos-title-bar-material", macos_title_bar_material, 0,
|
||||
({"titlebar", 0}, {"selection", 1}, {"menu", 2},
|
||||
{"popover", 3}, {"sidebar", 4}, {"headerView", 5},
|
||||
{"sheet", 6}, {"windowBackground", 7}, {"hudWindow", 8},
|
||||
{"fullScreen", 9}, {"toolTip", 10}, {"contentBackground", 11},
|
||||
{"underWindowBackground", 12}, {"underPageBackground", 13},
|
||||
{"dark", 14}, {"light", 15}, {"mediumLight", 16},
|
||||
{"ultraDark", 17})),
|
||||
OPT_CHOICE_OR_INT("macos-fs-animation-duration",
|
||||
macos_fs_animation_duration, 0, 0, 1000,
|
||||
({"default", -1})),
|
||||
OPT_CHOICE("cocoa-cb-sw-renderer", cocoa_cb_sw_renderer, 0,
|
||||
({"auto", -1}, {"no", 0}, {"yes", 1})),
|
||||
OPT_REMOVED("macos-title-bar-style", "Split into --macos-title-bar-appearance "
|
||||
"and --macos-title-bar-material"),
|
||||
{0}
|
||||
},
|
||||
.size = sizeof(struct macos_opts),
|
||||
|
|
|
@ -34,6 +34,24 @@ class TitleBar: NSVisualEffectView {
|
|||
get { return ([.closeButton, .miniaturizeButton, .zoomButton] as [NSWindowButton]).flatMap { cocoaCB.window.standardWindowButton($0) } }
|
||||
}
|
||||
|
||||
override var material: NSVisualEffectView.Material {
|
||||
get { return super.material }
|
||||
set {
|
||||
super.material = newValue
|
||||
// fix for broken deprecated materials
|
||||
if material == .light || material == .dark {
|
||||
state = .active
|
||||
} else if #available(macOS 10.11, *),
|
||||
material == .mediumLight || material == .ultraDark
|
||||
{
|
||||
state = .active
|
||||
} else {
|
||||
state = .followsWindowActiveState
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
convenience init(frame: NSRect, window: NSWindow, cocoaCB ccb: CocoaCB) {
|
||||
let f = NSMakeRect(0, frame.size.height - TitleBar.height,
|
||||
frame.size.width, TitleBar.height)
|
||||
|
@ -43,11 +61,13 @@ class TitleBar: NSVisualEffectView {
|
|||
blendingMode = .withinWindow
|
||||
autoresizingMask = [.viewWidthSizable, .viewMinYMargin]
|
||||
systemBar.alphaValue = 0
|
||||
state = .followsWindowActiveState
|
||||
|
||||
window.contentView!.addSubview(self, positioned: .above, relativeTo: nil)
|
||||
window.titlebarAppearsTransparent = true
|
||||
window.styleMask.insert(.fullSizeContentView)
|
||||
setStyle(Int(mpv.macOpts!.macos_title_bar_style))
|
||||
set(appearance: Int(mpv.macOpts!.macos_title_bar_appearance))
|
||||
set(material: Int(mpv.macOpts!.macos_title_bar_material))
|
||||
}
|
||||
|
||||
// catch these events so they are not propagated to the underlying view
|
||||
|
@ -72,55 +92,19 @@ class TitleBar: NSVisualEffectView {
|
|||
}
|
||||
}
|
||||
|
||||
func setStyle(_ style: Any) {
|
||||
var effect: String
|
||||
|
||||
if style is Int {
|
||||
switch style as! Int {
|
||||
case 4:
|
||||
effect = "auto"
|
||||
case 3:
|
||||
effect = "mediumlight"
|
||||
case 2:
|
||||
effect = "light"
|
||||
case 1:
|
||||
effect = "ultradark"
|
||||
case 0: fallthrough
|
||||
default:
|
||||
effect = "dark"
|
||||
}
|
||||
func set(appearance: Any) {
|
||||
if appearance is Int {
|
||||
window!.appearance = appearanceFrom(string: String(appearance as! Int))
|
||||
} else {
|
||||
effect = style as! String
|
||||
window!.appearance = appearanceFrom(string: appearance as! String)
|
||||
}
|
||||
}
|
||||
|
||||
switch effect {
|
||||
case "auto":
|
||||
if #available(macOS 10.14, *) {
|
||||
cocoaCB.window.appearance = nil
|
||||
material = .titlebar
|
||||
state = .followsWindowActiveState
|
||||
} else {
|
||||
let systemStyle = UserDefaults.standard.string(forKey: "AppleInterfaceStyle")
|
||||
effect = systemStyle == nil ? "mediumlight" : "ultradark"
|
||||
setStyle(effect)
|
||||
}
|
||||
case "mediumlight":
|
||||
cocoaCB.window.appearance = NSAppearance(named: NSAppearanceNameVibrantLight)
|
||||
material = .titlebar
|
||||
state = .followsWindowActiveState
|
||||
case "light":
|
||||
cocoaCB.window.appearance = NSAppearance(named: NSAppearanceNameVibrantLight)
|
||||
material = .light
|
||||
state = .active
|
||||
case "ultradark":
|
||||
cocoaCB.window.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
|
||||
material = .titlebar
|
||||
state = .followsWindowActiveState
|
||||
case "dark": fallthrough
|
||||
default:
|
||||
cocoaCB.window.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
|
||||
material = .dark
|
||||
state = .active
|
||||
func set(material: Any) {
|
||||
if material is Int {
|
||||
self.material = materialFrom(string: String(material as! Int))
|
||||
} else {
|
||||
self.material = materialFrom(string: material as! String)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,4 +151,75 @@ class TitleBar: NSVisualEffectView {
|
|||
object: nil)
|
||||
perform(#selector(hide), with: nil, afterDelay: 0.5)
|
||||
}
|
||||
|
||||
func appearanceFrom(string: String) -> NSAppearance? {
|
||||
switch string {
|
||||
case "1", "aqua":
|
||||
return NSAppearance(named: NSAppearanceNameAqua)
|
||||
case "3", "vibrantLight":
|
||||
return NSAppearance(named: NSAppearanceNameVibrantLight)
|
||||
case "4", "vibrantDark":
|
||||
return NSAppearance(named: NSAppearanceNameVibrantDark)
|
||||
default: break
|
||||
}
|
||||
|
||||
if #available(macOS 10.14, *) {
|
||||
switch string {
|
||||
case "2", "darkAqua":
|
||||
return NSAppearance(named: NSAppearanceNameDarkAqua)
|
||||
case "5", "aquaHighContrast":
|
||||
return NSAppearance(named: NSAppearanceNameAccessibilityHighContrastAqua)
|
||||
case "6", "darkAquaHighContrast":
|
||||
return NSAppearance(named: NSAppearanceNameAccessibilityHighContrastDarkAqua)
|
||||
case "7", "vibrantLightHighContrast":
|
||||
return NSAppearance(named: NSAppearanceNameAccessibilityHighContrastVibrantLight)
|
||||
case "8", "vibrantDarkHighContrast":
|
||||
return NSAppearance(named: NSAppearanceNameAccessibilityHighContrastVibrantDark)
|
||||
case "0", "auto": fallthrough
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
let style = UserDefaults.standard.string(forKey: "AppleInterfaceStyle")
|
||||
return appearanceFrom(string: style == nil ? "aqua" : "vibrantDark")
|
||||
}
|
||||
|
||||
func materialFrom(string: String) -> NSVisualEffectView.Material {
|
||||
switch string {
|
||||
case "1", "selection": return .selection
|
||||
case "0", "titlebar": return .titlebar
|
||||
case "14", "dark": return .dark
|
||||
case "15", "light": return .light
|
||||
default: break
|
||||
}
|
||||
|
||||
if #available(macOS 10.11, *) {
|
||||
switch string {
|
||||
case "2,", "menu": return .menu
|
||||
case "3", "popover": return .popover
|
||||
case "4", "sidebar": return .sidebar
|
||||
case "16", "mediumLight": return .mediumLight
|
||||
case "17", "ultraDark": return .ultraDark
|
||||
default: break
|
||||
}
|
||||
}
|
||||
|
||||
if #available(macOS 10.14, *) {
|
||||
switch string {
|
||||
case "5,", "headerView": return .headerView
|
||||
case "6", "sheet": return .sheet
|
||||
case "7", "windowBackground": return .windowBackground
|
||||
case "8", "hudWindow": return .hudWindow
|
||||
case "9", "fullScreen": return .fullScreenUI
|
||||
case "10", "toolTip": return .toolTip
|
||||
case "11", "contentBackground": return .contentBackground
|
||||
case "12", "underWindowBackground": return .underWindowBackground
|
||||
case "13", "underPageBackground": return .underPageBackground
|
||||
default: break
|
||||
}
|
||||
}
|
||||
|
||||
return .titlebar
|
||||
}
|
||||
}
|
||||
|
|
|
@ -513,9 +513,13 @@ class CocoaCB: NSObject {
|
|||
if let data = MPVHelper.mpvFlagToBool(property.data) {
|
||||
window.keepAspect = data
|
||||
}
|
||||
case "macos-title-bar-style":
|
||||
case "macos-title-bar-appearance":
|
||||
if let data = MPVHelper.mpvStringArrayToString(property.data) {
|
||||
titleBar.setStyle(data)
|
||||
titleBar.set(appearance: data)
|
||||
}
|
||||
case "macos-title-bar-material":
|
||||
if let data = MPVHelper.mpvStringArrayToString(property.data) {
|
||||
titleBar.set(material: data)
|
||||
}
|
||||
default:
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue