Skip to content

Commit

Permalink
macOS: Move NSScreen category to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
ePirat committed Mar 16, 2017
1 parent 9b1fc2d commit f4bced1
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 162 deletions.
6 changes: 6 additions & 0 deletions extras/package/macosx/VLC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
6B4D50901E79781F004479B5 /* VLCHotkeyChangeWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D508F1E79781F004479B5 /* VLCHotkeyChangeWindow.m */; };
6B4D50931E7979CB004479B5 /* VLCSimplePrefsWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50921E7979CB004479B5 /* VLCSimplePrefsWindow.m */; };
6B4D50961E7A7D16004479B5 /* NSSound+VLCAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50951E7A7D16004479B5 /* NSSound+VLCAdditions.m */; };
6B4D50A71E7AB52C004479B5 /* NSScreen+VLCAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50A61E7AB52C004479B5 /* NSScreen+VLCAdditions.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -205,6 +206,8 @@
6B4D50921E7979CB004479B5 /* VLCSimplePrefsWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCSimplePrefsWindow.m; sourceTree = "<group>"; };
6B4D50941E7A7D16004479B5 /* NSSound+VLCAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSSound+VLCAdditions.h"; sourceTree = "<group>"; };
6B4D50951E7A7D16004479B5 /* NSSound+VLCAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSSound+VLCAdditions.m"; sourceTree = "<group>"; };
6B4D50A51E7AB52C004479B5 /* NSScreen+VLCAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSScreen+VLCAdditions.h"; sourceTree = "<group>"; };
6B4D50A61E7AB52C004479B5 /* NSScreen+VLCAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSScreen+VLCAdditions.m"; sourceTree = "<group>"; };
6B6A499A1DFD9B23009128AC /* VLCDefaultValueSlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCDefaultValueSlider.h; sourceTree = "<group>"; };
6B6A499B1DFD9B23009128AC /* VLCDefaultValueSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCDefaultValueSlider.m; sourceTree = "<group>"; };
6B6A499C1DFD9B23009128AC /* VLCDefaultValueSliderCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCDefaultValueSliderCell.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -988,6 +991,8 @@
CC017A0C14A4C8AF00C09A4F /* VLCMainWindowTitleView.m */,
8ED6C27F03E2EB1C0059A3A7 /* misc.h */,
8ED6C28003E2EB1C0059A3A7 /* misc.m */,
6B4D50A51E7AB52C004479B5 /* NSScreen+VLCAdditions.h */,
6B4D50A61E7AB52C004479B5 /* NSScreen+VLCAdditions.m */,
6B4D50941E7A7D16004479B5 /* NSSound+VLCAdditions.h */,
6B4D50951E7A7D16004479B5 /* NSSound+VLCAdditions.m */,
8ED6C28103E2EB1C0059A3A7 /* VLCOpenWindowController.h */,
Expand Down Expand Up @@ -2047,6 +2052,7 @@
1C3113DA1E508C6900D4DD76 /* VLCStringUtility.h in Sources */,
1C3113DB1E508C6900D4DD76 /* VLCStringUtility.m in Sources */,
1C3113DC1E508C6900D4DD76 /* VLCTrackSynchronizationWindowController.h in Sources */,
6B4D50A71E7AB52C004479B5 /* NSScreen+VLCAdditions.m in Sources */,
1C3113DD1E508C6900D4DD76 /* VLCTrackSynchronizationWindowController.m in Sources */,
1C3113DE1E508C6900D4DD76 /* VLCVideoEffectsWindowController.h in Sources */,
1C3113DF1E508C6900D4DD76 /* VLCVideoEffectsWindowController.m in Sources */,
Expand Down
1 change: 1 addition & 0 deletions modules/gui/macosx/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ libmacosx_plugin_la_SOURCES = \
VLCMainWindowTitleView.h VLCMainWindowTitleView.m \
misc.h misc.m \
NSSound+VLCAdditions.h NSSound+VLCAdditions.m \
NSScreen+VLCAdditions.h NSScreen+VLCAdditions.m \
VLCOpenWindowController.h VLCOpenWindowController.m \
VLCOutput.h VLCOutput.m \
VLCPlaylistView.h VLCPlaylistView.m \
Expand Down
40 changes: 40 additions & 0 deletions modules/gui/macosx/NSScreen+VLCAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*****************************************************************************
* NSScreen+VLCAdditions.h: Category with some additions to NSScreen
*****************************************************************************
* Copyright (C) 2003-2014 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <[email protected]>
* Felix Paul Kühne <fkuehne at videolan dot org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/

#import <Cocoa/Cocoa.h>

@interface NSScreen (VLCAdditions)

+ (NSScreen *)screenWithDisplayID: (CGDirectDisplayID)displayID;
- (BOOL)hasMenuBar;
- (BOOL)hasDock;
- (BOOL)isScreen: (NSScreen*)screen;
- (CGDirectDisplayID)displayID;
- (void)blackoutOtherScreens;
+ (void)unblackoutScreens;

- (void)setFullscreenPresentationOptions;
- (void)setNonFullscreenPresentationOptions;

@end
164 changes: 164 additions & 0 deletions modules/gui/macosx/NSScreen+VLCAdditions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*****************************************************************************
* NSScreen+VLCAdditions.m: Category with some additions to NSScreen
*****************************************************************************
* Copyright (C) 2003-2015 VLC authors and VideoLAN
* $Id$
*
* Authors: Jon Lech Johansen <[email protected]>
* Felix Paul Kühne <fkuehne at videolan dot org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/

#import "NSScreen+VLCAdditions.h"
#import "CompatibilityFixes.h"
#import "VLCMainWindow.h"

@implementation NSScreen (VLCAdditions)

static NSMutableArray *blackoutWindows = NULL;

static bool b_old_spaces_style = YES;

+ (void)load
{
/* init our fake object attribute */
blackoutWindows = [[NSMutableArray alloc] initWithCapacity:1];

if (!OSX_LION && !OSX_MOUNTAIN_LION) {
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] init];
[userDefaults addSuiteNamed:@"com.apple.spaces"];
/* this is system settings -> mission control -> monitors using different spaces */
NSNumber *o_span_displays = [userDefaults objectForKey:@"spans-displays"];

b_old_spaces_style = [o_span_displays boolValue];
}
}

+ (NSScreen *)screenWithDisplayID: (CGDirectDisplayID)displayID
{
NSUInteger count = [[NSScreen screens] count];

for ( NSUInteger i = 0; i < count; i++ ) {
NSScreen *screen = [[NSScreen screens] objectAtIndex:i];
if ([screen displayID] == displayID)
return screen;
}
return nil;
}

- (BOOL)hasMenuBar
{
if (b_old_spaces_style)
return ([self displayID] == [[[NSScreen screens] firstObject] displayID]);
else
return YES;
}

- (BOOL)hasDock
{
NSRect screen_frame = [self frame];
NSRect screen_visible_frame = [self visibleFrame];
CGFloat f_menu_bar_thickness = [self hasMenuBar] ? [[NSStatusBar systemStatusBar] thickness] : 0.0;

BOOL b_found_dock = NO;
if (screen_visible_frame.size.width < screen_frame.size.width)
b_found_dock = YES;
else if (screen_visible_frame.size.height + f_menu_bar_thickness < screen_frame.size.height)
b_found_dock = YES;

return b_found_dock;
}

- (BOOL)isScreen: (NSScreen*)screen
{
return ([self displayID] == [screen displayID]);
}

- (CGDirectDisplayID)displayID
{
return (CGDirectDisplayID)[[[self deviceDescription] objectForKey: @"NSScreenNumber"] intValue];
}

- (void)blackoutOtherScreens
{
/* Free our previous blackout window (follow blackoutWindow alloc strategy) */
[blackoutWindows makeObjectsPerformSelector:@selector(close)];
[blackoutWindows removeAllObjects];

NSUInteger screenCount = [[NSScreen screens] count];
for (NSUInteger i = 0; i < screenCount; i++) {
NSScreen *screen = [[NSScreen screens] objectAtIndex:i];
VLCWindow *blackoutWindow;
NSRect screen_rect;

if ([self isScreen: screen])
continue;

screen_rect = [screen frame];
screen_rect.origin.x = screen_rect.origin.y = 0;

/* blackoutWindow alloc strategy
- The NSMutableArray blackoutWindows has the blackoutWindow references
- blackoutOtherDisplays is responsible for alloc/releasing its Windows
*/
blackoutWindow = [[VLCWindow alloc] initWithContentRect: screen_rect styleMask: NSBorderlessWindowMask
backing: NSBackingStoreBuffered defer: NO screen: screen];
[blackoutWindow setBackgroundColor:[NSColor blackColor]];
[blackoutWindow setLevel: NSFloatingWindowLevel]; /* Disappear when Expose is triggered */
[blackoutWindow setReleasedWhenClosed:NO]; // window is released when deleted from array above

[blackoutWindow displayIfNeeded];
[blackoutWindow orderFront: self animate: YES];

[blackoutWindows addObject: blackoutWindow];

[screen setFullscreenPresentationOptions];
}
}

