1 /*****************************************************************************
2 * VLCVoutWindowController.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2012 VLC authors and VideoLAN
7 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8 * David Fuhrmann <david dot fuhrmann at googlemail dot com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #import "VLCVoutWindowController.h"
27 #import "MainWindow.h"
30 @implementation VLCVoutWindowController
35 o_vout_dict = [[NSMutableDictionary alloc] init];
41 NSArray *keys = [o_vout_dict allKeys];
42 for (NSValue *key in keys)
43 [self removeVoutforDisplay:key];
45 [o_vout_dict release];
50 - (VLCVoutView *)setupVoutForWindow:(vout_window_t *)p_wnd withProposedVideoViewPosition:(NSRect)videoViewPosition
52 BOOL b_nonembedded = NO;
53 BOOL b_nativeFullscreenMode = [[VLCMain sharedInstance] nativeFullscreenMode];
54 BOOL b_video_deco = var_InheritBool(VLCIntf, "video-deco");
55 BOOL b_video_wallpaper = var_InheritBool(VLCIntf, "video-wallpaper");
56 BOOL b_multiple_vout_windows = [o_vout_dict count] > 0;
57 VLCVoutView *o_vout_view;
58 VLCVideoWindowCommon *o_new_video_window;
60 if (b_multiple_vout_windows && b_video_wallpaper)
61 b_video_wallpaper = false;
63 // TODO: make lion fullscreen compatible with video-wallpaper and !embedded-video
64 if ((b_video_wallpaper || !b_video_deco) && !b_nativeFullscreenMode) {
65 // b_video_wallpaper is priorized over !b_video_deco
67 msg_Dbg(VLCIntf, "Creating background / blank window");
68 NSScreen *screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
70 screen = [[VLCMainWindow sharedInstance] screen];
73 if (b_video_wallpaper)
74 window_rect = [screen frame];
76 window_rect = [[VLCMainWindow sharedInstance] frame];
78 NSUInteger mask = NSBorderlessWindowMask;
79 if (!OSX_SNOW_LEOPARD && !b_video_deco)
80 mask |= NSResizableWindowMask;
82 BOOL b_no_video_deco_only = !b_video_wallpaper;
83 o_new_video_window = [[VLCVideoWindowCommon alloc] initWithContentRect:window_rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
84 [o_new_video_window setDelegate:o_new_video_window];
86 if (b_video_wallpaper)
87 [o_new_video_window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey) + 1];
89 [o_new_video_window setBackgroundColor: [NSColor blackColor]];
90 [o_new_video_window setCanBecomeKeyWindow: !b_video_wallpaper];
91 [o_new_video_window setCanBecomeMainWindow: !b_video_wallpaper];
92 [o_new_video_window setAcceptsMouseMovedEvents: !b_video_wallpaper];
93 [o_new_video_window setMovableByWindowBackground: !b_video_wallpaper];
94 [o_new_video_window useOptimizedDrawing: YES];
96 o_vout_view = [[VLCVoutView alloc] initWithFrame:[[o_new_video_window contentView] bounds]];
97 [o_vout_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
98 [[o_new_video_window contentView] addSubview:o_vout_view positioned:NSWindowAbove relativeTo:nil];
99 [o_new_video_window setVideoView:o_vout_view];
102 if (b_video_wallpaper)
103 [o_new_video_window orderBack:nil];
105 // no frame autosave for additional vout windows
106 if (!b_multiple_vout_windows) {
107 // initial window position
108 [o_new_video_window center];
109 [o_new_video_window setFrameAutosaveName:@"extra-videowindow"];
112 [o_new_video_window setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
115 [[VLCMainWindow sharedInstance] setNonembedded:YES];
118 if ((var_InheritBool(VLCIntf, "embedded-video") && !b_multiple_vout_windows) || b_nativeFullscreenMode) {
119 // setup embedded video
120 o_vout_view = [[[VLCMainWindow sharedInstance] videoView] retain];
121 o_new_video_window = [[VLCMainWindow sharedInstance] retain];
124 // setup detached window with controls
125 NSWindowController *o_controller = [[NSWindowController alloc] initWithWindowNibName:@"DetachedVideoWindow"];
126 [o_controller loadWindow];
127 o_new_video_window = [(VLCDetachedVideoWindow *)[o_controller window] retain];
128 [o_controller release];
130 // no frame autosave for additional vout windows
131 if (b_multiple_vout_windows)
132 [o_new_video_window setFrameAutosaveName:@""];
134 [o_new_video_window setDelegate: o_new_video_window];
135 [o_new_video_window setLevel:NSNormalWindowLevel];
136 [o_new_video_window useOptimizedDrawing: YES];
137 o_vout_view = [[o_new_video_window videoView] retain];
142 if (!b_video_wallpaper) {
144 NSSize videoViewSize = NSMakeSize(videoViewPosition.size.width, videoViewPosition.size.height);
147 NSRect window_rect = [o_new_video_window getWindowRectForProposedVideoViewSize:videoViewSize];
148 [o_new_video_window setFrame:window_rect display:YES];
151 // cascade windows if we have more than one vout
152 if (b_multiple_vout_windows) {
153 if ([o_vout_dict count] == 1) {
154 NSWindow * o_first_window = [o_vout_dict objectForKey: [[o_vout_dict allKeys] objectAtIndex: 0]];
156 NSPoint topleftbase = NSMakePoint(0, [o_first_window frame].size.height);
157 top_left_point = [o_first_window convertBaseToScreen: topleftbase];
160 top_left_point = [o_new_video_window cascadeTopLeftFromPoint: top_left_point];
161 [o_new_video_window setFrameTopLeftPoint: top_left_point];
164 [o_new_video_window setNativeVideoSize:videoViewSize];
166 [o_new_video_window makeKeyAndOrderFront: self];
168 vout_thread_t *p_vout = getVout();
170 if (var_GetBool(p_vout, "video-on-top"))
171 [o_new_video_window setLevel: NSStatusWindowLevel];
173 [o_new_video_window setLevel: NSNormalWindowLevel];
174 vlc_object_release(p_vout);
178 [o_new_video_window setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
180 if (!b_multiple_vout_windows)
181 [[VLCMainWindow sharedInstance] setNonembedded:b_nonembedded];
183 [o_vout_view setVoutThread:(vout_thread_t *)p_wnd->p_parent];
184 [o_vout_dict setObject:[o_new_video_window autorelease] forKey:[NSValue valueWithPointer:p_wnd]];
187 // event occurs before window is created, so call again
188 [[VLCMain sharedInstance] playlistUpdated];
191 return [o_vout_view autorelease];
194 - (void)removeVoutforDisplay:(NSValue *)o_key
196 VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:o_key];
198 msg_Err(VLCIntf, "Cannot close nonexisting window");
202 if ([[VLCMainWindow sharedInstance] fullscreen] && ![[VLCMainWindow sharedInstance] nativeFullscreenMode])
203 [o_window leaveFullscreen];
205 if (![NSStringFromClass([o_window class]) isEqualToString:@"VLCMainWindow"]) {
206 [o_window orderOut:self];
209 [[o_window videoView] releaseVoutThread];
210 [o_vout_dict removeObjectForKey:o_key];
212 if ([o_vout_dict count] == 0)
213 [[VLCMain sharedInstance] setActiveVideoPlayback:NO];
216 - (void)updateWindowsControlsBarWithSelector:(SEL)aSel
218 [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
219 if ([obj respondsToSelector:@selector(controlsBar)]) {
220 id o_controlsBar = [obj controlsBar];
222 [o_controlsBar performSelector:aSel];
227 - (void)updateWindow:(vout_window_t *)p_wnd withSelector:(SEL)aSel;
229 VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]];
231 msg_Err(VLCIntf, "Cannot call selector for nonexisting window");
235 [o_window performSelector:aSel];
238 - (void)updateWindowsUsingBlock:(void (^)(VLCVideoWindowCommon *o_window))windowUpdater
240 [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
241 if ([obj isKindOfClass: [NSWindow class]])
246 - (void)setNativeVideoSize:(NSSize)size forWindow:(vout_window_t *)p_wnd
248 VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]];
250 msg_Err(VLCIntf, "Cannot set size for nonexisting window");
254 [o_window setNativeVideoSize:size];