]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/vout.m
Make mouse-moved and mouse-clicked coordinates, remove mouse-x and -y
[vlc] / modules / gui / macosx / vout.m
index 0f55c636d63d1b4ad7fb293ab63452834f00e5c0..554b90a2e99821c0511de637f3815972d4e442ba 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * vout.m: MacOS X video output module
  *****************************************************************************
- * Copyright (C) 2001-2008 the VideoLAN team
+ * Copyright (C) 2001-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Colin Delacroix <colin@zoy.org>
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <errno.h>                                                 /* ENOMEM */
 #include <stdlib.h>                                                /* free() */
 #include <string.h>
 
-/* BeginFullScreen, EndFullScreen */
-#include <QuickTime/QuickTime.h>
+/* prevent system sleep */
+#import <CoreServices/CoreServices.h>
+/* FIXME: HACK!! */
+#ifdef __x86_64__
+#import <CoreServices/../Frameworks/OSServices.framework/Headers/Power.h>
+#endif
+
+/* SystemUIMode */
+#import <Carbon/Carbon.h>
 
-#include <vlc_keys.h>
 
 #include "intf.h"
 #include "fspanel.h"
@@ -45,6 +50,9 @@
 #import "controls.h"
 #import "embeddedwindow.h"
 
+#include <vlc_common.h>
+#include <vlc_keys.h>
+
 /*****************************************************************************
  * DeviceCallback: Callback triggered when the video-device variable is changed
  *****************************************************************************/
@@ -76,7 +84,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     return self;
 }
 
-- (id)getEmbeddedVout
+- (id)embeddedVout
 {
     unsigned int i;
 
@@ -118,19 +126,24 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     {
         NSLog( @"We were not given a VLCVoutWindow" );
     }*/
-    return ([self getViewForWindow: o_window] == nil ? NO : YES );
+    return ([self viewForWindow: o_window] == nil ? NO : YES );
 }
 
