[vlc-commits] macosx: use a notification to update the window level instead of calling the singleton directly

Felix Paul Kühne git at videolan.org
Tue Jun 11 11:46:56 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Tue Jun 11 11:41:22 2019 +0200| [cf6a86401878ee618fe1aead26729f9ee4e8fb48] | committer: Felix Paul Kühne

macosx: use a notification to update the window level instead of calling the singleton directly

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

 .../gui/macosx/panels/VLCAudioEffectsWindowController.h   |  1 -
 .../gui/macosx/panels/VLCAudioEffectsWindowController.m   | 13 ++++++++++++-
 modules/gui/macosx/panels/VLCBookmarksWindowController.h  |  1 -
 modules/gui/macosx/panels/VLCBookmarksWindowController.m  |  7 +++++--
 .../gui/macosx/panels/VLCInformationWindowController.h    |  1 -
 .../gui/macosx/panels/VLCInformationWindowController.m    |  7 ++++++-
 .../panels/VLCTrackSynchronizationWindowController.h      |  2 --
 .../panels/VLCTrackSynchronizationWindowController.m      |  7 ++++++-
 .../gui/macosx/panels/VLCVideoEffectsWindowController.h   |  1 -
 .../gui/macosx/panels/VLCVideoEffectsWindowController.m   |  8 +++++++-
 .../gui/macosx/panels/dialogs/VLCResumeDialogController.h |  2 --
 .../gui/macosx/panels/dialogs/VLCResumeDialogController.m | 15 +++++++++++++--
 modules/gui/macosx/windows/video/VLCVideoOutputProvider.h |  3 +++
 modules/gui/macosx/windows/video/VLCVideoOutputProvider.m | 13 +++++--------
 modules/gui/macosx/windows/video/VLCVideoWindowCommon.m   | 12 +++++++-----
 15 files changed, 64 insertions(+), 29 deletions(-)

diff --git a/modules/gui/macosx/panels/VLCAudioEffectsWindowController.h b/modules/gui/macosx/panels/VLCAudioEffectsWindowController.h
index dff29b2dad..4eb4635a38 100644
--- a/modules/gui/macosx/panels/VLCAudioEffectsWindowController.h
+++ b/modules/gui/macosx/panels/VLCAudioEffectsWindowController.h
@@ -114,7 +114,6 @@
 - (IBAction)applyProfileCheckboxChanged:(id)sender;
 
 - (void)toggleWindow:(id)sender;
-- (void)updateCocoaWindowLevel:(NSInteger)i_level;
 - (void)saveCurrentProfileAtTerminate;
 
 /* Equalizer */
diff --git a/modules/gui/macosx/panels/VLCAudioEffectsWindowController.m b/modules/gui/macosx/panels/VLCAudioEffectsWindowController.m
index 4db5dc00c6..2b4af84f4e 100644
--- a/modules/gui/macosx/panels/VLCAudioEffectsWindowController.m
+++ b/modules/gui/macosx/panels/VLCAudioEffectsWindowController.m
@@ -204,6 +204,11 @@ NSString *VLCAudioEffectsProfileNamesKey = @"AudioEffectProfileNames";
 
 - (void)windowDidLoad
 {
+    [[NSNotificationCenter defaultCenter] addObserver:self
+                                             selector:@selector(updateCocoaWindowLevel:)
+                                                 name:VLCWindowShouldUpdateLevel
+                                               object:nil];
+
     [_applyProfileCheckbox setState:[[NSUserDefaults standardUserDefaults] boolForKey:@"AudioEffectApplyProfileOnStartup"]];
     [_applyProfileCheckbox setTitle:_NS("Apply profile at next launch")];
 
@@ -281,6 +286,11 @@ NSString *VLCAudioEffectsProfileNamesKey = @"AudioEffectProfileNames";
     [self resetProfileSelector];
 }
 
+- (void)dealloc
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
 #pragma mark -
 #pragma mark internal functions
 
@@ -333,8 +343,9 @@ NSString *VLCAudioEffectsProfileNamesKey = @"AudioEffectProfileNames";
 
 #pragma mark -
 #pragma mark generic code
-- (void)updateCocoaWindowLevel:(NSInteger)i_level
+- (void)updateCocoaWindowLevel:(NSNotification *)aNotification
 {
+    NSInteger i_level = [aNotification.userInfo[VLCWindowLevelKey] integerValue];
     if (self.isWindowLoaded && [self.window isVisible] && [self.window level] != i_level)
         [self.window setLevel: i_level];
 }
