]> git.sesse.net Git - vlc/blobdiff - modules/video_output/sdl.c
Revert the so-called whitelisting commits that are actually blacklisting
[vlc] / modules / video_output / sdl.c
index 376af5780bf12cb8090886f1b360d4910b93f158..30bc1bdf786e0a38a126318ad084833e12944eaf 100644 (file)
@@ -59,8 +59,10 @@ struct vout_sys_t
     int i_width;
     int i_height;
 
+#if SDL_VERSION_ATLEAST(1,2,10)
     unsigned int i_desktop_width;
     unsigned int i_desktop_height;
+#endif
 
     /* For YUV output */
     SDL_Overlay * p_overlay;   /* An overlay we keep to grab the XVideo port */
@@ -72,8 +74,6 @@ struct vout_sys_t
     vlc_bool_t  b_cursor_autohidden;
     mtime_t     i_lastmoved;
     mtime_t     i_lastpressed;                        /* to track dbl-clicks */
-
-    vlc_mutex_t lock;
 };
 
 /*****************************************************************************
@@ -156,8 +156,6 @@ static int Open ( vlc_object_t *p_this )
         return VLC_ENOMEM;
     }
 
-    vlc_mutex_init( p_vout, &p_vout->p_sys->lock );
-
     /* Check if SDL video module has been initialized */
     if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
     {
@@ -172,6 +170,7 @@ static int Open ( vlc_object_t *p_this )
     p_vout->pf_manage = Manage;
     p_vout->pf_render = NULL;
     p_vout->pf_display = Display;
+    p_vout->pf_control = NULL;
 
 #ifdef HAVE_SETENV
     psz_method = config_GetPsz( p_vout, "vout" );
@@ -214,12 +213,16 @@ static int Open ( vlc_object_t *p_this )
     SDL_EnableUNICODE(1);
 
     /* Get the desktop resolution */
+#if SDL_VERSION_ATLEAST(1,2,10)
+    /* FIXME: SDL has a problem with virtual desktop */
     p_vout->p_sys->i_desktop_width = SDL_GetVideoInfo()->current_w;
     p_vout->p_sys->i_desktop_height = SDL_GetVideoInfo()->current_h;
+#endif
 
+    /* Create the cursor */
     p_vout->p_sys->b_cursor = 1;
     p_vout->p_sys->b_cursor_autohidden = 0;
-    p_vout->p_sys->i_lastmoved = mdate();
+    p_vout->p_sys->i_lastmoved = p_vout->p_sys->i_lastpressed = mdate();
 
     if( OpenDisplay( p_vout ) )
     {
@@ -337,8 +340,6 @@ static void Close ( vlc_object_t *p_this )
     CloseDisplay( p_vout );
     SDL_QuitSubSystem( SDL_INIT_VIDEO );
 
-    vlc_mutex_destroy( &p_vout->p_sys->lock );
-
     free( p_vout->p_sys );
 }
 
@@ -354,15 +355,13 @@ static int Manage( vout_thread_t *p_vout )
     vlc_value_t val;
     unsigned int i_width, i_height, i_x, i_y;
 
-    vlc_mutex_lock( &p_vout->p_sys->lock );
-
     /* Process events */
     while( SDL_PollEvent( &event ) )
     {
         switch( event.type )
         {
-        case SDL_VIDEORESIZE:                          /* Resizing of window */
-            /* Update dimensions */
+        /* Resizing of window */
+        case SDL_VIDEORESIZE:
             p_vout->i_changes |= VOUT_SIZE_CHANGE;
             p_vout->i_window_width = p_vout->p_sys->i_width = event.resize.w;
             p_vout->i_window_height = p_vout->p_sys->i_height = event.resize.h;
@@ -374,18 +373,36 @@ static int Manage( vout_thread_t *p_vout )
                                p_vout->p_sys->i_height,
                                &i_x, &i_y, &i_width, &i_height );
 
-            val.i_int = ( event.motion.x - i_x )
-                         * p_vout->render.i_width / i_width;
+            /* Compute the x coordinate and check if the value is
+               in [0,p_vout->fmt_in.i_visible_width] */
+            val.i_int = ( event.motion.x - i_x ) *
+                        p_vout->fmt_in.i_visible_width / i_width +
+                        p_vout->fmt_in.i_x_offset;
+
+            if( (int)(event.motion.x - i_x) < 0 )
+                val.i_int = 0;
+            else if( (unsigned int)val.i_int > p_vout->fmt_in.i_visible_width )
+                val.i_int = p_vout->fmt_in.i_visible_width;
+
             var_Set( p_vout, "mouse-x", val );
-            val.i_int = ( event.motion.y - i_y )
-                         * p_vout->render.i_height / i_height;
+
+            /* compute the y coordinate and check if the value is
+               in [0,p_vout->fmt_in.i_visible_height] */
+            val.i_int = ( event.motion.y - i_y ) *
+                        p_vout->fmt_in.i_visible_height / i_height +
+                        p_vout->fmt_in.i_y_offset;
+
+            if( (int)(event.motion.y - i_y) < 0 )
+                val.i_int = 0;
+            else if( (unsigned int)val.i_int > p_vout->fmt_in.i_visible_height )
+                val.i_int = p_vout->fmt_in.i_visible_height;
+
             var_Set( p_vout, "mouse-y", val );
 
             val.b_bool = VLC_TRUE;
             var_Set( p_vout, "mouse-moved", val );
 
-            if( p_vout->p_sys->b_cursor &&
-                (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
+            if( p_vout->p_sys->b_cursor )
             {
                 if( p_vout->p_sys->b_cursor_autohidden )
                 {
@@ -508,13 +525,21 @@ static int Manage( vout_thread_t *p_vout )
 
         /* Key pressed */
         case SDL_KEYDOWN:
+            /* convert the key if possible */
             val.i_int = ConvertKey( event.key.keysym.sym );
 
             if( !val.i_int )
             {
+                /* Find the right caracter */
                 if( ( event.key.keysym.unicode & 0xff80 ) == 0 )
                 {
                     val.i_int = event.key.keysym.unicode & 0x7f;
+                    /* FIXME: find a better solution than this
+                              hack to find the right caracter */
+                    if( val.i_int >= 1 && val.i_int <= 26 )
+                        val.i_int += 96;
+                    else if( val.i_int >= 65 && val.i_int <= 90 )
+                        val.i_int += 32;
                 }
             }
 
@@ -603,8 +628,6 @@ static int Manage( vout_thread_t *p_vout )
         SDL_ShowCursor( 0 );
     }
 
-    vlc_mutex_unlock( &p_vout->p_sys->lock );
-
     return VLC_SUCCESS;
 }
 
@@ -684,8 +707,6 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic )
     unsigned int x, y, w, h;
     SDL_Rect disp;
 
-    vlc_mutex_lock( &p_vout->p_sys->lock );
-
     vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
                        &x, &y, &w, &h );
     disp.x = x;
@@ -705,8 +726,6 @@ static void Display( vout_thread_t *p_vout, picture_t *p_pic )
         SDL_DisplayYUVOverlay( p_pic->p_sys->p_overlay , &disp );
         SDL_LockYUVOverlay( p_pic->p_sys->p_overlay);
     }
-
-    vlc_mutex_unlock( &p_vout->p_sys->lock );
 }
 
 /* following functions are local */
