Commit 0da8979d authored by David Fuhrmann's avatar David Fuhrmann

macosx: implement native fullscreen behaviour for yosemite titlebar

(cherry picked from commit 0b001a0763aa2e34f6abd921184ce58d56947421)
Signed-off-by: default avatarDavid Fuhrmann <dfuhrmann@videolan.org>
parent 53363243
......@@ -39,6 +39,10 @@
NSImage * o_green_img;
NSImage * o_green_over_img;
NSImage * o_green_on_img;
// yosemite fullscreen images
NSImage * o_fullscreen_img;
NSImage * o_fullscreen_over_img;
NSImage * o_fullscreen_on_img;
NSShadow * o_window_title_shadow;
NSDictionary * o_window_title_attributes_dict;
......@@ -47,15 +51,21 @@
IBOutlet id o_green_btn;
IBOutlet id o_fullscreen_btn;
IBOutlet id o_title_lbl;
BOOL b_nativeFullscreenMode;
// state to determine correct image for green bubble
BOOL b_alt_pressed;
BOOL b_mouse_over;
}
@property (readonly) NSButton * closeButton;
@property (readonly) NSButton * minimizeButton;
@property (readonly) NSButton * zoomButton;
- (void)informModifierPressed:(BOOL)b_is_altkey;
- (void)loadButtonIcons;
- (IBAction)buttonAction:(id)sender;
- (void)setWindowTitle:(NSString *)title;
- (void)setFullscreenButtonHidden:(BOOL)b_value;
- (void)setWindowButtonOver:(BOOL)b_value;
- (void)setWindowFullscreenButtonOver:(BOOL)b_value;
......
......@@ -57,6 +57,9 @@
[o_green_img release];
[o_green_over_img release];
[o_green_on_img release];
[o_fullscreen_img release];
[o_fullscreen_over_img release];
[o_fullscreen_on_img release];
[o_window_title_shadow release];
[o_window_title_attributes_dict release];
......@@ -66,6 +69,16 @@
- (void)awakeFromNib
{
b_nativeFullscreenMode = NO;
#ifdef MAC_OS_X_VERSION_10_7
if (!OSX_SNOW_LEOPARD)
b_nativeFullscreenMode = var_InheritBool(VLCIntf, "macosx-nativefullscreenmode");
#endif
if (!b_nativeFullscreenMode || OSX_YOSEMITE) {
[o_fullscreen_btn setHidden: YES];
}
[self setAutoresizesSubviews: YES];
[self setImagesLeft:imageFromRes(@"topbar-dark-left") middle: imageFromRes(@"topbar-dark-center-fill") right:imageFromRes(@"topbar-dark-right")];
......@@ -75,16 +88,6 @@
- (void)controlTintChanged:(NSNotification *)notification
{
[o_red_img release];
[o_red_over_img release];
[o_red_on_img release];
[o_yellow_img release];
[o_yellow_over_img release];
[o_yellow_on_img release];
[o_green_img release];
[o_green_over_img release];
[o_green_on_img release];
[self loadButtonIcons];
[o_red_btn setNeedsDisplay];
......@@ -92,6 +95,17 @@
[o_green_btn setNeedsDisplay];
}
- (void)informModifierPressed:(BOOL)b_is_altkey;
{
BOOL b_state_changed = b_alt_pressed != b_is_altkey;
b_alt_pressed = b_is_altkey;
if (b_state_changed) {
[self updateGreenButton];
}
}
- (NSImage *)getButtonImage:(NSString *)o_id
{
NSString *o_name = @"";
......@@ -114,6 +128,19 @@
- (void)loadButtonIcons
{
[o_red_img release];
[o_red_over_img release];
[o_red_on_img release];
[o_yellow_img release];
[o_yellow_over_img release];
[o_yellow_on_img release];
[o_green_img release];
[o_green_over_img release];
[o_green_on_img release];
[o_fullscreen_img release];
[o_fullscreen_over_img release];
[o_fullscreen_on_img release];
o_red_img = [[self getButtonImage:@"window-close"] retain];
o_red_over_img = [[self getButtonImage:@"window-close-over"] retain];
o_red_on_img = [[self getButtonImage:@"window-close-on"] retain];
......@@ -124,6 +151,13 @@
o_green_over_img = [[self getButtonImage:@"window-zoom-over"] retain];
o_green_on_img = [[self getButtonImage:@"window-zoom-on"] retain];
// these files are only available in the yosemite variant
if (OSX_YOSEMITE) {
o_fullscreen_img = [[self getButtonImage:@"window-fullscreen"] retain];
o_fullscreen_over_img = [[self getButtonImage:@"window-fullscreen-over"] retain];
o_fullscreen_on_img = [[self getButtonImage:@"window-fullscreen-on"] retain];
}
[o_red_btn setImage: o_red_img];
[o_red_btn setAlternateImage: o_red_on_img];
[[o_red_btn cell] setShowsBorderOnlyWhileMouseInside: YES];
......@@ -132,8 +166,8 @@
[o_yellow_btn setAlternateImage: o_yellow_on_img];
[[o_yellow_btn cell] setShowsBorderOnlyWhileMouseInside: YES];
[[o_yellow_btn cell] setTag: 1];
[o_green_btn setImage: o_green_img];
[o_green_btn setAlternateImage: o_green_on_img];
[self updateGreenButton];
[[o_green_btn cell] setShowsBorderOnlyWhileMouseInside: YES];
[[o_green_btn cell] setTag: 2];
[o_fullscreen_btn setImage: [NSImage imageNamed:@"window-fullscreen"]];
......@@ -142,6 +176,31 @@
[[o_fullscreen_btn cell] setTag: 3];
}
- (void)updateGreenButton
{
// default image for old version, or if native fullscreen is
// disabled on yosemite, or if alt key is pressed
if (!OSX_YOSEMITE || !b_nativeFullscreenMode || b_alt_pressed) {
if (b_mouse_over) {
[o_green_btn setImage: o_green_over_img];
[o_green_btn setAlternateImage: o_green_on_img];
} else {
[o_green_btn setImage: o_green_img];
[o_green_btn setAlternateImage: o_green_on_img];
}
} else {
if (b_mouse_over) {
[o_green_btn setImage: o_fullscreen_over_img];
[o_green_btn setAlternateImage: o_fullscreen_on_img];
} else {
[o_green_btn setImage: o_fullscreen_img];
[o_green_btn setAlternateImage: o_fullscreen_on_img];
}
}
}
- (BOOL)mouseDownCanMoveWindow
{
return YES;
......@@ -153,9 +212,13 @@
[[self window] performClose: sender];
else if (sender == o_yellow_btn)
[[self window] miniaturize: sender];
else if (sender == o_green_btn)
else if (sender == o_green_btn) {
if (OSX_YOSEMITE && b_nativeFullscreenMode && !b_alt_pressed) {
[[self window] toggleFullScreen:self];
} else {
[[self window] performZoom: sender];
else if (sender == o_fullscreen_btn) {
}
} else if (sender == o_fullscreen_btn) {
// same action as native fs button
[[self window] toggleFullScreen:self];
......@@ -185,22 +248,18 @@
[o_attributed_title release];
}
- (void)setFullscreenButtonHidden:(BOOL)b_value
{
[o_fullscreen_btn setHidden: b_value];
}
- (void)setWindowButtonOver:(BOOL)b_value
{
b_mouse_over = b_value;
if (b_value) {
[o_red_btn setImage: o_red_over_img];
[o_yellow_btn setImage: o_yellow_over_img];
[o_green_btn setImage: o_green_over_img];
} else {
[o_red_btn setImage: o_red_img];
[o_yellow_btn setImage: o_yellow_img];
[o_green_btn setImage: o_green_img];
}
[self updateGreenButton];
}
- (void)setWindowFullscreenButtonOver:(BOOL)b_value
......
......@@ -74,6 +74,7 @@
static const float f_min_video_height = 70.0;
@class VLCControlsBarCommon;
@class VLCMainWindowTitleView;
/*****************************************************************************
* VLCVideoWindowCommon
......@@ -86,7 +87,7 @@ static const float f_min_video_height = 70.0;
NSRect previousSavedFrame;
BOOL b_dark_interface;
IBOutlet id o_titlebar_view; // only set in main or detached window
IBOutlet VLCMainWindowTitleView *o_titlebar_view; // only set in main or detached window
IBOutlet VLCVoutView *o_video_view;
IBOutlet VLCControlsBarCommon *o_controls_bar;
......
......@@ -335,10 +335,9 @@
if (b_nativeFullscreenMode) {
[self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
} else {
[o_titlebar_view setFullscreenButtonHidden: YES];
}
[super awakeFromNib];
}
......@@ -645,6 +644,17 @@
[super mouseMoved: theEvent];
}
#pragma mark -
#pragma mark Key events
- (void)flagsChanged:(NSEvent *)theEvent
{
BOOL b_alt_pressed = ([theEvent modifierFlags] & NSAlternateKeyMask) != 0;
[o_titlebar_view informModifierPressed: b_alt_pressed];
[super flagsChanged:theEvent];
}
#pragma mark -
#pragma mark Lion native fullscreen handling
......
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