vlc | branch: master | Marvin Scholz <[email protected]> | Thu Mar 16 13:11:06 2017 +0100| [f4bced161ae49dbb5813aed79e83310cc804cd4d] | committer: Marvin Scholz
macOS: Move NSScreen category to its own file > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f4bced161ae49dbb5813aed79e83310cc804cd4d --- .../package/macosx/VLC.xcodeproj/project.pbxproj | 6 + modules/gui/macosx/Makefile.am | 1 + modules/gui/macosx/NSScreen+VLCAdditions.h | 40 +++++ modules/gui/macosx/NSScreen+VLCAdditions.m | 164 +++++++++++++++++++++ modules/gui/macosx/VLCMainMenu.m | 1 + modules/gui/macosx/VLCSimplePrefsController.m | 1 + modules/gui/macosx/VLCVoutWindowController.m | 1 + modules/gui/macosx/Windows.m | 1 + modules/gui/macosx/misc.h | 20 --- modules/gui/macosx/misc.m | 142 ------------------ 10 files changed, 215 insertions(+), 162 deletions(-) diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj index de76afc..a323e05 100644 --- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj +++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj @@ -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 */ @@ -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>"; }; @@ -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 */, @@ -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 */, diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am index f4b4eec..7e4f74a 100644 --- a/modules/gui/macosx/Makefile.am +++ b/modules/gui/macosx/Makefile.am @@ -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 \ diff --git a/modules/gui/macosx/NSScreen+VLCAdditions.h b/modules/gui/macosx/NSScreen+VLCAdditions.h new file mode 100644 index 0000000..1f7038f --- /dev/null +++ b/modules/gui/macosx/NSScreen+VLCAdditions.h @@ -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 diff --git a/modules/gui/macosx/NSScreen+VLCAdditions.m b/modules/gui/macosx/NSScreen+VLCAdditions.m new file mode 100644 index 0000000..5074d28 --- /dev/null +++ b/modules/gui/macosx/NSScreen+VLCAdditions.m @@ -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 diff --git a/modules/gui/macosx/VLCMainMenu.m b/modules/gui/macosx/VLCMainMenu.m index cd40924..7264ed7 100644 --- a/modules/gui/macosx/VLCMainMenu.m +++ b/modules/gui/macosx/VLCMainMenu.m @@ -48,6 +48,7 @@ #import "VLCAddonsWindowController.h" #import "VLCTimeSelectionPanelController.h" #import "VLCRendererDialog.h" +#import "NSScreen+VLCAdditions.h" #ifdef HAVE_SPARKLE #import <Sparkle/Sparkle.h> diff --git a/modules/gui/macosx/VLCSimplePrefsController.m b/modules/gui/macosx/VLCSimplePrefsController.m index ba15e6a..2c4e549 100644 --- a/modules/gui/macosx/VLCSimplePrefsController.m +++ b/modules/gui/macosx/VLCSimplePrefsController.m @@ -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 diff --git a/modules/gui/macosx/VLCVoutWindowController.m b/modules/gui/macosx/VLCVoutWindowController.m index 8d7138d..eaf17ab 100644 --- a/modules/gui/macosx/VLCVoutWindowController.m +++ b/modules/gui/macosx/VLCVoutWindowController.m @@ -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); diff --git a/modules/gui/macosx/Windows.m b/modules/gui/macosx/Windows.m index b430866..4b34e64 100644 --- a/modules/gui/macosx/Windows.m +++ b/modules/gui/macosx/Windows.m @@ -28,6 +28,7 @@ #import "VLCControlsBarCommon.h" #import "VLCVoutView.h" #import "CompatibilityFixes.h" +#import "NSScreen+VLCAdditions.h" /***************************************************************************** * VLCWindow diff --git a/modules/gui/macosx/misc.h b/modules/gui/macosx/misc.h index b0561b6..6582272 100644 --- a/modules/gui/macosx/misc.h +++ b/modules/gui/macosx/misc.h @@ -25,26 +25,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 * * Disables default drag / drop behaviour of an NSImageView. diff --git a/modules/gui/macosx/misc.m b/modules/gui/macosx/misc.m index 9e5c2a6..d27e111 100644 --- a/modules/gui/macosx/misc.m +++ b/modules/gui/macosx/misc.m @@ -34,148 +34,6 @@ NSString *const VLCOpenTextFieldWasClicked = @"VLCOpenTextFieldWasClicked"; /***************************************************************************** - * NSScreen (VLCAdditions) - * - * Missing extension to NSScreen - *****************************************************************************/ - -@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 - -/***************************************************************************** * VLCDragDropView *****************************************************************************/ _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
