]> git.sesse.net Git - vlc/blobdiff - modules/control/gestures.c
android_window: check subtitles bounds
[vlc] / modules / control / gestures.c
index bc4740547c4ac3553bccfbdaf84b987b1145a76b..2b40fc482632613a7b010ba1ce5b3d61b2b73e91 100644 (file)
@@ -34,6 +34,7 @@
 #include <vlc_interface.h>
 #include <vlc_vout.h>
 #include <vlc_playlist.h>
+#include <vlc_input.h>
 #include <assert.h>
 
 /*****************************************************************************
@@ -47,7 +48,7 @@ struct intf_sys_t
     bool                b_button_pressed;
     int                 i_last_x, i_last_y;
     unsigned int        i_pattern;
-    int                 i_num_gestures;
+    unsigned int        i_num_gestures;
     int                 i_threshold;
     int                 i_button_mask;
 };
@@ -76,11 +77,7 @@ static void Close  ( vlc_object_t * );
 #define BUTTON_LONGTEXT N_( \
     "Trigger button for mouse gestures." )
 
-#if defined (HAVE_MAEMO)
-# define BUTTON_DEFAULT "left"
-#else
-# define BUTTON_DEFAULT "right"
-#endif
+#define BUTTON_DEFAULT "left"
 
 static const char *const button_list[] = { "left", "middle", "right" };
 static const char *const button_list_text[] =
@@ -150,7 +147,7 @@ static int Open ( vlc_object_t *p_this )
 /*****************************************************************************
  * gesture: return a subpattern within a pattern
  *****************************************************************************/
-static int gesture( int i_pattern, int i_num )
+static inline unsigned gesture( unsigned i_pattern, unsigned i_num )
 {
     return ( i_pattern >> ( i_num * 4 ) ) & 0xF;
 }
@@ -166,11 +163,8 @@ static void Close ( vlc_object_t *p_this )
     /* Destroy the callbacks (the order matters!) */
     var_DelCallback( pl_Get(p_intf), "input-current", PlaylistEvent, p_intf );
 
-    if( p_sys->p_input )
-    {
+    if( p_sys->p_input != NULL )
         var_DelCallback( p_sys->p_input, "intf-event", InputEvent, p_intf );
-        vlc_object_release( p_sys->p_input );
-    }
 
     if( p_sys->p_vout )
     {
@@ -386,10 +380,10 @@ static int MovedEvent( vlc_object_t *p_this, char const *psz_var,
     {
         int i_horizontal = newval.coords.x - p_sys->i_last_x;
         int i_vertical = newval.coords.y - p_sys->i_last_y;
-        int pattern = 0;
+        unsigned int pattern = 0;
 
-        i_horizontal = i_horizontal / p_sys->i_threshold;
-        i_vertical = i_vertical / p_sys->i_threshold;
+        i_horizontal /= p_sys->i_threshold;
+        i_vertical /= p_sys->i_threshold;
 
         if( i_horizontal < 0 )
         {
@@ -416,7 +410,8 @@ static int MovedEvent( vlc_object_t *p_this, char const *psz_var,
         {
             p_sys->i_last_x = newval.coords.x;
             p_sys->i_last_y = newval.coords.y;
-            if( gesture( p_sys->i_pattern, p_sys->i_num_gestures - 1 )
+            if( p_sys->i_num_gestures > 0
+             && gesture( p_sys->i_pattern, p_sys->i_num_gestures - 1 )
                     != pattern )
             {
                 p_sys->i_pattern |= pattern << ( p_sys->i_num_gestures * 4 );
@@ -472,11 +467,6 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_var,
 
     switch( val.i_int )
     {
-      case INPUT_EVENT_DEAD:
-        vlc_object_release( p_input );
-        p_sys->p_input = NULL; /* FIXME: locking!! */
-        break;
-
       case INPUT_EVENT_VOUT:
         /* intf-event is serialized against itself and is the sole user of
          * p_sys->p_vout. So there is no need to acquire the lock currently. */
@@ -484,7 +474,7 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_var,
         {   /* /!\ Beware of lock inversion with var_DelCallback() /!\ */
             var_DelCallback( p_sys->p_vout, "mouse-moved", MovedEvent,
                              p_intf );
-            var_DelCallback( p_sys->p_vout, "mouse-clicked", ButtonEvent,
+            var_DelCallback( p_sys->p_vout, "mouse-button-down", ButtonEvent,
                              p_intf );
             vlc_object_release( p_sys->p_vout );
         }
@@ -494,7 +484,7 @@ static int InputEvent( vlc_object_t *p_this, char const *psz_var,
         {
             var_AddCallback( p_sys->p_vout, "mouse-moved", MovedEvent,
                              p_intf );
-            var_AddCallback( p_sys->p_vout, "mouse-clicked", ButtonEvent,
+            var_AddCallback( p_sys->p_vout, "mouse-button-down", ButtonEvent,
                              p_intf );
         }
         break;
@@ -509,10 +499,18 @@ static int PlaylistEvent( vlc_object_t *p_this, char const *psz_var,
     intf_sys_t *p_sys = p_intf->p_sys;
     input_thread_t *p_input = val.p_address;
 
-    (void) p_this; (void) psz_var; (void) oldval;
+    (void) p_this; (void) psz_var;
+
+    if( p_sys->p_input != NULL )
+    {
+        assert( p_sys->p_input == oldval.p_address );
+        var_DelCallback( p_sys->p_input, "intf-event", InputEvent, p_intf );
+    }
+
+    p_sys->p_input = p_input;
+
+    if( p_input != NULL )
+        var_AddCallback( p_input, "intf-event", InputEvent, p_intf );
 
-    var_AddCallback( p_input, "intf-event", InputEvent, p_intf );
-    assert( p_sys->p_input == NULL );
-    p_sys->p_input = vlc_object_hold( p_input );
     return VLC_SUCCESS;
 }