diff options
author | Akemi <der.richter@gmx.de> | 2018-06-06 17:04:40 +0200 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2018-06-12 01:51:01 +0300 |
commit | 5865086aa84cae5e5505698ccf115a53a1b6b4fa (patch) | |
tree | 416b5ce30ae4c4d35af4130aa1956757fb6252ff /video/out/cocoa-cb/window.swift | |
parent | 20dffe0621b3e26674850ef0b46ba3e689931d87 (diff) | |
download | mpv-5865086aa84cae5e5505698ccf115a53a1b6b4fa.tar.bz2 mpv-5865086aa84cae5e5505698ccf115a53a1b6b4fa.tar.xz |
cocoa-cb: remove pre-allocation of window, view and layer
the pre-allocation was needed because the layer allocated a opengl
context async itself and we couldn't influence that. so we had to start
the core after the context was actually allocated. furthermore a window,
view and layer hierarchy had to be created so the layer would create
a context.
now, instead of relying on the layer to create a context we do this
manually and re-use that context later when the layer wants to create
one async itself.
Diffstat (limited to 'video/out/cocoa-cb/window.swift')
-rw-r--r-- | video/out/cocoa-cb/window.swift | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/video/out/cocoa-cb/window.swift b/video/out/cocoa-cb/window.swift index b3db7aeb8f..907476fc09 100644 --- a/video/out/cocoa-cb/window.swift +++ b/video/out/cocoa-cb/window.swift @@ -78,28 +78,23 @@ class Window: NSWindow, NSWindowDelegate { } } - convenience init(cocoaCB ccb: CocoaCB) { - self.init(contentRect: NSMakeRect(0, 0, 960, 480), - styleMask: [.titled, .closable, .miniaturizable, .resizable], - backing: .buffered, defer: false, screen: NSScreen.main()) - cocoaCB = ccb - title = "mpv" - } - - convenience init(contentRect: NSRect, styleMask style: NSWindowStyleMask, - screen: NSScreen?, cocoaCB ccb: CocoaCB) - { - self.init(contentRect: contentRect, styleMask: style, + convenience init(contentRect: NSRect, screen: NSScreen?, view: NSView, cocoaCB ccb: CocoaCB) { + self.init(contentRect: contentRect, + styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false, screen: screen) cocoaCB = ccb + title = cocoaCB.title minSize = NSMakeSize(160, 90) collectionBehavior = .fullScreenPrimary delegate = self + contentView!.addSubview(view) + view.frame = contentView!.frame unfsContentFrame = convertToScreen(contentView!.frame) targetScreen = screen! currentScreen = screen! unfScreen = screen! + initTitleBar() if let app = NSApp as? Application { app.menuBar.register(#selector(setHalfWindowSize), for: MPM_H_SIZE) @@ -123,14 +118,31 @@ class Window: NSWindow, NSWindowDelegate { titleBarEffect!.blendingMode = .withinWindow titleBarEffect!.autoresizingMask = [.viewWidthSizable, .viewMinYMargin] - setTitleBarStyle(mpv.getStringProperty("macos-title-bar-style") ?? "dark") + setTitleBarStyle(Int(mpv.macOpts!.macos_title_bar_style)) contentView!.addSubview(titleBarEffect!, positioned: .above, relativeTo: nil) - - border = mpv.getBoolProperty("border") } - func setTitleBarStyle(_ style: String) { - var effect = style + func setTitleBarStyle(_ 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" + } + } else { + effect = style as! String + } + if effect == "auto" { let systemStyle = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") effect = systemStyle == nil ? "mediumlight" : "ultradark" @@ -339,16 +351,26 @@ class Window: NSWindow, NSWindowDelegate { } } - func setOnTop(_ state: Bool) { + func setOnTop(_ state: Bool, _ ontopLevel: Any) { if state { - let ontopLevel = mpv.getStringProperty("ontop-level") ?? "window" - switch ontopLevel { - case "window": - level = Int(CGWindowLevelForKey(.floatingWindow)) - case "system": - level = Int(CGWindowLevelForKey(.statusWindow))+1 - default: - level = Int(ontopLevel)! + if ontopLevel is Int { + switch ontopLevel as! Int { + case -1: + level = Int(CGWindowLevelForKey(.floatingWindow)) + case -2: + level = Int(CGWindowLevelForKey(.statusWindow))+1 + default: + level = ontopLevel as! Int + } + } else { + switch ontopLevel as! String { + case "window": + level = Int(CGWindowLevelForKey(.floatingWindow)) + case "system": + level = Int(CGWindowLevelForKey(.statusWindow))+1 + default: + level = Int(ontopLevel as! String)! + } } collectionBehavior.remove(.transient) collectionBehavior.insert(.managed) |