-- (id)getViewForWindow: (id)o_window
+- (id)viewForWindow: (id)o_window
 {
-    id o_enumerator = [o_embedded_array objectEnumerator];
-    id o_current_embedded;
-
-    while( (o_current_embedded = [o_enumerator nextObject]) )
+    if( o_embedded_array != nil )
     {
-        if( [o_current_embedded getWindow] == o_window )
+        id o_enumerator = [o_embedded_array objectEnumerator];
+        id o_current_embedded;
+        if( o_window != nil )
         {
-            return o_current_embedded;
+            while( (o_current_embedded = [o_enumerator nextObject]) )
+            {
+                if( [o_current_embedded voutWindow] == o_window )
+                {
+                    return o_current_embedded;
+                }
+            }
         }
     }
     return nil;
@@ -145,7 +158,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 - (id)initWithFrame: (NSRect)frameRect
 {
-    [super initWithFrame: frameRect];
+    self = [super initWithFrame: frameRect];
     p_vout = NULL;
     o_view = nil;
     s_frame = &frameRect;
@@ -173,7 +186,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         return NO;
     }
 
-    p_real_vout = [VLCVoutView getRealVout: p_vout];
+    p_real_vout = [VLCVoutView realVout: p_vout];
 
     /* Get the pref value when this is the first time, otherwise retrieve the device from the top level video-device var */
     if( var_Type( p_real_vout->p_libvlc, "video-device" ) == 0 )
@@ -257,10 +270,10 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 - (void)closeVout
 {
-    [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeOut];
+    [[[[VLCMain sharedInstance] controls] fspanel] fadeOut];
 
     /* Make sure we don't see a white flash */
-    [[self window] disableScreenUpdatesUntilFlush];
+    [[self voutWindow] disableScreenUpdatesUntilFlush];
     [o_view removeFromSuperview];
     o_view = nil;
     p_vout = NULL;
@@ -278,7 +291,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
     if( !p_vout ) return;
 
-    p_input = vlc_object_find( p_vout, VLC_OBJECT_INPUT, FIND_PARENT );
+    p_input = getInput();
 
     if( !p_input ) return;
 
@@ -330,7 +343,6 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     vlc_object_release( p_input );
 }
 
-
 - (void)setOnTop:(BOOL)b_on_top
 {
     if( b_on_top )
@@ -423,9 +435,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 {
     vlc_value_t val;
     if( !p_real_vout ) return;
-    var_Get( p_real_vout, "fullscreen", &val );
-    val.b_bool = !val.b_bool;
-    var_Set( p_real_vout, "fullscreen", val );
+    var_ToggleBool( p_real_vout, "fullscreen" );
 }
 
 - (BOOL)isFullscreen
@@ -438,27 +448,27 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 - (void)snapshot
 {
-    vout_Control( p_real_vout, VOUT_SNAPSHOT );
+    var_TriggerCallback( p_real_vout, "video-snapshot" );
 }
 
 - (void)manage
 {
     /* Disable Screensaver, when we're playing something, but allow it on pause */
-    if( !VLCIntf || !VLCIntf->p_sys || !VLCIntf->p_sys->i_play_status )
+    if( !VLCIntf || !VLCIntf->p_sys )
         return;
 
     if( VLCIntf->p_sys->i_play_status == PLAYING_S )
         UpdateSystemActivity( UsrActivity );
 }
 
-- (id)getWindow
+- (id)voutWindow
 {
     return o_window;
 }
 
 - (void)scrollWheel:(NSEvent *)theEvent
 {
-    VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
+    VLCControls * o_controls = (VLCControls *)[[NSApp delegate] controls];
     [o_controls scrollWheel: theEvent];
 }
 
@@ -480,7 +490,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     if( i_pressed_modifiers & NSCommandKeyMask )
         val.i_int |= KEY_MODIFIER_COMMAND;
 
-    key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
+    key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0];
 
     if( key )
     {
@@ -494,19 +504,16 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         }
         else if ( p_vout )
         {
-            vlc_value_t val;
             if( key == ' ')
                 val.i_int = config_GetInt( p_vout, "key-play-pause" );
             else
-                val.i_int |= CocoaKeyToVLC( key );
+                val.i_int |= (int)CocoaKeyToVLC( key );
             var_Set( p_vout->p_libvlc, "key-pressed", val );
         }
         else NSLog( @"Could not send keyevent to VLC core" );
     }
     else
-    {
         [super keyDown: o_event];
-    }
 }
 
 - (void)mouseDown:(NSEvent *)o_event
@@ -535,7 +542,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
                  ( [o_event modifierFlags] &  NSControlKeyMask ) ) )
         {
             msg_Dbg( p_vout, "received NSRightMouseDown (generic method) or Ctrl clic" );
-            [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
+            [NSMenu popUpContextMenu: [[VLCMain sharedInstance] voutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] controls] voutView]];
         }
     }
 
@@ -561,7 +568,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     if( p_vout && [o_event type] == NSRightMouseDown )
     {
         msg_Dbg( p_vout, "received NSRightMouseDown (specific method)" );
-        [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
+        [NSMenu popUpContextMenu: [[VLCMain sharedInstance] voutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] controls] voutView]];
     }
 
     [super mouseDown: o_event];
@@ -573,9 +580,10 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
     if( p_vout && [o_event type] == NSLeftMouseUp )
     {
-        vlc_value_t b_val;
-        b_val.b_bool = true;
-        var_Set( p_vout, "mouse-clicked", b_val );
+        int x, y;
+
+        var_GetCoords( p_vout, "mouse-moved", &x, &y );
+        var_SetCoords( p_vout, "mouse-clicked", x, y );
 
         var_Get( p_vout, "mouse-button-down", &val );
         val.i_int &= ~1;
@@ -606,7 +614,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         /* FIXME: this isn't the appropriate place, but we can't receive
          * NSRightMouseDown some how */
         msg_Dbg( p_vout, "received NSRightMouseUp" );
-        [NSMenu popUpContextMenu: [[VLCMain sharedInstance] getVoutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] getControls] getVoutView]];
+        [NSMenu popUpContextMenu: [[VLCMain sharedInstance] voutMenu] withEvent: o_event forView: [[[VLCMain sharedInstance] controls] voutView]];
     }
 
     [super mouseUp: o_event];