diff --git a/modules/gui/macosx/panels/VLCBookmarksWindowController.h b/modules/gui/macosx/panels/VLCBookmarksWindowController.h
index 1fa07e3ced..b2b99a9971 100644
--- a/modules/gui/macosx/panels/VLCBookmarksWindowController.h
+++ b/modules/gui/macosx/panels/VLCBookmarksWindowController.h
@@ -42,7 +42,6 @@
 @property (readwrite, weak) IBOutlet NSTextField *editNameTextField;
 @property (readwrite, weak) IBOutlet NSTextField *editTimeTextField;
 
-- (void)updateCocoaWindowLevel:(NSInteger)i_level;
 - (IBAction)toggleWindow:(id)sender;
 
 - (IBAction)add:(id)sender;
diff --git a/modules/gui/macosx/panels/VLCBookmarksWindowController.m b/modules/gui/macosx/panels/VLCBookmarksWindowController.m
index 7bbfdf23e6..10000fc85a 100644
--- a/modules/gui/macosx/panels/VLCBookmarksWindowController.m
+++ b/modules/gui/macosx/panels/VLCBookmarksWindowController.m
@@ -54,7 +54,9 @@
 - (id)init
 {
     self = [super initWithWindowNibName:@"Bookmarks"];
-
+    if (self) {
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateCocoaWindowLevel:) name:VLCWindowShouldUpdateLevel object:nil];
+    }
     return self;
 }
 
@@ -93,8 +95,9 @@
     [_editTimeLabel setStringValue: _NS("Time")];
 }
 
-- (void)updateCocoaWindowLevel:(NSInteger)i_level
+- (void)updateCocoaWindowLevel:(NSNotification *)aNotification
 {
+    NSInteger i_level = [aNotification.userInfo[VLCWindowLevelKey] integerValue];
     if (self.isWindowLoaded && [self.window isVisible] && [self.window level] != i_level)
         [self.window setLevel: i_level];
 }
diff --git a/modules/gui/macosx/panels/VLCInformationWindowController.h b/modules/gui/macosx/panels/VLCInformationWindowController.h
index a87c992b4b..f6a5b78242 100644
--- a/modules/gui/macosx/panels/VLCInformationWindowController.h
+++ b/modules/gui/macosx/panels/VLCInformationWindowController.h
@@ -84,7 +84,6 @@
 @property (readwrite, weak) IBOutlet NSTextField *videoDecodedLabel;
 @property (readwrite, weak) IBOutlet NSTextField *videoDecodedTextField;
 
-- (void)updateCocoaWindowLevel:(NSInteger)i_level;
 - (IBAction)toggleWindow:(id)sender;
 
 - (IBAction)metaFieldChanged:(id)sender;
diff --git a/modules/gui/macosx/panels/VLCInformationWindowController.m b/modules/gui/macosx/panels/VLCInformationWindowController.m
index 8c603ee2d4..f3da3b4994 100644
--- a/modules/gui/macosx/panels/VLCInformationWindowController.m
+++ b/modules/gui/macosx/panels/VLCInformationWindowController.m
@@ -74,6 +74,10 @@
                                       selector:@selector(updateStatistics:)
                                           name:VLCPlayerStatisticsUpdated
                                         object:nil];
+        [defaultNotificationCenter addObserver:self
+                                      selector:@selector(updateCocoaWindowLevel:)
+                                          name:VLCWindowShouldUpdateLevel
+                                        object:nil];
     }
     return self;
 }
@@ -148,8 +152,9 @@
     [self updatePanelWithItem:_mediaItem];
 }
 
-- (void)updateCocoaWindowLevel:(NSInteger)i_level
+- (void)updateCocoaWindowLevel:(NSNotification *)aNotification
 {
+    NSInteger i_level = [aNotification.userInfo[VLCWindowLevelKey] integerValue];
     if (self.isWindowLoaded && [self.window isVisible] && [self.window level] != i_level)
         [self.window setLevel: i_level];
 }
diff --git a/modules/gui/macosx/panels/VLCTrackSynchronizationWindowController.h b/modules/gui/macosx/panels/VLCTrackSynchronizationWindowController.h
index 3f1d97788d..3bce0a62fb 100644
--- a/modules/gui/macosx/panels/VLCTrackSynchronizationWindowController.h
+++ b/modules/gui/macosx/panels/VLCTrackSynchronizationWindowController.h
@@ -46,8 +46,6 @@
 @property (readwrite, weak) IBOutlet NSTextField *sv_durTextField;
 @property (readwrite, weak) IBOutlet NSStepper *sv_durStepper;
 
-- (void)updateCocoaWindowLevel:(NSInteger)i_level;
-
 - (IBAction)toggleWindow:(id)sender;
 - (IBAction)resetValues:(id)sender;
 
diff --git a/modules/gui/macosx/panels/VLCTrackSynchronizationWindowController.m b/modules/gui/macosx/panels/VLCTrackSynchronizationWindowController.m
index 75431c0d0e..ccde9fa1fc 100644
--- a/modules/gui/macosx/panels/VLCTrackSynchronizationWindowController.m
+++ b/modules/gui/macosx/panels/VLCTrackSynchronizationWindowController.m
@@ -75,6 +75,10 @@
                            selector:@selector(updateValues:)
                                name:VLCPlayerSubtitlesFPSChanged
                              object:nil];
