[vlc-commits] [Git][videolan/vlc][master] 14 commits: macosx: Notify when VLCRendererDiscovery adds or removes renderers
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Tue Mar 12 20:27:34 UTC 2024
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
c7541f6a by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Notify when VLCRendererDiscovery adds or removes renderers
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
1c27a7d6 by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Replace previously unused rendererItems in VLCRendererMenuController with a nsarray, store the renderer items in it
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
c140b93c by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Add a renderers button to VLCLibraryWindow XIB
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
7c530d8e by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Add a reference outlet for renderers toolbar item
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
211e5ccb by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Setup a VLCRendererMenuController in VLCLibraryWindow
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
9ff5f21d by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Dynamically display renderers toolbar item in main library window depending on availability of renderers
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
2ea2a3f8 by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Display menu when pressing renderer toolbar item
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
af246562 by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Publically expose the renderermenuc0ontroller in VLCMainMenu
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
6ead46d2 by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Use rendereMenuController from VLCMainMenu in VLCLibraryWindow rather than instantiate new instance
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
cac0a4f9 by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Add method to renderer menu controller to start discovery with timeout
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
d7eb14e7 by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Use new discoveries with timeout method for renderer menu controller in VLCMainMenu
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
8c678cd9 by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Poll renderer discoveries every two minutes in library window
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
61fc9b72 by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Do not stop renderer discovery, keep running throughout application lifetime
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
aeac0654 by Claudio Cambra at 2024-03-12T20:09:48+00:00
macosx: Use antenna icon for renderers button
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
9 changed files:
- modules/gui/macosx/UI/VLCLibraryWindow.xib
- modules/gui/macosx/library/VLCLibraryWindow.h
- modules/gui/macosx/library/VLCLibraryWindow.m
- modules/gui/macosx/menus/VLCMainMenu.h
- modules/gui/macosx/menus/VLCMainMenu.m
- modules/gui/macosx/menus/renderers/VLCRendererDiscovery.h
- modules/gui/macosx/menus/renderers/VLCRendererDiscovery.m
- modules/gui/macosx/menus/renderers/VLCRendererMenuController.h
- modules/gui/macosx/menus/renderers/VLCRendererMenuController.m
Changes:
=====================================
modules/gui/macosx/UI/VLCLibraryWindow.xib
=====================================
@@ -697,6 +697,23 @@
</connections>
</button>
</toolbarItem>
+ <toolbarItem implicitItemIdentifier="C0F3283F-472F-46A6-910B-44EE5602E3D2" label="Renderers" paletteLabel="Renderers" image="antenna.radiowaves.left.and.right" catalog="system" bordered="YES" sizingBehavior="auto" id="YEO-08-Qzi">
+ <nil key="toolTip"/>
+ <button key="view" wantsLayer="YES" verticalHuggingPriority="750" misplaced="YES" id="ffS-QP-Om3">
+ <rect key="frame" x="18" y="14" width="26" height="19"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <constraints>
+ <constraint firstAttribute="width" constant="30" id="ann-oP-TCW"/>
+ </constraints>
+ <buttonCell key="cell" type="recessed" bezelStyle="recessed" image="antenna.radiowaves.left.and.right" catalog="system" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="CH2-Lq-KIb">
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+ <font key="font" metaFont="systemBold" size="12"/>
+ </buttonCell>
+ <connections>
+ <action selector="rendererControlAction:" target="QvC-M9-y7g" id="M1O-u2-5FO"/>
+ </connections>
+ </button>
+ </toolbarItem>
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="89f-AL-zuU"/>
<toolbarItem implicitItemIdentifier="85037E27-D263-490C-B4B2-0EFE5B5837AA" label="Library View Type" paletteLabel="Library View Type" sizingBehavior="auto" id="kBa-MC-Mdq">
<nil key="toolTip"/>
@@ -845,6 +862,8 @@
<outlet property="playlistTableView" destination="Fr1-af-8gb" id="yaB-Ab-jrx"/>
<outlet property="playlistView" destination="dus-WQ-AmE" id="fTF-HP-Chb"/>
<outlet property="playlistViewTitleTopConstraint" destination="5b2-gJ-uva" id="qoh-ro-EIN"/>
+ <outlet property="renderersButton" destination="ffS-QP-Om3" id="rOM-No-rd0"/>
+ <outlet property="renderersToolbarItem" destination="YEO-08-Qzi" id="mwx-8t-5o7"/>
<outlet property="repeatPlaylistButton" destination="8zF-Wo-H79" id="6bH-HF-arx"/>
<outlet property="shufflePlaylistButton" destination="jg5-33-vH0" id="FV2-36-3lG"/>
<outlet property="sortOrderToolbarItem" destination="Tbc-Ik-FaO" id="098-yp-97f"/>
@@ -1876,6 +1895,7 @@
<image name="VLCVolumeOffTemplate" width="128" height="128"/>
<image name="VLCVolumeOnTemplate" width="128" height="128"/>
<image name="arrow.up.arrow.down" catalog="system" width="18" height="15"/>
+ <image name="antenna.radiowaves.left.and.right" catalog="system" width="16" height="14"/>
<image name="dropzone" width="112" height="112"/>
<image name="fullscreen-one-button" width="29" height="23"/>
<image name="fullscreen-one-button-pressed" width="29" height="23"/>
=====================================
modules/gui/macosx/library/VLCLibraryWindow.h
=====================================
@@ -122,6 +122,7 @@ extern const NSUserInterfaceItemIdentifier VLCLibraryWindowIdentifier;
@property (readwrite, weak) IBOutlet NSButton *artworkButton;
@property (readwrite, weak) IBOutlet NSToolbarItem *toggleNavSidebarToolbarItem;
@property (readwrite, weak) IBOutlet NSToolbarItem *trackingSeparatorToolbarItem;
+ at property (readwrite, weak) IBOutlet NSButton *renderersButton;
@property (readwrite, weak) IBOutlet NSToolbarItem *backwardsToolbarItem;
@property (readwrite, weak) IBOutlet NSToolbarItem *forwardsToolbarItem;
@property (readwrite, weak) IBOutlet NSToolbarItem *libraryViewModeToolbarItem;
@@ -129,6 +130,7 @@ extern const NSUserInterfaceItemIdentifier VLCLibraryWindowIdentifier;
@property (readwrite, weak) IBOutlet NSToolbarItem *flexibleSpaceToolbarItem;
@property (readwrite, weak) IBOutlet NSToolbarItem *librarySearchToolbarItem;
@property (readwrite, weak) IBOutlet NSToolbarItem *togglePlaylistToolbarItem;
+ at property (readwrite, weak) IBOutlet NSToolbarItem *renderersToolbarItem;
@property (readwrite, weak) IBOutlet NSLayoutConstraint *splitViewBottomConstraintToBottomBar;
@property (nonatomic, readwrite, strong) IBOutlet NSView *emptyLibraryView;
@@ -171,6 +173,7 @@ extern const NSUserInterfaceItemIdentifier VLCLibraryWindowIdentifier;
- (IBAction)backwardsNavigationAction:(id)sender;
- (IBAction)forwardsNavigationAction:(id)sender;
- (IBAction)gridVsListSegmentedControlAction:(id)sender;
+- (IBAction)rendererControlAction:(id)sender;
@end
=====================================
modules/gui/macosx/library/VLCLibraryWindow.m
=====================================
@@ -32,6 +32,7 @@
#import "extensions/NSWindow+VLCAdditions.h"
#import "main/VLCMain.h"
+#import "menus/VLCMainMenu.h"
#import "playlist/VLCPlayerController.h"
#import "playlist/VLCPlaylistController.h"
@@ -63,6 +64,8 @@
#import "media-source/VLCMediaSourceBaseDataSource.h"
#import "media-source/VLCLibraryMediaSourceViewController.h"
+#import "menus/renderers/VLCRendererMenuController.h"
+
#import "views/VLCBottomBarView.h"
#import "views/VLCCustomWindowButton.h"
#import "views/VLCDragDropView.h"
@@ -210,6 +213,14 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
selector:@selector(playerStateChanged:)
name:VLCPlayerStateChanged
object:nil];
+ [notificationCenter addObserver:self
+ selector:@selector(renderersChanged:)
+ name:VLCRendererAddedNotification
+ object:nil];
+ [notificationCenter addObserver:self
+ selector:@selector(renderersChanged:)
+ name:VLCRendererRemovedNotification
+ object:nil];
if (@available(macOS 10.14, *)) {
[NSApplication.sharedApplication addObserver:self
@@ -259,6 +270,11 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
[self repeatStateUpdated:nil];
[self shuffleStateUpdated:nil];
+ // Hide renderers toolbar item at first. Start discoveries and wait for notifications about
+ // renderers being added or removed to keep hidden or show depending on outcome
+ [self hideToolbarItem:_renderersToolbarItem];
+ [VLCMain.sharedInstance.mainMenu.rendererMenuController startRendererDiscoveries];
+
// HACK: The size of the segmented title buttons is not always correctly calculated
// especially when the text we are setting differs from what is set in the storyboard.
// Hiding and showing the toolbar again must trigger something that causes the width
@@ -1038,4 +1054,27 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
}
}
+#pragma mark -
+#pragma mark respond to renderers
+
+- (void)renderersChanged:(NSNotification *)notification
+{
+ const NSUInteger rendererCount = VLCMain.sharedInstance.mainMenu.rendererMenuController.rendererItems.count;
+ const BOOL rendererToolbarItemVisible = [self.toolbar.items containsObject:_renderersToolbarItem];
+
+ if (rendererCount > 0 && !rendererToolbarItemVisible) {
+ [self insertToolbarItem:_renderersToolbarItem
+ inFrontOf:@[_sortOrderToolbarItem, _libraryViewModeToolbarItem, _forwardsToolbarItem, _backwardsToolbarItem]];
+ } else if (rendererCount == 0 && rendererToolbarItemVisible) {
+ [self hideToolbarItem:_renderersToolbarItem];
+ }
+}
+
+- (void)rendererControlAction:(id)sender
+{
+ [NSMenu popUpContextMenu:VLCMain.sharedInstance.mainMenu.rendererMenu
+ withEvent:NSApp.currentEvent
+ forView:sender];
+}
+
@end
=====================================
modules/gui/macosx/menus/VLCMainMenu.h
=====================================
@@ -25,6 +25,8 @@
#import <vlc_common.h>
#import <vlc_interface.h>
+ at class VLCRendererMenuController;
+
@interface VLCMainMenu : NSObject
/* main menu */
@@ -223,6 +225,8 @@
@property (readwrite, weak) IBOutlet NSPopUpButton *playlistSaveAccessoryPopup;
@property (readwrite, weak) IBOutlet NSTextField *playlistSaveAccessoryText;
+ at property (readonly, strong) VLCRendererMenuController *rendererMenuController;
+
- (void)releaseRepresentedObjects:(NSMenu *)the_menu;
- (IBAction)openAddonManager:(id)sender;
=====================================
modules/gui/macosx/menus/VLCMainMenu.m
=====================================
@@ -101,10 +101,8 @@ typedef NS_ENUM(NSInteger, VLCObjectType) {
VLCAboutWindowController *_aboutWindowController;
VLCHelpWindowController *_helpWindowController;
VLCAddonsWindowController *_addonsController;
- VLCRendererMenuController *_rendererMenuController;
VLCPlaylistController *_playlistController;
VLCPlayerController *_playerController;
- NSTimer *_cancelRendererDiscoveryTimer;
VLCPlaylistSortingMenuController *_playlistSortingController;
VLCInformationWindowController *_infoWindowController;
@@ -1891,7 +1889,6 @@ typedef NS_ENUM(NSInteger, VLCObjectType) {
- (void)menuWillOpen:(NSMenu *)menu
{
- [_cancelRendererDiscoveryTimer invalidate];
[_rendererMenuController startRendererDiscoveries];
if (@available(macOS 10.16, *)) {
@@ -1923,20 +1920,6 @@ typedef NS_ENUM(NSInteger, VLCObjectType) {
}
}
-- (void)menuDidClose:(NSMenu *)menu
-{
- _cancelRendererDiscoveryTimer = [NSTimer scheduledTimerWithTimeInterval:20.
- target:self
- selector:@selector(cancelRendererDiscovery)
- userInfo:nil
- repeats:NO];
-}
-
-- (void)cancelRendererDiscovery
-{
- [_rendererMenuController stopRendererDiscoveries];
-}
-
@end
@implementation VLCMainMenu (NSMenuValidation)
=====================================
modules/gui/macosx/menus/renderers/VLCRendererDiscovery.h
=====================================
@@ -24,6 +24,9 @@
#import "menus/renderers/VLCRendererItem.h"
+extern NSString * const VLCRendererAddedNotification;
+extern NSString * const VLCRendererRemovedNotification;
+
@protocol VLCRendererDiscoveryDelegate;
/**
=====================================
modules/gui/macosx/menus/renderers/VLCRendererDiscovery.m
=====================================
@@ -27,6 +27,9 @@
#import "main/VLCMain.h"
+NSString * const VLCRendererAddedNotification = @"VLCRendererAddedNotification";
+NSString * const VLCRendererRemovedNotification = @"VLCRendererRemovedNotification";
+
@interface VLCRendererDiscovery ()
{
intf_thread_t *p_intf;
@@ -36,6 +39,7 @@
- (void)handleItemAdded:(vlc_renderer_item_t *)item;
- (void)handleItemRemoved:(const vlc_renderer_item_t *)item;
+
@end
// C callback event handler functions
@@ -119,6 +123,9 @@ static void renderer_event_item_removed(vlc_renderer_discovery_t *rd,
[_rendererItems addObject:item];
if (_delegate)
[_delegate addedRendererItem:item from:self];
+
+ [NSNotificationCenter.defaultCenter postNotificationName:VLCRendererAddedNotification
+ object:item];
}
- (void)handleItemRemoved:(const vlc_renderer_item_t *)base_item
@@ -134,6 +141,8 @@ static void renderer_event_item_removed(vlc_renderer_discovery_t *rd,
if (_delegate)
[_delegate removedRendererItem:result_item from:self];
[_rendererItems removeObject:result_item];
+ [NSNotificationCenter.defaultCenter postNotificationName:VLCRendererRemovedNotification
+ object:result_item];
} else {
msg_Err(p_intf, "VLCRendererDiscovery could not find item to remove!");
}
=====================================
modules/gui/macosx/menus/renderers/VLCRendererMenuController.h
=====================================
@@ -29,6 +29,7 @@
@property (readwrite, weak) NSMenu *rendererMenu;
@property (readwrite, weak) NSMenuItem *rendererNoneItem;
+ at property (readonly, strong) NSArray<VLCRendererItem *> *rendererItems;
- (void)startRendererDiscoveries;
- (void)stopRendererDiscoveries;
=====================================
modules/gui/macosx/menus/renderers/VLCRendererMenuController.m
=====================================
@@ -32,7 +32,6 @@
@interface VLCRendererMenuController ()
{
- NSMutableDictionary *_rendererItems;
NSMutableArray *_rendererDiscoveries;
BOOL _isDiscoveryEnabled;
NSMenuItem *_selectedItem;
@@ -48,7 +47,6 @@
{
self = [super init];
if (self) {
- _rendererItems = [NSMutableDictionary dictionary];
_rendererDiscoveries = [NSMutableArray array];
_isDiscoveryEnabled = NO;
p_intf = getIntf();
@@ -95,6 +93,11 @@
- (void)addRendererItem:(VLCRendererItem *)item
{
+ NSParameterAssert(item != nil);
+ NSMutableArray * const mutableRenderers = _rendererItems.mutableCopy;
+ [mutableRenderers addObject:item];
+ _rendererItems = mutableRenderers.copy;
+
// Check if the item is already selected
if (_selectedItem.representedObject != nil)
{
@@ -133,14 +136,21 @@
- (void)removeRendererItem:(VLCRendererItem *)item
{
+ NSParameterAssert(item != nil);
+
// The main menu must only be updated from the main thread
dispatch_async(dispatch_get_main_queue(), ^{
- NSInteger index = [_rendererMenu indexOfItemWithRepresentedObject:item];
+ NSMutableArray * const mutableRenderers = _rendererItems.mutableCopy;
+ [mutableRenderers removeObject:item];
+ _rendererItems = mutableRenderers.copy;
+
+ const NSInteger index = [_rendererMenu indexOfItemWithRepresentedObject:item];
if (index >= 0) {
- NSMenuItem *menuItem = [_rendererMenu itemAtIndex:index];
+ NSMenuItem * const menuItem = [_rendererMenu itemAtIndex:index];
// Don't remove selected item
- if (menuItem != _selectedItem)
+ if (menuItem != _selectedItem) {
[_rendererMenu removeItemAtIndex:index];
+ }
}
});
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b40275da9c70f228f3742d8e5b07e613121dcea6...aeac0654dfdc307a480851e63728b484daa3057b
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b40275da9c70f228f3742d8e5b07e613121dcea6...aeac0654dfdc307a480851e63728b484daa3057b
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list