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;
61 // TODO: make lion fullscreen compatible with video-wallpaper and !embedded-video
62 if ((b_video_wallpaper || !b_video_deco) && !b_nativeFullscreenMode) {
63 // b_video_wallpaper is priorized over !b_video_deco
65 msg_Dbg(VLCIntf, "Creating background / blank window");
66 NSScreen *screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
68 screen = [[VLCMainWindow sharedInstance] screen];
71 if (b_video_wallpaper)
72 window_rect = [screen frame];
74 window_rect = [[VLCMainWindow sharedInstance] frame];
76 NSUInteger mask = NSBorderlessWindowMask;
77 if (!OSX_SNOW_LEOPARD && !b_video_deco)
78 mask |= NSResizableWindowMask;
80 BOOL b_no_video_deco_only = !b_video_wallpaper;
81 o_new_video_window = [[VLCVideoWindowCommon alloc] initWithContentRect:window_rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
82 [o_new_video_window setDelegate:o_new_video_window];
84 if (b_video_wallpaper)
85 [o_new_video_window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey) + 1];
87 [o_new_video_window setBackgroundColor: [NSColor blackColor]];
88 [o_new_video_window setCanBecomeKeyWindow: !b_video_wallpaper];
89 [o_new_video_window setCanBecomeMainWindow: !b_video_wallpaper];
90 [o_new_video_window setAcceptsMouseMovedEvents: !b_video_wallpaper];
91 [o_new_video_window setMovableByWindowBackground: !b_video_wallpaper];
92 [o_new_video_window useOptimizedDrawing: YES];
94 o_vout_view = [[VLCVoutView alloc] initWithFrame:[[o_new_video_window contentView] bounds]];
95 [o_vout_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
96 [[o_new_video_window contentView] addSubview:o_vout_view positioned:NSWindowAbove relativeTo:nil];
97 [o_new_video_window setVideoView:o_vout_view];
100 if (b_video_wallpaper)
101 [o_new_video_window orderBack:nil];
103 [o_new_video_window center];
104 [o_new_video_window setFrameAutosaveName:@"extra-videowindow"];
105 [o_new_video_window setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
108 [[VLCMainWindow sharedInstance] setNonembedded:YES];
111 if ((var_InheritBool(VLCIntf, "embedded-video") && !b_multiple_vout_windows) || b_nativeFullscreenMode) {
112 o_vout_view = [[[VLCMainWindow sharedInstance] videoView] retain];
113 o_new_video_window = [[VLCMainWindow sharedInstance] retain];
116 NSWindowController *o_controller = [[NSWindowController alloc] initWithWindowNibName:@"DetachedVideoWindow"];
117 [o_controller loadWindow];
118 o_new_video_window = [(VLCDetachedVideoWindow *)[o_controller window] retain];
119 [o_controller release];
121 [o_new_video_window setDelegate: o_new_video_window];
122 [o_new_video_window setLevel:NSNormalWindowLevel];
123 [o_new_video_window useOptimizedDrawing: YES];
124 o_vout_view = [[o_new_video_window videoView] retain];
129 if (!b_video_wallpaper) {
131 NSSize videoViewSize = NSMakeSize(videoViewPosition.size.width, videoViewPosition.size.height);
134 NSRect window_rect = [o_new_video_window getWindowRectForProposedVideoViewSize:videoViewSize];
135 [o_new_video_window setFrame:window_rect display:YES];
137 [o_new_video_window setNativeVideoSize:videoViewSize];
139 [o_new_video_window makeKeyAndOrderFront: self];
141 vout_thread_t *p_vout = getVout();
143 if (var_GetBool(p_vout, "video-on-top"))
144 [o_new_video_window setLevel: NSStatusWindowLevel];
146 [o_new_video_window setLevel: NSNormalWindowLevel];
147 vlc_object_release(p_vout);
151 [o_new_video_window setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
153 if (!b_multiple_vout_windows)
154 [[VLCMainWindow sharedInstance] setNonembedded:b_nonembedded];
156 [o_vout_view setVoutThread:(vout_thread_t *)p_wnd->p_parent];
157 [o_vout_dict setObject:[o_new_video_window autorelease] forKey:[NSValue valueWithPointer:p_wnd]];
160 // event occurs before window is created, so call again
161 [[VLCMain sharedInstance] playlistUpdated];
164 return [o_vout_view autorelease];
167 - (void)removeVoutforDisplay:(NSValue *)o_key
169 VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:o_key];
171 msg_Err(VLCIntf, "Cannot close nonexisting window");
175 if ([[VLCMainWindow sharedInstance] fullscreen] && ![[VLCMainWindow sharedInstance] nativeFullscreenMode])
176 [o_window leaveFullscreen];
178 if (![NSStringFromClass([o_window class]) isEqualToString:@"VLCMainWindow"]) {
179 [o_window orderOut:self];
182 [[o_window videoView] releaseVoutThread];
183 [o_vout_dict removeObjectForKey:o_key];
185 if ([o_vout_dict count] == 0)
186 [[VLCMain sharedInstance] setActiveVideoPlayback:NO];
189 - (void)updateWindowsControlsBarWithSelector:(SEL)aSel
191 [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
192 if ([obj respondsToSelector:@selector(controlsBar)]) {
193 id o_controlsBar = [obj controlsBar];
195 [o_controlsBar performSelector:aSel];
200 - (void)updateWindow:(vout_window_t *)p_wnd withSelector:(SEL)aSel;
202 VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]];
204 msg_Err(VLCIntf, "Cannot call selector for nonexisting window");
208 [o_window performSelector:aSel];
211 - (void)updateWindowsUsingBlock:(void (^)(VLCVideoWindowCommon *o_window))windowUpdater
213 [o_vout_dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
214 if ([obj isKindOfClass: [NSWindow class]])
219 - (void)setNativeVideoSize:(NSSize)size forWindow:(vout_window_t *)p_wnd
221 VLCVideoWindowCommon *o_window = [o_vout_dict objectForKey:[NSValue valueWithPointer:p_wnd]];
223 msg_Err(VLCIntf, "Cannot set size for nonexisting window");
227 [o_window setNativeVideoSize:size];