Commit b7f9c20f authored by David Fuhrmann's avatar 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.
parent a2c0b01c
......@@ -29,13 +29,12 @@
#import "misc.h"
#import "Windows.h"
#import "VLCDefaultValueSlider.h"
#import "VLCFSPanelDraggableView.h"
@interface VLCFSPanelController : NSWindowController
@property (readwrite, weak) NSTimer *hideTimer;
@property IBOutlet VLCFSPanelDraggableView *controlsView;
@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
......@@ -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 -
......
......@@ -25,7 +25,5 @@
@interface VLCFSPanelDraggableView : NSView
@property NSWindow *limitWindow;
@end
......@@ -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];
}
......
......@@ -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];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment