Commit 2ce08553 authored by David Fuhrmann's avatar David Fuhrmann

macosx: move mouse vout event code to vout module

Now it should be usable within own libvlc applications
(cherry picked from commit 729e509f11a90d417a2f28c84b68d3648167142b)
Signed-off-by: default avatarDavid Fuhrmann <david.fuhrmann@googlemail.com>
parent 672577b7
...@@ -706,7 +706,9 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -706,7 +706,9 @@ static VLCMainWindow *_o_sharedInstance = nil;
[o_split_view setHidden: YES]; [o_split_view setHidden: YES];
[o_video_view setHidden: NO]; [o_video_view setHidden: NO];
[self makeFirstResponder: o_video_view];
if( [[o_video_view subviews] count] > 0 )
[self makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
} }
- (IBAction)togglePlaylist:(id)sender - (IBAction)togglePlaylist:(id)sender
...@@ -767,8 +769,8 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -767,8 +769,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
[o_split_view setHidden: NO]; [o_split_view setHidden: NO];
[o_playlist_table setHidden: NO]; [o_playlist_table setHidden: NO];
[o_video_view setHidden: !b_activeVideo]; [o_video_view setHidden: !b_activeVideo];
if (b_activeVideo) if( b_activeVideo && [[o_video_view subviews] count] > 0 )
[o_detached_video_window makeFirstResponder: o_video_view]; [o_detached_video_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
} }
} }
} }
...@@ -1520,8 +1522,6 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -1520,8 +1522,6 @@ static VLCMainWindow *_o_sharedInstance = nil;
{ {
// look for 'start at fullscreen' // look for 'start at fullscreen'
[[VLCMain sharedInstance] fullscreenChanged]; [[VLCMain sharedInstance] fullscreenChanged];
[self makeFirstResponder: o_video_view];
} }
else else
{ {
...@@ -1832,7 +1832,7 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -1832,7 +1832,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
- (void)hasBecomeFullscreen - (void)hasBecomeFullscreen
{ {
[o_fullscreen_window makeFirstResponder: o_video_view]; [o_fullscreen_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
[o_fullscreen_window makeKeyWindow]; [o_fullscreen_window makeKeyWindow];
[o_fullscreen_window setAcceptsMouseMovedEvents: YES]; [o_fullscreen_window setAcceptsMouseMovedEvents: YES];
...@@ -1993,7 +1993,7 @@ static VLCMainWindow *_o_sharedInstance = nil; ...@@ -1993,7 +1993,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
[[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view]; [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
[o_video_view release]; [o_video_view release];
[o_video_view setFrame:[o_temp_view frame]]; [o_video_view setFrame:[o_temp_view frame]];
[[o_video_view window] makeFirstResponder: o_video_view]; [[o_video_view window] makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
if( [[o_video_view window] isVisible] ) if( [[o_video_view window] isVisible] )
{ {
if( !b_nonembedded ) if( !b_nonembedded )
......
...@@ -190,18 +190,12 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -190,18 +190,12 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
- (void)mouseDown:(NSEvent *)o_event - (void)mouseDown:(NSEvent *)o_event
{ {
vout_thread_t * p_vout = getVout(); vout_thread_t * p_vout = getVout();
vlc_value_t val;
if( p_vout ) if( p_vout )
{ {
if( ( [o_event type] == NSLeftMouseDown ) && if( ( [o_event type] == NSLeftMouseDown ) &&
( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) ) ( ! ( [o_event modifierFlags] & NSControlKeyMask ) ) )
{ {
if( [o_event clickCount] <= 1 ) if( [o_event clickCount] > 1 )
{
/* single clicking */
vout_display_SendEventMousePressed( [[[self subviews] objectAtIndex:0] voutDisplay], MOUSE_BUTTON_LEFT );
}
else
{ {
/* multiple clicking */ /* multiple clicking */
[[VLCCoreInteraction sharedInstance] toggleFullscreen]; [[VLCCoreInteraction sharedInstance] toggleFullscreen];
...@@ -220,23 +214,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -220,23 +214,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
[super mouseDown: o_event]; [super mouseDown: o_event];
} }
- (void)otherMouseDown:(NSEvent *)o_event
{
if( [o_event type] == NSOtherMouseDown )
{
vout_thread_t * p_vout = getVout();
vlc_value_t val;
if (p_vout)
{
vout_display_SendEventMousePressed( [[[self subviews] objectAtIndex:0] voutDisplay], MOUSE_BUTTON_CENTER );
}
vlc_object_release( p_vout );
}
[super mouseDown: o_event];
}
- (void)rightMouseDown:(NSEvent *)o_event - (void)rightMouseDown:(NSEvent *)o_event
{ {
if( [o_event type] == NSRightMouseDown ) if( [o_event type] == NSRightMouseDown )
...@@ -250,36 +227,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -250,36 +227,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
[super mouseDown: o_event]; [super mouseDown: o_event];
} }
- (void)mouseUp:(NSEvent *)o_event
{
if( [o_event type] == NSLeftMouseUp )
{
vout_thread_t * p_vout = getVout();
if (p_vout)
{
vout_display_SendEventMouseReleased( [[[self subviews] objectAtIndex:0] voutDisplay], MOUSE_BUTTON_LEFT );
vlc_object_release( p_vout );
}
}
[super mouseUp: o_event];
}
- (void)otherMouseUp:(NSEvent *)o_event
{
if( [o_event type] == NSOtherMouseUp )
{
vout_thread_t * p_vout = getVout();
if (p_vout)
{
vout_display_SendEventMouseReleased( [[[self subviews] objectAtIndex:0] voutDisplay], MOUSE_BUTTON_CENTER );
vlc_object_release( p_vout );
}
}
[super mouseUp: o_event];
}
- (void)rightMouseUp:(NSEvent *)o_event - (void)rightMouseUp:(NSEvent *)o_event
{ {
if( [o_event type] == NSRightMouseUp ) if( [o_event type] == NSRightMouseUp )
...@@ -295,56 +242,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -295,56 +242,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
[super mouseUp: o_event]; [super mouseUp: o_event];
} }
- (void)mouseDragged:(NSEvent *)o_event
{
[self mouseMoved: o_event];
}
- (void)otherMouseDragged:(NSEvent *)o_event
{
[self mouseMoved: o_event];
}
- (void)rightMouseDragged:(NSEvent *)o_event
{
[self mouseMoved: o_event];
}
- (void)mouseMoved:(NSEvent *)o_event - (void)mouseMoved:(NSEvent *)o_event
{ {
vout_thread_t * p_vout = getVout();
if( p_vout )
{
NSPoint ml;
NSRect s_rect;
BOOL b_inside;
s_rect = [self bounds];
ml = [self convertPoint: [o_event locationInWindow] fromView: nil];
b_inside = [self mouse: ml inRect: s_rect];
if( b_inside )
{
vout_display_t *vd = [[[self subviews] objectAtIndex:0] voutDisplay];
vout_display_place_t place;
vout_display_PlacePicture( &place, &vd->source, vd->cfg, false );
if( place.width > 0 && place.height > 0 )
{
const int x = vd->source.i_x_offset +
(int64_t)(ml.x - place.x) * vd->source.i_visible_width / place.width;
const int y = vd->source.i_y_offset +
(int64_t)((int)s_rect.size.height - (int)ml.y - place.y) * vd->source.i_visible_height / place.height;
vout_display_SendEventMouseMoved( vd, x, y );
}
[[VLCMain sharedInstance] showFullscreenController]; [[VLCMain sharedInstance] showFullscreenController];
}
vlc_object_release( p_vout );
}
[super mouseMoved: o_event]; [super mouseMoved: o_event];
} }
...@@ -368,4 +268,10 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -368,4 +268,10 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
/* while we need to be the first responder most of the time, we need to give up that status when toggling the playlist */ /* 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; return YES;
} }
-(void)didAddSubview:(NSView *)subview
{
[[self window] makeFirstResponder: subview];
}
@end @end
...@@ -687,11 +687,6 @@ static void OpenglSwap (vlc_gl_t *gl) ...@@ -687,11 +687,6 @@ static void OpenglSwap (vlc_gl_t *gl)
[super renewGState]; [super renewGState];
} }
- (BOOL)mouseDownCanMoveWindow
{
return YES;
}
- (BOOL)isOpaque - (BOOL)isOpaque
{ {
return YES; return YES;
...@@ -704,4 +699,98 @@ static void OpenglSwap (vlc_gl_t *gl) ...@@ -704,4 +699,98 @@ static void OpenglSwap (vlc_gl_t *gl)
else else
[[self window] setLevel: NSNormalWindowLevel]; [[self window] setLevel: NSNormalWindowLevel];
} }
#pragma mark -
#pragma mark Mouse handling
- (void)mouseDown:(NSEvent *)o_event
{
if ([o_event type] == NSLeftMouseDown && !([o_event modifierFlags] & NSControlKeyMask))
{
if ([o_event clickCount] <= 1)
vout_display_SendEventMousePressed (vd, MOUSE_BUTTON_LEFT);
}
[super mouseDown:o_event];
}
- (void)otherMouseDown:(NSEvent *)o_event
{
vout_display_SendEventMousePressed (vd, MOUSE_BUTTON_CENTER);
[super otherMouseDown: o_event];
}
- (void)mouseUp:(NSEvent *)o_event
{
if ([o_event type] == NSLeftMouseUp)
vout_display_SendEventMouseReleased (vd, MOUSE_BUTTON_LEFT);
[super mouseUp: o_event];
}
- (void)otherMouseUp:(NSEvent *)o_event
{
vout_display_SendEventMouseReleased (vd, MOUSE_BUTTON_CENTER);
[super otherMouseUp: o_event];
}
- (void)mouseMoved:(NSEvent *)o_event
{
NSPoint ml;
NSRect s_rect;
BOOL b_inside;
s_rect = [self bounds];
ml = [self convertPoint: [o_event locationInWindow] fromView: nil];
b_inside = [self mouse: ml inRect: s_rect];
if (b_inside)
{
vout_display_place_t place;
vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
if (place.width > 0 && place.height > 0)
{
const int x = vd->source.i_x_offset +
(int64_t)(ml.x - place.x) * vd->source.i_visible_width / place.width;
const int y = vd->source.i_y_offset +
(int64_t)((int)s_rect.size.height - (int)ml.y - place.y) * vd->source.i_visible_height / place.height;
vout_display_SendEventMouseMoved (vd, x, y);
}
}
[super mouseMoved: o_event];
}
- (void)mouseDragged:(NSEvent *)o_event
{
[self mouseMoved: o_event];
[super mouseDragged: o_event];
}
- (void)otherMouseDragged:(NSEvent *)o_event
{
[self mouseMoved: o_event];
[super otherMouseDragged: o_event];
}
- (void)rightMouseDragged:(NSEvent *)o_event
{
[self mouseMoved: o_event];
[super rightMouseDragged: o_event];
}
- (BOOL)acceptsFirstResponder
{
return YES;
}
- (BOOL)mouseDownCanMoveWindow
{
return YES;
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment