summaryrefslogtreecommitdiffstats
path: root/osdep/mac
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2024-04-27 22:11:33 +0200
committerder richter <der.richter@gmx.de>2024-04-28 20:21:18 +0200
commit8f1189341fcc5cddc92056078aa2439d451d1c98 (patch)
tree4ab3a10de71ff54ca05ddfb4498be17b17272f9d /osdep/mac
parent984c890661fef3bc5e326a291803c10ed86b6350 (diff)
downloadmpv-8f1189341fcc5cddc92056078aa2439d451d1c98.tar.bz2
mpv-8f1189341fcc5cddc92056078aa2439d451d1c98.tar.xz
mac: code cleanup and consistency changes, fix linting issues
Diffstat (limited to 'osdep/mac')
-rw-r--r--osdep/mac/app_hub.swift2
-rw-r--r--osdep/mac/application.swift6
-rw-r--r--osdep/mac/event_helper.swift10
-rw-r--r--osdep/mac/input_helper.swift44
-rw-r--r--osdep/mac/libmpv_helper.swift12
-rw-r--r--osdep/mac/log_helper.swift4
-rw-r--r--osdep/mac/menu_bar.swift30
-rw-r--r--osdep/mac/option_helper.swift14
-rw-r--r--osdep/mac/precise_timer.swift8
-rw-r--r--osdep/mac/remote_command_center.swift16
-rw-r--r--osdep/mac/swift_compat.swift3
-rw-r--r--osdep/mac/swift_extensions.swift28
-rw-r--r--osdep/mac/touch_bar.swift22
-rw-r--r--osdep/mac/type_helper.swift4
14 files changed, 95 insertions, 108 deletions
diff --git a/osdep/mac/app_hub.swift b/osdep/mac/app_hub.swift
index 997cc33847..81390744dc 100644
--- a/osdep/mac/app_hub.swift
+++ b/osdep/mac/app_hub.swift
@@ -37,7 +37,7 @@ class AppHub: NSObject {
#endif
let MPV_PROTOCOL: String = "mpv://"
- var isApplication: Bool { get { NSApp is Application } }
+ var isApplication: Bool { return NSApp is Application }
var openEvents: Int = 0
private override init() {
diff --git a/osdep/mac/application.swift b/osdep/mac/application.swift
index 30f37a6f49..23a15023e8 100644
--- a/osdep/mac/application.swift
+++ b/osdep/mac/application.swift
@@ -18,9 +18,9 @@
import Cocoa
class Application: NSApplication, NSApplicationDelegate {
- var appHub: AppHub { get { return AppHub.shared } }
- var eventManager: NSAppleEventManager { get { return NSAppleEventManager.shared() } }
- var isBundle: Bool { get { return ProcessInfo.processInfo.environment["MPVBUNDLE"] == "true" } }
+ var appHub: AppHub { return AppHub.shared }
+ var eventManager: NSAppleEventManager { return NSAppleEventManager.shared() }
+ var isBundle: Bool { return ProcessInfo.processInfo.environment["MPVBUNDLE"] == "true" }
var playbackThreadId: mp_thread!
var argc: Int32?
var argv: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?
diff --git a/osdep/mac/event_helper.swift b/osdep/mac/event_helper.swift
index ac388001c8..0f194ce8aa 100644
--- a/osdep/mac/event_helper.swift
+++ b/osdep/mac/event_helper.swift
@@ -23,7 +23,7 @@ protocol EventSubscriber: AnyObject {
}
extension EventSubscriber {
- var uid: Int { get { return Int(bitPattern: ObjectIdentifier(self)) }}
+ var uid: Int { return Int(bitPattern: ObjectIdentifier(self)) }
}
extension EventHelper {
@@ -31,10 +31,10 @@ extension EventHelper {
struct Event {
var id: String {
- get { name + (name.starts(with: "MPV_EVENT_") ? "" : String(format.rawValue)) }
+ return name + (name.starts(with: "MPV_EVENT_") ? "" : String(format.rawValue))
}
var idReset: String {
- get { name + (name.starts(with: "MPV_EVENT_") ? "" : String(MPV_FORMAT_NONE.rawValue)) }
+ return name + (name.starts(with: "MPV_EVENT_") ? "" : String(MPV_FORMAT_NONE.rawValue))
}
let name: String
let format: mpv_format
@@ -62,7 +62,7 @@ extension EventHelper {
class EventHelper {
unowned let appHub: AppHub
var mpv: OpaquePointer?
- var events: [String:[Int:EventSubscriber]] = [:]
+ var events: [String: [Int: EventSubscriber]] = [:]
init?(_ appHub: AppHub, _ mpv: OpaquePointer) {
if !appHub.isApplication {
@@ -128,7 +128,7 @@ class EventHelper {
let name = String(cString: property.name)
let format = property.format
for (_, subscriber) in events[name + String(format.rawValue)] ?? [:] {
- var event: Event? = nil
+ var event: Event?
switch format {
case MPV_FORMAT_STRING:
event = .init(name: name, format: format, string: TypeHelper.toString(property.data))
diff --git a/osdep/mac/input_helper.swift b/osdep/mac/input_helper.swift
index e5268ade4c..0fa0119ad4 100644
--- a/osdep/mac/input_helper.swift
+++ b/osdep/mac/input_helper.swift
@@ -25,24 +25,24 @@ class InputHelper: NSObject {
let keymap: [mp_keymap] = [
// special keys
- .init(kVK_Return, MP_KEY_ENTER), .init(kVK_Escape, MP_KEY_ESC),
- .init(kVK_Delete, MP_KEY_BACKSPACE), .init(kVK_Tab, MP_KEY_TAB),
+ .init(kVK_Return, MP_KEY_ENTER), .init(kVK_Escape, MP_KEY_ESC),
+ .init(kVK_Delete, MP_KEY_BACKSPACE), .init(kVK_Tab, MP_KEY_TAB),
.init(kVK_VolumeUp, MP_KEY_VOLUME_UP), .init(kVK_VolumeDown, MP_KEY_VOLUME_DOWN),
.init(kVK_Mute, MP_KEY_MUTE),
// cursor keys
- .init(kVK_UpArrow, MP_KEY_UP), .init(kVK_DownArrow, MP_KEY_DOWN),
+ .init(kVK_UpArrow, MP_KEY_UP), .init(kVK_DownArrow, MP_KEY_DOWN),
.init(kVK_LeftArrow, MP_KEY_LEFT), .init(kVK_RightArrow, MP_KEY_RIGHT),
// navigation block
- .init(kVK_Help, MP_KEY_INSERT), .init(kVK_ForwardDelete, MP_KEY_DELETE),
- .init(kVK_Home, MP_KEY_HOME), .init(kVK_End, MP_KEY_END),
+ .init(kVK_Help, MP_KEY_INSERT), .init(kVK_ForwardDelete, MP_KEY_DELETE),
+ .init(kVK_Home, MP_KEY_HOME), .init(kVK_End, MP_KEY_END),
.init(kVK_PageUp, MP_KEY_PAGE_UP), .init(kVK_PageDown, MP_KEY_PAGE_DOWN),
// F-keys
- .init(kVK_F1, MP_KEY_F + 1), .init(kVK_F2, MP_KEY_F + 2), .init(kVK_F3, MP_KEY_F + 3),
- .init(kVK_F4, MP_KEY_F + 4), .init(kVK_F5, MP_KEY_F + 5), .init(kVK_F6, MP_KEY_F + 6),
- .init(kVK_F7, MP_KEY_F + 7), .init(kVK_F8, MP_KEY_F + 8), .init(kVK_F9, MP_KEY_F + 9),
+ .init(kVK_F1, MP_KEY_F + 1), .init(kVK_F2, MP_KEY_F + 2), .init(kVK_F3, MP_KEY_F + 3),
+ .init(kVK_F4, MP_KEY_F + 4), .init(kVK_F5, MP_KEY_F + 5), .init(kVK_F6, MP_KEY_F + 6),
+ .init(kVK_F7, MP_KEY_F + 7), .init(kVK_F8, MP_KEY_F + 8), .init(kVK_F9, MP_KEY_F + 9),
.init(kVK_F10, MP_KEY_F + 10), .init(kVK_F11, MP_KEY_F + 11), .init(kVK_F12, MP_KEY_F + 12),
.init(kVK_F13, MP_KEY_F + 13), .init(kVK_F14, MP_KEY_F + 14), .init(kVK_F15, MP_KEY_F + 15),
.init(kVK_F16, MP_KEY_F + 16), .init(kVK_F17, MP_KEY_F + 17), .init(kVK_F18, MP_KEY_F + 18),
@@ -54,11 +54,11 @@ class InputHelper: NSObject {
.init(kVK_ANSI_KeypadMultiply, Int32(Character("*").asciiValue ?? 0)),
.init(kVK_ANSI_KeypadDivide, Int32(Character("/").asciiValue ?? 0)),
.init(kVK_ANSI_KeypadEnter, MP_KEY_KPENTER), .init(kVK_ANSI_KeypadDecimal, MP_KEY_KPDEC),
- .init(kVK_ANSI_Keypad0, MP_KEY_KP0), .init(kVK_ANSI_Keypad1, MP_KEY_KP1),
- .init(kVK_ANSI_Keypad2, MP_KEY_KP2), .init(kVK_ANSI_Keypad3, MP_KEY_KP3),
- .init(kVK_ANSI_Keypad4, MP_KEY_KP4), .init(kVK_ANSI_Keypad5, MP_KEY_KP5),
- .init(kVK_ANSI_Keypad6, MP_KEY_KP6), .init(kVK_ANSI_Keypad7, MP_KEY_KP7),
- .init(kVK_ANSI_Keypad8, MP_KEY_KP8), .init(kVK_ANSI_Keypad9, MP_KEY_KP9),
+ .init(kVK_ANSI_Keypad0, MP_KEY_KP0), .init(kVK_ANSI_Keypad1, MP_KEY_KP1),
+ .init(kVK_ANSI_Keypad2, MP_KEY_KP2), .init(kVK_ANSI_Keypad3, MP_KEY_KP3),
+ .init(kVK_ANSI_Keypad4, MP_KEY_KP4), .init(kVK_ANSI_Keypad5, MP_KEY_KP5),
+ .init(kVK_ANSI_Keypad6, MP_KEY_KP6), .init(kVK_ANSI_Keypad7, MP_KEY_KP7),
+ .init(kVK_ANSI_Keypad8, MP_KEY_KP8), .init(kVK_ANSI_Keypad9, MP_KEY_KP9),
.init(0, 0)
]
@@ -187,7 +187,7 @@ class InputHelper: NSObject {
}
private func mapType(_ type: NSEvent.EventType) -> Int32 {
- let typeMapping: [NSEvent.EventType:UInt32] = [
+ let typeMapping: [NSEvent.EventType: UInt32] = [
.keyDown: MP_KEY_STATE_DOWN,
.keyUp: MP_KEY_STATE_UP,
.leftMouseDown: MP_KEY_STATE_DOWN,
@@ -195,14 +195,14 @@ class InputHelper: NSObject {
.rightMouseDown: MP_KEY_STATE_DOWN,
.rightMouseUp: MP_KEY_STATE_UP,
.otherMouseDown: MP_KEY_STATE_DOWN,
- .otherMouseUp: MP_KEY_STATE_UP,
+ .otherMouseUp: MP_KEY_STATE_UP
]
- return Int32(typeMapping[type] ?? 0);
+ return Int32(typeMapping[type] ?? 0)
}
private func mapModifier(_ modifiers: NSEvent.ModifierFlags) -> Int32 {
- var mask: UInt32 = 0;
+ var mask: UInt32 = 0
if modifiers.contains(.shift) {
mask |= MP_KEY_MODIFIER_SHIFT
@@ -221,15 +221,15 @@ class InputHelper: NSObject {
}
private func map(button: Int) -> Int32 {
- let buttonMapping: [Int:Int32] = [
+ let buttonMapping: [Int: Int32] = [
0: SWIFT_MBTN_LEFT,
1: SWIFT_MBTN_RIGHT,
2: SWIFT_MBTN_MID,
3: SWIFT_MBTN_FORWARD,
- 4: SWIFT_MBTN_BACK,
+ 4: SWIFT_MBTN_BACK
]
- return Int32(buttonMapping[button] ?? SWIFT_MBTN9 + Int32(button - 5));
+ return Int32(buttonMapping[button] ?? SWIFT_MBTN9 + Int32(button - 5))
}
func mapDeadKey(_ event: NSEvent) -> String {
@@ -257,12 +257,12 @@ class InputHelper: NSObject {
var action = DND_APPEND
if !append {
action = NSEvent.modifierFlags.contains(.shift) ? DND_APPEND : DND_REPLACE
- if (option?.vo.drag_and_drop ?? -1) >= 0 {
+ if (option?.vo.drag_and_drop ?? -1) >= 0 {
action = mp_dnd_action(UInt32(option?.vo.drag_and_drop ?? Int32(DND_REPLACE.rawValue)))
}
}
- let filesClean = files.map{ $0.hasPrefix("file:///.file/id=") ? (URL(string: $0)?.path ?? $0) : $0 }
+ let filesClean = files.map { $0.hasPrefix("file:///.file/id=") ? (URL(string: $0)?.path ?? $0) : $0 }
var filesPtr = filesClean.map { UnsafeMutablePointer<CChar>(strdup($0)) }
mp_event_drop_files(input, Int32(files.count), &filesPtr, action)
for charPtr in filesPtr { free(UnsafeMutablePointer(mutating: charPtr)) }
diff --git a/osdep/mac/libmpv_helper.swift b/osdep/mac/libmpv_helper.swift
index 23953eb145..e26d33edda 100644
--- a/osdep/mac/libmpv_helper.swift
+++ b/osdep/mac/libmpv_helper.swift
@@ -47,7 +47,7 @@ class LibmpvHelper {
mpv_render_param()
]
- if (mpv_render_context_create(&mpvRenderContext, mpv, &params) < 0) {
+ if mpv_render_context_create(&mpvRenderContext, mpv, &params) < 0 {
log.error("Render context init has failed.")
exit(1)
}
@@ -55,12 +55,8 @@ class LibmpvHelper {
}
let getProcAddress: (@convention(c) (UnsafeMutableRawPointer?, UnsafePointer<Int8>?)
- -> UnsafeMutableRawPointer?) =
- {
- (ctx: UnsafeMutableRawPointer?, name: UnsafePointer<Int8>?)
- -> UnsafeMutableRawPointer? in
- let symbol: CFString = CFStringCreateWithCString(
- kCFAllocatorDefault, name, kCFStringEncodingASCII)
+ -> UnsafeMutableRawPointer?) = { (_ ctx: UnsafeMutableRawPointer?, name: UnsafePointer<Int8>?) -> UnsafeMutableRawPointer? in
+ let symbol: CFString = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingASCII)
let identifier = CFBundleGetBundleWithIdentifier("com.apple.opengl" as CFString)
let addr = CFBundleGetFunctionPointerForName(identifier, symbol)
@@ -128,7 +124,7 @@ class LibmpvHelper {
mpv_render_param(type: MPV_RENDER_PARAM_SKIP_RENDERING, data: pointers[3]),
mpv_render_param()
]
- mpv_render_context_render(mpvRenderContext, &params);
+ mpv_render_context_render(mpvRenderContext, &params)
}
} else {
glClearColor(0, 0, 0, 1)
diff --git a/osdep/mac/log_helper.swift b/osdep/mac/log_helper.swift
index 3d349a487c..690d7bcbc1 100644
--- a/osdep/mac/log_helper.swift
+++ b/osdep/mac/log_helper.swift
@@ -22,11 +22,11 @@ class LogHelper {
var log: OpaquePointer?
let logger = Logger(subsystem: "io.mpv", category: "mpv")
- let loggerMapping: [Int:OSLogType] = [
+ let loggerMapping: [Int: OSLogType] = [
MSGL_V: .debug,
MSGL_INFO: .info,
MSGL_WARN: .error,
- MSGL_ERR: .fault,
+ MSGL_ERR: .fault
]
init(_ log: OpaquePointer? = nil) {
diff --git a/osdep/mac/menu_bar.swift b/osdep/mac/menu_bar.swift
index b58367a7a6..4abbd912e1 100644
--- a/osdep/mac/menu_bar.swift
+++ b/osdep/mac/menu_bar.swift
@@ -74,7 +74,7 @@ class MenuBar: NSObject {
let mainMenu = NSMenu(title: "Main")
let servicesMenu = NSMenu(title: "Services")
var menuConfigs: [Config] = []
- var dynamicMenuItems: [Type:[MenuItem]] = [:]
+ var dynamicMenuItems: [Type: [MenuItem]] = [:]
let appIcon: NSImage
@objc init(_ appHub: AppHub) {
@@ -111,7 +111,7 @@ class MenuBar: NSObject {
Config(name: "Show All", action: #selector(NSApp.unhideAllApplications(_:))),
Config(type: .separator),
Config(name: "Quit and Remember Position", action: #selector(command(_:)), target: self, command: "quit-watch-later"),
- Config(name: "Quit mpv", key: "q", action: #selector(command(_:)), target: self, command: "quit"),
+ Config(name: "Quit mpv", key: "q", action: #selector(command(_:)), target: self, command: "quit")
]
let fileMenuConfigs = [
@@ -120,7 +120,7 @@ class MenuBar: NSObject {
Config(name: "Open Playlist…", action: #selector(openPlaylist), target: self),
Config(type: .separator),
Config(name: "Close", key: "w", action: #selector(NSWindow.performClose(_:))),
- Config(name: "Save Screenshot", action: #selector(command(_:)), target: self, command: "async screenshot"),
+ Config(name: "Save Screenshot", action: #selector(command(_:)), target: self, command: "async screenshot")
]
let editMenuConfigs = [
@@ -130,7 +130,7 @@ class MenuBar: NSObject {
Config(name: "Cut", key: "x", action: #selector(NSText.cut(_:))),
Config(name: "Copy", key: "c", action: #selector(NSText.copy(_:))),
Config(name: "Paste", key: "v", action: #selector(NSText.paste(_:))),
- Config(name: "Select All", key: "a", action: #selector(NSResponder.selectAll(_:))),
+ Config(name: "Select All", key: "a", action: #selector(NSResponder.selectAll(_:)))
]
var viewMenuConfigs = [
@@ -141,12 +141,12 @@ class MenuBar: NSObject {
action: #selector(command(_:)),
target: self,
command: "cycle on-all-workspaces"
- ),
+ )
]
#if HAVE_MACOS_TOUCHBAR
viewMenuConfigs += [
Config(type: .separator),
- Config(name: "Customize Touch Bar…", action: #selector(NSApp.toggleTouchBarCustomizationPalette(_:))),
+ Config(name: "Customize Touch Bar…", action: #selector(NSApp.toggleTouchBarCustomizationPalette(_:)))
]
#endif
@@ -167,7 +167,7 @@ class MenuBar: NSObject {
Config(type: .separator),
Config(name: "Half Size", key: "0", type: .itemHalfSize),
Config(name: "Normal Size", key: "1", type: .itemNormalSize),
- Config(name: "Double Size", key: "2", type: .itemDoubleSize),
+ Config(name: "Double Size", key: "2", type: .itemDoubleSize)
]
let audioMenuConfigs = [
@@ -178,7 +178,7 @@ class MenuBar: NSObject {
Config(type: .separator),
Config(name: "Play Audio Later", action: #selector(command(_:)), target: self, command: "add audio-delay 0.1"),
Config(name: "Play Audio Earlier", action: #selector(command(_:)), target: self, command: "add audio-delay -0.1"),
- Config(name: "Reset Audio Delay", action: #selector(command(_:)), target: self, command: "set audio-delay 0.0"),
+ Config(name: "Reset Audio Delay", action: #selector(command(_:)), target: self, command: "set audio-delay 0.0")
]
let subtitleMenuConfigs = [
@@ -189,7 +189,7 @@ class MenuBar: NSObject {
Config(type: .separator),
Config(name: "Display Subtitles Later", action: #selector(command(_:)), target: self, command: "add sub-delay 0.1"),
Config(name: "Display Subtitles Earlier", action: #selector(command(_:)), target: self, command: "add sub-delay -0.1"),
- Config(name: "Reset Subtitle Delay", action: #selector(command(_:)), target: self, command: "set sub-delay 0.0"),
+ Config(name: "Reset Subtitle Delay", action: #selector(command(_:)), target: self, command: "set sub-delay 0.0")
]
let playbackMenuConfigs = [
@@ -212,12 +212,12 @@ class MenuBar: NSObject {
Config(name: "Previous Chapter", action: #selector(command(_:)), target: self, command: "add chapter -1"),
Config(type: .separator),
Config(name: "Step Forward", action: #selector(command(_:)), target: self, command: "frame-step"),
- Config(name: "Step Backward", action: #selector(command(_:)), target: self, command: "frame-back-step"),
+ Config(name: "Step Backward", action: #selector(command(_:)), target: self, command: "frame-back-step")
]
let windowMenuConfigs = [
Config(name: "Minimize", key: "m", type: .itemMinimize),
- Config(name: "Zoom", type: .itemZoom),
+ Config(name: "Zoom", type: .itemZoom)
]
var helpMenuConfigs = [
@@ -229,7 +229,7 @@ class MenuBar: NSObject {
Config(name: "Release Notes…", action: #selector(url(_:)), target: self, url: "https://github.com/mpv-player/mpv/blob/master/RELEASE_NOTES"),
Config(name: "Keyboard Shortcuts…", action: #selector(url(_:)), target: self, url: "https://github.com/mpv-player/mpv/blob/master/etc/input.conf"),
Config(type: .separator),
- Config(name: "Report Issue…", action: #selector(url(_:)), target: self, url: "https://github.com/mpv-player/mpv/issues/new/choose"),
+ Config(name: "Report Issue…", action: #selector(url(_:)), target: self, url: "https://github.com/mpv-player/mpv/issues/new/choose")
]
if ProcessInfo.processInfo.environment["MPVBUNDLE"] == "true" {
helpMenuConfigs += [
@@ -247,7 +247,7 @@ class MenuBar: NSObject {
Config(name: "Subtitle", configs: subtitleMenuConfigs),
Config(name: "Playback", configs: playbackMenuConfigs),
Config(name: "Window", configs: windowMenuConfigs),
- Config(name: "Help", configs: helpMenuConfigs),
+ Config(name: "Help", configs: helpMenuConfigs)
]
createMenu(parentMenu: mainMenu, configs: menuConfigs)
@@ -290,7 +290,7 @@ class MenuBar: NSObject {
.applicationName: "mpv",
.applicationIcon: appIcon,
.applicationVersion: String(cString: swift_mpv_version),
- .init(rawValue: "Copyright"): String(cString: swift_mpv_copyright),
+ .init(rawValue: "Copyright"): String(cString: swift_mpv_copyright)
])
}
@@ -298,7 +298,7 @@ class MenuBar: NSObject {
guard let menuConfig = menuItem.config else { return }
let configPaths: [URL] = [
URL(fileURLWithPath: NSHomeDirectory() + "/.config/mpv/", isDirectory: true),
- URL(fileURLWithPath: NSHomeDirectory() + "/.mpv/", isDirectory: true),
+ URL(fileURLWithPath: NSHomeDirectory() + "/.mpv/", isDirectory: true)
]
for path in configPaths {
diff --git a/osdep/mac/option_helper.swift b/osdep/mac/option_helper.swift
index d7aaa0c670..40caed2eb7 100644
--- a/osdep/mac/option_helper.swift
+++ b/osdep/mac/option_helper.swift
@@ -25,16 +25,18 @@ class OptionHelper {
var voCachePtr: UnsafeMutablePointer<m_config_cache>
var macCachePtr: UnsafeMutablePointer<m_config_cache>
- var voPtr: UnsafeMutablePointer<mp_vo_opts>
- { get { return UnsafeMutablePointer<mp_vo_opts>(OpaquePointer(voCachePtr.pointee.opts)) } }
- var macPtr: UnsafeMutablePointer<macos_opts>
- { get { return UnsafeMutablePointer<macos_opts>(OpaquePointer(macCachePtr.pointee.opts)) } }
+ var voPtr: UnsafeMutablePointer<mp_vo_opts> {
+ return UnsafeMutablePointer<mp_vo_opts>(OpaquePointer(voCachePtr.pointee.opts))
+ }
+ var macPtr: UnsafeMutablePointer<macos_opts> {
+ return UnsafeMutablePointer<macos_opts>(OpaquePointer(macCachePtr.pointee.opts))
+ }
// these computed properties return a local copy of the struct accessed:
// - don't use if you rely on the pointers
// - only for reading
- var vo: mp_vo_opts { get { return voPtr.pointee } }
- var mac: macos_opts { get { return macPtr.pointee } }
+ var vo: mp_vo_opts { return voPtr.pointee }
+ var mac: macos_opts { return macPtr.pointee }
init(_ taParent: UnsafeMutableRawPointer, _ global: OpaquePointer?) {
voCachePtr = m_config_cache_alloc(taParent, global, AppHub.shared.getVoConf())
diff --git a/osdep/mac/precise_timer.swift b/osdep/mac/precise_timer.swift
index d4837f92f0..6d5f0b43d0 100644
--- a/osdep/mac/precise_timer.swift
+++ b/osdep/mac/precise_timer.swift
@@ -19,7 +19,7 @@ import Cocoa
struct Timing {
let time: UInt64
- let closure: () -> ()
+ let closure: () -> Void
}
class PreciseTimer {
@@ -97,14 +97,14 @@ class PreciseTimer {
pthread_join(thread, nil)
}
- func scheduleAt(time: UInt64, closure: @escaping () -> ()) {
+ func scheduleAt(time: UInt64, closure: @escaping () -> Void) {
condition.lock()
let firstEventTime = events.first?.time ?? 0
let lastEventTime = events.last?.time ?? 0
events.append(Timing(time: time, closure: closure))
if lastEventTime > time {
- events.sort{ $0.time < $1.time }
+ events.sort { $0.time < $1.time }
}
condition.signal()
@@ -115,7 +115,7 @@ class PreciseTimer {
}
}
- let threadSignal: @convention(c) (Int32) -> () = { (sig: Int32) in }
+ let threadSignal: @convention(c) (Int32) -> Void = { (_ sig: Int32) in }
let entryC: @convention(c) (UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? = { (ptr: UnsafeMutableRawPointer) in
let ptimer: PreciseTimer = TypeHelper.bridge(ptr: ptr)
diff --git a/osdep/mac/remote_command_center.swift b/osdep/mac/remote_command_center.swift
index 0e0eaeb439..e5a937e36f 100644
--- a/osdep/mac/remote_command_center.swift
+++ b/osdep/mac/remote_command_center.swift
@@ -32,7 +32,7 @@ extension RemoteCommandCenter {
var state: NSEvent.EventType = .applicationDefined
let handler: ConfigHandler
- init(key: Int32 = 0, type: KeyType = .normal, handler: @escaping ConfigHandler = { event in return .commandFailed }) {
+ init(key: Int32 = 0, type: KeyType = .normal, handler: @escaping ConfigHandler = { _ in return .commandFailed }) {
self.key = key
self.type = type
self.handler = handler
@@ -42,9 +42,9 @@ extension RemoteCommandCenter {
class RemoteCommandCenter: EventSubscriber {
unowned let appHub: AppHub
- var event: EventHelper? { get { return appHub.event } }
- var input: InputHelper { get { return appHub.input } }
- var configs: [MPRemoteCommand:Config] = [:]
+ var event: EventHelper? { return appHub.event }
+ var input: InputHelper { return appHub.input }
+ var configs: [MPRemoteCommand: Config] = [:]
var disabledCommands: [MPRemoteCommand] = []
var isPaused: Bool = false { didSet { updateInfoCenter() } }
var duration: Double = 0 { didSet { updateInfoCenter() } }
@@ -56,8 +56,8 @@ class RemoteCommandCenter: EventSubscriber {
var artist: String? { didSet { updateInfoCenter() } }
var cover: NSImage
- var infoCenter: MPNowPlayingInfoCenter { get { return MPNowPlayingInfoCenter.default() } }
- var commandCenter: MPRemoteCommandCenter { get { return MPRemoteCommandCenter.shared() } }
+ var infoCenter: MPNowPlayingInfoCenter { return MPNowPlayingInfoCenter.default() }
+ var commandCenter: MPRemoteCommandCenter { return MPRemoteCommandCenter.shared() }
init(_ appHub: AppHub) {
self.appHub = appHub
@@ -72,7 +72,7 @@ class RemoteCommandCenter: EventSubscriber {
commandCenter.togglePlayPauseCommand: Config(key: MP_KEY_PLAY, handler: keyHandler),
commandCenter.seekForwardCommand: Config(key: MP_KEY_FORWARD, type: .repeatable, handler: keyHandler),
commandCenter.seekBackwardCommand: Config(key: MP_KEY_REWIND, type: .repeatable, handler: keyHandler),
- commandCenter.changePlaybackPositionCommand: Config(handler: seekHandler),
+ commandCenter.changePlaybackPositionCommand: Config(handler: seekHandler)
]
disabledCommands = [
@@ -86,7 +86,7 @@ class RemoteCommandCenter: EventSubscriber {
commandCenter.ratingCommand,
commandCenter.likeCommand,
commandCenter.dislikeCommand,
- commandCenter.bookmarkCommand,
+ commandCenter.bookmarkCommand
]
for cmd in disabledCommands {
diff --git a/osdep/mac/swift_compat.swift b/osdep/mac/swift_compat.swift
index 83059dae5c..6924d5cfca 100644
--- a/osdep/mac/swift_compat.swift
+++ b/osdep/mac/swift_compat.swift
@@ -15,7 +15,6 @@
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
-
#if !swift(>=5.0)
extension Data {
mutating func withUnsafeMutableBytes<Type>(_ body: (UnsafeMutableRawBufferPointer) throws -> Type) rethrows -> Type {
@@ -30,7 +29,7 @@ extension Data {
#if !swift(>=4.2)
extension NSDraggingInfo {
var draggingPasteboard: NSPasteboard {
- get { return draggingPasteboard() }
+ return draggingPasteboard()
}
}
#endif
diff --git a/osdep/mac/swift_extensions.swift b/osdep/mac/swift_extensions.swift
index 2bb3d4bf7c..2399c86509 100644
--- a/osdep/mac/swift_extensions.swift
+++ b/osdep/mac/swift_extensions.swift
@@ -24,33 +24,25 @@ extension NSDeviceDescriptionKey {
extension NSScreen {
public var displayID: CGDirectDisplayID {
- get {
- return deviceDescription[.screenNumber] as? CGDirectDisplayID ?? 0
- }
+ return deviceDescription[.screenNumber] as? CGDirectDisplayID ?? 0
}
public var serialNumber: String {
- get {
- return String(CGDisplaySerialNumber(displayID))
- }
+ return String(CGDisplaySerialNumber(displayID))
}
public var name: String {
- get {
- // force unwrapping is fine here, regex is guaranteed to be valid
- let regex = try! NSRegularExpression(pattern: " \\(\\d+\\)$", options: .caseInsensitive)
- return regex.stringByReplacingMatches(
- in: localizedName,
- range: NSRange(location: 0, length: localizedName.count),
- withTemplate: ""
- )
- }
+ // force unwrapping is fine here, regex is guaranteed to be valid
+ let regex = try! NSRegularExpression(pattern: " \\(\\d+\\)$", options: .caseInsensitive)
+ return regex.stringByReplacingMatches(
+ in: localizedName,
+ range: NSRange(location: 0, length: localizedName.count),
+ withTemplate: ""
+ )
}
public var uniqueName: String {
- get {
- return name + " (\(serialNumber))"
- }
+ return name + " (\(serialNumber))"
}
}
diff --git a/osdep/mac/touch_bar.swift b/osdep/mac/touch_bar.swift
index 89c52702f4..6c4ad57169 100644
--- a/osdep/mac/touch_bar.swift
+++ b/osdep/mac/touch_bar.swift
@@ -72,9 +72,9 @@ extension TouchBar {
class TouchBar: NSTouchBar, NSTouchBarDelegate, EventSubscriber {
unowned let appHub: AppHub
- var event: EventHelper? { get { return appHub.event } }
- var input: InputHelper { get { return appHub.input } }
- var configs: [NSTouchBarItem.Identifier:Config] = [:]
+ var event: EventHelper? { return appHub.event }
+ var input: InputHelper { return appHub.input }
+ var configs: [NSTouchBarItem.Identifier: Config] = [:]
var observers: [NSKeyValueObservation] = []
var isPaused: Bool = false { didSet { updatePlayButton() } }
var position: Double = 0 { didSet { updateTouchBarTimeItems() } }
@@ -135,11 +135,11 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate, EventSubscriber {
]
delegate = self
- customizationIdentifier = .customId;
+ customizationIdentifier = .customId
defaultItemIdentifiers = [.play, .previousItem, .nextItem, .seekBar]
customizationAllowedItemIdentifiers = [.play, .seekBar, .previousItem, .nextItem,
.previousChapter, .nextChapter, .cycleAudio, .cycleSubtitle, .currentPosition, .timeLeft]
- observers += [observe(\.isVisible, options: [.new]) { object, change in self.changed(visibility: change.newValue) }]
+ observers += [observe(\.isVisible, options: [.new]) { _, change in self.changed(visibility: change.newValue) }]
event?.subscribe(self, event: .init(name: "duration", format: MPV_FORMAT_DOUBLE))
event?.subscribe(self, event: .init(name: "time-pos", format: MPV_FORMAT_DOUBLE))
@@ -159,7 +159,7 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate, EventSubscriber {
item.view = config.handler(config)
item.customizationLabel = config.name
configs[identifier]?.item = item
- observers += [item.observe(\.isVisible, options: [.new]) { object, change in self.changed(visibility: change.newValue) }]
+ observers += [item.observe(\.isVisible, options: [.new]) { _, change in self.changed(visibility: change.newValue) }]
return item
}
@@ -167,13 +167,13 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate, EventSubscriber {
return NSButton(image: config.image, target: self, action: #selector(Self.buttonAction(_:)))
}
- lazy var createText: ViewHandler = { config in
+ lazy var createText: ViewHandler = { _ in
let text = NSTextField(labelWithString: "0:00")
text.alignment = .center
return text
}
- lazy var createSlider: ViewHandler = { config in
+ lazy var createSlider: ViewHandler = { _ in
let slider = NSSlider(target: self, action: #selector(Self.seekbarChanged(_:)))
slider.minValue = 0
slider.maxValue = 100
@@ -265,10 +265,8 @@ class TouchBar: NSTouchBar, NSTouchBarDelegate, EventSubscriber {
}
func getIdentifierFrom(view: NSView) -> NSTouchBarItem.Identifier? {
- for (identifier, config) in configs {
- if config.item?.view == view {
- return identifier
- }
+ for (identifier, config) in configs where config.item?.view == view {
+ return identifier
}
return nil
}
diff --git a/osdep/mac/type_helper.swift b/osdep/mac/type_helper.swift
index bd90d0ac59..f76a693f71 100644
--- a/osdep/mac/type_helper.swift
+++ b/osdep/mac/type_helper.swift
@@ -27,8 +27,8 @@ class TypeHelper {
}
class func withUnsafeMutableRawPointers(_ arguments: [Any],
- pointers: [UnsafeMutableRawPointer?] = [],
- closure: (_ pointers: [UnsafeMutableRawPointer?]) -> Void) {
+ pointers: [UnsafeMutableRawPointer?] = [],
+ closure: (_ pointers: [UnsafeMutableRawPointer?]) -> Void) {
if arguments.count > 0 {
let args = Array(arguments.dropFirst(1))
var newPtrs = pointers