@@ -728,10 +747,17 @@ static int OpenDisplay( vout_thread_t *p_vout )
     uint32_t i_chroma = 0;
 
     /* Set main window's size */
+#if SDL_VERSION_ATLEAST(1,2,10)
     p_vout->p_sys->i_width = p_vout->b_fullscreen ? p_vout->p_sys->i_desktop_width :
                                                     p_vout->i_window_width;
     p_vout->p_sys->i_height = p_vout->b_fullscreen ? p_vout->p_sys->i_desktop_height :
                                                      p_vout->i_window_height;
+#else
+    p_vout->p_sys->i_width = p_vout->b_fullscreen ? p_vout->output.i_width :
+                                                    p_vout->i_window_width;
+    p_vout->p_sys->i_height = p_vout->b_fullscreen ? p_vout->output.i_height :
+                                                     p_vout->i_window_height;
+#endif
 
     /* Initialize flags and cursor */
     i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;
@@ -746,8 +772,8 @@ static int OpenDisplay( vout_thread_t *p_vout )
     }
 
     p_vout->p_sys->p_display = SDL_SetVideoMode( p_vout->p_sys->i_width,
-                                                   p_vout->p_sys->i_height,
-                                                   i_bpp, i_flags );
+                                                 p_vout->p_sys->i_height,
+                                                 i_bpp, i_flags );
 
     if( p_vout->p_sys->p_display == NULL )
     {