[vlc-commits] macosx: Support Sierra enhanchments for VLCs status icon
David Fuhrmann
git at videolan.org
Sat Aug 20 17:44:34 CEST 2016
vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sat Aug 20 15:26:20 2016 +0200| [fcbdbaba8433abbdfd74ade54e58ef9fe98b6a1b] | committer: David Fuhrmann
macosx: Support Sierra enhanchments for VLCs status icon
This adds support for Sierra's new possibility to hide or move VLCs
status bar. It is synced with the VLC config setting.
Code also works if it gets compiled with a <10.12 SDK and it runs
on Sierra.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fcbdbaba8433abbdfd74ade54e58ef9fe98b6a1b
---
modules/gui/macosx/CompatibilityFixes.h | 19 +++++++++++++++
modules/gui/macosx/VLCStatusBarIcon.h | 2 +-
modules/gui/macosx/VLCStatusBarIcon.m | 41 ++++++++++++++++++++++++++++-----
3 files changed, 55 insertions(+), 7 deletions(-)
diff --git a/modules/gui/macosx/CompatibilityFixes.h b/modules/gui/macosx/CompatibilityFixes.h
index 85d052c..4a35c1c 100644
--- a/modules/gui/macosx/CompatibilityFixes.h
+++ b/modules/gui/macosx/CompatibilityFixes.h
@@ -31,3 +31,22 @@
#define OSX_YOSEMITE (NSAppKitVersionNumber < 1404 && NSAppKitVersionNumber >= 1334)
#define OSX_EL_CAPITAN (NSAppKitVersionNumber >= 1404 && NSAppKitVersionNumber < 1485)
#define OSX_SIERRA (NSAppKitVersionNumber >= 1485)
+
+// Sierra only APIs
+#ifndef MAC_OS_X_VERSION_10_12
+
+typedef NS_OPTIONS(NSUInteger, NSStatusItemBehavior) {
+
+ NSStatusItemBehaviorRemovalAllowed = (1 << 1),
+ NSStatusItemBehaviorTerminationOnRemoval = (1 << 2),
+};
+
+ at interface NSStatusItem(IntroducedInSierra)
+
+ at property (assign) NSStatusItemBehavior behavior;
+ at property (assign, getter=isVisible) BOOL visible;
+ at property (null_resettable, copy) NSString *autosaveName;
+
+ at end
+
+#endif
diff --git a/modules/gui/macosx/VLCStatusBarIcon.h b/modules/gui/macosx/VLCStatusBarIcon.h
index f5b12a4..65cfdb0 100644
--- a/modules/gui/macosx/VLCStatusBarIcon.h
+++ b/modules/gui/macosx/VLCStatusBarIcon.h
@@ -25,7 +25,7 @@
@interface VLCStatusBarIcon : NSObject <NSMenuDelegate>
- at property NSStatusItem *statusItem;
+ at property (readwrite, strong) NSStatusItem *statusItem;
@property (readwrite, strong) IBOutlet NSMenu *vlcStatusBarIconMenu;
// Get data from VLC and update the little status menu
diff --git a/modules/gui/macosx/VLCStatusBarIcon.m b/modules/gui/macosx/VLCStatusBarIcon.m
index e56cfad..f2b6903 100644
--- a/modules/gui/macosx/VLCStatusBarIcon.m
+++ b/modules/gui/macosx/VLCStatusBarIcon.m
@@ -30,6 +30,7 @@
#import <vlc_playlist.h>
#import <vlc_input.h>
+#import "CompatibilityFixes.h"
#import "VLCCoreInteraction.h"
#import "VLCStringUtility.h"
@@ -123,6 +124,22 @@
object:nil];
}
+- (void)observeValueForKeyPath:(NSString *)keyPath
+ ofObject:(id)object
+ change:(NSDictionary *)change
+ context:(void *)context
+{
+ if ([keyPath isEqualToString: NSStringFromSelector(@selector(isVisible))]) {
+ bool isVisible = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
+
+ // Sync status bar visibility with VLC setting
+ msg_Dbg(getIntf(), "Status bar icon visibility changed to %i", isVisible);
+ config_PutInt(getIntf(), "macosx-statusicon", isVisible ? 1 : 0);
+ } else {
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+ }
+}
+
/* Enables the Status Bar Item and initializes it's image
* and context menu
*/
@@ -132,22 +149,34 @@
return;
// Init the status item
- _statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
- [_statusItem setHighlightMode:YES];
- [_statusItem setEnabled:YES];
- [_statusItem setTarget:self];
+ self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
+ [self.statusItem setHighlightMode:YES];
+ [self.statusItem setEnabled:YES];
+
+ // Sync VLC setting with status bar visibility setting (10.12 runtime only)
+ if ([self.statusItem respondsToSelector:@selector(isVisible)]) {
+ [self.statusItem setBehavior:NSStatusItemBehaviorRemovalAllowed];
+ [self.statusItem setAutosaveName:@"statusBarItem"];
+ [self.statusItem setVisible:YES];
+ [self.statusItem addObserver:self forKeyPath:NSStringFromSelector(@selector(isVisible))
+ options:0 context:NULL];
+ }
// Set the status item image
NSImage *menuIcon = [NSImage imageNamed:@"VLCStatusBarIcon"];
[menuIcon setTemplate:YES];
- [_statusItem setImage:menuIcon];
+ [self.statusItem setImage:menuIcon];
// Attach pull-down menu
- [_statusItem setMenu:_vlcStatusBarIconMenu];
+ [self.statusItem setMenu:_vlcStatusBarIconMenu];
}
- (void)dealloc
{
+ if (self.statusItem && [self.statusItem respondsToSelector:@selector(isVisible)]) {
+ [self.statusItem removeObserver:self forKeyPath:NSStringFromSelector(@selector(isVisible)) context:NULL];
+ }
+
// Cleanup
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
More information about the vlc-commits
mailing list