+    [notificationCenter addObserver:self
+                           selector:@selector(updateCocoaWindowLevel:)
+                               name:VLCWindowShouldUpdateLevel
+                             object:nil];
 
     [self.window setTitle:_NS("Track Synchronization")];
     [_resetButton setTitle:_NS("Reset")];
@@ -117,8 +121,9 @@
     [self resetValues:self];
 }
 
-- (void)updateCocoaWindowLevel:(NSInteger)i_level
+- (void)updateCocoaWindowLevel:(NSNotification *)aNotification
 {
+    NSInteger i_level = [aNotification.userInfo[VLCWindowLevelKey] integerValue];
     if (self.isWindowLoaded && [self.window isVisible] && [self.window level] != i_level)
         [self.window setLevel: i_level];
 }
diff --git a/modules/gui/macosx/panels/VLCVideoEffectsWindowController.h b/modules/gui/macosx/panels/VLCVideoEffectsWindowController.h
index ec2c76cab6..cab80a0de6 100644
--- a/modules/gui/macosx/panels/VLCVideoEffectsWindowController.h
+++ b/modules/gui/macosx/panels/VLCVideoEffectsWindowController.h
@@ -167,7 +167,6 @@
 @property (nonatomic) int posterizeValue;
 
 /* generic */
-- (void)updateCocoaWindowLevel:(NSInteger)i_level;
 - (void)saveCurrentProfileAtTerminate;
 
 - (void)toggleWindow:(id)sender;
