[vlc-commits] mac plugin: propagate mouse events to the vout module

Felix Paul Kühne git at videolan.org
Wed Apr 23 16:48:48 CEST 2014


npapi-vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Wed Apr 23 16:44:45 2014 +0200| [e760fcfc4121cbcaf802c3d0941d0a0af4df0b69] | committer: Felix Paul Kühne

mac plugin: propagate mouse events to the vout module

Needs testing on a HiDPI device

> http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=e760fcfc4121cbcaf802c3d0941d0a0af4df0b69
---

 npapi/vlcplugin_mac.mm |   68 +++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 65 insertions(+), 3 deletions(-)

diff --git a/npapi/vlcplugin_mac.mm b/npapi/vlcplugin_mac.mm
index fa33ef8..6f5e58a 100644
--- a/npapi/vlcplugin_mac.mm
+++ b/npapi/vlcplugin_mac.mm
@@ -33,6 +33,16 @@
 #include <QuartzCore/QuartzCore.h>
 #include <AppKit/AppKit.h>
 
+/* compilation support for 10.6 */
+#define OSX_LION NSAppKitVersionNumber >= 1115.2
+#ifndef MAC_OS_X_VERSION_10_7
+
+ at interface NSView (IntroducedInLion)
+- (NSRect)convertRectToBacking:(NSRect)aRect;
+ at end
+
+#endif
+
 @interface VLCNoMediaLayer : CALayer {
     VlcPluginMac *_cppPlugin;
 }
@@ -94,6 +104,12 @@
 - (CGRect)_sliderRect;
 @end
 
+ at interface VLCPlaybackLayer : CALayer
+- (void)mouseButtonDown:(int)buttonNumber;
+- (void)mouseButtonUp:(int)buttonNumber;
+- (void)mouseMovedToX:(double)xValue Y:(double)yValue;
+ at end
+
 @interface VLCFullscreenContentView : NSView {
     VlcPluginMac *_cppPlugin;
     NSTimeInterval _timeSinceLastMouseMove;
@@ -119,7 +135,7 @@
 @end
 
 static VLCBrowserRootLayer * browserRootLayer;
-static CALayer * playbackLayer;
+static VLCPlaybackLayer * playbackLayer;
 static VLCNoMediaLayer * noMediaLayer;
 static VLCControllerLayer * controllerLayer;
 static VLCFullscreenWindow * fullscreenWindow;
@@ -307,6 +323,10 @@ bool VlcPluginMac::handle_event(void *event)
     switch (eventType) {
         case NPCocoaEventMouseDown:
         {
+            if (playbackLayer) {
+                if ([playbackLayer respondsToSelector:@selector(mouseButtonDown:)])
+                    [playbackLayer mouseButtonDown:cocoaEvent->data.mouse.buttonNumber];
+            }
             if (cocoaEvent->data.mouse.clickCount >= 2)
                 VlcPluginMac::toggle_fullscreen();
 
@@ -319,6 +339,10 @@ bool VlcPluginMac::handle_event(void *event)
         }
         case NPCocoaEventMouseUp:
         {
+            if (playbackLayer) {
+                if ([playbackLayer respondsToSelector:@selector(mouseButtonUp:)])
+                    [playbackLayer mouseButtonUp:cocoaEvent->data.mouse.buttonNumber];
+            }
             CGPoint point = CGPointMake(cocoaEvent->data.mouse.pluginX,
                                         // Flip the y coordinate
                                         npwindow.height - cocoaEvent->data.mouse.pluginY);
@@ -327,6 +351,13 @@ bool VlcPluginMac::handle_event(void *event)
 
             return true;
         }
+        case NPCocoaEventMouseMoved:
+        {
+            if (playbackLayer) {
+                if ([playbackLayer respondsToSelector:@selector(mouseMovedToX:Y:)])
+                    [playbackLayer mouseMovedToX:cocoaEvent->data.mouse.pluginX Y:cocoaEvent->data.mouse.pluginY];
+            }
+        }
         case NPCocoaEventMouseDragged:
         {
             CGPoint point = CGPointMake(cocoaEvent->data.mouse.pluginX,
@@ -441,7 +472,7 @@ bool VlcPluginMac::handle_event(void *event)
 - (void)addVoutLayer:(CALayer *)aLayer
 {
     [CATransaction begin];
-    playbackLayer = [aLayer retain];
+    playbackLayer = (VLCPlaybackLayer *)[aLayer retain];
     playbackLayer.opaque = 1.;
     playbackLayer.hidden = NO;
     playbackLayer.bounds = noMediaLayer.bounds;
@@ -915,7 +946,9 @@ bool VlcPluginMac::handle_event(void *event)
 
 - (void)mouseDown:(NSEvent *)theEvent
 {
-    if ([theEvent type] == NSLeftMouseDown && !([theEvent modifierFlags] & NSControlKeyMask)) {
+    NSEventType eventType = [theEvent type];
+
+    if (eventType == NSLeftMouseDown && !([theEvent modifierFlags] & NSControlKeyMask)) {
         if ([theEvent clickCount] >= 2)
             self.cppPlugin->toggle_fullscreen();
         else {
@@ -924,6 +957,16 @@ bool VlcPluginMac::handle_event(void *event)
             [controllerLayer handleMouseDown:[browserRootLayer convertPoint:CGPointMake(point.x, point.y) toLayer:controllerLayer]];
         }
     }
+    if (playbackLayer) {
+        if ([playbackLayer respondsToSelector:@selector(mouseButtonDown:)]) {
+            if (eventType == NSLeftMouseDown)
+                [playbackLayer mouseButtonDown:0];
+            else if (eventType == NSRightMouseDown)
+                [playbackLayer mouseButtonDown:1];
+            else
+                [playbackLayer mouseButtonDown:2];
+        }
+    }
 
     [super mouseDown: theEvent];
 }
@@ -931,9 +974,21 @@ bool VlcPluginMac::handle_event(void *event)
 - (void)mouseUp:(NSEvent *)theEvent
 {
     NSPoint point = [NSEvent mouseLocation];
+    NSEventType eventType = [theEvent type];
 
     [controllerLayer handleMouseUp:[browserRootLayer convertPoint:CGPointMake(point.x, point.y) toLayer:controllerLayer]];
 
+    if (playbackLayer) {
+        if ([playbackLayer respondsToSelector:@selector(mouseButtonUp:)]) {
+            if (eventType == NSLeftMouseUp)
+                [playbackLayer mouseButtonUp:0];
+            else if (eventType == NSRightMouseUp)
+                [playbackLayer mouseButtonUp:1];
+            else
+                [playbackLayer mouseButtonUp:2];
+        }
+    }
+
     [super mouseUp: theEvent];
 }
 
@@ -952,6 +1007,13 @@ bool VlcPluginMac::handle_event(void *event)
     _timeSinceLastMouseMove = [NSDate timeIntervalSinceReferenceDate];
     [self performSelector:@selector(hideToolbar) withObject:nil afterDelay: 4.1];
 
+    if (playbackLayer) {
+        if ([playbackLayer respondsToSelector:@selector(mouseMovedToX:Y:)]) {
+            NSPoint ml = [theEvent locationInWindow];
+            [playbackLayer mouseMovedToX:ml.x Y:([self.window frame].size.height - ml.y)];
+        }
+    }
+
     [super mouseMoved: theEvent];
 }
 



More information about the vlc-commits mailing list