[vlc-commits] macosx: fix legacy media key support activation
Felix Paul Kühne
git at videolan.org
Wed Apr 17 00:18:13 CEST 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Wed Apr 17 00:06:55 2019 +0200| [7d109ecf350da49a1e52287c0a2d720743c63453] | committer: Felix Paul Kühne
macosx: fix legacy media key support activation
This also fixes #21358.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7d109ecf350da49a1e52287c0a2d720743c63453
---
.../gui/macosx/os-integration/VLCClickerManager.m | 57 +++++++++++++++++-----
1 file changed, 46 insertions(+), 11 deletions(-)
diff --git a/modules/gui/macosx/os-integration/VLCClickerManager.m b/modules/gui/macosx/os-integration/VLCClickerManager.m
index c75045aafa..c0a87cf4a8 100644
--- a/modules/gui/macosx/os-integration/VLCClickerManager.m
+++ b/modules/gui/macosx/os-integration/VLCClickerManager.m
@@ -66,6 +66,14 @@
name:VLCMediaKeySupportSettingChangedNotification
object:nil];
[notificationCenter addObserver:self
+ selector:@selector(playlistUpdated:)
+ name:VLCPlaylistItemsAdded
+ object:nil];
+ [notificationCenter addObserver:self
+ selector:@selector(playlistUpdated:)
+ name:VLCPlaylistItemsRemoved
+ object:nil];
+ [notificationCenter addObserver:self
selector:@selector(coreChangedAppleRemoteSetting:)
name:VLCAppleRemoteSettingChangedNotification
object:nil];
@@ -115,24 +123,51 @@
VLCMain *main = [VLCMain sharedInstance];
if (b_mediaKeySupport && ([[[main playlistController] playlistModel] numberOfPlaylistItems] > 0)) {
if (!b_mediaKeyTrapEnabled) {
- msg_Dbg(p_intf, "Enabling media key support");
- if ([_mediaKeyController startWatchingMediaKeys]) {
- b_mediaKeyTrapEnabled = YES;
- } else {
- msg_Warn(p_intf, "Failed to enable media key support, likely "
- "app needs to be whitelisted in Security Settings.");
- }
+ [self enableMediaKeySupport];
}
} else {
if (b_mediaKeyTrapEnabled) {
- b_mediaKeyTrapEnabled = NO;
- msg_Dbg(p_intf, "Disabling media key support");
- [_mediaKeyController stopWatchingMediaKeys];
+ [self disableMediaKeySupport];
}
+ _mediaKeyController = nil;
+ }
+}
+
+- (void)enableMediaKeySupport
+{
+ intf_thread_t *p_intf = getIntf();
+ msg_Dbg(p_intf, "Enabling media key support");
+ if ([_mediaKeyController startWatchingMediaKeys]) {
+ b_mediaKeyTrapEnabled = YES;
+ } else {
+ msg_Warn(p_intf, "Failed to enable media key support, likely "
+ "app needs to be whitelisted in Security Settings.");
+ }
+}
+
+- (void)disableMediaKeySupport
+{
+ b_mediaKeyTrapEnabled = NO;
+ msg_Dbg(getIntf(), "Disabling media key support");
+ [_mediaKeyController stopWatchingMediaKeys];
+}
+
+- (void)playlistUpdated:(NSNotification *)aNotification
+{
+ if (!_mediaKeyController) {
+ return;
+ }
+
+ BOOL numberOfMediaLargerThanZero = [[[[VLCMain sharedInstance] playlistController] playlistModel] numberOfPlaylistItems] > 0;
+
+ if (b_mediaKeyTrapEnabled && !numberOfMediaLargerThanZero) {
+ [self disableMediaKeySupport];
+ } else if (!b_mediaKeyTrapEnabled && numberOfMediaLargerThanZero) {
+ [self enableMediaKeySupport];
}
}
--(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event
+- (void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event
{
if (b_mediaKeySupport) {
assert([event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys);
More information about the vlc-commits
mailing list