[vlc-commits] [Git][videolan/vlc][3.0.x] 2 commits: macosx: Support safe area of new M1 macs for VLC fullscreen

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Mon Jan 17 07:49:43 UTC 2022



Hugo Beauzée-Luyssen pushed to branch 3.0.x at VideoLAN / VLC


Commits:
eb737101 by David Fuhrmann at 2022-01-17T07:35:43+00:00
macosx: Support safe area of new M1 macs for VLC fullscreen

New M1 Macs contain a notch, covering part of the screen. Analog to
the Quicktime player, when implementing VLCs internal fullscreen,
the video is scaled inside the safe area of the notch only, leaving
the top area black.

Fixes #26291

- - - - -
7d014e8d by David Fuhrmann at 2022-01-17T07:35:43+00:00
macosx: Disables safe area compatibility mode in Info.plist

Signal that the compatibility mode is not needed and VLC takes
care about the safe area directly.

- - - - -


3 changed files:

- modules/gui/macosx/CompatibilityFixes.h
- modules/gui/macosx/Windows.m
- share/Info.plist.in


Changes:

=====================================
modules/gui/macosx/CompatibilityFixes.h
=====================================
@@ -22,6 +22,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#import <AvailabilityMacros.h>
 #import <Cocoa/Cocoa.h>
 
 NS_ASSUME_NONNULL_BEGIN
@@ -82,4 +83,10 @@ extern NSString *const NSAppearanceNameDarkAqua;
 
 #endif
 
+#ifndef MAC_OS_VERSION_12_0
+ at interface NSScreen (IntroducedInMonterey)
+ at property (readonly) NSEdgeInsets safeAreaInsets;
+ at end
+#endif
+
 NS_ASSUME_NONNULL_END


=====================================
modules/gui/macosx/Windows.m
=====================================
@@ -743,6 +743,16 @@
 #pragma mark -
 #pragma mark Fullscreen Logic
 
+- (NSRect)transformRect:(NSRect)src withSafeAreaFromScreen:(NSScreen *)screen multiplier:(CGFloat)multiplier
+{
+    if (@available (macOS 12, *)) {
+        NSEdgeInsets insets = screen.safeAreaInsets;
+        src.size.height -= multiplier * insets.top;
+    }
+
+    return src;
+}
+
 - (void)enterFullscreenWithAnimation:(BOOL)b_animation
 {
     NSMutableDictionary *dict1, *dict2;
@@ -763,6 +773,8 @@
     }
 
     screen_rect = [screen frame];
+    // Cut of safe area at the top of the screen
+    screen_rect = [self transformRect:screen_rect withSafeAreaFromScreen:screen multiplier:+1.];
 
     if (self.controlsBar)
         [self.controlsBar setFullscreenState:YES];
@@ -785,6 +797,7 @@
         rect = [[_videoView superview] convertRect: [_videoView frame] toView: nil]; /* Convert to Window base coord */
         rect.origin.x += [self frame].origin.x;
         rect.origin.y += [self frame].origin.y;
+
         o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
         [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
         [o_fullscreen_window setCanBecomeKeyWindow: YES];
@@ -898,6 +911,13 @@
 
 - (void)hasBecomeFullscreen
 {
+    // Cover the top of the screen with the black window
+    NSRect window_frame = [self transformRect:o_fullscreen_window.frame withSafeAreaFromScreen:o_fullscreen_window.screen multiplier:-1.];
+    [o_fullscreen_window setFrame:window_frame display:YES];
+
+    NSRect video_frame = [self transformRect:_videoView.frame withSafeAreaFromScreen:o_fullscreen_window.screen multiplier:+1.];
+    _videoView.frame = video_frame;
+
     if ([[_videoView subviews] count] > 0)
         [o_fullscreen_window makeFirstResponder: [[_videoView subviews] firstObject]];
 
@@ -935,6 +955,13 @@
         return;
     }
 
+    // Convert black safe area from top screen
+    NSRect window_frame = [self transformRect:o_fullscreen_window.frame withSafeAreaFromScreen:o_fullscreen_window.screen multiplier:+1.];
+    [o_fullscreen_window setFrame:window_frame display:YES];
+
+    NSRect video_frame = [self transformRect:_videoView.frame withSafeAreaFromScreen:o_fullscreen_window.screen multiplier:-1.];
+    _videoView.frame = video_frame;
+
     [[[[VLCMain sharedInstance] mainWindow] fspanel] setNonActive];
     [[o_fullscreen_window screen] setNonFullscreenPresentationOptions];
 
@@ -1056,9 +1083,10 @@
         [[[viewAnimations firstObject] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
         /* Fullscreen ended */
         [self hasEndedFullscreen];
-    } else
-    /* Fullscreen started */
+    } else {
+        /* Fullscreen started */
         [self hasBecomeFullscreen];
+    }
 }
 
 #pragma mark -


=====================================
share/Info.plist.in
=====================================
@@ -8,6 +8,8 @@
 	<true/>
 	<key>CFBundleAllowMixedLocalizations</key>
 	<true/>
+	<key>NSPrefersDisplaySafeAreaCompatibilityMode</key>
+	<false/>
 	<key>CFBundleDocumentTypes</key>
 	<array>
 		<dict>



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/02448d19dd7b4965718ffc97faba3a659f356d7b...7d014e8d4b7a911a0d823075658d3ea390ddf5dc

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/02448d19dd7b4965718ffc97faba3a659f356d7b...7d014e8d4b7a911a0d823075658d3ea390ddf5dc
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list