summaryrefslogtreecommitdiffstats
path: root/osdep/macos
diff options
context:
space:
mode:
Diffstat (limited to 'osdep/macos')
-rw-r--r--osdep/macos/libmpv_helper.swift251
-rw-r--r--osdep/macos/log_helper.swift48
-rw-r--r--osdep/macos/mpv_helper.swift114
-rw-r--r--osdep/macos/remote_command_center.swift190
-rw-r--r--osdep/macos/swift_compat.swift97
-rw-r--r--osdep/macos/swift_extensions.swift89
6 files changed, 0 insertions, 789 deletions
diff --git a/osdep/macos/libmpv_helper.swift b/osdep/macos/libmpv_helper.swift
deleted file mode 100644
index 5f465370dd..0000000000
--- a/osdep/macos/libmpv_helper.swift
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * This file is part of mpv.
- *
- * mpv is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * mpv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import Cocoa
-import OpenGL.GL
-import OpenGL.GL3
-
-let glDummy: @convention(c) () -> Void = {}
-
-class LibmpvHelper: LogHelper {
-
- var mpvHandle: OpaquePointer?
- var mpvRenderContext: OpaquePointer?
- var macOptsPtr: UnsafeMutableRawPointer?
- var macOpts: macos_opts = macos_opts()
- var fbo: GLint = 1
- let deinitLock = NSLock()
-
- init(_ mpv: OpaquePointer, _ name: String) {
- let newlog = mp_log_new(UnsafeMutablePointer<MPContext>(mpv), mp_client_get_log(mpv), name)
- super.init(newlog)
- mpvHandle = mpv
-
- guard let app = NSApp as? Application,
- let ptr = mp_get_config_group(nil,
- mp_client_get_global(mpvHandle),
- app.getMacOSConf()) else
- {
- sendError("macOS config group couldn't be retrieved'")
- exit(1)
- }
- macOptsPtr = ptr
- macOpts = UnsafeMutablePointer<macos_opts>(OpaquePointer(ptr)).pointee
- }
-
- func initRender() {
- var advanced: CInt = 1
- let api = UnsafeMutableRawPointer(mutating: (MPV_RENDER_API_TYPE_OPENGL as NSString).utf8String)
- var pAddress = mpv_opengl_init_params(get_proc_address: getProcAddress,
- get_proc_address_ctx: nil,
- extra_exts: nil)
- var params: [mpv_render_param] = [
- mpv_render_param(type: MPV_RENDER_PARAM_API_TYPE, data: api),
- mpv_render_param(type: MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, data: &pAddress),
- mpv_render_param(type: MPV_RENDER_PARAM_ADVANCED_CONTROL, data: &advanced),
- mpv_render_param()
- ]
-
- if (mpv_render_context_create(&mpvRenderContext, mpvHandle, &params) < 0)
- {
- sendError("Render context init has failed.")
- exit(1)
- }
- }
-
- let getProcAddress: (@convention(c) (UnsafeMutableRawPointer?, UnsafePointer<Int8>?)
- -> UnsafeMutableRawPointer?) =
- {
- (ctx: UnsafeMutableRawPointer?, name: UnsafePointer<Int8>?)
- -> UnsafeMutableRawPointer? in
- let symbol: CFString = CFStringCreateWithCString(
- kCFAllocatorDefault, name, kCFStringEncodingASCII)
- let indentifier = CFBundleGetBundleWithIdentifier("com.apple.opengl" as CFString)
- let addr = CFBundleGetFunctionPointerForName(indentifier, symbol)
-
- if symbol as String == "glFlush" {
- return unsafeBitCast(glDummy, to: UnsafeMutableRawPointer.self)
- }
-
- return addr
- }
-
- func setRenderUpdateCallback(_ callback: @escaping mpv_render_update_fn, context object: AnyObject) {
- if mpvRenderContext == nil {
- sendWarning("Init mpv render context first.")
- } else {
- mpv_render_context_set_update_callback(mpvRenderContext, callback, MPVHelper.bridge(obj: object))
- }
- }
-
- func setRenderControlCallback(_ callback: @escaping mp_render_cb_control_fn, context object: AnyObject) {
- if mpvRenderContext == nil {
- sendWarning("Init mpv render context first.")
- } else {
- mp_render_context_set_control_callback(mpvRenderContext, callback, MPVHelper.bridge(obj: object))
- }
- }
-
- func reportRenderFlip() {
- if mpvRenderContext == nil { return }
- mpv_render_context_report_swap(mpvRenderContext)
- }
-
- func isRenderUpdateFrame() -> Bool {
- deinitLock.lock()
- if mpvRenderContext == nil {
- deinitLock.unlock()
- return false
- }
- let flags: UInt64 = mpv_render_context_update(mpvRenderContext)
- deinitLock.unlock()
- return flags & UInt64(MPV_RENDER_UPDATE_FRAME.rawValue) > 0
- }
-
- func drawRender(_ surface: NSSize, _ depth: GLint, _ ctx: CGLContextObj, skip: Bool = false) {
- deinitLock.lock()
- if mpvRenderContext != nil {
- var i: GLint = 0
- var flip: CInt = 1
- var skip: CInt = skip ? 1 : 0
- var ditherDepth = depth
- glGetIntegerv(GLenum(GL_DRAW_FRAMEBUFFER_BINDING), &i)
- // CAOpenGLLayer has ownership of FBO zero yet can return it to us,
- // so only utilize a newly received FBO ID if it is nonzero.
- fbo = i != 0 ? i : fbo
-
- var data = mpv_opengl_fbo(fbo: Int32(fbo),
- w: Int32(surface.width),
- h: Int32(surface.height),
- internal_format: 0)
- var params: [mpv_render_param] = [
- mpv_render_param(type: MPV_RENDER_PARAM_OPENGL_FBO, data: &data),
- mpv_render_param(type: MPV_RENDER_PARAM_FLIP_Y, data: &flip),
- mpv_render_param(type: MPV_RENDER_PARAM_DEPTH, data: &ditherDepth),
- mpv_render_param(type: MPV_RENDER_PARAM_SKIP_RENDERING, data: &skip),
- mpv_render_param()
- ]
- mpv_render_context_render(mpvRenderContext, &params);
- } else {
- glClearColor(0, 0, 0, 1)
- glClear(GLbitfield(GL_COLOR_BUFFER_BIT))
- }
-
- if !skip { CGLFlushDrawable(ctx) }
-
- deinitLock.unlock()
- }
-
- func setRenderICCProfile(_ profile: NSColorSpace) {
- if mpvRenderContext == nil { return }
- guard var iccData = profile.iccProfileData else {
- sendWarning("Invalid ICC profile data.")
- return
- }
- iccData.withUnsafeMutableBytes { (ptr: UnsafeMutableRawBufferPointer) in
- guard let baseAddress = ptr.baseAddress, ptr.count > 0 else { return }
-
- let u8Ptr = baseAddress.assumingMemoryBound(to: UInt8.self)
- let iccBstr = bstrdup(nil, bstr(start: u8Ptr, len: ptr.count))
- var icc = mpv_byte_array(data: iccBstr.start, size: iccBstr.len)
- let params = mpv_render_param(type: MPV_RENDER_PARAM_ICC_PROFILE, data: &icc)
- mpv_render_context_set_parameter(mpvRenderContext, params)
- }
- }
-
- func setRenderLux(_ lux: Int) {
- if mpvRenderContext == nil { return }
- var light = lux
- let params = mpv_render_param(type: MPV_RENDER_PARAM_AMBIENT_LIGHT, data: &light)
- mpv_render_context_set_parameter(mpvRenderContext, params)
- }
-
- func commandAsync(_ cmd: [String?], id: UInt64 = 1) {
- if mpvHandle == nil { return }
- var mCmd = cmd
- mCmd.append(nil)
- var cargs = mCmd.map { $0.flatMap { UnsafePointer<Int8>(strdup($0)) } }
- mpv_command_async(mpvHandle, id, &cargs)
- for ptr in cargs { free(UnsafeMutablePointer(mutating: ptr)) }
- }
-
- func observeString(_ property: String) {
- mpv_observe_property(mpvHandle, 0, property, MPV_FORMAT_STRING)
- }
-
- func observeFlag(_ property: String) {
- mpv_observe_property(mpvHandle, 0, property, MPV_FORMAT_FLAG)
- }
-
- // Unsafe function when called while using the render API
- func command(_ cmd: String) {
- if mpvHandle == nil { return }
- mpv_command_string(mpvHandle, cmd)
- }
-
- func getBoolProperty(_ name: String) -> Bool {
- if mpvHandle == nil { return false }
- var value = Int32()
- mpv_get_property(mpvHandle, name, MPV_FORMAT_FLAG, &value)
- return value > 0
- }
-
- func getIntProperty(_ name: String) -> Int {
- if mpvHandle == nil { return 0 }
- var value = Int64()
- mpv_get_property(mpvHandle, name, MPV_FORMAT_INT64, &value)
- return Int(value)
- }
-
- func getStringProperty(_ name: String) -> String? {
- guard let mpv = mpvHandle else { return nil }
- guard let value = mpv_get_property_string(mpv, name) else { return nil }
- let str = String(cString: value)
- mpv_free(value)
- return str
- }
-
- func deinitRender() {
- mpv_render_context_set_update_callback(mpvRenderContext, nil, nil)
- mp_render_context_set_control_callback(mpvRenderContext, nil, nil)
- deinitLock.lock()
- mpv_render_context_free(mpvRenderContext)
- mpvRenderContext = nil
- deinitLock.unlock()
- }
-
- func deinitMPV(_ destroy: Bool = false) {
- if destroy {
- mpv_destroy(mpvHandle)
- }
- ta_free(macOptsPtr)
- macOptsPtr = nil
- mpvHandle = nil
- log = nil
- }
-
- // *(char **) MPV_FORMAT_STRING on mpv_event_property
- class func mpvStringArrayToString(_ obj: UnsafeMutableRawPointer) -> String? {
- let cstr = UnsafeMutablePointer<UnsafeMutablePointer<Int8>>(OpaquePointer(obj))
- return String(cString: cstr[0])
- }
-
- // MPV_FORMAT_FLAG
- class func mpvFlagToBool(_ obj: UnsafeMutableRawPointer) -> Bool? {
- return UnsafePointer<Bool>(OpaquePointer(obj))?.pointee
- }
-}
diff --git a/osdep/macos/log_helper.swift b/osdep/macos/log_helper.swift
deleted file mode 100644
index 6d834c0631..0000000000
--- a/osdep/macos/log_helper.swift
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * This file is part of mpv.
- *
- * mpv is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * mpv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import Cocoa
-
-class LogHelper: NSObject {
-
- var log: OpaquePointer?
-
- init(_ log: OpaquePointer?) {
- self.log = log
- }
-
- func sendVerbose(_ msg: String) {
- send(message: msg, type: MSGL_V)
- }
-
- func sendInfo(_ msg: String) {
- send(message: msg, type: MSGL_INFO)
- }
-
- func sendWarning(_ msg: String) {
- send(message: msg, type: MSGL_WARN)
- }
-
- func sendError(_ msg: String) {
- send(message: msg, type: MSGL_ERR)
- }
-
- func send(message msg: String, type t: Int) {
- let args: [CVarArg] = [ (msg as NSString).utf8String ?? "NO MESSAGE"]
- mp_msg_va(log, Int32(t), "%s\n", getVaList(args))
- }
-}
diff --git a/osdep/macos/mpv_helper.swift b/osdep/macos/mpv_helper.swift
deleted file mode 100644
index 00c34924e3..0000000000
--- a/osdep/macos/mpv_helper.swift
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * This file is part of mpv.
- *
- * mpv is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * mpv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import Cocoa
-
-class MPVHelper: LogHelper {
-
- var vo: UnsafeMutablePointer<vo>
- var optsCachePtr: UnsafeMutablePointer<m_config_cache>
- var optsPtr: UnsafeMutablePointer<mp_vo_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 vout: vo { get { return vo.pointee } }
- var optsCache: m_config_cache { get { return optsCachePtr.pointee } }
- var opts: mp_vo_opts { get { return optsPtr.pointee } }
-
- var input: OpaquePointer { get { return vout.input_ctx } }
- var macOpts: macos_opts = macos_opts()
-
- init(_ vo: UnsafeMutablePointer<vo>, _ name: String) {
- self.vo = vo
-
- guard let app = NSApp as? Application,
- let cache = m_config_cache_alloc(vo, vo.pointee.global, app.getVoSubConf()) else
- {
- print("NSApp couldn't be retrieved")
- exit(1)
- }
-
- let newlog = mp_log_new(vo, vo.pointee.log, name)
- optsCachePtr = cache
- optsPtr = UnsafeMutablePointer<mp_vo_opts>(OpaquePointer(cache.pointee.opts))
-
- super.init(newlog)
-
- guard let ptr = mp_get_config_group(vo,
- vo.pointee.global,
- app.getMacOSConf()) else
- {
- // will never be hit, mp_get_config_group asserts for invalid groups
- return
- }
- macOpts = UnsafeMutablePointer<macos_opts>(OpaquePointer(ptr)).pointee
- }
-
- func canBeDraggedAt(_ pos: NSPoint) -> Bool {
- let canDrag = !mp_input_test_dragging(input, Int32(pos.x), Int32(pos.y))
- return canDrag
- }
-
- func mouseEnabled() -> Bool {
- return mp_input_mouse_enabled(input)
- }
-
- func setMousePosition(_ pos: NSPoint) {
- mp_input_set_mouse_pos(input, Int32(pos.x), Int32(pos.y))
- }
-
- func putAxis(_ mpkey: Int32, delta: Double) {
- mp_input_put_wheel(input, mpkey, delta)
- }
-
- func nextChangedConfig(property: inout UnsafeMutableRawPointer?) -> Bool {
- return m_config_cache_get_next_changed(optsCachePtr, &property)
- }
-
- func setConfigProperty(fullscreen: Bool) {
- optsPtr.pointee.fullscreen = Int32(fullscreen)
- m_config_cache_write_opt(optsCachePtr, UnsafeMutableRawPointer(&optsPtr.pointee.fullscreen))
- }
-
- func setConfigProperty(minimized: Bool) {
- optsPtr.pointee.window_minimized = Int32(minimized)
- m_config_cache_write_opt(optsCachePtr, UnsafeMutableRawPointer(&optsPtr.pointee.window_minimized))
- }
-
- func setConfigProperty(maximized: Bool) {
- optsPtr.pointee.window_maximized = Int32(maximized)
- m_config_cache_write_opt(optsCachePtr, UnsafeMutableRawPointer(&optsPtr.pointee.window_maximized))
- }
-
- func command(_ cmd: String) {
- let cCmd = UnsafePointer<Int8>(strdup(cmd))
- let mpvCmd = mp_input_parse_cmd(input, bstr0(cCmd), "")
- mp_input_queue_cmd(input, mpvCmd)
- free(UnsafeMutablePointer(mutating: cCmd))
- }
-
- // (__bridge void*)
- class func bridge<T: AnyObject>(obj: T) -> UnsafeMutableRawPointer {
- return UnsafeMutableRawPointer(Unmanaged.passUnretained(obj).toOpaque())
- }
-
- // (__bridge T*)
- class func bridge<T: AnyObject>(ptr: UnsafeRawPointer) -> T {
- return Unmanaged<T>.fromOpaque(ptr).takeUnretainedValue()
- }
-}
diff --git a/osdep/macos/remote_command_center.swift b/osdep/macos/remote_command_center.swift
deleted file mode 100644
index b08a726183..0000000000
--- a/osdep/macos/remote_command_center.swift
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * This file is part of mpv.
- *
- * mpv is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * mpv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import MediaPlayer
-
-@available(macOS 10.12.2, *)
-class RemoteCommandCenter: NSObject {
-
- enum KeyType {
- case normal
- case repeatable
- }
-
- var config: [MPRemoteCommand:[String:Any]] = [
- MPRemoteCommandCenter.shared().pauseCommand: [
- "mpKey": MP_KEY_PAUSEONLY,
- "keyType": KeyType.normal
- ],
- MPRemoteCommandCenter.shared().playCommand: [
- "mpKey": MP_KEY_PLAYONLY,
- "keyType": KeyType.normal
- ],
- MPRemoteCommandCenter.shared().stopCommand: [
- "mpKey": MP_KEY_STOP,
- "keyType": KeyType.normal
- ],
- MPRemoteCommandCenter.shared().nextTrackCommand: [
- "mpKey": MP_KEY_NEXT,
- "keyType": KeyType.normal
- ],
- MPRemoteCommandCenter.shared().previousTrackCommand: [
- "mpKey": MP_KEY_PREV,
- "keyType": KeyType.normal
- ],
- MPRemoteCommandCenter.shared().togglePlayPauseCommand: [
- "mpKey": MP_KEY_PLAY,
- "keyType": KeyType.normal
- ],
- MPRemoteCommandCenter.shared().seekForwardCommand: [
- "mpKey": MP_KEY_FORWARD,
- "keyType": KeyType.repeatable,
- "state": MP_KEY_STATE_UP
- ],
- MPRemoteCommandCenter.shared().seekBackwardCommand: [
- "mpKey": MP_KEY_REWIND,
- "keyType": KeyType.repeatable,
- "state": MP_KEY_STATE_UP
- ],
- ]
-
- var nowPlayingInfo: [String: Any] = [
- MPNowPlayingInfoPropertyMediaType: NSNumber(value: MPNowPlayingInfoMediaType.video.rawValue),
- MPNowPlayingInfoPropertyDefaultPlaybackRate: NSNumber(value: 1),
- MPNowPlayingInfoPropertyPlaybackProgress: NSNumber(value: 0.0),
- MPMediaItemPropertyPlaybackDuration: NSNumber(value: 0),
- MPMediaItemPropertyTitle: "mpv",
- MPMediaItemPropertyAlbumTitle: "mpv",
- MPMediaItemPropertyArtist: "mpv",
- ]
-
- let disabledCommands: [MPRemoteCommand] = [
- MPRemoteCommandCenter.shared().changePlaybackRateCommand,
- MPRemoteCommandCenter.shared().changeRepeatModeCommand,
- MPRemoteCommandCenter.shared().changeShuffleModeCommand,
- MPRemoteCommandCenter.shared().skipForwardCommand,
- MPRemoteCommandCenter.shared().skipBackwardCommand,
- MPRemoteCommandCenter.shared().changePlaybackPositionCommand,
- MPRemoteCommandCenter.shared().enableLanguageOptionCommand,
- MPRemoteCommandCenter.shared().disableLanguageOptionCommand,
- MPRemoteCommandCenter.shared().ratingCommand,
- MPRemoteCommandCenter.shared().likeCommand,
- MPRemoteCommandCenter.shared().dislikeCommand,
- MPRemoteCommandCenter.shared().bookmarkCommand,
- ]
-
- let application: Application
-
- var mpInfoCenter: MPNowPlayingInfoCenter { get { return MPNowPlayingInfoCenter.default() } }
- var isPaused: Bool = false { didSet { updatePlaybackState() } }
-
- @objc init(app: Application) {
- application = app
-
- super.init()
-
- for cmd in disabledCommands {
- cmd.isEnabled = false
- }
- }
-
- @objc func start() {
- for (cmd, _) in config {
- cmd.isEnabled = true
- cmd.addTarget { [unowned self] event in
- return self.cmdHandler(event)
- }
- }
-
- if let icon = application.getMPVIcon(), #available(macOS 10.13.2, *) {
- let albumArt = MPMediaItemArtwork(boundsSize:icon.size) { _ in
- return icon
- }
- nowPlayingInfo[MPMediaItemPropertyArtwork] = albumArt
- }
-
- mpInfoCenter.nowPlayingInfo = nowPlayingInfo
- mpInfoCenter.playbackState = .playing
- }
-
- @objc func stop() {
- for (cmd, _) in config {
- cmd.isEnabled = false
- cmd.removeTarget(nil)
- }
-
- mpInfoCenter.nowPlayingInfo = nil
- mpInfoCenter.playbackState = .unknown
- }
-
- @objc func makeCurrent() {
- mpInfoCenter.playbackState = .paused
- mpInfoCenter.playbackState = .playing
- updatePlaybackState()
- }
-
- func updatePlaybackState() {
- mpInfoCenter.playbackState = isPaused ? .paused : .playing
- }
-
- func cmdHandler(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
- guard let cmdConfig = config[event.command],
- let mpKey = cmdConfig["mpKey"] as? Int32,
- let keyType = cmdConfig["keyType"] as? KeyType else
- {
- return .commandFailed
- }
-
- var state = cmdConfig["state"] as? UInt32 ?? 0
-
- if let currentState = cmdConfig["state"] as? UInt32, keyType == .repeatable {
- state = MP_KEY_STATE_DOWN
- config[event.command]?["state"] = MP_KEY_STATE_DOWN
- if currentState == MP_KEY_STATE_DOWN {
- state = MP_KEY_STATE_UP
- config[event.command]?["state"] = MP_KEY_STATE_UP
- }
- }
-
- application.handleMPKey(mpKey, withMask: Int32(state));
-
- return .success
- }
-
- @objc func processEvent(_ event: UnsafeMutablePointer<mpv_event>) {
- switch event.pointee.event_id {
- case MPV_EVENT_PROPERTY_CHANGE:
- handlePropertyChange(event)
- default:
- break
- }
- }
-
- func handlePropertyChange(_ event: UnsafeMutablePointer<mpv_event>) {
- let pData = OpaquePointer(event.pointee.data)
- guard let property = UnsafePointer<mpv_event_property>(pData)?.pointee else {
- return
- }
-
- switch String(cString: property.name) {
- case "pause" where property.format == MPV_FORMAT_FLAG:
- isPaused = LibmpvHelper.mpvFlagToBool(property.data) ?? false
- default:
- break
- }
- }
-}
diff --git a/osdep/macos/swift_compat.swift b/osdep/macos/swift_compat.swift
deleted file mode 100644
index c14aa08282..0000000000
--- a/osdep/macos/swift_compat.swift
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * This file is part of mpv.
- *
- * mpv is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * mpv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#if !HAVE_MACOS_10_14_FEATURES
-extension NSAppearance.Name {
- static let darkAqua: NSAppearance.Name = NSAppearance.Name(rawValue: "NSAppearanceNameDarkAqua")
- static let accessibilityHighContrastAqua: NSAppearance.Name = NSAppearance.Name(rawValue: "NSAppearanceNameAccessibilityAqua")
- static let accessibilityHighContrastDarkAqua: NSAppearance.Name = NSAppearance.Name(rawValue: "NSAppearanceNameAccessibilityDarkAqua")
- static let accessibilityHighContrastVibrantLight: NSAppearance.Name = NSAppearance.Name(rawValue: "NSAppearanceNameAccessibilityVibrantLight")
- static let accessibilityHighContrastVibrantDark: NSAppearance.Name = NSAppearance.Name(rawValue: "NSAppearanceNameAccessibilityVibrantDark")
-}
-
-@available(OSX 10.12, *)
-extension String {
- static let RGBA16Float: String = kCAContentsFormatRGBA16Float
- static let RGBA8Uint: String = kCAContentsFormatRGBA8Uint
- static let gray8Uint: String = kCAContentsFormatGray8Uint
-}
-#endif
-
-extension NSPasteboard.PasteboardType {
-
- static let fileURLCompat: NSPasteboard.PasteboardType = {
- if #available(OSX 10.13, *) {
- return .fileURL
- } else {
- return NSPasteboard.PasteboardType(kUTTypeURL as String)
- }
- } ()
-
- static let URLCompat: NSPasteboard.PasteboardType = {
- if #available(OSX 10.13, *) {
- return .URL
- } else {
- return NSPasteboard.PasteboardType(kUTTypeFileURL as String)
- }
- } ()
-}
-
-#if !swift(>=5.0)
-extension Data {
-
- mutating func withUnsafeMutableBytes<Type>(_ body: (UnsafeMutableRawBufferPointer) throws -> Type) rethrows -> Type {
- let dataCount = count
- return try withUnsafeMutableBytes { (ptr: UnsafeMutablePointer<UInt8>) throws -> Type in
- try body(UnsafeMutableRawBufferPointer(start: ptr, count: dataCount))
- }
- }
-}
-#endif
-
-#if !swift(>=4.2)
-extension NSDraggingInfo {
-
- var draggingPasteboard: NSPasteboard {
- get { return draggingPasteboard() }
- }
-}
-#endif
-
-#if !swift(>=4.1)
-extension Array {
-
- func compactMap<ElementOfResult>(_ transform: (Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult] {
- return try self.flatMap(transform)
- }
-}
-
-extension Array where Element == [CGLPixelFormatAttribute] {
-
- func contains(_ obj: [CGLPixelFormatAttribute]) -> Bool {
- return self.contains(where:{ $0 == obj })
- }
-}
-
-extension NSWindow.Level {
-
- static func +(left: NSWindow.Level, right: Int) -> NSWindow.Level {
- return NSWindow.Level(left.rawValue + right)
- }
-}
-#endif
-
diff --git a/osdep/macos/swift_extensions.swift b/osdep/macos/swift_extensions.swift
deleted file mode 100644
index a1aeb0abf7..0000000000
--- a/osdep/macos/swift_extensions.swift
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * This file is part of mpv.
- *
- * mpv is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * mpv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with mpv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import Cocoa
-
-extension NSDeviceDescriptionKey {
- static let screenNumber = NSDeviceDescriptionKey("NSScreenNumber")
-}
-
-extension NSScreen {
-
- public var displayID: CGDirectDisplayID {
- get {
- return deviceDescription[.screenNumber] as? CGDirectDisplayID ?? 0
- }
- }
-
- public var displayName: String? {
- get {
- var name: String? = nil
- var object: io_object_t
- var iter = io_iterator_t()
- let matching = IOServiceMatching("IODisplayConnect")
- let result = IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &iter)
-
- if result != KERN_SUCCESS || iter == 0 { return nil }
-
- repeat {
- object = IOIteratorNext(iter)
- if let info = IODisplayCreateInfoDictionary(object, IOOptionBits(kIODisplayOnlyPreferredName)).takeRetainedValue() as? [String:AnyObject],
- (info[kDisplayVendorID] as? UInt32 == CGDisplayVendorNumber(displayID) &&
- info[kDisplayProductID] as? UInt32 == CGDisplayModelNumber(displayID) &&
- info[kDisplaySerialNumber] as? UInt32 ?? 0 == CGDisplaySerialNumber(displayID))
- {
- if let productNames = info["DisplayProductName"] as? [String:String],
- let productName = productNames.first?.value
- {
- name = productName
- break
- }
- }
- } while object != 0
-
- IOObjectRelease(iter)
- return name
- }
- }
-}
-
-extension NSColor {
-
- convenience init(hex: String) {
- let int = Int(hex.dropFirst(), radix: 16) ?? 0
- 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)
- }
-}
-
-extension Bool {
-
- init(_ int32: Int32) {
- self.init(int32 != 0)
- }
-}
-
-extension Int32 {
-
- init(_ bool: Bool) {
- self.init(bool ? 1 : 0)
- }
-}