[vlc-commits] macosx: move mouse vout event code to vout module

David Fuhrmann git at videolan.org
Fri May 11 17:32:37 CEST 2012


vlc/vlc-2.0 | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Sat May  5 21:54:59 2012 +0200| [2ce08553100f19884a3ed68001045906f18383f2] | committer: 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: David Fuhrmann <david.fuhrmann at googlemail.com>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=2ce08553100f19884a3ed68001045906f18383f2
---

 modules/gui/macosx/MainWindow.m |   14 +++---
 modules/gui/macosx/VideoView.m  |  110 +++------------------------------------
 modules/video_output/macosx.m   |   99 +++++++++++++++++++++++++++++++++--
 3 files changed, 109 insertions(+), 114 deletions(-)

diff --git a/modules/gui/macosx/MainWindow.m b/modules/gui/macosx/MainWindow.m
index 3bd9554..3576be8 100644
--- a/modules/gui/macosx/MainWindow.m
+++ b/modules/gui/macosx/MainWindow.m
@@ -706,7 +706,9 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
     [o_split_view setHidden: YES];
     [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
@@ -767,8 +769,8 @@ static VLCMainWindow *_o_sharedInstance = nil;
             [o_split_view setHidden: NO];
             [o_playlist_table setHidden: NO];
             [o_video_view setHidden: !b_activeVideo];
-            if (b_activeVideo)
-                [o_detached_video_window makeFirstResponder: o_video_view];
+            if( b_activeVideo && [[o_video_view subviews] count] > 0 )
+                [o_detached_video_window makeFirstResponder: [[o_video_view subviews] objectAtIndex:0]];
         }
     }
 }
@@ -1520,8 +1522,6 @@ static VLCMainWindow *_o_sharedInstance = nil;
     {
         // look for 'start at fullscreen'
         [[VLCMain sharedInstance] fullscreenChanged];
-
-        [self makeFirstResponder: o_video_view];
     }
     else
     {
@@ -1832,7 +1832,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
 
 - (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 setAcceptsMouseMovedEvents: YES];
@@ -1993,7 +1993,7 @@ static VLCMainWindow *_o_sharedInstance = nil;
     [[o_temp_view superview] replaceSubview:o_temp_view with:o_video_view];
     [o_video_view release];
     [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( !b_nonembedded )
diff --git a/modules/gui/macosx/VideoView.m b/modules/gui/macosx/VideoView.m
index 0a6a530..469b198 100644
--- a/modules/gui/macosx/VideoView.m
+++ b/modules/gui/macosx/VideoView.m
@@ -190,18 +190,12 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 - (void)mouseDown:(NSEvent *)o_event
 {
     vout_thread_t * p_vout = getVout();
-    vlc_value_t val;
     if( p_vout )
     {
         if( ( [o_event type] == NSLeftMouseDown ) &&
           ( ! ( [o_event modifierFlags] &  NSControlKeyMask ) ) )
         {
-            if( [o_event clickCount] <= 1 )
-            {
-                /* single clicking */
-                vout_display_SendEventMousePressed( [[[self subviews] objectAtIndex:0] voutDisplay], MOUSE_BUTTON_LEFT );
-            }
-            else
+            if( [o_event clickCount] > 1 )
             {
                 /* multiple clicking */
                 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
@@ -220,23 +214,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     [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
 {
     if( [o_event type] == NSRightMouseDown )
@@ -250,36 +227,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     [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
 {
     if( [o_event type] == NSRightMouseUp )
@@ -295,56 +242,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     [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
 {
-    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];
-        }
-        vlc_object_release( p_vout );
-    }
-
+    [[VLCMain sharedInstance] showFullscreenController];
     [super mouseMoved: o_event];
 }
 
@@ -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 */
     return YES;
 }
+
+-(void)didAddSubview:(NSView *)subview
+{
+    [[self window] makeFirstResponder: subview];
+}
+
 @end
diff --git a/modules/video_output/macosx.m b/modules/video_output/macosx.m
index 9a40d81..1b236a7 100644
--- a/modules/video_output/macosx.m
+++ b/modules/video_output/macosx.m
@@ -687,11 +687,6 @@ static void OpenglSwap (vlc_gl_t *gl)
     [super renewGState];
 }
 
-- (BOOL)mouseDownCanMoveWindow
-{
-    return YES;
-}
-
 - (BOOL)isOpaque
 {
     return YES;
@@ -704,4 +699,98 @@ static void OpenglSwap (vlc_gl_t *gl)
     else
         [[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



More information about the vlc-commits mailing list