1 /*****************************************************************************
2 * MainWindow.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2012 VLC authors and VideoLAN
7 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8 * Jon Lech Johansen <jon-vl@nanocrew.net>
9 * Christophe Massiot <massiot@via.ecp.fr>
10 * Derk-Jan Hartman <hartman at videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 #import "CompatibilityFixes.h"
28 #import "MainWindow.h"
30 #import "CoreInteraction.h"
31 #import "AudioEffects.h"
34 #import "controls.h" // TODO: remove me
36 #import "SideBarItem.h"
38 #import <vlc_playlist.h>
39 #import <vlc_aout_intf.h>
41 #import <vlc_strings.h>
42 #import <vlc_services_discovery.h>
43 #import <vlc_aout_intf.h>
45 #import "ControlsBar.h"
48 @interface VLCMainWindow ()
49 - (void)resizePlaylistAfterCollapse;
50 - (void)makeSplitViewVisible;
51 - (void)makeSplitViewHidden;
55 @implementation VLCMainWindow
56 static const float f_min_video_height = 70.0;
58 static VLCMainWindow *_o_sharedInstance = nil;
60 + (VLCMainWindow *)sharedInstance
62 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
66 #pragma mark Initialization
70 if (_o_sharedInstance) {
72 return _o_sharedInstance;
74 _o_sharedInstance = [super init];
76 return _o_sharedInstance;
79 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask
80 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
82 self = [super initWithContentRect:contentRect styleMask:styleMask
83 backing:backingType defer:flag];
84 _o_sharedInstance = self;
86 [[VLCMain sharedInstance] updateTogglePlaylistState];
91 - (BOOL)isEvent:(NSEvent *)o_event forKey:(const char *)keyString
96 key = config_GetPsz(VLCIntf, keyString);
97 o_key = [NSString stringWithFormat:@"%s", key];
100 unsigned int i_keyModifiers = [[VLCStringUtility sharedInstance] VLCModifiersToCocoa:o_key];
102 NSString * characters = [o_event charactersIgnoringModifiers];
103 if ([characters length] > 0) {
104 return [[characters lowercaseString] isEqualToString: [[VLCStringUtility sharedInstance] VLCKeyToString: o_key]] &&
105 (i_keyModifiers & NSShiftKeyMask) == ([o_event modifierFlags] & NSShiftKeyMask) &&
106 (i_keyModifiers & NSControlKeyMask) == ([o_event modifierFlags] & NSControlKeyMask) &&
107 (i_keyModifiers & NSAlternateKeyMask) == ([o_event modifierFlags] & NSAlternateKeyMask) &&
108 (i_keyModifiers & NSCommandKeyMask) == ([o_event modifierFlags] & NSCommandKeyMask);
113 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
116 // these are key events which should be handled by vlc core, but are attached to a main menu item
117 if (![self isEvent: o_event forKey: "key-vol-up"] &&
118 ![self isEvent: o_event forKey: "key-vol-down"] &&
119 ![self isEvent: o_event forKey: "key-vol-mute"]) {
120 /* We indeed want to prioritize some Cocoa key equivalent against libvlc,
121 so we perform the menu equivalent now. */
122 if ([[NSApp mainMenu] performKeyEquivalent:o_event])
128 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event force:b_force] ||
129 [(VLCControls *)[[VLCMain sharedInstance] controls] keyEvent:o_event];
134 if (b_dark_interface)
135 [o_color_backdrop release];
137 [[NSNotificationCenter defaultCenter] removeObserver: self];
138 [o_sidebaritems release];
140 if (o_extra_video_window) {
141 [o_extra_video_window release];
142 o_extra_video_window = nil;
150 BOOL b_splitviewShouldBeHidden = NO;
152 /* setup the styled interface */
153 b_nativeFullscreenMode = NO;
154 #ifdef MAC_OS_X_VERSION_10_7
155 if (!OSX_SNOW_LEOPARD)
156 b_nativeFullscreenMode = var_InheritBool(VLCIntf, "macosx-nativefullscreenmode");
158 t_hide_mouse_timer = nil;
159 [o_detached_video_window setDelegate: self];
160 [self useOptimizedDrawing: YES];
162 [[o_search_fld cell] setPlaceholderString: _NS("Search")];
163 [[o_search_fld cell] accessibilitySetOverrideValue:_NS("Enter a term to search the playlist. Results will be selected in the table.") forAttribute:NSAccessibilityDescriptionAttribute];
165 [o_dropzone_btn setTitle: _NS("Open media...")];
166 [[o_dropzone_btn cell] accessibilitySetOverrideValue:_NS("Click to open an advanced dialog to select the media to play. You can also drop files here to play.") forAttribute:NSAccessibilityDescriptionAttribute];
167 [o_dropzone_lbl setStringValue: _NS("Drop media here")];
169 [o_podcast_add_btn setTitle: _NS("Subscribe")];
170 [o_podcast_remove_btn setTitle: _NS("Unsubscribe")];
171 [o_podcast_subscribe_title_lbl setStringValue: _NS("Subscribe to a podcast")];
172 [o_podcast_subscribe_subtitle_lbl setStringValue: _NS("Enter URL of the podcast to subscribe to:")];
173 [o_podcast_subscribe_cancel_btn setTitle: _NS("Cancel")];
174 [o_podcast_subscribe_ok_btn setTitle: _NS("Subscribe")];
175 [o_podcast_unsubscribe_title_lbl setStringValue: _NS("Unsubscribe from a podcast")];
176 [o_podcast_unsubscribe_subtitle_lbl setStringValue: _NS("Select the podcast you would like to unsubscribe from:")];
177 [o_podcast_unsubscribe_ok_btn setTitle: _NS("Unsubscribe")];
178 [o_podcast_unsubscribe_cancel_btn setTitle: _NS("Cancel")];
180 /* interface builder action */
181 float f_threshold_height = f_min_video_height + [[o_controls_bar bottomBarView] frame].size.height;
182 if (b_dark_interface)
183 f_threshold_height += [o_titlebar_view frame].size.height;
184 if ([[self contentView] frame].size.height < f_threshold_height)
185 b_splitviewShouldBeHidden = YES;
187 [self setDelegate: self];
188 [self setExcludedFromWindowsMenu: YES];
189 [self setAcceptsMouseMovedEvents: YES];
190 // Set that here as IB seems to be buggy
191 if (b_dark_interface) {
192 [self setContentMinSize:NSMakeSize(604., 288. + [o_titlebar_view frame].size.height)];
193 [o_detached_video_window setContentMinSize: NSMakeSize(363., f_min_video_height + [[[o_detached_video_window controlsBar] bottomBarView] frame].size.height + [o_titlebar_view frame].size.height)];
195 [self setContentMinSize:NSMakeSize(604., 288.)];
196 [o_detached_video_window setContentMinSize: NSMakeSize(363., f_min_video_height + [[[o_detached_video_window controlsBar] bottomBarView] frame].size.height)];
199 [self setTitle: _NS("VLC media player")];
201 b_dropzone_active = YES;
202 o_temp_view = [[NSView alloc] init];
203 [o_temp_view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
204 [o_dropzone_view setFrame: [o_playlist_table frame]];
205 [o_left_split_view setFrame: [o_sidebar_view frame]];
207 if (b_nativeFullscreenMode) {
208 [self setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary];
210 [o_titlebar_view setFullscreenButtonHidden: YES];
213 if (!OSX_SNOW_LEOPARD) {
214 /* the default small size of the search field is slightly different on Lion, let's work-around that */
216 frame = [o_search_fld frame];
217 frame.origin.y = frame.origin.y + 2.0;
218 frame.size.height = frame.size.height - 1.0;
219 [o_search_fld setFrame: frame];
222 /* create the sidebar */
223 o_sidebaritems = [[NSMutableArray alloc] init];
224 SideBarItem *libraryItem = [SideBarItem itemWithTitle:_NS("LIBRARY") identifier:@"library"];
225 SideBarItem *playlistItem = [SideBarItem itemWithTitle:_NS("Playlist") identifier:@"playlist"];
226 [playlistItem setIcon: [NSImage imageNamed:@"sidebar-playlist"]];
227 SideBarItem *medialibraryItem = [SideBarItem itemWithTitle:_NS("Media Library") identifier:@"medialibrary"];
228 [medialibraryItem setIcon: [NSImage imageNamed:@"sidebar-playlist"]];
229 SideBarItem *mycompItem = [SideBarItem itemWithTitle:_NS("MY COMPUTER") identifier:@"mycomputer"];
230 SideBarItem *devicesItem = [SideBarItem itemWithTitle:_NS("DEVICES") identifier:@"devices"];
231 SideBarItem *lanItem = [SideBarItem itemWithTitle:_NS("LOCAL NETWORK") identifier:@"localnetwork"];
232 SideBarItem *internetItem = [SideBarItem itemWithTitle:_NS("INTERNET") identifier:@"internet"];
234 /* SD subnodes, inspired by the Qt4 intf */
235 char **ppsz_longnames;
237 char **ppsz_names = vlc_sd_GetNames(pl_Get(VLCIntf), &ppsz_longnames, &p_categories);
239 msg_Err(VLCIntf, "no sd item found"); //TODO
240 char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
241 int *p_category = p_categories;
242 NSMutableArray *internetItems = [[NSMutableArray alloc] init];
243 NSMutableArray *devicesItems = [[NSMutableArray alloc] init];
244 NSMutableArray *lanItems = [[NSMutableArray alloc] init];
245 NSMutableArray *mycompItems = [[NSMutableArray alloc] init];
246 NSString *o_identifier;
247 for (; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++) {
248 o_identifier = [NSString stringWithCString: *ppsz_name encoding: NSUTF8StringEncoding];
249 switch (*p_category) {
250 case SD_CAT_INTERNET:
251 [internetItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
252 if (!strncmp(*ppsz_name, "podcast", 7))
253 [[internetItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-podcast"]];
255 [[internetItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
256 [[internetItems lastObject] setSdtype: SD_CAT_INTERNET];
257 [[internetItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
260 [devicesItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
261 [[devicesItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
262 [[devicesItems lastObject] setSdtype: SD_CAT_DEVICES];
263 [[devicesItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
266 [lanItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
267 [[lanItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-local"]];
268 [[lanItems lastObject] setSdtype: SD_CAT_LAN];
269 [[lanItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
271 case SD_CAT_MYCOMPUTER:
272 [mycompItems addObject: [SideBarItem itemWithTitle: _NS(*ppsz_longname) identifier: o_identifier]];
273 if (!strncmp(*ppsz_name, "video_dir", 9))
274 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-movie"]];
275 else if (!strncmp(*ppsz_name, "audio_dir", 9))
276 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-music"]];
277 else if (!strncmp(*ppsz_name, "picture_dir", 11))
278 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"sidebar-pictures"]];
280 [[mycompItems lastObject] setIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
281 [[mycompItems lastObject] setUntranslatedTitle: [NSString stringWithUTF8String: *ppsz_longname]];
282 [[mycompItems lastObject] setSdtype: SD_CAT_MYCOMPUTER];
285 msg_Warn(VLCIntf, "unknown SD type found, skipping (%s)", *ppsz_name);
290 free(*ppsz_longname);
292 [mycompItem setChildren: [NSArray arrayWithArray: mycompItems]];
293 [devicesItem setChildren: [NSArray arrayWithArray: devicesItems]];
294 [lanItem setChildren: [NSArray arrayWithArray: lanItems]];
295 [internetItem setChildren: [NSArray arrayWithArray: internetItems]];
296 [mycompItems release];
297 [devicesItems release];
299 [internetItems release];
301 free(ppsz_longnames);
304 [libraryItem setChildren: [NSArray arrayWithObjects: playlistItem, medialibraryItem, nil]];
305 [o_sidebaritems addObject: libraryItem];
306 if ([mycompItem hasChildren])
307 [o_sidebaritems addObject: mycompItem];
308 if ([devicesItem hasChildren])
309 [o_sidebaritems addObject: devicesItem];
310 if ([lanItem hasChildren])
311 [o_sidebaritems addObject: lanItem];
312 if ([internetItem hasChildren])
313 [o_sidebaritems addObject: internetItem];
315 [o_sidebar_view reloadData];
316 [o_sidebar_view selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
317 [o_sidebar_view setDropItem:playlistItem dropChildIndex:NSOutlineViewDropOnItemIndex];
318 [o_sidebar_view registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]];
320 [o_sidebar_view setAutosaveName:@"mainwindow-sidebar"];
321 [(PXSourceList *)o_sidebar_view setDataSource:self];
322 [o_sidebar_view setDelegate:self];
323 [o_sidebar_view setAutosaveExpandedItems:YES];
325 [o_sidebar_view expandItem: libraryItem expandChildren: YES];
327 /* make sure we display the desired default appearance when VLC launches for the first time */
328 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
329 if (![defaults objectForKey:@"VLCFirstRun"]) {
330 [defaults setObject:[NSDate date] forKey:@"VLCFirstRun"];
332 NSUInteger i_sidebaritem_count = [o_sidebaritems count];
333 for (NSUInteger x = 0; x < i_sidebaritem_count; x++)
334 [o_sidebar_view expandItem: [o_sidebaritems objectAtIndex: x] expandChildren: YES];
337 if (b_dark_interface) {
338 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidResizeNotification object: nil];
339 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(windowResizedOrMoved:) name: NSWindowDidMoveNotification object: nil];
341 [self setBackgroundColor: [NSColor clearColor]];
342 [self setOpaque: NO];
344 [self setHasShadow:NO];
345 [self setHasShadow:YES];
347 NSRect winrect = [self frame];
348 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
350 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
351 winrect.size.width, f_titleBarHeight)];
352 [[self contentView] addSubview: o_titlebar_view positioned: NSWindowAbove relativeTo: o_split_view];
354 if (winrect.size.height > 100) {
355 [self setFrame: winrect display:YES animate:YES];
356 previousSavedFrame = winrect;
359 winrect = [o_split_view frame];
360 winrect.size.height = winrect.size.height - f_titleBarHeight;
361 [o_split_view setFrame: winrect];
362 [o_video_view setFrame: winrect];
364 o_color_backdrop = [[VLCColorView alloc] initWithFrame: [o_split_view frame]];
365 [[self contentView] addSubview: o_color_backdrop positioned: NSWindowBelow relativeTo: o_split_view];
366 [o_color_backdrop setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
369 [o_video_view setFrame: [o_split_view frame]];
370 [o_playlist_table setBorderType: NSNoBorder];
371 [o_sidebar_scrollview setBorderType: NSNoBorder];
374 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillClose:) name: NSWindowWillCloseNotification object: nil];
375 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(someWindowWillMiniaturize:) name: NSWindowWillMiniaturizeNotification object:nil];
376 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(applicationWillTerminate:) name: NSApplicationWillTerminateNotification object: nil];
378 [o_split_view setAutosaveName:@"10thanniversary-splitview"];
379 if (b_splitviewShouldBeHidden) {
380 [self hideSplitView];
381 i_lastSplitViewHeight = 300;
384 /* sanity check for the window size */
385 NSRect frame = [self frame];
386 NSSize screenSize = [[self screen] frame].size;
387 if (screenSize.width <= frame.size.width || screenSize.height <= frame.size.height) {
388 nativeVideoSize = screenSize;
395 - (VLCMainWindowControlsBar *)controlsBar;
397 return (VLCMainWindowControlsBar *)o_controls_bar;
400 - (void)resizePlaylistAfterCollapse
403 plrect = [o_playlist_table frame];
404 plrect.size.height = i_lastSplitViewHeight - 20.0; // actual pl top bar height, which differs from its frame
405 [[o_playlist_table animator] setFrame: plrect];
407 NSRect rightSplitRect;
408 rightSplitRect = [o_right_split_view frame];
409 plrect = [o_dropzone_box frame];
410 plrect.origin.x = (rightSplitRect.size.width - plrect.size.width) / 2;
411 plrect.origin.y = (rightSplitRect.size.height - plrect.size.height) / 2;
412 [[o_dropzone_box animator] setFrame: plrect];
415 - (void)makeSplitViewVisible
417 if (b_dark_interface)
418 [self setContentMinSize: NSMakeSize(604., 288. + [o_titlebar_view frame].size.height)];
420 [self setContentMinSize: NSMakeSize(604., 288.)];
422 NSRect old_frame = [self frame];
423 float newHeight = [self minSize].height;
424 if (old_frame.size.height < newHeight) {
425 NSRect new_frame = old_frame;
426 new_frame.origin.y = old_frame.origin.y + old_frame.size.height - newHeight;
427 new_frame.size.height = newHeight;
429 [[self animator] setFrame: new_frame display: YES animate: YES];
432 [o_video_view setHidden: YES];
433 [o_split_view setHidden: NO];
434 [self makeFirstResponder: nil];
438 - (void)makeSplitViewHidden
440 if (b_dark_interface)
441 [self setContentMinSize: NSMakeSize(604., f_min_video_height + [o_titlebar_view frame].size.height)];
443 [self setContentMinSize: NSMakeSize(604., f_min_video_height)];
445 [o_split_view setHidden: YES];
446 [o_video_view setHidden: NO];
448 if ([[o_video_view subviews] count] > 0)
449 [self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
452 // only exception for an controls bar button action
453 - (IBAction)togglePlaylist:(id)sender
455 if (![self isVisible] && sender != nil) {
456 [self makeKeyAndOrderFront: sender];
460 BOOL b_activeVideo = [[VLCMain sharedInstance] activeVideoPlayback];
461 BOOL b_restored = NO;
463 // TODO: implement toggle playlist in this situation (triggerd via menu item).
464 // but for now we block this case, to avoid displaying only the half
465 if (b_nativeFullscreenMode && b_fullscreen && b_activeVideo && sender != nil)
468 if (b_dropzone_active && ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0) {
473 if (!(b_nativeFullscreenMode && b_fullscreen) && !b_splitview_removed && ((([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) != 0 && b_activeVideo)
474 || (b_nonembedded && sender != nil)
475 || (!b_activeVideo && sender != nil)
476 || b_minimized_view))
477 [self hideSplitView];
479 if (b_splitview_removed) {
480 if (!b_nonembedded || (sender != nil && b_nonembedded))
481 [self showSplitView];
484 b_minimized_view = YES;
486 b_minimized_view = NO;
492 if (!b_nonembedded) {
493 if (([o_video_view isHidden] && b_activeVideo) || b_restored || (b_activeVideo && sender == nil))
494 [self makeSplitViewHidden];
496 [self makeSplitViewVisible];
498 [o_split_view setHidden: NO];
499 [o_playlist_table setHidden: NO];
500 [o_video_view setHidden: !b_activeVideo];
501 if (b_activeVideo && [[o_video_view subviews] count] > 0)
502 [[o_video_view window] makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
507 - (IBAction)dropzoneButtonAction:(id)sender
509 [[[VLCMain sharedInstance] open] openFileGeneric];
513 #pragma mark overwritten default functionality
515 - (void)windowResizedOrMoved:(NSNotification *)notification
517 [self saveFrameUsingName: [self frameAutosaveName]];
520 - (void)applicationWillTerminate:(NSNotification *)notification
522 [self saveFrameUsingName: [self frameAutosaveName]];
526 - (void)someWindowWillClose:(NSNotification *)notification
528 id obj = [notification object];
529 if (obj == o_detached_video_window || obj == o_extra_video_window || (obj == self && !b_nonembedded)) {
530 if ([[VLCMain sharedInstance] activeVideoPlayback])
531 [[VLCCoreInteraction sharedInstance] stop];
535 - (void)someWindowWillMiniaturize:(NSNotification *)notification
537 if (config_GetInt(VLCIntf, "macosx-pause-minimized")) {
538 id obj = [notification object];
539 if (obj == o_detached_video_window || obj == o_extra_video_window || (obj == self && !b_nonembedded)) {
540 if ([[VLCMain sharedInstance] activeVideoPlayback])
541 [[VLCCoreInteraction sharedInstance] pause];
546 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
548 id videoWindow = [o_video_view window];
549 if (![[VLCMain sharedInstance] activeVideoPlayback] || nativeVideoSize.width == 0. || nativeVideoSize.height == 0. || window != videoWindow)
550 return proposedFrameSize;
552 // needed when entering lion fullscreen mode
554 return proposedFrameSize;
556 if ([[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]) {
557 NSRect videoWindowFrame = [videoWindow frame];
558 NSRect viewRect = [o_video_view convertRect:[o_video_view bounds] toView: nil];
559 NSRect contentRect = [videoWindow contentRectForFrameRect:videoWindowFrame];
560 float marginy = viewRect.origin.y + videoWindowFrame.size.height - contentRect.size.height;
561 float marginx = contentRect.size.width - viewRect.size.width;
562 if (b_dark_interface)// && b_video_deco)
563 marginy += [o_titlebar_view frame].size.height;
565 proposedFrameSize.height = (proposedFrameSize.width - marginx) * nativeVideoSize.height / nativeVideoSize.width + marginy;
568 return proposedFrameSize;
572 #pragma mark Update interface and respond to foreign events
575 b_dropzone_active = YES;
576 [o_right_split_view addSubview: o_dropzone_view positioned:NSWindowAbove relativeTo:o_playlist_table];
577 [o_dropzone_view setFrame: [o_playlist_table frame]];
578 [[o_playlist_table animator] setHidden:YES];
583 b_dropzone_active = NO;
584 [o_dropzone_view removeFromSuperview];
585 [[o_playlist_table animator] setHidden: NO];
588 - (void)hideSplitView
590 NSRect winrect = [self frame];
591 i_lastSplitViewHeight = [o_split_view frame].size.height;
592 winrect.size.height = winrect.size.height - i_lastSplitViewHeight;
593 winrect.origin.y = winrect.origin.y + i_lastSplitViewHeight;
594 [self setFrame: winrect display: YES animate: YES];
595 [self performSelector:@selector(hideDropZone) withObject:nil afterDelay:0.1];
596 if (b_dark_interface) {
597 [self setContentMinSize: NSMakeSize(604., [[o_controls_bar bottomBarView] frame].size.height + [o_titlebar_view frame].size.height)];
598 [self setContentMaxSize: NSMakeSize(FLT_MAX, [[o_controls_bar bottomBarView] frame].size.height + [o_titlebar_view frame].size.height)];
600 [self setContentMinSize: NSMakeSize(604., [[o_controls_bar bottomBarView] frame].size.height)];
601 [self setContentMaxSize: NSMakeSize(FLT_MAX, [[o_controls_bar bottomBarView] frame].size.height)];
604 b_splitview_removed = YES;
607 - (void)showSplitView
610 if (b_dark_interface)
611 [self setContentMinSize:NSMakeSize(604., 288. + [o_titlebar_view frame].size.height)];
613 [self setContentMinSize:NSMakeSize(604., 288.)];
614 [self setContentMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
617 winrect = [self frame];
618 winrect.size.height = winrect.size.height + i_lastSplitViewHeight;
619 winrect.origin.y = winrect.origin.y - i_lastSplitViewHeight;
620 [self setFrame: winrect display: YES animate: YES];
622 [self performSelector:@selector(resizePlaylistAfterCollapse) withObject: nil afterDelay:0.75];
624 b_splitview_removed = NO;
627 - (void)updateTimeSlider
629 [o_controls_bar updateTimeSlider];
630 [[self controlsBar] updatePosAndTimeInFSPanel:o_fspanel];
631 [[o_detached_video_window controlsBar] updateTimeSlider];
636 input_thread_t * p_input;
637 p_input = pl_CurrentInput(VLCIntf);
640 char *format = var_InheritString(VLCIntf, "input-title-format");
641 char *formated = str_format_meta(pl_Get(VLCIntf), format);
643 aString = [NSString stringWithUTF8String:formated];
646 char *uri = input_item_GetURI(input_GetItem(p_input));
648 NSURL * o_url = [NSURL URLWithString: [NSString stringWithUTF8String: uri]];
649 if ([o_url isFileURL]) {
650 [self setRepresentedURL: o_url];
651 [o_detached_video_window setRepresentedURL: o_url];
653 [self setRepresentedURL: nil];
654 [o_detached_video_window setRepresentedURL: nil];
658 if ([aString isEqualToString:@""]) {
659 if ([o_url isFileURL])
660 aString = [[NSFileManager defaultManager] displayNameAtPath: [o_url path]];
662 aString = [o_url absoluteString];
665 [self setTitle: aString];
666 if (b_nonembedded && [[VLCMain sharedInstance] activeVideoPlayback])
667 [o_detached_video_window setTitle: aString];
669 [o_fspanel setStreamTitle: aString];
670 vlc_object_release(p_input);
672 [self setTitle: _NS("VLC media player")];
673 [self setRepresentedURL: nil];
679 [o_controls_bar updateControls];
680 [[o_detached_video_window controlsBar] updateControls];
682 bool b_seekable = false;
684 playlist_t * p_playlist = pl_Get(VLCIntf);
685 input_thread_t * p_input = playlist_CurrentInput(p_playlist);
687 /* seekable streams */
688 b_seekable = var_GetBool(p_input, "can-seek");
690 vlc_object_release(p_input);
693 [self updateTimeSlider];
694 [o_fspanel setSeekable: b_seekable];
697 if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot] != p_playlist->p_local_category || p_playlist->p_local_category->i_children > 0)
702 [o_sidebar_view setNeedsDisplay:YES];
707 [o_controls_bar setPause];
708 [[o_detached_video_window controlsBar] setPause];
709 [o_fspanel setPause];
714 [o_controls_bar setPlay];
715 [[o_detached_video_window controlsBar] setPlay];
719 - (void)updateVolumeSlider
721 [[self controlsBar] updateVolumeSlider];
722 [o_fspanel setVolumeLevel: [[VLCCoreInteraction sharedInstance] volume]];
726 #pragma mark Video Output handling
732 - (void)setupVideoView
734 BOOL b_video_deco = var_InheritBool(VLCIntf, "video-deco");
735 BOOL b_video_wallpaper = var_InheritBool(VLCIntf, "video-wallpaper");
737 // TODO: make lion fullscreen compatible with video-wallpaper and !embedded-video
738 if ((b_video_wallpaper || !b_video_deco) && !b_nativeFullscreenMode) {
739 // b_video_wallpaper is priorized over !b_video_deco
741 msg_Dbg(VLCIntf, "Creating background / blank window");
742 NSScreen *screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
744 screen = [self screen];
747 if (b_video_wallpaper)
748 window_rect = [screen frame];
750 window_rect = [self frame];
752 if (o_extra_video_window)
753 [o_extra_video_window release];
755 NSUInteger mask = NSBorderlessWindowMask;
756 if (!OSX_SNOW_LEOPARD && !b_video_deco)
757 mask |= NSResizableWindowMask;
759 BOOL b_no_video_deco_only = !b_video_wallpaper;
760 o_extra_video_window = [[VLCVideoWindowCommon alloc] initWithContentRect:window_rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
761 [o_extra_video_window setDelegate:self];
763 if (b_video_wallpaper)
764 [o_extra_video_window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey) + 1];
766 [o_extra_video_window setBackgroundColor: [NSColor blackColor]];
767 [o_extra_video_window setCanBecomeKeyWindow: !b_video_wallpaper];
768 [o_extra_video_window setCanBecomeMainWindow: !b_video_wallpaper];
769 [o_extra_video_window setAcceptsMouseMovedEvents:!b_video_wallpaper];
770 [o_extra_video_window setMovableByWindowBackground: !b_video_wallpaper];
771 [o_extra_video_window useOptimizedDrawing: YES];
773 [o_video_view retain];
774 if ([o_video_view superview] != NULL)
775 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
776 window_rect.origin.x = window_rect.origin.y = 0;
777 [o_video_view setFrame: window_rect];
778 [[o_extra_video_window contentView] addSubview: o_video_view positioned:NSWindowAbove relativeTo:nil];
779 [o_video_view release];
781 if (b_video_wallpaper)
782 [o_extra_video_window orderBack:nil];
784 [o_extra_video_window center];
785 [o_extra_video_window setFrameAutosaveName:@"extra-videowindow"];
786 [o_extra_video_window setContentMinSize: NSMakeSize(f_min_video_height, f_min_video_height)];
791 if (var_InheritBool(VLCIntf, "embedded-video") || b_nativeFullscreenMode) {
792 if ([o_video_view window] != self) {
793 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
794 [o_video_view setFrame: [o_split_view frame]];
795 [[self contentView] addSubview:o_video_view positioned:NSWindowAbove relativeTo:nil];
799 if ([o_video_view superview] != NULL)
800 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
803 videoFrame.size = [[o_detached_video_window contentView] frame].size;
804 videoFrame.size.height -= [[[o_detached_video_window controlsBar] bottomBarView] frame].size.height;
805 if (b_dark_interface)
806 videoFrame.size.height -= [o_titlebar_view frame].size.height;
808 videoFrame.origin.x = .0;
809 videoFrame.origin.y = [[[o_detached_video_window controlsBar] bottomBarView] frame].size.height;
811 [o_video_view setFrame: videoFrame];
812 [[o_detached_video_window contentView] addSubview: o_video_view positioned:NSWindowAbove relativeTo:nil];
813 [o_detached_video_window setLevel:NSNormalWindowLevel];
814 [o_detached_video_window useOptimizedDrawing: YES];
819 if (!b_video_wallpaper) {
820 [[o_video_view window] makeKeyAndOrderFront: self];
822 vout_thread_t *p_vout = getVout();
824 if (var_GetBool(p_vout, "video-on-top"))
825 [[o_video_view window] setLevel: NSStatusWindowLevel];
827 [[o_video_view window] setLevel: NSNormalWindowLevel];
828 vlc_object_release(p_vout);
832 [[o_video_view window] setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
835 - (void)setVideoplayEnabled
837 BOOL b_videoPlayback = [[VLCMain sharedInstance] activeVideoPlayback];
839 if (b_videoPlayback) {
840 frameBeforePlayback = [self frame];
842 // look for 'start at fullscreen'
843 [[VLCMain sharedInstance] fullscreenChanged];
846 [[self animator] setFrame:frameBeforePlayback display:YES];
848 [self makeFirstResponder: nil];
849 [o_detached_video_window orderOut: nil];
850 if (o_extra_video_window)
851 [o_extra_video_window orderOut: nil];
853 if ([self level] != NSNormalWindowLevel)
854 [self setLevel: NSNormalWindowLevel];
855 if ([o_detached_video_window level] != NSNormalWindowLevel)
856 [o_detached_video_window setLevel: NSNormalWindowLevel];
858 // restore alpha value to 1 for the case that macosx-opaqueness is set to < 1
859 [self setAlphaValue:1.0];
862 if (b_nativeFullscreenMode) {
863 if ([NSApp presentationOptions] & NSApplicationPresentationFullScreen)
864 [[o_controls_bar bottomBarView] setHidden: b_videoPlayback];
866 [[o_controls_bar bottomBarView] setHidden: NO];
867 if (b_videoPlayback && b_fullscreen)
868 [o_fspanel setActive: nil];
869 if (!b_videoPlayback)
870 [o_fspanel setNonActive: nil];
873 if (!b_videoPlayback && b_fullscreen) {
874 if (!b_nativeFullscreenMode)
875 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
881 if (b_fullscreen || (b_nativeFullscreenMode && [NSApp presentationOptions] & NSApplicationPresentationFullScreen))
884 id o_videoWindow = [o_video_view window];
885 NSSize windowMinSize = [o_videoWindow minSize];
886 NSRect screenFrame = [[o_videoWindow screen] visibleFrame];
888 NSPoint topleftbase = NSMakePoint(0, [o_videoWindow frame].size.height);
889 NSPoint topleftscreen = [o_videoWindow convertBaseToScreen: topleftbase];
891 unsigned int i_width = nativeVideoSize.width;
892 unsigned int i_height = nativeVideoSize.height;
893 if (i_width < windowMinSize.width)
894 i_width = windowMinSize.width;
895 if (i_height < f_min_video_height)
896 i_height = f_min_video_height;
898 /* Calculate the window's new size */
900 new_frame.size.width = [o_videoWindow frame].size.width - [o_video_view frame].size.width + i_width;
901 new_frame.size.height = [o_videoWindow frame].size.height - [o_video_view frame].size.height + i_height;
902 new_frame.origin.x = topleftscreen.x;
903 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
905 /* make sure the window doesn't exceed the screen size the window is on */
906 if (new_frame.size.width > screenFrame.size.width) {
907 new_frame.size.width = screenFrame.size.width;
908 new_frame.origin.x = screenFrame.origin.x;
910 if (new_frame.size.height > screenFrame.size.height) {
911 new_frame.size.height = screenFrame.size.height;
912 new_frame.origin.y = screenFrame.origin.y;
914 if (new_frame.origin.y < screenFrame.origin.y)
915 new_frame.origin.y = screenFrame.origin.y;
917 CGFloat right_screen_point = screenFrame.origin.x + screenFrame.size.width;
918 CGFloat right_window_point = new_frame.origin.x + new_frame.size.width;
919 if (right_window_point > right_screen_point)
920 new_frame.origin.x -= (right_window_point - right_screen_point);
922 [[o_videoWindow animator] setFrame:new_frame display:YES];
925 - (void)setNativeVideoSize:(NSSize)size
927 nativeVideoSize = size;
929 if (var_InheritBool(VLCIntf, "macosx-video-autoresize") && !b_fullscreen && !var_InheritBool(VLCIntf, "video-wallpaper"))
930 [self performSelectorOnMainThread:@selector(resizeWindow) withObject:nil waitUntilDone:NO];
933 // Called automatically if window's acceptsMouseMovedEvents property is true
934 - (void)mouseMoved:(NSEvent *)theEvent
937 [self recreateHideMouseTimer];
939 [super mouseMoved: theEvent];
942 - (void)recreateHideMouseTimer
944 if (t_hide_mouse_timer != nil) {
945 [t_hide_mouse_timer invalidate];
946 [t_hide_mouse_timer release];
949 t_hide_mouse_timer = [NSTimer scheduledTimerWithTimeInterval:2
951 selector:@selector(hideMouseCursor:)
954 [t_hide_mouse_timer retain];
957 // NSTimer selectors require this function signature as per Apple's docs
958 - (void)hideMouseCursor:(NSTimer *)timer
960 [NSCursor setHiddenUntilMouseMoves: YES];
964 #pragma mark Fullscreen support
965 - (void)showFullscreenController
967 if (b_fullscreen && [[VLCMain sharedInstance] activeVideoPlayback])
976 - (void)lockFullscreenAnimation
978 [o_animation_lock lock];
981 - (void)unlockFullscreenAnimation
983 [o_animation_lock unlock];
986 - (void)enterFullscreen
988 NSMutableDictionary *dict1, *dict2;
992 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
993 o_current_video_window = [o_video_view window];
995 screen = [NSScreen screenWithDisplayID:(CGDirectDisplayID)var_InheritInteger(VLCIntf, "macosx-vdev")];
996 [self lockFullscreenAnimation];
999 msg_Dbg(VLCIntf, "chosen screen isn't present, using current screen for fullscreen mode");
1000 screen = [o_current_video_window screen];
1003 msg_Dbg(VLCIntf, "Using deepest screen");
1004 screen = [NSScreen deepestScreen];
1007 screen_rect = [screen frame];
1009 [o_controls_bar setFullscreenState:YES];
1010 [[o_detached_video_window controlsBar] setFullscreenState:YES];
1012 [self recreateHideMouseTimer];
1014 if (blackout_other_displays)
1015 [screen blackoutOtherScreens];
1017 /* Make sure we don't see the window flashes in float-on-top mode */
1018 i_originalLevel = [o_current_video_window level];
1019 [o_current_video_window setLevel:NSNormalWindowLevel];
1021 /* Only create the o_fullscreen_window if we are not in the middle of the zooming animation */
1022 if (!o_fullscreen_window) {
1023 /* We can't change the styleMask of an already created NSWindow, so we create another window, and do eye catching stuff */
1025 rect = [[o_video_view superview] convertRect: [o_video_view frame] toView: nil]; /* Convert to Window base coord */
1026 rect.origin.x += [o_current_video_window frame].origin.x;
1027 rect.origin.y += [o_current_video_window frame].origin.y;
1028 o_fullscreen_window = [[VLCWindow alloc] initWithContentRect:rect styleMask: NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
1029 [o_fullscreen_window setBackgroundColor: [NSColor blackColor]];
1030 [o_fullscreen_window setCanBecomeKeyWindow: YES];
1031 [o_fullscreen_window setCanBecomeMainWindow: YES];
1033 if (![o_current_video_window isVisible] || [o_current_video_window alphaValue] == 0.0) {
1034 /* We don't animate if we are not visible, instead we
1035 * simply fade the display */
1036 CGDisplayFadeReservationToken token;
1038 if (blackout_other_displays) {
1039 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1040 CGDisplayFade(token, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
1043 if ([screen mainScreen])
1044 [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
1046 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
1047 [o_temp_view setFrame:[o_video_view frame]];
1048 [o_fullscreen_window setContentView:o_video_view];
1050 [o_fullscreen_window makeKeyAndOrderFront:self];
1051 [o_fullscreen_window orderFront:self animate:YES];
1053 [o_fullscreen_window setFrame:screen_rect display:YES animate:YES];
1054 [o_fullscreen_window setLevel:NSNormalWindowLevel];
1056 if (blackout_other_displays) {
1057 CGDisplayFade(token, 0.3, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
1058 CGReleaseDisplayFadeReservation(token);
1061 /* Will release the lock */
1062 [self hasBecomeFullscreen];
1067 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
1068 NSDisableScreenUpdates();
1069 [[o_video_view superview] replaceSubview:o_video_view with:o_temp_view];
1070 [o_temp_view setFrame:[o_video_view frame]];
1071 [o_fullscreen_window setContentView:o_video_view];
1072 [o_fullscreen_window makeKeyAndOrderFront:self];
1073 NSEnableScreenUpdates();
1076 /* We are in fullscreen (and no animation is running) */
1078 /* Make sure we are hidden */
1079 [o_current_video_window orderOut: self];
1081 [self unlockFullscreenAnimation];
1085 if (o_fullscreen_anim1) {
1086 [o_fullscreen_anim1 stopAnimation];
1087 [o_fullscreen_anim1 release];
1089 if (o_fullscreen_anim2) {
1090 [o_fullscreen_anim2 stopAnimation];
1091 [o_fullscreen_anim2 release];
1094 if ([screen mainScreen])
1095 [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
1097 dict1 = [[NSMutableDictionary alloc] initWithCapacity:2];
1098 dict2 = [[NSMutableDictionary alloc] initWithCapacity:3];
1100 [dict1 setObject:o_current_video_window forKey:NSViewAnimationTargetKey];
1101 [dict1 setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
1103 [dict2 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
1104 [dict2 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
1105 [dict2 setObject:[NSValue valueWithRect:screen_rect] forKey:NSViewAnimationEndFrameKey];
1107 /* Strategy with NSAnimation allocation:
1108 - Keep at most 2 animation at a time
1109 - leaveFullscreen/enterFullscreen are the only responsible for releasing and alloc-ing
1111 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict1]];
1112 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict2]];
1117 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
1118 [o_fullscreen_anim1 setDuration: 0.3];
1119 [o_fullscreen_anim1 setFrameRate: 30];
1120 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
1121 [o_fullscreen_anim2 setDuration: 0.2];
1122 [o_fullscreen_anim2 setFrameRate: 30];
1124 [o_fullscreen_anim2 setDelegate: self];
1125 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
1127 [o_fullscreen_anim1 startAnimation];
1128 /* fullscreenAnimation will be unlocked when animation ends */
1131 - (void)hasBecomeFullscreen
1133 if ([[o_video_view subviews] count] > 0)
1134 [o_fullscreen_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
1136 [o_fullscreen_window makeKeyWindow];
1137 [o_fullscreen_window setAcceptsMouseMovedEvents: YES];
1139 /* tell the fspanel to move itself to front next time it's triggered */
1140 [o_fspanel setVoutWasUpdated: (int)[[o_fullscreen_window screen] displayID]];
1141 [o_fspanel setActive: nil];
1143 if ([o_current_video_window isVisible])
1144 [o_current_video_window orderOut: self];
1147 [self unlockFullscreenAnimation];
1150 - (void)leaveFullscreen
1152 [self leaveFullscreenAndFadeOut: NO];
1155 - (void)leaveFullscreenAndFadeOut: (BOOL)fadeout
1157 NSMutableDictionary *dict1, *dict2;
1159 BOOL blackout_other_displays = var_InheritBool(VLCIntf, "macosx-black");
1161 if (!o_current_video_window)
1164 [self lockFullscreenAnimation];
1166 [o_controls_bar setFullscreenState:NO];
1167 [[o_detached_video_window controlsBar] setFullscreenState:NO];
1169 /* We always try to do so */
1170 [NSScreen unblackoutScreens];
1172 vout_thread_t *p_vout = getVout();
1174 if (var_GetBool(p_vout, "video-on-top"))
1175 [[o_video_view window] setLevel: NSStatusWindowLevel];
1177 [[o_video_view window] setLevel: NSNormalWindowLevel];
1178 vlc_object_release(p_vout);
1180 [[o_video_view window] makeKeyAndOrderFront: nil];
1182 /* Don't do anything if o_fullscreen_window is already closed */
1183 if (!o_fullscreen_window) {
1184 [self unlockFullscreenAnimation];
1189 /* We don't animate if we are not visible, instead we
1190 * simply fade the display */
1191 CGDisplayFadeReservationToken token;
1193 if (blackout_other_displays) {
1194 CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
1195 CGDisplayFade(token, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, YES);
1198 [o_fspanel setNonActive: nil];
1199 [NSApp setPresentationOptions: NSApplicationPresentationDefault];
1201 /* Will release the lock */
1202 [self hasEndedFullscreen];
1204 /* Our window is hidden, and might be faded. We need to workaround that, so note it
1206 b_window_is_invisible = YES;
1208 if (blackout_other_displays) {
1209 CGDisplayFade(token, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, NO);
1210 CGReleaseDisplayFadeReservation(token);
1216 [o_current_video_window setAlphaValue: 0.0];
1217 [o_current_video_window orderFront: self];
1218 [[o_video_view window] orderFront: self];
1220 [o_fspanel setNonActive: nil];
1221 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
1223 if (o_fullscreen_anim1) {
1224 [o_fullscreen_anim1 stopAnimation];
1225 [o_fullscreen_anim1 release];
1227 if (o_fullscreen_anim2) {
1228 [o_fullscreen_anim2 stopAnimation];
1229 [o_fullscreen_anim2 release];
1232 frame = [[o_temp_view superview] convertRect: [o_temp_view frame] toView: nil]; /* Convert to Window base coord */
1233 frame.origin.x += [o_current_video_window frame].origin.x;
1234 frame.origin.y += [o_current_video_window frame].origin.y;
1236 dict2 = [[NSMutableDictionary alloc] initWithCapacity:2];
1237 [dict2 setObject:o_current_video_window forKey:NSViewAnimationTargetKey];
1238 [dict2 setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
1240 o_fullscreen_anim2 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict2, nil]];
1243 [o_fullscreen_anim2 setAnimationBlockingMode: NSAnimationNonblocking];
1244 [o_fullscreen_anim2 setDuration: 0.3];
1245 [o_fullscreen_anim2 setFrameRate: 30];
1247 [o_fullscreen_anim2 setDelegate: self];
1249 dict1 = [[NSMutableDictionary alloc] initWithCapacity:3];
1251 [dict1 setObject:o_fullscreen_window forKey:NSViewAnimationTargetKey];
1252 [dict1 setObject:[NSValue valueWithRect:[o_fullscreen_window frame]] forKey:NSViewAnimationStartFrameKey];
1253 [dict1 setObject:[NSValue valueWithRect:frame] forKey:NSViewAnimationEndFrameKey];
1255 o_fullscreen_anim1 = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:dict1, nil]];
1258 [o_fullscreen_anim1 setAnimationBlockingMode: NSAnimationNonblocking];
1259 [o_fullscreen_anim1 setDuration: 0.2];
1260 [o_fullscreen_anim1 setFrameRate: 30];
1261 [o_fullscreen_anim2 startWhenAnimation: o_fullscreen_anim1 reachesProgress: 1.0];
1263 /* Make sure o_fullscreen_window is the frontmost window */
1264 [o_fullscreen_window orderFront: self];
1266 [o_fullscreen_anim1 startAnimation];
1267 /* fullscreenAnimation will be unlocked when animation ends */
1270 - (void)hasEndedFullscreen
1274 /* This function is private and should be only triggered at the end of the fullscreen change animation */
1275 /* Make sure we don't see the o_video_view disappearing of the screen during this operation */
1276 NSDisableScreenUpdates();
1277 [o_video_view retain];
1278 [o_video_view removeFromSuperviewWithoutNeedingDisplay];
1279 [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
1280 [o_video_view release];
1281 [o_video_view setFrame:[o_temp_view frame]];
1282 if ([[o_video_view subviews] count] > 0)
1283 [[o_video_view window] makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
1285 [super makeKeyAndOrderFront:self]; /* our version contains a workaround */
1287 [[o_video_view window] makeKeyAndOrderFront: self];
1288 [o_fullscreen_window orderOut: self];
1289 NSEnableScreenUpdates();
1291 [o_fullscreen_window release];
1292 o_fullscreen_window = nil;
1293 [[o_video_view window] setLevel:i_originalLevel];
1294 [[o_video_view window] setAlphaValue: config_GetFloat(VLCIntf, "macosx-opaqueness")];
1296 // if we quit fullscreen because there is no video anymore, make sure non-embedded window is not visible
1297 if (![[VLCMain sharedInstance] activeVideoPlayback] && b_nonembedded)
1298 [o_current_video_window orderOut: self];
1300 o_current_video_window = nil;
1301 [self unlockFullscreenAnimation];
1304 - (void)animationDidEnd:(NSAnimation*)animation
1306 NSArray *viewAnimations;
1307 if (o_makekey_anim == animation) {
1308 [o_makekey_anim release];
1311 if ([animation currentValue] < 1.0)
1314 /* Fullscreen ended or started (we are a delegate only for leaveFullscreen's/enterFullscren's anim2) */
1315 viewAnimations = [o_fullscreen_anim2 viewAnimations];
1316 if ([viewAnimations count] >=1 &&
1317 [[[viewAnimations objectAtIndex: 0] objectForKey: NSViewAnimationEffectKey] isEqualToString:NSViewAnimationFadeInEffect]) {
1318 /* Fullscreen ended */
1319 [self hasEndedFullscreen];
1321 /* Fullscreen started */
1322 [self hasBecomeFullscreen];
1325 - (void)makeKeyAndOrderFront: (id)sender
1328 * when we exit fullscreen and fade out, we may endup in
1329 * having a window that is faded. We can't have it fade in unless we
1332 if (!b_window_is_invisible) {
1333 /* Make sure we don't do it too much */
1334 [super makeKeyAndOrderFront: sender];
1338 [super setAlphaValue:0.0f];
1339 [super makeKeyAndOrderFront: sender];
1341 NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:2];
1342 [dict setObject:self forKey:NSViewAnimationTargetKey];
1343 [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
1345 o_makekey_anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
1348 [o_makekey_anim setAnimationBlockingMode: NSAnimationNonblocking];
1349 [o_makekey_anim setDuration: 0.1];
1350 [o_makekey_anim setFrameRate: 30];
1351 [o_makekey_anim setDelegate: self];
1353 [o_makekey_anim startAnimation];
1354 b_window_is_invisible = NO;
1356 /* fullscreenAnimation will be unlocked when animation ends */
1360 #pragma mark Lion native fullscreen handling
1361 - (void)windowWillEnterFullScreen:(NSNotification *)notification
1363 // workaround, see #6668
1364 [NSApp setPresentationOptions:(NSApplicationPresentationFullScreen | NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
1366 var_SetBool(pl_Get(VLCIntf), "fullscreen", true);
1368 vout_thread_t *p_vout = getVout();
1370 var_SetBool(p_vout, "fullscreen", true);
1371 vlc_object_release(p_vout);
1374 [o_video_view setFrame: [[self contentView] frame]];
1377 [self recreateHideMouseTimer];
1378 i_originalLevel = [self level];
1379 [self setLevel:NSNormalWindowLevel];
1381 if (b_dark_interface) {
1382 [o_titlebar_view removeFromSuperviewWithoutNeedingDisplay];
1385 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
1386 winrect = [self frame];
1388 winrect.size.height = winrect.size.height - f_titleBarHeight;
1389 [self setFrame: winrect display:NO animate:NO];
1390 winrect = [o_split_view frame];
1391 winrect.size.height = winrect.size.height + f_titleBarHeight;
1392 [o_split_view setFrame: winrect];
1395 if ([[VLCMain sharedInstance] activeVideoPlayback])
1396 [[o_controls_bar bottomBarView] setHidden: YES];
1398 [self setMovableByWindowBackground: NO];
1401 - (void)windowDidEnterFullScreen:(NSNotification *)notification
1403 // Indeed, we somehow can have an "inactive" fullscreen (but a visible window!).
1404 // But this creates some problems when leaving fs over remote intfs, so activate app here.
1405 [NSApp activateIgnoringOtherApps:YES];
1407 [o_fspanel setVoutWasUpdated: (int)[[self screen] displayID]];
1408 [o_fspanel setActive: nil];
1411 - (void)windowWillExitFullScreen:(NSNotification *)notification
1414 var_SetBool(pl_Get(VLCIntf), "fullscreen", false);
1416 vout_thread_t *p_vout = getVout();
1418 var_SetBool(p_vout, "fullscreen", false);
1419 vlc_object_release(p_vout);
1422 [o_video_view setFrame: [o_split_view frame]];
1423 [NSCursor setHiddenUntilMouseMoves: NO];
1424 [o_fspanel setNonActive: nil];
1425 [self setLevel:i_originalLevel];
1428 if (b_dark_interface) {
1430 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
1431 winrect = [self frame];
1433 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight,
1434 winrect.size.width, f_titleBarHeight)];
1435 [[self contentView] addSubview: o_titlebar_view];
1437 winrect.size.height = winrect.size.height + f_titleBarHeight;
1438 [self setFrame: winrect display:NO animate:NO];
1439 winrect = [o_split_view frame];
1440 winrect.size.height = winrect.size.height - f_titleBarHeight;
1441 [o_split_view setFrame: winrect];
1442 [o_video_view setFrame: winrect];
1445 if ([[VLCMain sharedInstance] activeVideoPlayback])
1446 [[o_controls_bar bottomBarView] setHidden: NO];
1448 [self setMovableByWindowBackground: YES];
1452 #pragma mark split view delegate
1453 - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMax ofSubviewAt:(NSInteger)dividerIndex
1455 if (dividerIndex == 0)
1461 - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMin ofSubviewAt:(NSInteger)dividerIndex
1463 if (dividerIndex == 0)
1469 - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview
1471 return ([subview isEqual:o_left_split_view]);
1474 - (BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)subview
1476 if ([subview isEqual:o_left_split_view])
1482 #pragma mark Side Bar Data handling
1483 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
1484 - (NSUInteger)sourceList:(PXSourceList*)sourceList numberOfChildrenOfItem:(id)item
1486 //Works the same way as the NSOutlineView data source: `nil` means a parent item
1488 return [o_sidebaritems count];
1490 return [[item children] count];
1494 - (id)sourceList:(PXSourceList*)aSourceList child:(NSUInteger)index ofItem:(id)item
1496 //Works the same way as the NSOutlineView data source: `nil` means a parent item
1498 return [o_sidebaritems objectAtIndex:index];
1500 return [[item children] objectAtIndex:index];
1504 - (id)sourceList:(PXSourceList*)aSourceList objectValueForItem:(id)item
1506 return [item title];
1509 - (void)sourceList:(PXSourceList*)aSourceList setObjectValue:(id)object forItem:(id)item
1511 [item setTitle:object];
1514 - (BOOL)sourceList:(PXSourceList*)aSourceList isItemExpandable:(id)item
1516 return [item hasChildren];
1520 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasBadge:(id)item
1522 if ([[item identifier] isEqualToString: @"playlist"] || [[item identifier] isEqualToString: @"medialibrary"])
1525 return [item hasBadge];
1529 - (NSInteger)sourceList:(PXSourceList*)aSourceList badgeValueForItem:(id)item
1531 playlist_t * p_playlist = pl_Get(VLCIntf);
1532 NSInteger i_playlist_size;
1534 if ([[item identifier] isEqualToString: @"playlist"]) {
1536 i_playlist_size = p_playlist->p_local_category->i_children;
1539 return i_playlist_size;
1541 if ([[item identifier] isEqualToString: @"medialibrary"]) {
1543 i_playlist_size = p_playlist->p_ml_category->i_children;
1546 return i_playlist_size;
1549 return [item badgeValue];
1553 - (BOOL)sourceList:(PXSourceList*)aSourceList itemHasIcon:(id)item
1555 return [item hasIcon];
1559 - (NSImage*)sourceList:(PXSourceList*)aSourceList iconForItem:(id)item
1564 - (NSMenu*)sourceList:(PXSourceList*)aSourceList menuForEvent:(NSEvent*)theEvent item:(id)item
1566 if ([theEvent type] == NSRightMouseDown || ([theEvent type] == NSLeftMouseDown && ([theEvent modifierFlags] & NSControlKeyMask) == NSControlKeyMask)) {
1569 if ([item sdtype] > 0)
1571 m = [[NSMenu alloc] init];
1572 playlist_t * p_playlist = pl_Get(VLCIntf);
1573 BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded(p_playlist, [[item identifier] UTF8String]);
1575 [m addItemWithTitle:_NS("Enable") action:@selector(sdmenuhandler:) keyEquivalent:@""];
1577 [m addItemWithTitle:_NS("Disable") action:@selector(sdmenuhandler:) keyEquivalent:@""];
1578 [[m itemAtIndex:0] setRepresentedObject: [item identifier]];
1580 return [m autorelease];
1587 - (IBAction)sdmenuhandler:(id)sender
1589 NSString * identifier = [sender representedObject];
1590 if ([identifier length] > 0 && ![identifier isEqualToString:@"lua{sd='freebox',longname='Freebox TV'}"]) {
1591 playlist_t * p_playlist = pl_Get(VLCIntf);
1592 BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded(p_playlist, [identifier UTF8String]);
1595 playlist_ServicesDiscoveryAdd(p_playlist, [identifier UTF8String]);
1597 playlist_ServicesDiscoveryRemove(p_playlist, [identifier UTF8String]);
1602 #pragma mark Side Bar Delegate Methods
1603 /* taken under BSD-new from the PXSourceList sample project, adapted for VLC */
1604 - (BOOL)sourceList:(PXSourceList*)aSourceList isGroupAlwaysExpanded:(id)group
1606 if ([[group identifier] isEqualToString:@"library"])
1612 - (void)sourceListSelectionDidChange:(NSNotification *)notification
1614 playlist_t * p_playlist = pl_Get(VLCIntf);
1616 NSIndexSet *selectedIndexes = [o_sidebar_view selectedRowIndexes];
1617 id item = [o_sidebar_view itemAtRow:[selectedIndexes firstIndex]];
1620 //Set the label text to represent the new selection
1621 if ([item sdtype] > -1 && [[item identifier] length] > 0) {
1622 BOOL sd_loaded = playlist_IsServicesDiscoveryLoaded(p_playlist, [[item identifier] UTF8String]);
1624 playlist_ServicesDiscoveryAdd(p_playlist, [[item identifier] UTF8String]);
1627 [o_chosen_category_lbl setStringValue:[item title]];
1629 if ([[item identifier] isEqualToString:@"playlist"]) {
1630 [[[VLCMain sharedInstance] playlist] setPlaylistRoot:p_playlist->p_local_category];
1631 } else if ([[item identifier] isEqualToString:@"medialibrary"]) {
1632 [[[VLCMain sharedInstance] playlist] setPlaylistRoot:p_playlist->p_ml_category];
1634 playlist_item_t * pl_item;
1636 pl_item = playlist_ChildSearchName(p_playlist->p_root, [[item untranslatedTitle] UTF8String]);
1638 [[[VLCMain sharedInstance] playlist] setPlaylistRoot: pl_item];
1642 if ([[[VLCMain sharedInstance] playlist] currentPlaylistRoot] != p_playlist->p_local_category || p_playlist->p_local_category->i_children > 0)
1643 [self hideDropZone];
1645 [self showDropZone];
1648 if ([[item identifier] isEqualToString:@"podcast{longname=\"Podcasts\"}"])
1649 [self showPodcastControls];
1651 [self hidePodcastControls];
1654 - (NSDragOperation)sourceList:(PXSourceList *)aSourceList validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1656 if ([[item identifier] isEqualToString:@"playlist"] || [[item identifier] isEqualToString:@"medialibrary"]) {
1657 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1658 if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"] || [[o_pasteboard types] containsObject: NSFilenamesPboardType])
1659 return NSDragOperationGeneric;
1661 return NSDragOperationNone;
1664 - (BOOL)sourceList:(PXSourceList *)aSourceList acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1666 NSPasteboard *o_pasteboard = [info draggingPasteboard];
1668 playlist_t * p_playlist = pl_Get(VLCIntf);
1669 playlist_item_t *p_node;
1671 if ([[item identifier] isEqualToString:@"playlist"])
1672 p_node = p_playlist->p_local_category;
1674 p_node = p_playlist->p_ml_category;
1676 if ([[o_pasteboard types] containsObject: NSFilenamesPboardType]) {
1677 NSArray *o_values = [[o_pasteboard propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)];
1678 NSUInteger count = [o_values count];
1679 NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
1681 for(NSUInteger i = 0; i < count; i++) {
1682 NSDictionary *o_dic;
1683 char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], NULL);
1687 o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
1691 [o_array addObject: o_dic];
1694 [[[VLCMain sharedInstance] playlist] appendNodeArray:o_array inNode: p_node atPos:-1 enqueue:YES];
1697 else if ([[o_pasteboard types] containsObject: @"VLCPlaylistItemPboardType"]) {
1698 NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
1700 NSUInteger count = [array count];
1701 playlist_item_t * p_item = NULL;
1704 for(NSUInteger i = 0; i < count; i++) {
1705 p_item = [[array objectAtIndex:i] pointerValue];
1706 if (!p_item) continue;
1707 playlist_NodeAddCopy(p_playlist, p_item, p_node, PLAYLIST_END);
1716 - (id)sourceList:(PXSourceList *)aSourceList persistentObjectForItem:(id)item
1718 return [item identifier];
1721 - (id)sourceList:(PXSourceList *)aSourceList itemForPersistentObject:(id)object
1723 /* the following code assumes for sakes of simplicity that only the top level
1724 * items are allowed to have children */
1726 NSArray * array = [NSArray arrayWithArray: o_sidebaritems]; // read-only arrays are noticebly faster
1727 NSUInteger count = [array count];
1731 for (NSUInteger x = 0; x < count; x++) {
1732 id item = [array objectAtIndex: x]; // save one objc selector call
1733 if ([[item identifier] isEqualToString:object])
1741 #pragma mark Podcast
1743 - (IBAction)addPodcast:(id)sender
1745 [NSApp beginSheet:o_podcast_subscribe_window modalForWindow:self modalDelegate:self didEndSelector:NULL contextInfo:nil];
1748 - (IBAction)addPodcastWindowAction:(id)sender
1750 [o_podcast_subscribe_window orderOut:sender];
1751 [NSApp endSheet: o_podcast_subscribe_window];
1753 if (sender == o_podcast_subscribe_ok_btn && [[o_podcast_subscribe_url_fld stringValue] length] > 0) {
1754 NSMutableString * podcastConf = [[NSMutableString alloc] init];
1755 if (config_GetPsz(VLCIntf, "podcast-urls") != NULL)
1756 [podcastConf appendFormat:@"%s|", config_GetPsz(VLCIntf, "podcast-urls")];
1758 [podcastConf appendString: [o_podcast_subscribe_url_fld stringValue]];
1759 config_PutPsz(VLCIntf, "podcast-urls", [podcastConf UTF8String]);
1761 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name(VLCIntf->p_libvlc, "podcast");
1763 var_SetString(p_obj, "podcast-urls", [podcastConf UTF8String]);
1764 vlc_object_release(p_obj);
1766 [podcastConf release];
1770 - (IBAction)removePodcast:(id)sender
1772 if (config_GetPsz(VLCIntf, "podcast-urls") != NULL) {
1773 [o_podcast_unsubscribe_pop removeAllItems];
1774 [o_podcast_unsubscribe_pop addItemsWithTitles:[[NSString stringWithUTF8String:config_GetPsz(VLCIntf, "podcast-urls")] componentsSeparatedByString:@"|"]];
1775 [NSApp beginSheet:o_podcast_unsubscribe_window modalForWindow:self modalDelegate:self didEndSelector:NULL contextInfo:nil];
1779 - (IBAction)removePodcastWindowAction:(id)sender
1781 [o_podcast_unsubscribe_window orderOut:sender];
1782 [NSApp endSheet: o_podcast_unsubscribe_window];
1784 if (sender == o_podcast_unsubscribe_ok_btn) {
1785 NSMutableArray * urls = [[NSMutableArray alloc] initWithArray:[[NSString stringWithUTF8String:config_GetPsz(VLCIntf, "podcast-urls")] componentsSeparatedByString:@"|"]];
1786 [urls removeObjectAtIndex: [o_podcast_unsubscribe_pop indexOfSelectedItem]];
1787 config_PutPsz(VLCIntf, "podcast-urls", [[urls componentsJoinedByString:@"|"] UTF8String]);
1790 vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name(VLCIntf->p_libvlc, "podcast");
1792 var_SetString(p_obj, "podcast-urls", config_GetPsz(VLCIntf, "podcast-urls"));
1793 vlc_object_release(p_obj);
1796 /* reload the podcast module, since it won't update its list when removing podcasts */
1797 playlist_t * p_playlist = pl_Get(VLCIntf);
1798 if (playlist_IsServicesDiscoveryLoaded(p_playlist, "podcast{longname=\"Podcasts\"}")) {
1799 playlist_ServicesDiscoveryRemove(p_playlist, "podcast{longname=\"Podcasts\"}");
1800 playlist_ServicesDiscoveryAdd(p_playlist, "podcast{longname=\"Podcasts\"}");
1801 [o_playlist_table reloadData];
1807 - (void)showPodcastControls
1809 NSRect podcastViewDimensions = [o_podcast_view frame];
1810 NSRect rightSplitRect = [o_right_split_view frame];
1811 NSRect playlistTableRect = [o_playlist_table frame];
1813 podcastViewDimensions.size.width = rightSplitRect.size.width;
1814 podcastViewDimensions.origin.x = podcastViewDimensions.origin.y = .0;
1815 [o_podcast_view setFrame:podcastViewDimensions];
1817 playlistTableRect.origin.y = playlistTableRect.origin.y + podcastViewDimensions.size.height;
1818 playlistTableRect.size.height = playlistTableRect.size.height - podcastViewDimensions.size.height;
1819 [o_playlist_table setFrame:playlistTableRect];
1820 [o_playlist_table setNeedsDisplay:YES];
1822 [o_right_split_view addSubview: o_podcast_view positioned: NSWindowAbove relativeTo: o_right_split_view];
1823 b_podcastView_displayed = YES;
1826 - (void)hidePodcastControls
1828 if (b_podcastView_displayed) {
1829 NSRect podcastViewDimensions = [o_podcast_view frame];
1830 NSRect playlistTableRect = [o_playlist_table frame];
1832 playlistTableRect.origin.y = playlistTableRect.origin.y - podcastViewDimensions.size.height;
1833 playlistTableRect.size.height = playlistTableRect.size.height + podcastViewDimensions.size.height;
1835 [o_podcast_view removeFromSuperviewWithoutNeedingDisplay];
1836 [o_playlist_table setFrame: playlistTableRect];
1837 b_podcastView_displayed = NO;
1843 @implementation VLCDetachedVideoWindow
1845 - (void)awakeFromNib
1847 [self setAcceptsMouseMovedEvents: YES];
1849 if (b_dark_interface) {
1850 [self setBackgroundColor: [NSColor clearColor]];
1851 [self setOpaque: NO];
1853 [self setHasShadow:NO];
1854 [self setHasShadow:YES];
1856 NSRect winrect = [self frame];
1857 CGFloat f_titleBarHeight = [o_titlebar_view frame].size.height;
1859 [self setTitle: _NS("VLC media player")];
1860 [o_titlebar_view setFrame: NSMakeRect(0, winrect.size.height - f_titleBarHeight, winrect.size.width, f_titleBarHeight)];
1861 [[self contentView] addSubview: o_titlebar_view positioned: NSWindowAbove relativeTo: nil];
1863 // native fs not supported with detached view yet
1864 [o_titlebar_view setFullscreenButtonHidden: YES];