1 /*****************************************************************************
2 * VideoView.m: MacOS X video output module
3 *****************************************************************************
4 * Copyright (C) 2002-2012 VLC authors and VideoLAN
7 * Authors: Derk-Jan Hartman <hartman at videolan dot org>
8 * Eric Petit <titer@m0k.org>
9 * Benjamin Pracht <bigben at videolan dot org>
10 * Pierre d'Herbemont <pdherbemont # videolan org>
11 * Felix Paul Kühne <fkuehne at videolan dot org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
30 *****************************************************************************/
31 #import <stdlib.h> /* free() */
36 #import "CoreInteraction.h"
38 #import "MainWindow.h"
40 #import <vlc_common.h>
41 #import <vlc_vout_window.h>
42 #import <vlc_vout_display.h>
45 /*****************************************************************************
46 * DeviceCallback: Callback triggered when the video-device variable is changed
47 *****************************************************************************/
48 int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
49 vlc_value_t old_val, vlc_value_t new_val, void *param )
52 vout_thread_t *p_vout = (vout_thread_t *)p_this;
54 msg_Dbg( p_vout, "set %"PRId64, new_val.i_int );
55 var_Create( p_vout->p_libvlc, "video-device", VLC_VAR_INTEGER );
56 var_Set( p_vout->p_libvlc, "video-device", new_val );
59 var_Set( p_vout, "intf-change", val );
63 /*****************************************************************************
64 * VLCVoutView implementation
65 *****************************************************************************/
66 @implementation VLCVoutView
69 #pragma mark drag & drop support
73 [self unregisterDraggedTypes];
79 [self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]];
82 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
84 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
85 return NSDragOperationGeneric;
86 return NSDragOperationNone;
89 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
94 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
97 b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender];
99 [self setNeedsDisplay:YES];
103 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
105 [self setNeedsDisplay:YES];
109 #pragma mark vout actions
113 vout_thread_t * p_vout = getVout();
116 var_DelCallback( p_vout, "video-device", DeviceCallback, NULL );
117 vlc_object_release( p_vout );
121 - (void)scrollWheel:(NSEvent *)theEvent
123 VLCControls * o_controls = (VLCControls *)[[NSApp delegate] controls];
124 [o_controls scrollWheel: theEvent];
127 - (void)keyDown:(NSEvent *)o_event
131 unsigned int i_pressed_modifiers = 0;
134 i_pressed_modifiers = [o_event modifierFlags];
136 if( i_pressed_modifiers & NSShiftKeyMask )
137 val.i_int |= KEY_MODIFIER_SHIFT;
138 if( i_pressed_modifiers & NSControlKeyMask )
139 val.i_int |= KEY_MODIFIER_CTRL;
140 if( i_pressed_modifiers & NSAlternateKeyMask )
141 val.i_int |= KEY_MODIFIER_ALT;
142 if( i_pressed_modifiers & NSCommandKeyMask )
143 val.i_int |= KEY_MODIFIER_COMMAND;
145 key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0];
149 vout_thread_t * p_vout = getVout();
150 /* Escape should always get you out of fullscreen */
151 if( key == (unichar) 0x1b )
153 playlist_t * p_playlist = pl_Get( VLCIntf );
154 if( var_GetBool( p_playlist, "fullscreen") )
155 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
157 /* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */
158 else if( key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask )
159 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
164 [[VLCCoreInteraction sharedInstance] play];
168 val.i_int |= (int)CocoaKeyToVLC( key );
169 var_Set( p_vout->p_libvlc, "key-pressed", val );
171 vlc_object_release( p_vout );
174 msg_Dbg( VLCIntf, "could not send keyevent to VLC core" );
177 [super keyDown: o_event];
180 - (void)mouseDown:(NSEvent *)o_event
182 if( ( [o_event type] == NSLeftMouseDown ) &&
183 ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
185 if( [o_event clickCount] > 1 )
187 /* multiple clicking */
188 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
191 else if( ( [o_event type] == NSRightMouseDown ) ||
192 ( ( [o_event type] == NSLeftMouseDown ) &&
193 ( [o_event modifierFlags] & NSControlKeyMask ) ) )
195 [NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
198 [super mouseDown: o_event];
201 - (void)rightMouseDown:(NSEvent *)o_event
203 if( [o_event type] == NSRightMouseDown )
204 [NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
206 [super mouseDown: o_event];
209 - (void)rightMouseUp:(NSEvent *)o_event
211 if( [o_event type] == NSRightMouseUp )
212 [NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
214 [super mouseUp: o_event];
217 - (void)mouseMoved:(NSEvent *)o_event
219 [[VLCMain sharedInstance] showFullscreenController];
220 [super mouseMoved: o_event];
223 - (BOOL)mouseDownCanMoveWindow
228 - (BOOL)acceptsFirstResponder
233 - (BOOL)becomeFirstResponder
238 - (BOOL)resignFirstResponder
240 /* while we need to be the first responder most of the time, we need to give up that status when toggling the playlist */
244 -(void)didAddSubview:(NSView *)subview
246 [[self window] makeFirstResponder: subview];