[vlc-commits] macosx: Use @available instead of own macros
David Fuhrmann
git at videolan.org
Mon Sep 24 09:36:23 CEST 2018
vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Fri Sep 21 00:18:24 2018 +0200| [218da7ee4e4547034680435307b98dc0ad37d6d2] | committer: David Fuhrmann
macosx: Use @available instead of own macros
@available is advocated now since Xcode 9, it does both a runtime
check for a minimal required OS version, as well as it guards
for partial availability warnings.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=218da7ee4e4547034680435307b98dc0ad37d6d2
---
modules/gui/macosx/AppleRemote.m | 2 +-
modules/gui/macosx/CompatibilityFixes.h | 7 ---
modules/gui/macosx/VLCInputManager.m | 72 ++++++++++++----------------
modules/gui/macosx/VLCRemoteControlService.m | 9 +---
modules/gui/macosx/VLCStatusBarIcon.m | 11 ++---
modules/gui/macosx/VLCVideoWindowCommon.m | 2 +-
6 files changed, 38 insertions(+), 65 deletions(-)
diff --git a/modules/gui/macosx/AppleRemote.m b/modules/gui/macosx/AppleRemote.m
index 452a1e5d22..2556934cca 100644
--- a/modules/gui/macosx/AppleRemote.m
+++ b/modules/gui/macosx/AppleRemote.m
@@ -89,7 +89,7 @@ const NSTimeInterval HOLD_RECOGNITION_TIME_INTERVAL=0.4;
[mutableCookieToButtonMapping setObject:[NSNumber numberWithInt:k2009RemoteButtonFullscreen] forKey:@"33_21_20_3_2_33_21_20_3_2_"];
[mutableCookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched] forKey:@"42_33_23_21_20_2_33_23_21_20_2_"];
- if (OSX_HIGH_SIERRA_AND_HIGHER) {
+ if (@available(macOS 10.13, *)) {
[mutableCookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonVolume_Plus] forKey:@"33_21_20_15_12_2_"];
[mutableCookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonVolume_Minus] forKey:@"33_21_20_16_12_2_"];
}
diff --git a/modules/gui/macosx/CompatibilityFixes.h b/modules/gui/macosx/CompatibilityFixes.h
index 7e91054cfd..20ecf6abba 100644
--- a/modules/gui/macosx/CompatibilityFixes.h
+++ b/modules/gui/macosx/CompatibilityFixes.h
@@ -25,11 +25,4 @@
#import <Cocoa/Cocoa.h>
#pragma mark -
-#pragma OS detection code
-#define OSX_EL_CAPITAN_AND_HIGHER (NSAppKitVersionNumber >= 1404)
-#define OSX_SIERRA_AND_HIGHER (NSAppKitVersionNumber >= 1485)
-#define OSX_SIERRA_DOT_TWO_AND_HIGHER (NSAppKitVersionNumber >= 1504.76) // this is needed to check for MPRemoteCommandCenter
-#define OSX_HIGH_SIERRA_AND_HIGHER (NSAppKitVersionNumber >= 1560)
-#define OSX_MOJAVE_AND_HIGHER (NSAppKitVersionNumber >= 1639.10)
-
void swapoutOverride(Class _Nonnull cls, SEL _Nonnull selector);
diff --git a/modules/gui/macosx/VLCInputManager.m b/modules/gui/macosx/VLCInputManager.m
index b01ac10bf0..dbe245bb73 100644
--- a/modules/gui/macosx/VLCInputManager.m
+++ b/modules/gui/macosx/VLCInputManager.m
@@ -191,8 +191,10 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
informInputChangedQueue = dispatch_queue_create("org.videolan.vlc.inputChangedQueue", DISPATCH_QUEUE_SERIAL);
- _remoteControlService = [[VLCRemoteControlService alloc] init];
- [_remoteControlService subscribeToRemoteCommands];
+ if (@available(macOS 10.12.2, *)) {
+ _remoteControlService = [[VLCRemoteControlService alloc] init];
+ [_remoteControlService subscribeToRemoteCommands];
+ }
}
return self;
}
@@ -207,7 +209,9 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
- (void)deinit
{
msg_Dbg(getIntf(), "Deinitializing input manager");
- [_remoteControlService unsubscribeFromRemoteCommands];
+ if (@available(macOS 10.12.2, *)) {
+ [_remoteControlService unsubscribeFromRemoteCommands];
+ }
if (p_current_input) {
/* continue playback where you left off */
@@ -317,11 +321,8 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
[[o_main mainMenu] setPause];
[[o_main mainWindow] setPause];
- if (OSX_SIERRA_DOT_TWO_AND_HIGHER) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
+ if (@available(macOS 10.12.2, *)) {
[MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStatePlaying;
-#pragma clang diagnostic pop
}
} else {
[[o_main mainMenu] setSubmenusEnabled: FALSE];
@@ -331,11 +332,8 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
if (state == PAUSE_S) {
[self releaseSleepBlockers];
- if (OSX_SIERRA_DOT_TWO_AND_HIGHER) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
+ if (@available(macOS 10.12.2, *)) {
[MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStatePaused;
-#pragma clang diagnostic pop
}
}
@@ -353,11 +351,8 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
userInfo: nil
repeats: NO];
- if (OSX_SIERRA_DOT_TWO_AND_HIGHER) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
+ if (@available(macOS 10.12.2, *)) {
[MPNowPlayingInfoCenter defaultCenter].playbackState = MPNowPlayingPlaybackStateStopped;
-#pragma clang diagnostic pop
}
}
}
@@ -525,42 +520,37 @@ static int InputEvent(vlc_object_t *p_this, const char *psz_var,
[[[o_main playlist] model] updateItem:p_input_item];
[[[VLCMain sharedInstance] currentMediaInfoPanel] updatePanelWithItem:p_input_item];
- if (!OSX_SIERRA_DOT_TWO_AND_HIGHER) {
- return;
- }
-
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
if (!p_input_item) {
return;
}
- NSMutableDictionary *currentlyPlayingTrackInfo = [NSMutableDictionary dictionary];
+ if (@available(macOS 10.12.2, *)) {
+ NSMutableDictionary *currentlyPlayingTrackInfo = [NSMutableDictionary dictionary];
- currentlyPlayingTrackInfo[MPMediaItemPropertyPlaybackDuration] = @(SEC_FROM_VLC_TICK(input_item_GetDuration(p_input_item)));
- currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(var_GetInteger(p_current_input, "time"));
- currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyPlaybackRate] = @(var_GetFloat(p_current_input, "rate"));
+ currentlyPlayingTrackInfo[MPMediaItemPropertyPlaybackDuration] = @(SEC_FROM_VLC_TICK(input_item_GetDuration(p_input_item)));
+ currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(var_GetInteger(p_current_input, "time"));
+ currentlyPlayingTrackInfo[MPNowPlayingInfoPropertyPlaybackRate] = @(var_GetFloat(p_current_input, "rate"));
- char *psz_title = input_item_GetTitle(p_input_item);
- if (!psz_title)
- psz_title = input_item_GetName(p_input_item);
- currentlyPlayingTrackInfo[MPMediaItemPropertyTitle] = toNSStr(psz_title);
- FREENULL(psz_title);
+ char *psz_title = input_item_GetTitle(p_input_item);
+ if (!psz_title)
+ psz_title = input_item_GetName(p_input_item);
+ currentlyPlayingTrackInfo[MPMediaItemPropertyTitle] = toNSStr(psz_title);
+ FREENULL(psz_title);
- char *psz_artist = input_item_GetArtist(p_input_item);
- currentlyPlayingTrackInfo[MPMediaItemPropertyArtist] = toNSStr(psz_artist);
- FREENULL(psz_artist);
+ char *psz_artist = input_item_GetArtist(p_input_item);
+ currentlyPlayingTrackInfo[MPMediaItemPropertyArtist] = toNSStr(psz_artist);
+ FREENULL(psz_artist);
- char *psz_album = input_item_GetAlbum(p_input_item);
- currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTitle] = toNSStr(psz_album);
- FREENULL(psz_album);
+ char *psz_album = input_item_GetAlbum(p_input_item);
+ currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTitle] = toNSStr(psz_album);
+ FREENULL(psz_album);
- char *psz_track_number = input_item_GetTrackNumber(p_input_item);
- currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTrackNumber] = @([toNSStr(psz_track_number) intValue]);
- FREENULL(psz_track_number);
+ char *psz_track_number = input_item_GetTrackNumber(p_input_item);
+ currentlyPlayingTrackInfo[MPMediaItemPropertyAlbumTrackNumber] = @([toNSStr(psz_track_number) intValue]);
+ FREENULL(psz_track_number);
- [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
-#pragma clang diagnostic pop
+ [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
+ }
}
- (void)updateMainWindow
diff --git a/modules/gui/macosx/VLCRemoteControlService.m b/modules/gui/macosx/VLCRemoteControlService.m
index 2e68cacd52..7dc95a9e18 100644
--- a/modules/gui/macosx/VLCRemoteControlService.m
+++ b/modules/gui/macosx/VLCRemoteControlService.m
@@ -56,10 +56,6 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle()
- (void)subscribeToRemoteCommands
{
- if (!OSX_SIERRA_DOT_TWO_AND_HIGHER) {
- return;
- }
-
MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
//Enable when you want to support these
@@ -78,14 +74,11 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle()
for (MPRemoteCommand *command in RemoteCommandCenterCommandsToHandle()) {
[command addTarget:self action:@selector(remoteCommandEvent:)];
}
+
}
- (void)unsubscribeFromRemoteCommands
{
- if (!OSX_SIERRA_DOT_TWO_AND_HIGHER) {
- return;
- }
-
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil;
for (MPRemoteCommand *command in RemoteCommandCenterCommandsToHandle()) {
diff --git a/modules/gui/macosx/VLCStatusBarIcon.m b/modules/gui/macosx/VLCStatusBarIcon.m
index 53951c65de..2fa8529d37 100644
--- a/modules/gui/macosx/VLCStatusBarIcon.m
+++ b/modules/gui/macosx/VLCStatusBarIcon.m
@@ -168,10 +168,8 @@
// Attach pull-down menu
[self.statusItem setMenu:_vlcStatusBarIconMenu];
- // Visibility is 10.12+
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
- if (OSX_SIERRA_AND_HIGHER) {
+
+ if (@available(macOS 10.12, *)) {
[self.statusItem setBehavior:NSStatusItemBehaviorRemovalAllowed];
[self.statusItem setAutosaveName:@"statusBarItem"];
[self.statusItem addObserver:self forKeyPath:NSStringFromSelector(@selector(isVisible))
@@ -179,7 +177,7 @@
}
}
- if (OSX_SIERRA_AND_HIGHER) {
+ if (@available(macOS 10.12, *)) {
// Sync VLC setting with status bar visibility setting (10.12 runtime only)
[self.statusItem setVisible:YES];
}
@@ -191,13 +189,12 @@
return;
// Lets keep alive the object in Sierra, and destroy it in older OS versions
- if (OSX_SIERRA_AND_HIGHER) {
+ if (@available(macOS 10.12, *)) {
self.statusItem.visible = NO;
} else {
[[NSStatusBar systemStatusBar] removeStatusItem:self.statusItem];
self.statusItem = nil;
}
-#pragma clang diagnostic pop
}
- (void)dealloc
diff --git a/modules/gui/macosx/VLCVideoWindowCommon.m b/modules/gui/macosx/VLCVideoWindowCommon.m
index 9785862fdb..63c65abd3d 100644
--- a/modules/gui/macosx/VLCVideoWindowCommon.m
+++ b/modules/gui/macosx/VLCVideoWindowCommon.m
@@ -84,7 +84,7 @@
if (b_nativeFullscreenMode) {
[self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
- } else if (OSX_EL_CAPITAN_AND_HIGHER) {
+ } else if (@available(macOS 10.11, *)) {
// Native fullscreen seems to be default on El Capitan, this disables it explicitely
[self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
}
More information about the vlc-commits
mailing list