vlc | branch: master | David Fuhrmann <[email protected]> | Sat Aug 20 
23:04:32 2016 +0200| [a7536bc7671f29cf37f6f408eef2c1d677277990] | committer: 
David Fuhrmann

macosx: Directly apply visibility change for status bar icon

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a7536bc7671f29cf37f6f408eef2c1d677277990
---

 modules/gui/macosx/VLCMain.h          |  2 +
 modules/gui/macosx/VLCStatusBarIcon.m | 69 +++++++++++++++++++++++++----------
 modules/gui/macosx/simple_prefs.m     |  1 +
 3 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/modules/gui/macosx/VLCMain.h b/modules/gui/macosx/VLCMain.h
index cf49fbe..0123f1c 100644
--- a/modules/gui/macosx/VLCMain.h
+++ b/modules/gui/macosx/VLCMain.h
@@ -51,6 +51,8 @@
 intf_thread_t *getIntf();
 
 static NSString * VLCInputChangedNotification = @"VLCInputChangedNotification";
+static NSString * VLCConfigurationChangedNotification = 
@"VLCConfigurationChangedNotification";
+
 
 /*****************************************************************************
  * VLCMain interface
diff --git a/modules/gui/macosx/VLCStatusBarIcon.m 
b/modules/gui/macosx/VLCStatusBarIcon.m
index f2b6903..b597cdc 100644
--- a/modules/gui/macosx/VLCStatusBarIcon.m
+++ b/modules/gui/macosx/VLCStatusBarIcon.m
@@ -90,7 +90,7 @@
 - (void)awakeFromNib
 {
     [super awakeFromNib];
-    [self enableMenuIcon];
+    [self configurationChanged:nil];
 
     // Set Accessibility Attributes for Image Buttons
     [backwardsButton.cell accessibilitySetOverrideValue:_NS("Go to previous 
track")
@@ -122,6 +122,11 @@
                                              
selector:@selector(updateNowPlayingInfo)
                                                  
name:VLCInputChangedNotification
                                                object:nil];
+
+    [[NSNotificationCenter defaultCenter] addObserver:self
+                                             
selector:@selector(configurationChanged:)
+                                                 
name:VLCConfigurationChangedNotification
+                                               object:nil];
 }
 
 - (void)observeValueForKeyPath:(NSString *)keyPath
@@ -140,35 +145,59 @@
     }
 }
 
+- (void)configurationChanged:(id)obj
+{
+    if (var_InheritBool(getIntf(), "macosx-statusicon"))
+        [self enableMenuIcon];
+    else
+        [self disableStatusItem];
+}
+
 /* Enables the Status Bar Item and initializes it's image
  * and context menu
  */
 - (void)enableMenuIcon
 {
-    if (!var_InheritBool(getIntf(), "macosx-statusicon"))
-        return;
-
-    // Init the status item
-    self.statusItem = [[NSStatusBar systemStatusBar] 
statusItemWithLength:NSVariableStatusItemLength];
-    [self.statusItem setHighlightMode:YES];
-    [self.statusItem setEnabled:YES];
+    if (!self.statusItem) {
+        // Init the status item
+        self.statusItem = [[NSStatusBar systemStatusBar] 
statusItemWithLength:NSVariableStatusItemLength];
+        [self.statusItem setHighlightMode:YES];
+        [self.statusItem setEnabled:YES];
+
+        // Set the status item image
+        NSImage *menuIcon = [NSImage imageNamed:@"VLCStatusBarIcon"];
+        [menuIcon setTemplate:YES];
+        [self.statusItem setImage:menuIcon];
+
+        // Attach pull-down menu
+        [self.statusItem setMenu:_vlcStatusBarIconMenu];
+
+        if (OSX_SIERRA) {
+            [self.statusItem setBehavior:NSStatusItemBehaviorRemovalAllowed];
+            [self.statusItem setAutosaveName:@"statusBarItem"];
+            [self.statusItem addObserver:self 
forKeyPath:NSStringFromSelector(@selector(isVisible))
+                                 options:0 context:NULL];
+        }
+    }
 
-    // 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"];
+    if (OSX_SIERRA) {
+        // Sync VLC setting with status bar visibility setting (10.12 runtime 
only)
         [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];
-    [self.statusItem setImage:menuIcon];
+- (void)disableStatusItem
+{
+    if (!self.statusItem)
+        return;
 
-    // Attach pull-down menu
-    [self.statusItem setMenu:_vlcStatusBarIconMenu];
+    // Lets keep alive the object in Sierra, and destroy it in older OS 
versions
+    if (OSX_SIERRA) {
+        self.statusItem.visible = NO;
+    } else {
+        [[NSStatusBar systemStatusBar] removeStatusItem:self.statusItem];
+        self.statusItem = nil;
+    }
 }
 
 - (void)dealloc
diff --git a/modules/gui/macosx/simple_prefs.m 
b/modules/gui/macosx/simple_prefs.m
index ba8627d..afddf2f 100644
--- a/modules/gui/macosx/simple_prefs.m
+++ b/modules/gui/macosx/simple_prefs.m
@@ -1083,6 +1083,7 @@ static inline void save_string_list(intf_thread_t * 
p_intf, id object, const cha
     [[NSNotificationCenter defaultCenter] postNotificationName: 
@"VLCMediaKeySupportSettingChanged"
                                                             object: nil
                                                           userInfo: nil];
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:VLCConfigurationChangedNotification object:nil];
 }
 
 - (void)showSettingsForCategory:(id)new_categoryView

_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to