summaryrefslogtreecommitdiffstats
path: root/video/out/cocoa-cb
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2019-07-20 12:16:37 +0200
committerJan Ekström <jeebjp@gmail.com>2019-07-21 18:13:07 +0300
commita8c2e2986838dccbcc4bd218b501f0bf86b36e2c (patch)
tree0f9ce3f16cc72c47dd70e9961e6c9b9f1cdabd43 /video/out/cocoa-cb
parent0602f082cb9775b4c9c8e256b1cb9de218a3b5fc (diff)
downloadmpv-a8c2e2986838dccbcc4bd218b501f0bf86b36e2c.tar.bz2
mpv-a8c2e2986838dccbcc4bd218b501f0bf86b36e2c.tar.xz
cocoa-cb: migrate to swift 5 with swift 4 fallback
this migrates our current swift code to version 5 and 4. building is support from 10.12.6 and xcode 9.1 onwards. dynamic linking is the new default, since Apple removed static libs from their new toolchains and it's the recommended way. additionally the found macOS SDK version is printed since it's an important information for finding possible errors now. Fixes #6470
Diffstat (limited to 'video/out/cocoa-cb')
-rw-r--r--video/out/cocoa-cb/events_view.swift39
-rw-r--r--video/out/cocoa-cb/title_bar.swift22
-rw-r--r--video/out/cocoa-cb/window.swift28
3 files changed, 40 insertions, 49 deletions
diff --git a/video/out/cocoa-cb/events_view.swift b/video/out/cocoa-cb/events_view.swift
index 9c30e32ca0..59441d9793 100644
--- a/video/out/cocoa-cb/events_view.swift
+++ b/video/out/cocoa-cb/events_view.swift
@@ -32,11 +32,9 @@ class EventsView: NSView {
init(cocoaCB ccb: CocoaCB) {
cocoaCB = ccb
super.init(frame: NSMakeRect(0, 0, 960, 480))
- autoresizingMask = [.viewWidthSizable, .viewHeightSizable]
+ autoresizingMask = [.width, .height]
wantsBestResolutionOpenGLSurface = true
- register(forDraggedTypes: [ NSFilenamesPboardType,
- NSURLPboardType,
- NSPasteboardTypeString ])
+ registerForDraggedTypes([ .fileURLCompat, .URLCompat, .string ])
}
required init?(coder: NSCoder) {
@@ -60,11 +58,8 @@ class EventsView: NSView {
}
override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation {
- guard let types = sender.draggingPasteboard().types else { return [] }
- if types.contains(NSFilenamesPboardType) ||
- types.contains(NSURLPboardType) ||
- types.contains(NSPasteboardTypeString)
- {
+ guard let types = sender.draggingPasteboard.types else { return [] }
+ if types.contains(.fileURLCompat) || types.contains(.URLCompat) || types.contains(.string) {
return .copy
}
return []
@@ -81,21 +76,17 @@ class EventsView: NSView {
}
override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
- let pb = sender.draggingPasteboard()
- guard let types = sender.draggingPasteboard().types else { return false }
- if types.contains(NSFilenamesPboardType) {
- if let files = pb.propertyList(forType: NSFilenamesPboardType) as? [Any] {
+ let pb = sender.draggingPasteboard
+ guard let types = pb.types else { return false }
+
+ if types.contains(.fileURLCompat) || types.contains(.URLCompat) {
+ if let urls = pb.readObjects(forClasses: [NSURL.self]) as? [URL] {
+ let files = urls.map { $0.absoluteString }
EventsResponder.sharedInstance().handleFilesArray(files)
return true
}
- } else if types.contains(NSURLPboardType) {
- if var url = pb.propertyList(forType: NSURLPboardType) as? [String] {
- url = url.filter{ !$0.isEmpty }
- EventsResponder.sharedInstance().handleFilesArray(url)
- return true
- }
- } else if types.contains(NSPasteboardTypeString) {
- guard let str = pb.string(forType: NSPasteboardTypeString) else { return false }
+ } else if types.contains(.string) {
+ guard let str = pb.string(forType: .string) else { return false }
var filesArray: [String] = []
for val in str.components(separatedBy: "\n") {
@@ -220,7 +211,7 @@ class EventsView: NSView {
var delta: Double
var cmd: Int32
- if fabs(event.deltaY) >= fabs(event.deltaX) {
+ if abs(event.deltaY) >= abs(event.deltaX) {
delta = Double(event.deltaY) * 0.1;
cmd = delta > 0 ? SWIFT_WHEEL_UP : SWIFT_WHEEL_DOWN;
} else {
@@ -228,7 +219,7 @@ class EventsView: NSView {
cmd = delta > 0 ? SWIFT_WHEEL_RIGHT : SWIFT_WHEEL_LEFT;
}
- mpv.putAxis(cmd, delta: fabs(delta))
+ mpv.putAxis(cmd, delta: abs(delta))
}
override func scrollWheel(with event: NSEvent) {
@@ -244,7 +235,7 @@ class EventsView: NSView {
let deltaY = modifiers.contains(.shift) ? event.scrollingDeltaX : event.scrollingDeltaY
var mpkey: Int32
- if fabs(deltaY) >= fabs(deltaX) {
+ if abs(deltaY) >= abs(deltaX) {
mpkey = deltaY > 0 ? SWIFT_WHEEL_UP : SWIFT_WHEEL_DOWN;
} else {
mpkey = deltaX > 0 ? SWIFT_WHEEL_RIGHT : SWIFT_WHEEL_LEFT;
diff --git a/video/out/cocoa-cb/title_bar.swift b/video/out/cocoa-cb/title_bar.swift
index f5979c71e9..f961b1908a 100644
--- a/video/out/cocoa-cb/title_bar.swift
+++ b/video/out/cocoa-cb/title_bar.swift
@@ -29,7 +29,7 @@ class TitleBar: NSVisualEffectView {
get { return NSWindow.frameRect(forContentRect: CGRect.zero, styleMask: .titled).size.height }
}
var buttons: [NSButton] {
- get { return ([.closeButton, .miniaturizeButton, .zoomButton] as [NSWindowButton]).flatMap { cocoaCB.window?.standardWindowButton($0) } }
+ get { return ([.closeButton, .miniaturizeButton, .zoomButton] as [NSWindow.ButtonType]).compactMap { cocoaCB.window?.standardWindowButton($0) } }
}
override var material: NSVisualEffectView.Material {
@@ -57,7 +57,7 @@ class TitleBar: NSVisualEffectView {
super.init(frame: f)
alphaValue = 0
blendingMode = .withinWindow
- autoresizingMask = [.viewWidthSizable, .viewMinYMargin]
+ autoresizingMask = [.width, .minYMargin]
systemBar?.alphaValue = 0
state = .followsWindowActiveState
wantsLayer = true
@@ -148,7 +148,7 @@ class TitleBar: NSVisualEffectView {
}
}
- func hide() {
+ @objc func hide() {
guard let window = cocoaCB.window else { return }
if window.isInFullscreen && !window.isAnimating {
alphaValue = 0
@@ -175,26 +175,26 @@ class TitleBar: NSVisualEffectView {
func appearanceFrom(string: String) -> NSAppearance? {
switch string {
case "1", "aqua":
- return NSAppearance(named: NSAppearanceNameAqua)
+ return NSAppearance(named: .aqua)
case "3", "vibrantLight":
- return NSAppearance(named: NSAppearanceNameVibrantLight)
+ return NSAppearance(named: .vibrantLight)
case "4", "vibrantDark":
- return NSAppearance(named: NSAppearanceNameVibrantDark)
+ return NSAppearance(named: .vibrantDark)
default: break
}
if #available(macOS 10.14, *) {
switch string {
case "2", "darkAqua":
- return NSAppearance(named: NSAppearanceNameDarkAqua)
+ return NSAppearance(named: .darkAqua)
case "5", "aquaHighContrast":
- return NSAppearance(named: NSAppearanceNameAccessibilityHighContrastAqua)
+ return NSAppearance(named: .accessibilityHighContrastAqua)
case "6", "darkAquaHighContrast":
- return NSAppearance(named: NSAppearanceNameAccessibilityHighContrastDarkAqua)
+ return NSAppearance(named: .accessibilityHighContrastDarkAqua)
case "7", "vibrantLightHighContrast":
- return NSAppearance(named: NSAppearanceNameAccessibilityHighContrastVibrantLight)
+ return NSAppearance(named: .accessibilityHighContrastVibrantLight)
case "8", "vibrantDarkHighContrast":
- return NSAppearance(named: NSAppearanceNameAccessibilityHighContrastVibrantDark)
+ return NSAppearance(named: .accessibilityHighContrastVibrantDark)
case "0", "auto": fallthrough
default:
return nil
diff --git a/video/out/cocoa-cb/window.swift b/video/out/cocoa-cb/window.swift
index dc7762c5af..2f87711d22 100644
--- a/video/out/cocoa-cb/window.swift
+++ b/video/out/cocoa-cb/window.swift
@@ -54,7 +54,7 @@ class Window: NSWindow, NSWindowDelegate {
override var canBecomeKey: Bool { return true }
override var canBecomeMain: Bool { return true }
- override var styleMask: NSWindowStyleMask {
+ override var styleMask: NSWindow.StyleMask {
get { return super.styleMask }
set {
let responder = firstResponder
@@ -72,7 +72,7 @@ class Window: NSWindow, NSWindowDelegate {
// workaround for an AppKit bug where the NSWindow can't be placed on a
// none Main screen NSScreen outside the Main screen's frame bounds
- if let wantedScreen = screen, screen != NSScreen.main() {
+ if let wantedScreen = screen, screen != NSScreen.main {
var absoluteWantedOrigin = contentRect.origin
absoluteWantedOrigin.x += wantedScreen.frame.origin.x
absoluteWantedOrigin.y += wantedScreen.frame.origin.y
@@ -255,26 +255,26 @@ class Window: NSWindow, NSWindowDelegate {
}
func setOnTop(_ state: Bool, _ ontopLevel: Any) {
- let stdLevel = Int(CGWindowLevelForKey(.normalWindow))
+ let stdLevel: NSWindow.Level = .normal
if state {
if ontopLevel is Int {
switch ontopLevel as? Int {
case .some(-1):
- level = Int(CGWindowLevelForKey(.floatingWindow))
+ level = .floating
case .some(-2):
- level = Int(CGWindowLevelForKey(.statusWindow))+1
+ level = .statusBar + 1
default:
- level = ontopLevel as? Int ?? stdLevel
+ level = NSWindow.Level(ontopLevel as? Int ?? stdLevel.rawValue)
}
} else {
switch ontopLevel as? String {
case .some("window"):
- level = Int(CGWindowLevelForKey(.floatingWindow))
+ level = .floating
case .some("system"):
- level = Int(CGWindowLevelForKey(.statusWindow))+1
+ level = .statusBar + 1
default:
- level = Int(ontopLevel as? String ?? "") ?? stdLevel
+ level = NSWindow.Level(Int(ontopLevel as? String ?? "") ?? stdLevel.rawValue)
}
}
collectionBehavior.remove(.transient)
@@ -410,7 +410,7 @@ class Window: NSWindow, NSWindowDelegate {
return frameRect
}
- guard let ts: NSScreen = tScreen ?? screen ?? NSScreen.main() else {
+ guard let ts: NSScreen = tScreen ?? screen ?? NSScreen.main else {
return frameRect
}
var nf: NSRect = frameRect
@@ -443,9 +443,9 @@ class Window: NSWindow, NSWindowDelegate {
return nf
}
- func setNormalWindowSize() { setWindowScale(1.0) }
- func setHalfWindowSize() { setWindowScale(0.5) }
- func setDoubleWindowSize() { setWindowScale(2.0) }
+ @objc func setNormalWindowSize() { setWindowScale(1.0) }
+ @objc func setHalfWindowSize() { setWindowScale(0.5) }
+ @objc func setDoubleWindowSize() { setWindowScale(2.0) }
func setWindowScale(_ scale: Double) {
mpv.commandAsync(["osd-auto", "set", "window-scale", "\(scale)"])
@@ -480,7 +480,7 @@ class Window: NSWindow, NSWindowDelegate {
cocoaCB.layer?.inLiveResize = false
}
- func windowShouldClose(_ sender: Any) -> Bool {
+ func windowShouldClose(_ sender: NSWindow) -> Bool {
cocoa_put_key(SWIFT_KEY_CLOSE_WIN)
return false
}