diff --git a/modules/gui/macosx/panels/VLCVideoEffectsWindowController.m b/modules/gui/macosx/panels/VLCVideoEffectsWindowController.m
index 625fdf53c6..05b602329e 100644
--- a/modules/gui/macosx/panels/VLCVideoEffectsWindowController.m
+++ b/modules/gui/macosx/panels/VLCVideoEffectsWindowController.m
@@ -72,6 +72,11 @@ NSString *VLCVideoEffectsProfileNamesKey = @"VideoEffectProfileNames";
 {
     self = [super initWithWindowNibName:@"VideoEffects"];
     if (self) {
+        [[NSNotificationCenter defaultCenter] addObserver:self
+                                                 selector:@selector(updateCocoaWindowLevel:)
+                                                     name:VLCWindowShouldUpdateLevel
+                                                   object:nil];
+
         self.popupPanel = [[VLCPopupPanelController alloc] init];
         self.textfieldPanel = [[VLCTextfieldPanelController alloc] init];
 
@@ -334,8 +339,9 @@ NSString *VLCVideoEffectsProfileNamesKey = @"VideoEffectProfileNames";
     [[NSNotificationCenter defaultCenter] removeObserver:self];
 }
 
-- (void)updateCocoaWindowLevel:(NSInteger)i_level
+- (void)updateCocoaWindowLevel:(NSNotification *)aNotification
 {
+    NSInteger i_level = [aNotification.userInfo[VLCWindowLevelKey] integerValue];
     if (self.isWindowLoaded && [self.window isVisible] && [self.window level] != i_level)
         [self.window setLevel: i_level];
 }
diff --git a/modules/gui/macosx/panels/dialogs/VLCResumeDialogController.h b/modules/gui/macosx/panels/dialogs/VLCResumeDialogController.h
index 1c96e9caea..811294dc0f 100644
--- a/modules/gui/macosx/panels/dialogs/VLCResumeDialogController.h
+++ b/modules/gui/macosx/panels/dialogs/VLCResumeDialogController.h
@@ -51,8 +51,6 @@ typedef void(^CompletionBlock)(enum ResumeResult);
 
 - (void)showWindowWithItem:(input_item_t *)p_item withLastPosition:(NSInteger)pos completionBlock:(CompletionBlock)block;
 
-- (void)updateCocoaWindowLevel:(NSInteger)i_level;
-
 - (void)cancel;
 
 @end
diff --git a/modules/gui/macosx/panels/dialogs/VLCResumeDialogController.m b/modules/gui/macosx/panels/dialogs/VLCResumeDialogController.m
index eb29d87dda..6d60c78f3a 100644
--- a/modules/gui/macosx/panels/dialogs/VLCResumeDialogController.m
+++ b/modules/gui/macosx/panels/dialogs/VLCResumeDialogController.m
@@ -40,10 +40,21 @@
 - (id)init
 {
     self = [super initWithWindowNibName:@"ResumeDialog"];
+    if (self) {
+        [[NSNotificationCenter defaultCenter] addObserver:self
+                                                 selector:@selector(updateCocoaWindowLevel:)
+                                                     name:VLCWindowShouldUpdateLevel
+                                                   object:nil];
+    }
 
     return self;
 }
 
+- (void)dealloc
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
 - (void)windowDidLoad
 {
     [o_title_lbl setStringValue:_NS("Continue playback?")];
@@ -59,7 +70,6 @@
     currentResumeTimeout = 10;
     completionBlock = [block copy];
 
-
     NSString *o_restartButtonLabel = _NS("Restart playback");
     o_restartButtonLabel = [o_restartButtonLabel stringByAppendingFormat:@" (%d)", currentResumeTimeout];
     [o_restart_btn setTitle:o_restartButtonLabel];
@@ -122,8 +132,9 @@
     config_PutInt("macosx-continue-playback", newState);
 }
 
-- (void)updateCocoaWindowLevel:(NSInteger)i_level
+- (void)updateCocoaWindowLevel:(NSNotification *)aNotification
 {
+    NSInteger i_level = [aNotification.userInfo[VLCWindowLevelKey] integerValue];
     if (self.isWindowLoaded && [self.window isVisible] && [self.window level] != i_level)
         [self.window setLevel: i_level];
 }
diff --git a/modules/gui/macosx/windows/video/VLCVideoOutputProvider.h b/modules/gui/macosx/windows/video/VLCVideoOutputProvider.h
index 716ed439c8..5a2c3876c5 100644
--- a/modules/gui/macosx/windows/video/VLCVideoOutputProvider.h
+++ b/modules/gui/macosx/windows/video/VLCVideoOutputProvider.h
@@ -29,6 +29,9 @@
 @class VLCVideoWindowCommon;
 @class VLCVoutView;
 
+extern NSString *VLCWindowShouldUpdateLevel;
+extern NSString *VLCWindowLevelKey;
+
 @interface VLCVideoOutputProvider : NSObject
 
 @property (readonly, nonatomic) NSInteger currentStatusWindowLevel;
diff --git a/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m b/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m
index d9d6ce2026..378dce3f2d 100644
--- a/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m
+++ b/modules/gui/macosx/windows/video/VLCVideoOutputProvider.m
@@ -43,6 +43,9 @@
 #import "panels/VLCBookmarksWindowController.h"
 #import "panels/VLCTrackSynchronizationWindowController.h"
 
+NSString *VLCWindowShouldUpdateLevel = @"VLCWindowShouldUpdateLevel";
+NSString *VLCWindowLevelKey = @"VLCWindowLevelKey";
+
 static int WindowEnable(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
 {
     @autoreleasepool {
@@ -551,16 +554,10 @@ int WindowOpen(vout_window_t *p_wnd)
         _currentStatusWindowLevel = i_level + 1;
     }
 
-    NSInteger currentStatusWindowLevel = self.currentStatusWindowLevel;
-
     VLCMain *main = [VLCMain sharedInstance];
     [[main libraryWindow] setWindowLevel:i_level];
-    [[main videoEffectsPanel] updateCocoaWindowLevel:currentStatusWindowLevel];
-    [[main audioEffectsPanel] updateCocoaWindowLevel:currentStatusWindowLevel];
-    [[main currentMediaInfoPanel] updateCocoaWindowLevel:currentStatusWindowLevel];
-    [[main bookmarks] updateCocoaWindowLevel:currentStatusWindowLevel];
-    [[main trackSyncPanel] updateCocoaWindowLevel:currentStatusWindowLevel];
-    [[main resumeDialog] updateCocoaWindowLevel:currentStatusWindowLevel];
+
+    [[NSNotificationCenter defaultCenter] postNotificationName:VLCWindowShouldUpdateLevel object:self userInfo:@{VLCWindowLevelKey : @(_currentWindowLevel)}];
 }
 
 @end
diff --git a/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m b/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m
index 311afe4f36..cdd7713630 100644
--- a/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m
+++ b/modules/gui/macosx/windows/video/VLCVideoWindowCommon.m
@@ -78,12 +78,14 @@ NSString *VLCVideoWindowDidEnterFullscreen = @"VLCVideoWindowDidEnterFullscreen"
     self = [super initWithContentRect:contentRect styleMask:styleMask
                               backing:backingType defer:flag];
 
-    /* we want to be moveable regardless of our style */
-    [self setMovableByWindowBackground: YES];
-    [self setCanBecomeKeyWindow:YES];
+    if (self) {
+        /* we want to be moveable regardless of our style */
+        [self setMovableByWindowBackground: YES];
+        [self setCanBecomeKeyWindow:YES];
 
-    o_temp_view = [[NSView alloc] init];
-    [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
+        o_temp_view = [[NSView alloc] init];
+        [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
+    }
 
     return self;
 }



More information about the vlc-commits mailing list