@@ -641,34 +649,27 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
         if( b_inside )
         {
-            vlc_value_t val;
+            int x, y;
             unsigned int i_width, i_height, i_x, i_y;
 
             vout_PlacePicture( p_vout, (unsigned int)s_rect.size.width,
                                        (unsigned int)s_rect.size.height,
                                        &i_x, &i_y, &i_width, &i_height );
 
-            val.i_int = ( ((int)ml.x) - i_x ) *
-                        p_vout->render.i_width / i_width;
-            var_Set( p_vout, "mouse-x", val );
-
+            x = (((int)ml.x) - i_x) * p_vout->render.i_width / i_width;
             if( [[o_view className] isEqualToString: @"VLCGLView"] )
             {
-                val.i_int = ( ((int)(s_rect.size.height - ml.y)) - i_y ) *
+                y = (((int)(s_rect.size.height - ml.y)) - i_y) *
                             p_vout->render.i_height / i_height;
             }
             else
             {
-                val.i_int = ( ((int)ml.y) - i_y ) *
-                            p_vout->render.i_height / i_height;
+                y = (((int)ml.y) - i_y) * p_vout->render.i_height / i_height;
             }
-            var_Set( p_vout, "mouse-y", val );
-
-            val.b_bool = true;
-            var_Set( p_vout, "mouse-moved", val );
+            var_SetCoords( p_vout, "mouse-moved", x, y );
         }
         if( [self isFullscreen] )
-            [[[[VLCMain sharedInstance] getControls] getFSPanel] fadeIn];
+            [[[[VLCMain sharedInstance] controls] fspanel] fadeIn];
     }
 
     [super mouseMoved: o_event];
@@ -693,30 +694,25 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
 /* Class methods used by the different vout modules */
 
-+ (vout_thread_t *)getRealVout: (vout_thread_t *)p_vout
++ (vout_thread_t *)realVout: (vout_thread_t *)p_vout
 {
     /* p_real_vout: the vout we have to use to check for video-on-top
        and a few other things. If we are the QuickTime output, it's us.
-       It we are the OpenGL provider, it is our parent. */
-    if( p_vout->i_object_type == VLC_OBJECT_OPENGL )
-    {
-        return (vout_thread_t *) p_vout->p_parent;
-    }
-    else
-    {
-        return p_vout;
-    }
-
+       It we are the OpenGL provider, it is our parent.
+       Since we can't be the QuickTime output anymore, we need to be
+       the parent.
+       FIXME: check with the caca and x11 vouts! */
+    return (vout_thread_t *) p_vout->p_parent;
 }
 
-+ (id)getVoutView: (vout_thread_t *)p_vout subView: (NSView *)view
-                                    frame: (NSRect *)s_frame
++ (id)voutView: (vout_thread_t *)p_vout subView: (NSView *)view
+         frame: (NSRect *)s_frame
 {
-    vlc_value_t value_drawable;
+    int i_drawable_gl;
     int i_timeout;
     id o_return = nil;
 
-    var_Get( p_vout->p_libvlc, "drawable", &value_drawable );
+    i_drawable_gl = var_GetInteger( p_vout->p_libvlc, "drawable-gl" );
 
     var_Create( p_vout, "macosx-vdev", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "macosx-stretch", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
@@ -727,9 +723,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
     /* We only wait for NSApp to initialise if we're not embedded (as in the
      * case of the Mozilla plugin).  We can tell whether we're embedded or not
-     * by examining the "drawable" value: if it's zero, we're running in the
+     * by examining the "drawable-gl" value: if it's zero, we're running in the
      * main Mac intf; if it's non-zero, we're embedded. */
-    if( value_drawable.i_int == 0 )
+    if( i_drawable_gl == 0 )
     {
         /* Wait for a MacOS X interface to appear. Timeout is 2 seconds. */
         for( i_timeout = 20 ; i_timeout-- ; )
@@ -752,8 +748,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
                         !(var_GetBool( p_vout, "macosx-background" )) &&
                         var_GetBool( p_vout, "embedded-video") )
             {
-                o_return = [[[VLCMain sharedInstance] getEmbeddedList]
-                                                            getEmbeddedVout];
+                o_return = [[[VLCMain sharedInstance] embeddedList] embeddedVout];
             }
         }
     }
