]> git.sesse.net Git - vlc/blobdiff - modules/video_output/sdl.c
Use gettext_noop() consistently
[vlc] / modules / video_output / sdl.c
index 0966b02fcb8343950c5a1d62fa598553bdfaf405..86a0da4e7bb85b596872c72c8bebf62b7bbed690 100644 (file)
  *****************************************************************************/
 #include <errno.h>                                                 /* ENOMEM */
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
+#include <vlc_plugin.h>
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include <vlc_vout.h>
@@ -59,15 +64,21 @@ 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 */
 
     /* For RGB output */
     int i_surfaces;
 
-    vlc_bool_t  b_cursor;
-    vlc_bool_t  b_cursor_autohidden;
+    bool  b_cursor;
+    bool  b_cursor_autohidden;
     mtime_t     i_lastmoved;
+    mtime_t     i_mouse_hide_timeout;
     mtime_t     i_lastpressed;                        /* to track dbl-clicks */
 };
 
@@ -113,10 +124,10 @@ vlc_module_begin();
     set_shortname( "SDL" );
     set_category( CAT_VIDEO );
     set_subcategory( SUBCAT_VIDEO_VOUT );
-    set_description( _("Simple DirectMedia Layer video output") );
+    set_description( N_("Simple DirectMedia Layer video output") );
     set_capability( "video output", 60 );
     add_shortcut( "sdl" );
-    add_string( "sdl-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, VLC_TRUE );
+    add_string( "sdl-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true );
     set_callbacks( Open, Close );
 #if defined( __i386__ ) || defined( __x86_64__ )
     /* On i386, SDL is linked against svgalib */
@@ -151,6 +162,7 @@ static int Open ( vlc_object_t *p_this )
         return VLC_ENOMEM;
     }
 
+    /* Check if SDL video module has been initialized */
     if( SDL_WasInit( SDL_INIT_VIDEO ) != 0 )
     {
         vlc_mutex_unlock( lock );
@@ -159,12 +171,12 @@ static int Open ( vlc_object_t *p_this )
     }
 
     /* Allocate structure */
-
     p_vout->pf_init = Init;
     p_vout->pf_end = End;
     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" );
@@ -188,7 +200,7 @@ static int Open ( vlc_object_t *p_this )
     /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
                 | SDL_INIT_EVENTTHREAD
 #endif
-#ifdef DEBUG
+#ifndef NDEBUG
     /* In debug mode you may want vlc to dump a core instead of staying
      * stuck */
                 | SDL_INIT_NOPARACHUTE
@@ -201,14 +213,24 @@ static int Open ( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
+    vlc_mutex_unlock( lock );
+
     /* Translate keys into unicode */
     SDL_EnableUNICODE(1);
 
-    vlc_mutex_unlock( lock );
+    /* 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();
+    p_vout->p_sys->i_mouse_hide_timeout =
+        var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;
 
     if( OpenDisplay( p_vout ) )
     {
@@ -346,8 +368,8 @@ static int Manage( vout_thread_t *p_vout )
     {
         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;
@@ -359,18 +381,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;
+            val.b_bool = 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 )
                 {
@@ -393,7 +433,7 @@ static int Manage( vout_thread_t *p_vout )
                 val.i_int &= ~1;
                 var_Set( p_vout, "mouse-button-down", val );
 
-                val.b_bool = VLC_TRUE;
+                val.b_bool = true;
                 var_Set( p_vout, "mouse-clicked", val );
                 break;
 
@@ -440,7 +480,7 @@ static int Manage( vout_thread_t *p_vout )
                     if( p_playlist != NULL )
                     {
                         vlc_value_t val;
-                        val.b_bool = VLC_TRUE;
+                        val.b_bool = true;
                         var_Set( p_playlist, "intf-popupmenu", val );
                         vlc_object_release( p_playlist );
                     }
@@ -493,13 +533,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;
                 }
             }
 
@@ -581,7 +629,8 @@ static int Manage( vout_thread_t *p_vout )
 
     /* Pointer change */
     if( ! p_vout->p_sys->b_cursor_autohidden &&
-        ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
+        ( mdate() - p_vout->p_sys->i_lastmoved >
+            p_vout->p_sys->i_mouse_hide_timeout ) )
     {
         /* Hide the mouse automatically */
         p_vout->p_sys->b_cursor_autohidden = 1;
@@ -707,10 +756,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;