1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
/*****************************************************************************
* VideoView.m: MacOS X video output module
*****************************************************************************
* Copyright (C) 2002-2014 VLC authors and VideoLAN
* $Id: 6cc583b5ea970056df8e327f0f0e7dfa8f010b71 $
*
* Authors: Derk-Jan Hartman <hartman at videolan dot org>
* Eric Petit <titer@m0k.org>
* Benjamin Pracht <bigben at videolan dot org>
* Pierre d'Herbemont <pdherbemont # videolan org>
* Felix Paul Kühne <fkuehne at videolan dot org>
* David Fuhrmann <david dot fuhrmann at googlemail dot com>
*
* 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.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#import <stdlib.h> /* free() */
#import "CompatibilityFixes.h"
#import "intf.h"
#import "VideoView.h"
#import "CoreInteraction.h"
#import "MainMenu.h"
#import <vlc_keys.h>
/*****************************************************************************
* VLCVoutView implementation
*****************************************************************************/
@implementation VLCVoutView
#pragma mark -
#pragma mark drag & drop support
- (void)dealloc
{
if (p_vout)
vlc_object_release(p_vout);
[self unregisterDraggedTypes];
[super dealloc];
}
-(id)initWithFrame:(NSRect)frameRect
{
if (self = [super initWithFrame:frameRect]) {
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
}
i_lastScrollWheelDirection = 0;
f_cumulated_magnification = 0.0;
return self;
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
return NSDragOperationGeneric;
return NSDragOperationNone;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
BOOL b_returned;
b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender];
[self setNeedsDisplay:YES];
return b_returned;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
[self setNeedsDisplay:YES];
}
#pragma mark -
#pragma mark vout actions
- (void)keyDown:(NSEvent *)o_event
{
unichar key = 0;
vlc_value_t val;
unsigned int i_pressed_modifiers = 0;
val.i_int = 0;
i_pressed_modifiers = [o_event modifierFlags];
if (i_pressed_modifiers & NSShiftKeyMask)
val.i_int |= KEY_MODIFIER_SHIFT;
if (i_pressed_modifiers & NSControlKeyMask)
val.i_int |= KEY_MODIFIER_CTRL;
if (i_pressed_modifiers & NSAlternateKeyMask)
val.i_int |= KEY_MODIFIER_ALT;
if (i_pressed_modifiers & NSCommandKeyMask)
val.i_int |= KEY_MODIFIER_COMMAND;
NSString * characters = [o_event charactersIgnoringModifiers];
if ([characters length] > 0) {
key = [[characters lowercaseString] characterAtIndex: 0];
if (key) {
/* Escape should always get you out of fullscreen */
if (key == (unichar) 0x1b) {
playlist_t * p_playlist = pl_Get(VLCIntf);
if (var_GetBool(p_playlist, "fullscreen"))
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
}
/* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */
else if (key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask)
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
else if (p_vout) {
val.i_int |= (int)CocoaKeyToVLC(key);
var_Set(p_vout->p_libvlc, "key-pressed", val);
}
else
msg_Dbg(VLCIntf, "could not send keyevent to VLC core");
return;
}
}
[super keyDown: o_event];
}
- (BOOL)performKeyEquivalent:(NSEvent *)o_event
{
return [[VLCMainWindow sharedInstance] performKeyEquivalent: o_event];
}
- (void)mouseDown:(NSEvent *)o_event
{
if (([o_event type] == NSLeftMouseDown) && (! ([o_event modifierFlags] & NSControlKeyMask))) {
if ([o_event clickCount] == 2)
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
} else if (([o_event type] == NSRightMouseDown) ||
(([o_event type] == NSLeftMouseDown) &&
([o_event modifierFlags] & NSControlKeyMask)))
[NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
[super mouseDown: o_event];
}
- (void)rightMouseDown:(NSEvent *)o_event
{
if ([o_event type] == NSRightMouseDown)
[NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
[super mouseDown: o_event];
}
- (void)rightMouseUp:(NSEvent *)o_event
{
if ([o_event type] == NSRightMouseUp)
[NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
[super mouseUp: o_event];
}
- (void)mouseMoved:(NSEvent *)o_event
{
NSPoint ml = [self convertPoint: [o_event locationInWindow] fromView: nil];
if ([self mouse: ml inRect: [self bounds]])
[[VLCMain sharedInstance] showFullscreenController];
[super mouseMoved: o_event];
}
- (void)resetScrollWheelDirection
{
i_lastScrollWheelDirection = 0;
f_cumulatedXScrollValue = f_cumulatedYScrollValue = 0.;
msg_Dbg(VLCIntf, "Reset scrolling timer");
}
- (void)scrollWheel:(NSEvent *)theEvent
{
const CGFloat f_xThreshold = 0.8;
const CGFloat f_yThreshold = 1.0;
const CGFloat f_directionThreshold = 0.05;
intf_thread_t * p_intf = VLCIntf;
CGFloat f_deltaX = [theEvent deltaX];
CGFloat f_deltaY = [theEvent deltaY];
if (!OSX_SNOW_LEOPARD && [theEvent isDirectionInvertedFromDevice]) {
f_deltaX = -f_deltaX;
f_deltaY = -f_deltaY;
}
CGFloat f_deltaXAbs = ABS(f_deltaX);
CGFloat f_deltaYAbs = ABS(f_deltaY);
// A mouse scroll wheel has lower sensitivity. We want to scroll at least
// with every event here.
BOOL isMouseScrollWheel = ([theEvent subtype] == NSMouseEventSubtype);
if (isMouseScrollWheel && f_deltaYAbs < f_yThreshold)
f_deltaY = f_deltaY > 0. ? f_yThreshold : -f_yThreshold;
if (isMouseScrollWheel && f_deltaXAbs < f_xThreshold)
f_deltaX = f_deltaX > 0. ? f_xThreshold : -f_xThreshold;
/* in the following, we're forwarding either a x or a y event */
/* Multiple key events are send depending on the intensity of the event */
/* the opposite direction is being blocked for a couple of milli seconds */
if (f_deltaYAbs > f_directionThreshold) {
if (i_lastScrollWheelDirection < 0) // last was a X
return;
i_lastScrollWheelDirection = 1; // Y
f_cumulatedYScrollValue += f_deltaY;
int key = f_cumulatedYScrollValue < 0.0f ? KEY_MOUSEWHEELDOWN : KEY_MOUSEWHEELUP;
while (ABS(f_cumulatedYScrollValue) >= f_yThreshold) {
f_cumulatedYScrollValue -= (f_cumulatedYScrollValue > 0 ? f_yThreshold : -f_yThreshold);
var_SetInteger(p_intf->p_libvlc, "key-pressed", key);
msg_Dbg(p_intf, "Scrolling in y direction");
}
} else if (f_deltaXAbs > f_directionThreshold) {
if (i_lastScrollWheelDirection > 0) // last was a Y
return;
i_lastScrollWheelDirection = -1; // X
f_cumulatedXScrollValue += f_deltaX;
int key = f_cumulatedXScrollValue < 0.0f ? KEY_MOUSEWHEELRIGHT : KEY_MOUSEWHEELLEFT;
while (ABS(f_cumulatedXScrollValue) >= f_xThreshold) {
f_cumulatedXScrollValue -= (f_cumulatedXScrollValue > 0 ? f_xThreshold : -f_xThreshold);
var_SetInteger(p_intf->p_libvlc, "key-pressed", key);
msg_Dbg(p_intf, "Scrolling in x direction");
}
}
if (p_scrollTimer) {
[p_scrollTimer invalidate];
[p_scrollTimer release];
p_scrollTimer = nil;
}
p_scrollTimer = [[NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(resetScrollWheelDirection) userInfo:nil repeats:NO] retain];
}
#pragma mark -
#pragma mark Handling of vout related actions
- (void)setVoutThread:(vout_thread_t *)p_vout_thread
{
assert(p_vout == NULL);
p_vout = p_vout_thread;
vlc_object_hold(p_vout);
}
- (vout_thread_t *)voutThread
{
if (p_vout) {
vlc_object_hold(p_vout);
return p_vout;
}
return NULL;
}
- (void)releaseVoutThread
{
if (p_vout) {
vlc_object_release(p_vout);
p_vout = NULL;
}
}
#pragma mark -
#pragma mark Basic view behaviour and touch events handling
- (BOOL)mouseDownCanMoveWindow
{
return YES;
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (BOOL)becomeFirstResponder
{
return YES;
}
- (BOOL)resignFirstResponder
{
/* while we need to be the first responder most of the time, we need to give up that status when toggling the playlist */
return YES;
}
-(void)didAddSubview:(NSView *)subview
{
[[self window] makeFirstResponder: subview];
}
- (void)magnifyWithEvent:(NSEvent *)event
{
f_cumulated_magnification += [event magnification];
// This is the result of [NSEvent standardMagnificationThreshold].
// Unfortunately, this is a private API, currently.
CGFloat f_threshold = 0.3;
BOOL b_fullscreen = [(VLCVideoWindowCommon *)[self window] fullscreen];
if ((f_cumulated_magnification > f_threshold && !b_fullscreen) || (f_cumulated_magnification < -f_threshold && b_fullscreen)) {
f_cumulated_magnification = 0.0;
[[VLCCoreInteraction sharedInstance] toggleFullscreen];
}
}
- (void)beginGestureWithEvent:(NSEvent *)event
{
f_cumulated_magnification = 0.0;
}
@end
|