@@ -772,17 +767,15 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 - (void)enterFullscreen
 {
     /* Save the settings for next playing item */
-    playlist_t * p_playlist = pl_Yield( p_real_vout );
+    playlist_t * p_playlist = pl_Get( p_real_vout );
     var_SetBool( p_playlist, "fullscreen", true );
-    pl_Release( p_real_vout );
 }
 
 - (void)leaveFullscreen
 {
     /* Save the settings for next playing item */
-    playlist_t * p_playlist = pl_Yield( p_real_vout );
+    playlist_t * p_playlist = pl_Get( p_real_vout );
     var_SetBool( p_playlist, "fullscreen", false );
-    pl_Release( p_real_vout );
 }
 
 @end
@@ -804,7 +797,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     return YES;
 }
 
-- (bool)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
+- (BOOL)setVout: (vout_thread_t *) p_arg_vout subView: (NSView *) view
                      frame: (NSRect *) s_arg_frame
 {
     BOOL b_return = [super setVout: p_arg_vout subView: view frame:s_arg_frame];
@@ -923,7 +916,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     if(self = [super initWithFrame: frameRect])
     {
         b_used = NO;
-        [[[VLCMain sharedInstance] getEmbeddedList] addEmbeddedVout: self];
+        [[[VLCMain sharedInstance] embeddedList] addEmbeddedVout: self];
         o_embeddedwindow = nil; /* Filled later on in -awakeFromNib */
     }
     return self;
@@ -969,7 +962,8 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
         if ([o_window isVisible] && (![o_window isFullscreen]))
             [o_window makeKeyAndOrderFront: self];
 
-        [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])];
+        if ( [self window] != o_embeddedwindow )
+            [self scaleWindowWithFactor: 1.0 animate: [o_window isVisible] && (![o_window isFullscreen])];
 
         [o_embeddedwindow setVideoRatio:[self voutSizeForFactor:1.0]];
 
@@ -1002,7 +996,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     /* FIXME: fix core */
     [o_embeddedwindow performSelector:@selector(orderOut:) withObject:nil afterDelay:3.];
 
-    [[[VLCMain sharedInstance] getEmbeddedList] releaseEmbeddedVout: self];
+    [[[VLCMain sharedInstance] embeddedList] releaseEmbeddedVout: self];
 }
 
 - (void)enterFullscreen
@@ -1126,8 +1120,8 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     [self setLevel:NSNormalWindowLevel];
 
     /* tell the fspanel to move itself to front next time it's triggered */
-    [[[[VLCMain sharedInstance] getControls] getFSPanel] setVoutWasUpdated: i_device];
-    [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
+    [[[[VLCMain sharedInstance] controls] fspanel] setVoutWasUpdated: i_device];
+    [[[[VLCMain sharedInstance] controls] fspanel] setActive: nil];
 
     fullscreen = YES;
 }
@@ -1139,15 +1133,16 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
 
     [NSScreen unblackoutScreens];
 
-    [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
+    [[[[VLCMain sharedInstance] controls] fspanel] setNonActive: nil];
     SetSystemUIMode( kUIModeNormal, kUIOptionAutoShowMenuBar);
+
     [self setFrame:initialFrame display:YES animate:YES];
     [self setMovableByWindowBackground: YES];
     if( var_GetBool( p_vout, "video-on-top" ) )
         [self setLevel: NSStatusWindowLevel];
 }
 
-- (id)getVoutView // FIXME Naming scheme!
+- (id)voutView
 {
     return o_view;
 }