+ (void)unblackoutScreens
{
NSUInteger blackoutWindowCount = [blackoutWindows count];

for (NSUInteger i = 0; i < blackoutWindowCount; i++) {
VLCWindow *blackoutWindow = [blackoutWindows objectAtIndex:i];
[[blackoutWindow screen] setNonFullscreenPresentationOptions];
[blackoutWindow closeAndAnimate: YES];
}
}

- (void)setFullscreenPresentationOptions
{
NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
if ([self hasMenuBar])
presentationOpts |= NSApplicationPresentationAutoHideMenuBar;
if ([self hasMenuBar] || [self hasDock])
presentationOpts |= NSApplicationPresentationAutoHideDock;
[NSApp setPresentationOptions:presentationOpts];
}

- (void)setNonFullscreenPresentationOptions
{
NSApplicationPresentationOptions presentationOpts = [NSApp presentationOptions];
if ([self hasMenuBar])
presentationOpts &= (~NSApplicationPresentationAutoHideMenuBar);
if ([self hasMenuBar] || [self hasDock])
presentationOpts &= (~NSApplicationPresentationAutoHideDock);
[NSApp setPresentationOptions:presentationOpts];
}


@end
1 change: 1 addition & 0 deletions modules/gui/macosx/VLCMainMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#import "VLCAddonsWindowController.h"
#import "VLCTimeSelectionPanelController.h"
#import "VLCRendererDialog.h"
#import "NSScreen+VLCAdditions.h"

#ifdef HAVE_SPARKLE
#import <Sparkle/Sparkle.h>
Expand Down
1 change: 1 addition & 0 deletions modules/gui/macosx/VLCSimplePrefsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#import "VLCMain+OldPrefs.h"
#import "AppleRemote.h"
#import "VLCCoreInteraction.h"
#import "NSScreen+VLCAdditions.h"

#ifdef HAVE_SPARKLE
#import <Sparkle/Sparkle.h> //for o_intf_last_updateLabel
Expand Down
1 change: 1 addition & 0 deletions modules/gui/macosx/VLCVoutWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#import "VLCTrackSynchronizationWindowController.h"
#import "VLCResumeDialogController.h"
#import "VLCPlaylist.h"
#import "NSScreen+VLCAdditions.h"

static atomic_bool b_intf_starting = ATOMIC_VAR_INIT(false);

Expand Down
1 change: 1 addition & 0 deletions modules/gui/macosx/Windows.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "VLCControlsBarCommon.h"
#import "VLCVoutView.h"
#import "CompatibilityFixes.h"
#import "NSScreen+VLCAdditions.h"

/*****************************************************************************
* VLCWindow
Expand Down
20 changes: 0 additions & 20 deletions modules/gui/macosx/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@

#import <Cocoa/Cocoa.h>

/*****************************************************************************
* NSScreen (VLCAdditions)
*
* Missing extension to NSScreen
*****************************************************************************/

@interface NSScreen (VLCAdditions)

+ (NSScreen *)screenWithDisplayID: (CGDirectDisplayID)displayID;
- (BOOL)hasMenuBar;
- (BOOL)hasDock;
- (BOOL)isScreen: (NSScreen*)screen;
- (CGDirectDisplayID)displayID;
- (void)blackoutOtherScreens;
+ (void)unblackoutScreens;

- (void)setFullscreenPresentationOptions;
- (void)setNonFullscreenPresentationOptions;
@end

/*****************************************************************************
* VLCDragDropView
*
Expand Down
Loading

0 comments on commit f4bced1

Please sign in to comment.