Commit f2c77da9 authored by Rémi Duraffort's avatar Rémi Duraffort

improve sdl video output. If there is some stupidities feel free to revert. And Merry Christmas.

parent f0875028
...@@ -30,8 +30,10 @@ ...@@ -30,8 +30,10 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc_interface.h> #include <vlc_interface.h>
#include <vlc_playlist.h>
#include <vlc_vout.h> #include <vlc_vout.h>
#include <vlc_aout.h> #include <vlc_keys.h>
//#include <vlc_aout.h>
#include <sys/types.h> #include <sys/types.h>
#ifndef WIN32 #ifndef WIN32
...@@ -96,6 +98,9 @@ static int NewPicture ( vout_thread_t *, picture_t * ); ...@@ -96,6 +98,9 @@ static int NewPicture ( vout_thread_t *, picture_t * );
static void SetPalette ( vout_thread_t *, static void SetPalette ( vout_thread_t *,
uint16_t *, uint16_t *, uint16_t * ); uint16_t *, uint16_t *, uint16_t * );
static int ConvertKey( SDLKey );
#define CHROMA_TEXT N_("SDL chroma format") #define CHROMA_TEXT N_("SDL chroma format")
#define CHROMA_LONGTEXT N_( \ #define CHROMA_LONGTEXT N_( \
"Force the SDL renderer to use a specific chroma format instead of " \ "Force the SDL renderer to use a specific chroma format instead of " \
...@@ -196,6 +201,9 @@ static int Open ( vlc_object_t *p_this ) ...@@ -196,6 +201,9 @@ static int Open ( vlc_object_t *p_this )
return VLC_EGENERIC; return VLC_EGENERIC;
} }
/* Translate keys into unicode */
SDL_EnableUNICODE(1);
vlc_mutex_unlock( lock ); vlc_mutex_unlock( lock );
p_vout->p_sys->b_cursor = 1; p_vout->p_sys->b_cursor = 1;
...@@ -334,7 +342,7 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -334,7 +342,7 @@ static int Manage( vout_thread_t *p_vout )
unsigned int i_width, i_height, i_x, i_y; unsigned int i_width, i_height, i_x, i_y;
/* Process events */ /* Process events */
while( SDL_PollEvent(&event) ) while( SDL_PollEvent( &event ) )
{ {
switch( event.type ) switch( event.type )
{ {
...@@ -345,6 +353,7 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -345,6 +353,7 @@ static int Manage( vout_thread_t *p_vout )
p_vout->i_window_height = p_vout->p_sys->i_height = event.resize.h; p_vout->i_window_height = p_vout->p_sys->i_height = event.resize.h;
break; break;
/* Mouse move */
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
vout_PlacePicture( p_vout, p_vout->p_sys->i_width, vout_PlacePicture( p_vout, p_vout->p_sys->i_width,
p_vout->p_sys->i_height, p_vout->p_sys->i_height,
...@@ -375,17 +384,48 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -375,17 +384,48 @@ static int Manage( vout_thread_t *p_vout )
} }
break; break;
/* Mouse button pressed */
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
switch( event.button.button ) switch( event.button.button )
{ {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
var_Get( p_vout, "mouse-button-down", &val );
val.i_int &= ~1;
var_Set( p_vout, "mouse-button-down", val );
val.b_bool = VLC_TRUE; val.b_bool = VLC_TRUE;
var_Set( p_vout, "mouse-clicked", val ); var_Set( p_vout, "mouse-clicked", val );
break; break;
case SDL_BUTTON_MIDDLE:
{
playlist_t *p_playlist;
var_Get( p_vout, "mouse-button-down", &val );
val.i_int &= ~2;
var_Set( p_vout, "mouse-button-down", val );
p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist != NULL )
{
vlc_value_t val;
var_Get( p_playlist, "intf-show", &val );
val.b_bool = !val.b_bool;
var_Set( p_playlist, "intf-show", val );
vlc_object_release( p_playlist );
}
}
break;
case SDL_BUTTON_RIGHT: case SDL_BUTTON_RIGHT:
{ {
intf_thread_t *p_intf; intf_thread_t *p_intf;
playlist_t *p_playlist;
var_Get( p_vout, "mouse-button-down", &val );
val.i_int &= ~4;
var_Set( p_vout, "mous-button-down", val );
p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
FIND_ANYWHERE ); FIND_ANYWHERE );
if( p_intf ) if( p_intf )
...@@ -393,17 +433,30 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -393,17 +433,30 @@ static int Manage( vout_thread_t *p_vout )
p_intf->b_menu_change = 1; p_intf->b_menu_change = 1;
vlc_object_release( p_intf ); vlc_object_release( p_intf );
} }
p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
FIND_ANYWHERE );
if( p_playlist != NULL )
{
vlc_value_t val;
val.b_bool = VLC_TRUE;
var_Set( p_playlist, "intf-popupmenu", val );
vlc_object_release( p_playlist );
}
} }
break; break;
} }
break; break;
/* Mouse button released */
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
switch( event.button.button ) switch( event.button.button )
{ {
case SDL_BUTTON_LEFT: case SDL_BUTTON_LEFT:
/* In this part we will eventually manage var_Get( p_vout, "mouse-button-down", &val );
* clicks for DVD navigation for instance. */ val.i_int |= 1;
var_Set( p_vout, "mouse-button-down", val );
/* detect double-clicks */ /* detect double-clicks */
if( ( mdate() - p_vout->p_sys->i_lastpressed ) < 300000 ) if( ( mdate() - p_vout->p_sys->i_lastpressed ) < 300000 )
...@@ -412,118 +465,60 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -412,118 +465,60 @@ static int Manage( vout_thread_t *p_vout )
p_vout->p_sys->i_lastpressed = mdate(); p_vout->p_sys->i_lastpressed = mdate();
break; break;
case 4: case SDL_BUTTON_MIDDLE:
var_Get( p_vout, "mouse-button-down", &val );
val.i_int |= 2;
var_Set( p_vout, "mouse-button-down", val );
break; break;
case 5: case SDL_BUTTON_RIGHT:
var_Get( p_vout, "mouse-button-down", &val );
val.i_int |= 4;
var_Set( p_vout, "mouse-button-down", val );
break; break;
} }
break; break;
/* Quit event (close the window) */
case SDL_QUIT: case SDL_QUIT:
vlc_object_kill( p_vout->p_libvlc );
break;
case SDL_KEYDOWN: /* if a key is pressed */
switch( event.key.keysym.sym )
{ {
case SDLK_ESCAPE: playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
if( p_vout->b_fullscreen ) if( p_playlist != NULL )
{ {
p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; playlist_Stop( p_playlist );
vlc_object_release( p_playlist );
} }
else
{
vlc_object_kill( p_vout->p_libvlc );
} }
break; break;
case SDLK_q: /* quit */ /* Key pressed */
vlc_object_kill( p_vout->p_libvlc ); case SDL_KEYDOWN:
break; val.i_int = ConvertKey( event.key.keysym.sym );
case SDLK_f: /* switch to fullscreen */
p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
break;
case SDLK_c: /* toggle grayscale */ if( !val.i_int )
p_vout->b_grayscale = ! p_vout->b_grayscale;
p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
break;
case SDLK_i: /* toggle info */
p_vout->b_info = ! p_vout->b_info;
p_vout->i_changes |= VOUT_INFO_CHANGE;
break;
case SDLK_s: /* toggle scaling */
p_vout->b_scale = ! p_vout->b_scale;
p_vout->i_changes |= VOUT_SCALE_CHANGE;
break;
case SDLK_SPACE: /* toggle interface */
p_vout->b_interface = ! p_vout->b_interface;
p_vout->i_changes |= VOUT_INTF_CHANGE;
break;
case SDLK_MENU:
{ {
intf_thread_t *p_intf; if( ( event.key.keysym.unicode & 0xff80 ) == 0 )
p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
FIND_ANYWHERE );
if( p_intf != NULL )
{ {
p_intf->b_menu_change = 1; val.i_int = event.key.keysym.unicode & 0x7f;
vlc_object_release( p_intf );
} }
} }
break;
case SDLK_LEFT:
break;
case SDLK_RIGHT:
break;
case SDLK_UP:
break;
case SDLK_DOWN:
break;
case SDLK_b: if( val.i_int )
{ {
audio_volume_t i_volume; if( ( event.key.keysym.mod & KMOD_SHIFT ) )
if ( !aout_VolumeDown( p_vout, 1, &i_volume ) )
{ {
msg_Dbg( p_vout, "audio volume is now %d", i_volume ); val.i_int |= KEY_MODIFIER_SHIFT;
} }
else if( ( event.key.keysym.mod & KMOD_CTRL ) )
{ {
msg_Dbg( p_vout, "audio volume: operation not supported" ); val.i_int |= KEY_MODIFIER_CTRL;
}
} }
break; if( ( event.key.keysym.mod & KMOD_ALT ) )
case SDLK_n:
{
audio_volume_t i_volume;
if ( !aout_VolumeUp( p_vout, 1, &i_volume ) )
{ {
msg_Dbg( p_vout, "audio volume is now %d", i_volume ); val.i_int |= KEY_MODIFIER_ALT;
}
else
{
msg_Dbg( p_vout, "audio volume: operation not supported" );
} }
var_Set( p_vout->p_libvlc, "key-pressed", val );
} }
break;
default:
break;
}
break;
default: default:
break; break;
...@@ -533,7 +528,14 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -533,7 +528,14 @@ static int Manage( vout_thread_t *p_vout )
/* Fullscreen change */ /* Fullscreen change */
if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE ) if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
{ {
p_vout->b_fullscreen = ! p_vout->b_fullscreen; vlc_value_t val_fs;
/* Update the object variable and trigger callback */
val_fs.b_bool = !p_vout->b_fullscreen;
p_vout->b_fullscreen = !p_vout->b_fullscreen;
var_Set( p_vout, "fullscreen", val_fs );
/*TODO: add the always on top code !*/
p_vout->p_sys->b_cursor_autohidden = 0; p_vout->p_sys->b_cursor_autohidden = 0;
SDL_ShowCursor( p_vout->p_sys->b_cursor && SDL_ShowCursor( p_vout->p_sys->b_cursor &&
...@@ -543,9 +545,7 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -543,9 +545,7 @@ static int Manage( vout_thread_t *p_vout )
p_vout->i_changes |= VOUT_SIZE_CHANGE; p_vout->i_changes |= VOUT_SIZE_CHANGE;
} }
/* /* Size change */
* Size change
*/
if( p_vout->i_changes & VOUT_SIZE_CHANGE ) if( p_vout->i_changes & VOUT_SIZE_CHANGE )
{ {
msg_Dbg( p_vout, "video display resized (%dx%d)", msg_Dbg( p_vout, "video display resized (%dx%d)",
...@@ -573,6 +573,72 @@ static int Manage( vout_thread_t *p_vout ) ...@@ -573,6 +573,72 @@ static int Manage( vout_thread_t *p_vout )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
/*****************************************************************************
* Key events handling
*****************************************************************************/
static struct
{
SDLKey sdl_key;
int i_vlckey;
} sdlkeys_to_vlckeys[] =
{
{ SDLK_F1, KEY_F1 },
{ SDLK_F2, KEY_F2 },
{ SDLK_F3, KEY_F3 },
{ SDLK_F4, KEY_F4 },
{ SDLK_F5, KEY_F5 },
{ SDLK_F6, KEY_F6 },
{ SDLK_F7, KEY_F7 },
{ SDLK_F8, KEY_F8 },
{ SDLK_F9, KEY_F9 },
{ SDLK_F10, KEY_F10 },
{ SDLK_F11, KEY_F11 },
{ SDLK_F12, KEY_F12 },
{ SDLK_RETURN, KEY_ENTER },
{ SDLK_KP_ENTER, KEY_ENTER },
{ SDLK_SPACE, KEY_SPACE },
{ SDLK_ESCAPE, KEY_ESC },
{ SDLK_MENU, KEY_MENU },
{ SDLK_LEFT, KEY_LEFT },
{ SDLK_RIGHT, KEY_RIGHT },
{ SDLK_UP, KEY_UP },
{ SDLK_DOWN, KEY_DOWN },
{ SDLK_HOME, KEY_HOME },
{ SDLK_END, KEY_END },
{ SDLK_PAGEUP, KEY_PAGEUP },
{ SDLK_PAGEDOWN, KEY_PAGEDOWN },
{ SDLK_INSERT, KEY_INSERT },
{ SDLK_DELETE, KEY_DELETE },
/*TODO: find a equivalent for SDL
{ , KEY_MEDIA_NEXT_TRACK }
{ , KEY_MEDIA_PREV_TRACK }
{ , KEY_VOLUME_MUTE }
{ , KEY_VOLUME_DOWN }
{ , KEY_VOLUME_UP }
{ , KEY_MEDIA_PLAY_PAUSE }
{ , KEY_MEDIA_PLAY_PAUSE }*/
{ 0, 0 }
};
static int ConvertKey( SDLKey sdl_key )
{
int i;
for( i=0; sdlkeys_to_vlckeys[i].sdl_key != 0; i++ )
{
if( sdlkeys_to_vlckeys[i].sdl_key == sdl_key )
{
return sdlkeys_to_vlckeys[i].i_vlckey;
}
}
return 0;
}
/***************************************************************************** /*****************************************************************************
* Display: displays previously rendered output * Display: displays previously rendered output
***************************************************************************** *****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment