[vlc-commits] macosx: center fullscreen panel for new fullscreen size

David Fuhrmann git at videolan.org
Sun Jan 29 22:49:23 CET 2017


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sun Jan 29 21:48:47 2017 +0100| [b7f9c20f7ab0d54e2432e1b9685675bda6184c66] | committer: David Fuhrmann

macosx: center fullscreen panel for new fullscreen size

The fullscreen window can have a new size if the fullscreen monitor
was switched or the user used split screen in between.

Center FS panel in those cases. Also constrain size as the new
available space might be smaller.

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

 modules/gui/macosx/VLCFSPanelController.h    | 14 ++-----
 modules/gui/macosx/VLCFSPanelController.m    | 61 ++++++++++++++++++----------
 modules/gui/macosx/VLCFSPanelDraggableView.h |  2 -
 modules/gui/macosx/VLCFSPanelDraggableView.m | 20 ++-------
 modules/gui/macosx/VLCMainWindow.m           |  1 -
 5 files changed, 45 insertions(+), 53 deletions(-)

diff --git a/modules/gui/macosx/VLCFSPanelController.h b/modules/gui/macosx/VLCFSPanelController.h
index ee8ec95..e1f6194 100644
--- a/modules/gui/macosx/VLCFSPanelController.h
+++ b/modules/gui/macosx/VLCFSPanelController.h
@@ -29,13 +29,12 @@
 #import "misc.h"
 #import "Windows.h"
 #import "VLCDefaultValueSlider.h"
-#import "VLCFSPanelDraggableView.h"
 
 @interface VLCFSPanelController : NSWindowController
 
 @property (readwrite, weak) NSTimer   *hideTimer;
 
- at property IBOutlet VLCFSPanelDraggableView *controlsView;
+ at property IBOutlet NSView       *controlsView;
 @property IBOutlet NSButton     *playPauseButton;
 @property IBOutlet NSButton     *forwardButton;
 @property IBOutlet NSButton     *backwardButton;
@@ -61,7 +60,6 @@
 
 - (void)fadeIn;
 - (void)fadeOut;
-- (void)center;
 - (void)setActive;
 - (void)setNonActive;
 - (void)setVoutWasUpdated:(VLCWindow *)voutWindow;
@@ -73,13 +71,7 @@
 - (void)setPlay;
 - (void)setPause;
 
-/**
- Center the window on the specified screen in the lower third
-
- \note If the screen is invalid, the main screen is used
-
- \param screenID    The screen on which to center the window
- */
-- (void)centerWindowOnScreen:(CGDirectDisplayID)screenID;
+// Constrain frame to window. Used by VLCFSPanelDraggableView.
+- (NSRect)contrainFrameToAssociatedVoutWindow:(NSRect)frame;
 
 @end
diff --git a/modules/gui/macosx/VLCFSPanelController.m b/modules/gui/macosx/VLCFSPanelController.m
index 9b3ce0d..0984fb2 100644
--- a/modules/gui/macosx/VLCFSPanelController.m
+++ b/modules/gui/macosx/VLCFSPanelController.m
@@ -31,7 +31,11 @@
 
 @interface VLCFSPanelController () {
     BOOL _isCounting;
-    CGDirectDisplayID _displayID;
+
+    // Only used to track changes and trigger centering of FS panel
+    NSRect _associatedVoutFrame;
+    // Used to ask for current constraining rect on movement
+    NSWindow *_associatedVoutWindow;
 }
 
 @end
@@ -283,29 +287,41 @@
     [NSAnimationContext endGrouping];
 }
 
-- (void)centerWindowOnScreen:(CGDirectDisplayID)screenID
+- (void)centerPanel
 {
-    /* Find screen by its ID */
-    NSScreen *screen = [NSScreen screenWithDisplayID:screenID];
-
-    /* Check screen validity, fallback to mainScreen */
-    if (!screen)
-        screen = [NSScreen mainScreen];
-
-    NSRect screenFrame = [screen frame];
     NSRect windowFrame = [self.window frame];
+    windowFrame = [self contrainFrameToAssociatedVoutWindow:windowFrame];
 
-    /* Calculate coordinates for new NSWindow position */
-    NSPoint coordinates;
-    coordinates.x = (screenFrame.size.width - windowFrame.size.width) / 2 + screenFrame.origin.x;
-    coordinates.y = (screenFrame.size.height / 3) - windowFrame.size.height + screenFrame.origin.y;
+    /* Calculate coordinates for centered position */
+    NSRect limitFrame = _associatedVoutWindow.frame;
+    windowFrame.origin.x = (limitFrame.size.width - windowFrame.size.width) / 2 + limitFrame.origin.x;
+    windowFrame.origin.y = (limitFrame.size.height / 5) - windowFrame.size.height + limitFrame.origin.y;
 
-    [self.window setFrameTopLeftPoint:coordinates];
+    [self.window setFrame:windowFrame display:YES animate:NO];
 }
 
-- (void)center
+- (NSRect)contrainFrameToAssociatedVoutWindow:(NSRect)frame
 {
-    [self centerWindowOnScreen:_displayID];
+    NSRect limitFrame = _associatedVoutWindow.frame;
+
+    // Limit rect to limitation view
+    if (frame.origin.x < limitFrame.origin.x)
+        frame.origin.x = limitFrame.origin.x;
+    if (frame.origin.y < limitFrame.origin.y)
+        frame.origin.y = limitFrame.origin.y;
+
+    // Limit size (could be needed after resolution changes)
+    if (frame.size.height > limitFrame.size.height)
+        frame.size.height = limitFrame.size.height;
+    if (frame.size.width > limitFrame.size.width)
+        frame.size.width = limitFrame.size.width;
+
+    if (frame.origin.x + frame.size.width > limitFrame.origin.x + limitFrame.size.width)
+        frame.origin.x = limitFrame.origin.x + limitFrame.size.width - frame.size.width;
+    if (frame.origin.y + frame.size.height > limitFrame.origin.y + limitFrame.size.height)
+        frame.origin.y = limitFrame.origin.y + limitFrame.size.height - frame.size.height;
+
+    return frame;
 }
 
 - (void)setNonActive
@@ -329,13 +345,14 @@
 
 - (void)setVoutWasUpdated:(VLCWindow *)voutWindow
 {
-    [_controlsView setLimitWindow:voutWindow];
-    int newDisplayID = [[self.window screen] displayID];
+    _associatedVoutWindow = voutWindow;
 
-    if (_displayID != newDisplayID) {
-        _displayID = newDisplayID;
-        [self center];
+    NSRect voutRect = voutWindow.frame;
+    if (!NSEqualRects(_associatedVoutFrame, voutRect)) {
+        _associatedVoutFrame = voutRect;
+        [self centerPanel];
     }
+
 }
 
 #pragma mark -
diff --git a/modules/gui/macosx/VLCFSPanelDraggableView.h b/modules/gui/macosx/VLCFSPanelDraggableView.h
index ceec719..5fd3182 100644
--- a/modules/gui/macosx/VLCFSPanelDraggableView.h
+++ b/modules/gui/macosx/VLCFSPanelDraggableView.h
@@ -25,7 +25,5 @@
 
 @interface VLCFSPanelDraggableView : NSView
 
- at property NSWindow     *limitWindow;
-
 @end
 
diff --git a/modules/gui/macosx/VLCFSPanelDraggableView.m b/modules/gui/macosx/VLCFSPanelDraggableView.m
index 1fa0f04..d6fa2c7 100644
--- a/modules/gui/macosx/VLCFSPanelDraggableView.m
+++ b/modules/gui/macosx/VLCFSPanelDraggableView.m
@@ -23,6 +23,8 @@
 
 #import "VLCFSPanelDraggableView.h"
 
+#import "VLCFSPanelController.h"
+
 @implementation VLCFSPanelDraggableView
 
 - (BOOL)mouseDownCanMoveWindow
@@ -52,27 +54,11 @@
         NSPoint delta = NSMakePoint(newMouseLocation.x - originalMouseLocation.x,
                                     newMouseLocation.y - originalMouseLocation.y);
 
-        NSRect limitFrame = _limitWindow.frame;
         NSRect newFrame = originalFrame;
         newFrame.origin.x += delta.x;
         newFrame.origin.y += delta.y;
 
-        // Limit rect to limitation view
-        if (newFrame.origin.x < limitFrame.origin.x)
-            newFrame.origin.x = limitFrame.origin.x;
-        if (newFrame.origin.y < limitFrame.origin.y)
-            newFrame.origin.y = limitFrame.origin.y;
-
-        // Limit size (could be needed after resolution changes)
-        if (newFrame.size.height > limitFrame.size.height)
-            newFrame.size.height = limitFrame.size.height;
-        if (newFrame.size.width > limitFrame.size.width)
-            newFrame.size.width = limitFrame.size.width;
-
-        if (newFrame.origin.x + newFrame.size.width > limitFrame.origin.x + limitFrame.size.width)
-            newFrame.origin.x = limitFrame.origin.x + limitFrame.size.width - newFrame.size.width;
-        if (newFrame.origin.y + newFrame.size.height > limitFrame.origin.y + limitFrame.size.height)
-            newFrame.origin.y = limitFrame.origin.y + limitFrame.size.height - newFrame.size.height;
+        newFrame = [(VLCFSPanelController *)[[self window] delegate] contrainFrameToAssociatedVoutWindow: newFrame];
 
         [window setFrame:newFrame display:YES animate:NO];
     }
diff --git a/modules/gui/macosx/VLCMainWindow.m b/modules/gui/macosx/VLCMainWindow.m
index fe62713..fa6f247 100644
--- a/modules/gui/macosx/VLCMainWindow.m
+++ b/modules/gui/macosx/VLCMainWindow.m
@@ -244,7 +244,6 @@ static const float f_min_window_height = 307.;
         [defaults setObject:[NSDate date] forKey:@"VLCFirstRun"];
 
         [_sidebarView expandItem:nil expandChildren:YES];
-        [_fspanel center];
 
         NSAlert *albumArtAlert = [NSAlert alertWithMessageText:_NS("Check for album art and metadata?") defaultButton:_NS("Enable Metadata Retrieval") alternateButton:_NS("No, Thanks") otherButton:nil informativeTextWithFormat:@"%@",_NS("VLC can check online for album art and metadata to enrich your playback experience, e.g. by providing track information when playing Audio CDs. To provide this functionality, VLC will send information about your contents to trusted services in an anonymized form.")];
         NSInteger returnValue = [albumArtAlert runModal];



More information about the vlc-commits mailing list