]> git.sesse.net Git - vlc/blob - modules/control/hotkeys.c
* Remove Advanced/Misc
[vlc] / modules / control / hotkeys.c
1 /*****************************************************************************
2  * hotkeys.c: Hotkey handling for vlc
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8  *          Jean-Paul Saman <jpsaman #_at_# m2x.nl>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29
30 #include <vlc/vlc.h>
31 #include <vlc/intf.h>
32 #include <vlc/input.h>
33 #include <vlc/vout.h>
34 #include <vlc/aout.h>
35 #include <vlc_osd.h>
36
37 #include "vlc_keys.h"
38
39 #define BUFFER_SIZE 10
40
41 #define CHANNELS_NUMBER 4
42 #define VOLUME_TEXT_CHAN     p_intf->p_sys->p_channels[ 0 ]
43 #define VOLUME_WIDGET_CHAN   p_intf->p_sys->p_channels[ 1 ]
44 #define POSITION_TEXT_CHAN   p_intf->p_sys->p_channels[ 2 ]
45 #define POSITION_WIDGET_CHAN p_intf->p_sys->p_channels[ 3 ]
46 /*****************************************************************************
47  * intf_sys_t: description and status of FB interface
48  *****************************************************************************/
49 struct intf_sys_t
50 {
51     vlc_mutex_t         change_lock;  /* mutex to keep the callback
52                                        * and the main loop from
53                                        * stepping on each others
54                                        * toes */
55     int                 p_keys[ BUFFER_SIZE ]; /* buffer that contains
56                                                 * keyevents */
57     int                 i_size;        /* number of events in buffer */
58     int                 p_channels[ CHANNELS_NUMBER ]; /* contains registered
59                                                         * channel IDs */
60     input_thread_t *    p_input;       /* pointer to input */
61     vout_thread_t *     p_vout;        /* pointer to vout object */
62 };
63
64 /*****************************************************************************
65  * Local prototypes
66  *****************************************************************************/
67 static int  Open    ( vlc_object_t * );
68 static void Close   ( vlc_object_t * );
69 static void Run     ( intf_thread_t * );
70 static int  GetKey  ( intf_thread_t *);
71 static int  KeyEvent( vlc_object_t *, char const *,
72                       vlc_value_t, vlc_value_t, void * );
73 static int  ActionKeyCB( vlc_object_t *, char const *,
74                          vlc_value_t, vlc_value_t, void * );
75 static void PlayBookmark( intf_thread_t *, int );
76 static void SetBookmark ( intf_thread_t *, int );
77 static void DisplayPosition( intf_thread_t *, vout_thread_t *, input_thread_t * );
78 static void DisplayVolume  ( intf_thread_t *, vout_thread_t *, audio_volume_t );
79 static void ClearChannels  ( intf_thread_t *, vout_thread_t * );
80
81 /*****************************************************************************
82  * Module descriptor
83  *****************************************************************************/
84 #define BOOKMARK1_TEXT N_("Playlist bookmark 1")
85 #define BOOKMARK2_TEXT N_("Playlist bookmark 2")
86 #define BOOKMARK3_TEXT N_("Playlist bookmark 3")
87 #define BOOKMARK4_TEXT N_("Playlist bookmark 4")
88 #define BOOKMARK5_TEXT N_("Playlist bookmark 5")
89 #define BOOKMARK6_TEXT N_("Playlist bookmark 6")
90 #define BOOKMARK7_TEXT N_("Playlist bookmark 7")
91 #define BOOKMARK8_TEXT N_("Playlist bookmark 8")
92 #define BOOKMARK9_TEXT N_("Playlist bookmark 9")
93 #define BOOKMARK10_TEXT N_("Playlist bookmark 10")
94 #define BOOKMARK_LONGTEXT N_( \
95     "This option allows you to define playlist bookmarks.")
96
97 vlc_module_begin();
98     set_shortname( _("Hotkeys") );
99     set_description( _("Hotkeys management interface") );
100     set_capability( "interface", 0 );
101     set_callbacks( Open, Close );
102 vlc_module_end();
103
104 /*****************************************************************************
105  * Open: initialize interface
106  *****************************************************************************/
107 static int Open( vlc_object_t *p_this )
108 {
109     intf_thread_t *p_intf = (intf_thread_t *)p_this;
110
111     /* Allocate instance and initialize some members */
112     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
113     if( p_intf->p_sys == NULL )
114     {
115         msg_Err( p_intf, "out of memory" );
116         return 1;
117     }
118     vlc_mutex_init( p_intf, &p_intf->p_sys->change_lock );
119     p_intf->p_sys->i_size = 0;
120     p_intf->pf_run = Run;
121
122     p_intf->p_sys->p_input = NULL;
123     p_intf->p_sys->p_vout = NULL;
124
125     var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
126     return 0;
127 }
128
129 /*****************************************************************************
130  * Close: destroy interface
131  *****************************************************************************/
132 static void Close( vlc_object_t *p_this )
133 {
134     intf_thread_t *p_intf = (intf_thread_t *)p_this;
135
136     var_DelCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
137     if( p_intf->p_sys->p_input )
138     {
139         vlc_object_release( p_intf->p_sys->p_input );
140     }
141     if( p_intf->p_sys->p_vout )
142     {
143         vlc_object_release( p_intf->p_sys->p_vout );
144     }
145     /* Destroy structure */
146     free( p_intf->p_sys );
147 }
148
149 /*****************************************************************************
150  * Run: main loop
151  *****************************************************************************/
152 static void Run( intf_thread_t *p_intf )
153 {
154     playlist_t *p_playlist = NULL;
155     input_thread_t *p_input = NULL;
156     vout_thread_t *p_vout = NULL;
157     vout_thread_t *p_last_vout = NULL;
158     struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
159     vlc_value_t val;
160     int i;
161
162     /* Initialize hotkey structure */
163     for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
164     {
165         var_Create( p_intf->p_vlc, p_hotkeys[i].psz_action,
166                     VLC_VAR_HOTKEY | VLC_VAR_DOINHERIT );
167
168         var_AddCallback( p_intf->p_vlc, p_hotkeys[i].psz_action,
169                          ActionKeyCB, NULL );
170         var_Get( p_intf->p_vlc, p_hotkeys[i].psz_action, &val );
171         var_Set( p_intf->p_vlc, p_hotkeys[i].psz_action, val );
172     }
173
174     while( !p_intf->b_die )
175     {
176         int i_key, i_action;
177         int i_times = 0;
178
179         /* Sleep a bit */
180         msleep( INTF_IDLE_SLEEP );
181
182         /* Update the input */
183         if( p_intf->p_sys->p_input == NULL )
184         {
185             p_playlist = (playlist_t *)vlc_object_find( p_intf,
186                                          VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
187             if( p_playlist )
188             {
189                 p_intf->p_sys->p_input = p_playlist->p_input;
190                 if( p_intf->p_sys->p_input )
191                     vlc_object_yield( p_intf->p_sys->p_input );
192                 vlc_object_release( p_playlist );
193             }
194         }
195         else if( p_intf->p_sys->p_input->b_dead )
196         {
197             vlc_object_release( p_intf->p_sys->p_input );
198             p_intf->p_sys->p_input = NULL;
199         }
200         p_input = p_intf->p_sys->p_input;
201
202         /* Update the vout */
203         p_last_vout = p_intf->p_sys->p_vout;
204         if( p_vout == NULL )
205         {
206             p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
207             p_intf->p_sys->p_vout = p_vout;
208         }
209         else if( p_vout->b_die )
210         {
211             vlc_object_release( p_vout );
212             p_vout = NULL;
213             p_intf->p_sys->p_vout = NULL;
214         }
215
216         /* Register OSD channels */
217         if( p_vout && p_vout != p_last_vout )
218         {
219             for( i = 0; i < CHANNELS_NUMBER; i++ )
220             {
221                 spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER,
222                              &p_intf->p_sys->p_channels[ i ] );
223             }
224         }
225
226         /* Find action triggered by hotkey */
227         i_action = 0;
228         i_key = GetKey( p_intf );
229         for( i = 0; i_key != -1 && p_hotkeys[i].psz_action != NULL; i++ )
230         {
231             if( p_hotkeys[i].i_key == i_key )
232             {
233                 i_action = p_hotkeys[i].i_action;
234                 i_times  = p_hotkeys[i].i_times; /* times key pressed within max. delta time */
235                 p_hotkeys[i].i_times = 0;
236             }
237         }
238
239         if( !i_action )
240         {
241             /* No key pressed, sleep a bit more */
242             msleep( INTF_IDLE_SLEEP );
243             continue;
244         }
245
246         if( i_action == ACTIONID_QUIT )
247         {
248             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
249                                     FIND_ANYWHERE );
250             if( p_playlist )
251             {
252                 playlist_Stop( p_playlist );
253                 vlc_object_release( p_playlist );
254             }
255             /* Playlist is stopped now kill vlc. */
256             p_intf->p_vlc->b_die = VLC_TRUE;
257             ClearChannels( p_intf, p_vout );
258             vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Quit" ) );
259             continue;
260         }
261         else if( i_action == ACTIONID_VOL_UP )
262         {
263             audio_volume_t i_newvol;
264             aout_VolumeUp( p_intf, 1, &i_newvol );
265             DisplayVolume( p_intf, p_vout, i_newvol );
266         }
267         else if( i_action == ACTIONID_VOL_DOWN )
268         {
269             audio_volume_t i_newvol;
270             aout_VolumeDown( p_intf, 1, &i_newvol );
271             DisplayVolume( p_intf, p_vout, i_newvol );
272         }
273         else if( i_action == ACTIONID_VOL_MUTE )
274         {
275             audio_volume_t i_newvol = -1;
276             aout_VolumeMute( p_intf, &i_newvol );
277             if( p_vout )
278             {
279                 if( i_newvol == 0 )
280                 {
281                     ClearChannels( p_intf, p_vout );
282                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
283                                   OSD_MUTE_ICON );
284                 }
285                 else
286                 {
287                     DisplayVolume( p_intf, p_vout, i_newvol );
288                 }
289             }
290         }
291         else if( i_action == ACTIONID_INTF_SHOW )
292         {
293             val.b_bool = VLC_TRUE;
294             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
295                                           FIND_ANYWHERE );
296             if( p_playlist )
297             {
298                 var_Set( p_playlist, "intf-show", val );
299                 vlc_object_release( p_playlist );
300             }
301         }
302         else if( i_action == ACTIONID_INTF_HIDE )
303         {
304             val.b_bool = VLC_FALSE;
305             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
306                                           FIND_ANYWHERE );
307             if( p_playlist )
308             {
309                 var_Set( p_playlist, "intf-show", val );
310                 vlc_object_release( p_playlist );
311             }
312         }
313         else if( i_action == ACTIONID_SNAPSHOT )
314         {
315             if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
316         }
317         else if( i_action == ACTIONID_FULLSCREEN )
318         {
319             if( p_vout )
320             {
321                 var_Get( p_vout, "fullscreen", &val ); val.b_bool = !val.b_bool;
322                 var_Set( p_vout, "fullscreen", val );
323             }
324             else
325             {
326                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
327                                           FIND_ANYWHERE );
328                 if( p_playlist )
329                 {
330                     var_Get( p_playlist, "fullscreen", &val ); val.b_bool = !val.b_bool;
331                     var_Set( p_playlist, "fullscreen", val );
332                     vlc_object_release( p_playlist );
333                 }
334             }
335         }
336         else if( i_action == ACTIONID_PLAY_PAUSE )
337         {
338             val.i_int = PLAYING_S;
339             if( p_input )
340             {
341                 var_Get( p_input, "state", &val );
342             }
343             if( p_input && val.i_int != PAUSE_S )
344             {
345                 ClearChannels( p_intf, p_vout );
346                 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
347                               OSD_PAUSE_ICON );
348                 val.i_int = PAUSE_S;
349                 var_Set( p_input, "state", val );
350             }
351             else
352             {
353                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
354                                               FIND_ANYWHERE );
355                 if( p_playlist )
356                 {
357                     ClearChannels( p_intf, p_vout );
358                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
359                                   OSD_PLAY_ICON );
360                     playlist_Play( p_playlist );
361                     vlc_object_release( p_playlist );
362                 }
363             }
364         }
365         else if( p_input )
366         {
367             /* FIXME --fenrir
368              * How to get a valid value ?
369              * That's not that easy with some special stream
370              */
371             vlc_bool_t b_seekable = VLC_TRUE;
372             int i_interval =0;
373
374             if( i_action == ACTIONID_PAUSE )
375             {
376                 ClearChannels( p_intf, p_vout );
377                 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
378                               OSD_PAUSE_ICON );
379                 val.i_int = PAUSE_S;
380                 var_Set( p_input, "state", val );
381             }
382             else if( i_action == ACTIONID_JUMP_BACKWARD_EXTRASHORT && b_seekable )
383             {
384 #define SET_TIME( a, b ) \
385     i_interval = config_GetInt( p_input, a "-jump-size" ); \
386     if( i_interval > 0 ) { \
387         val.i_time = ( (mtime_t)(i_interval * b) * 1000000L \
388                        * ((mtime_t)(1 << i_times))); \
389         var_Set( p_input, "time-offset", val ); \
390         DisplayPosition( p_intf, p_vout, p_input ); \
391     }
392                 SET_TIME( "extrashort", -1 );
393             }
394             else if( i_action == ACTIONID_JUMP_FORWARD_EXTRASHORT && b_seekable )
395             {
396                 SET_TIME( "extrashort", 1 );
397             }
398             else if( i_action == ACTIONID_JUMP_BACKWARD_SHORT && b_seekable )
399             {
400                 SET_TIME( "short", -1 );
401             }
402             else if( i_action == ACTIONID_JUMP_FORWARD_SHORT && b_seekable )
403             {
404                 SET_TIME( "short", 1 );
405             }
406             else if( i_action == ACTIONID_JUMP_BACKWARD_MEDIUM && b_seekable )
407             {
408                 SET_TIME( "medium", -1 );
409             }
410             else if( i_action == ACTIONID_JUMP_FORWARD_MEDIUM && b_seekable )
411             {
412                 SET_TIME( "medium", 1 );
413             }
414             else if( i_action == ACTIONID_JUMP_BACKWARD_LONG && b_seekable )
415             {
416                 SET_TIME( "long", -1 );
417             }
418             else if( i_action == ACTIONID_JUMP_FORWARD_LONG && b_seekable )
419             {
420                 SET_TIME( "long", 1 );
421 #undef SET_TIME
422             }
423             else if( i_action == ACTIONID_AUDIO_TRACK )
424             {
425                 vlc_value_t val, list, list2;
426                 int i_count, i;
427                 var_Get( p_input, "audio-es", &val );
428                 var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
429                             &list, &list2 );
430                 i_count = list.p_list->i_count;
431                 if( i_count <= 1 )
432                 {
433                     continue;
434                 }
435                 for( i = 0; i < i_count; i++ )
436                 {
437                     if( val.i_int == list.p_list->p_values[i].i_int )
438                     {
439                         break;
440                     }
441                 }
442                 /* value of audio-es was not in choices list */
443                 if( i == i_count )
444                 {
445                     msg_Warn( p_input,
446                               "invalid current audio track, selecting 0" );
447                     var_Set( p_input, "audio-es",
448                              list.p_list->p_values[0] );
449                     i = 0;
450                 }
451                 else if( i == i_count - 1 )
452                 {
453                     var_Set( p_input, "audio-es",
454                              list.p_list->p_values[1] );
455                     i = 1;
456                 }
457                 else
458                 {
459                     var_Set( p_input, "audio-es",
460                              list.p_list->p_values[i+1] );
461                     i++;
462                 }
463                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
464                                  _("Audio track: %s"),
465                                  list2.p_list->p_values[i].psz_string );
466             }
467             else if( i_action == ACTIONID_SUBTITLE_TRACK )
468             {
469                 vlc_value_t val, list, list2;
470                 int i_count, i;
471                 var_Get( p_input, "spu-es", &val );
472
473                 var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
474                             &list, &list2 );
475                 i_count = list.p_list->i_count;
476                 if( i_count <= 1 )
477                 {
478                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Subtitle track: %s"), _("N/A") );
479                     continue;
480                 }
481                 for( i = 0; i < i_count; i++ )
482                 {
483                     if( val.i_int == list.p_list->p_values[i].i_int )
484                     {
485                         break;
486                     }
487                 }
488                 /* value of spu-es was not in choices list */
489                 if( i == i_count )
490                 {
491                     msg_Warn( p_input, "invalid current subtitle track, selecting 0" );
492                     var_Set( p_input, "spu-es", list.p_list->p_values[0] );
493                     i = 0;
494                 }
495                 else if( i == i_count - 1 )
496                 {
497                     var_Set( p_input, "spu-es", list.p_list->p_values[0] );
498                     i = 0;
499                 }
500                 else
501                 {
502                     var_Set( p_input, "spu-es", list.p_list->p_values[i+1] );
503                     i = i + 1;
504                 }
505                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
506                                  _("Subtitle track: %s"),
507                                  list2.p_list->p_values[i].psz_string );
508             }
509             else if( i_action == ACTIONID_ASPECT_RATIO )
510             {
511                 vlc_value_t val={0}, val_list, text_list;
512                 var_Get( p_vout, "aspect-ratio", &val );
513                 if( var_Change( p_vout, "aspect-ratio", VLC_VAR_GETLIST,
514                                 &val_list, &text_list ) >= 0 )
515                 {
516                     int i;
517                     for( i = 0; i < val_list.p_list->i_count; i++ )
518                     {
519                         if( !strcmp( val_list.p_list->p_values[i].psz_string,
520                                      val.psz_string ) )
521                         {
522                             i++;
523                             break;
524                         }
525                     }
526                     if( i == val_list.p_list->i_count ) i = 0;
527                     var_SetString( p_vout, "aspect-ratio",
528                                    val_list.p_list->p_values[i].psz_string );
529                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
530                                      _("Aspect ratio: %s"),
531                                      text_list.p_list->p_values[i].psz_string );
532                 }
533                 free( val.psz_string );
534             }
535             else if( i_action == ACTIONID_CROP )
536             {
537                 vlc_value_t val={0}, val_list, text_list;
538                 var_Get( p_vout, "crop", &val );
539                 if( var_Change( p_vout, "crop", VLC_VAR_GETLIST,
540                                 &val_list, &text_list ) >= 0 )
541                 {
542                     int i;
543                     for( i = 0; i < val_list.p_list->i_count; i++ )
544                     {
545                         if( !strcmp( val_list.p_list->p_values[i].psz_string,
546                                      val.psz_string ) )
547                         {
548                             i++;
549                             break;
550                         }
551                     }
552                     if( i == val_list.p_list->i_count ) i = 0;
553                     var_SetString( p_vout, "crop",
554                                    val_list.p_list->p_values[i].psz_string );
555                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
556                                      _("Crop: %s"),
557                                      text_list.p_list->p_values[i].psz_string );
558                 }
559                 free( val.psz_string );
560             }
561             else if( i_action == ACTIONID_DEINTERLACE )
562             {
563                 vlc_value_t val={0}, val_list, text_list;
564                 var_Get( p_vout, "deinterlace", &val );
565                 if( var_Change( p_vout, "deinterlace", VLC_VAR_GETLIST,
566                                 &val_list, &text_list ) >= 0 )
567                 {
568                     int i;
569                     for( i = 0; i < val_list.p_list->i_count; i++ )
570                     {
571                         if( !strcmp( val_list.p_list->p_values[i].psz_string,
572                                      val.psz_string ) )
573                         {
574                             i++;
575                             break;
576                         }
577                     }
578                     if( i == val_list.p_list->i_count ) i = 0;
579                     var_SetString( p_vout, "deinterlace",
580                                    val_list.p_list->p_values[i].psz_string );
581                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
582                                      _("Deinterlace mode: %s"),
583                                      text_list.p_list->p_values[i].psz_string );
584                 }
585                 free( val.psz_string );
586             }
587             else if( i_action == ACTIONID_NEXT )
588             {
589                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
590                                               FIND_ANYWHERE );
591                 if( p_playlist )
592                 {
593                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Next") );
594                     playlist_Next( p_playlist );
595                     vlc_object_release( p_playlist );
596                 }
597             }
598             else if( i_action == ACTIONID_PREV )
599             {
600                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
601                                               FIND_ANYWHERE );
602                 if( p_playlist )
603                 {
604                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Previous") );
605                     playlist_Prev( p_playlist );
606                     vlc_object_release( p_playlist );
607                 }
608             }
609             else if( i_action == ACTIONID_STOP )
610             {
611                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
612                                               FIND_ANYWHERE );
613                 if( p_playlist )
614                 {
615                     playlist_Stop( p_playlist );
616                     vlc_object_release( p_playlist );
617                 }
618             }
619             else if( i_action == ACTIONID_FASTER )
620             {
621                 vlc_value_t val;
622                 val.b_bool = VLC_TRUE;
623                 var_Set( p_input, "rate-faster", val );
624                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Faster") );
625             }
626             else if( i_action == ACTIONID_SLOWER )
627             {
628                 vlc_value_t val;
629                 val.b_bool = VLC_TRUE;
630                 var_Set( p_input, "rate-slower", val );
631                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Slower") );
632             }
633             else if( i_action == ACTIONID_POSITION && b_seekable )
634             {
635                 DisplayPosition( p_intf, p_vout, p_input );
636             }
637             else if( i_action >= ACTIONID_PLAY_BOOKMARK1 &&
638                      i_action <= ACTIONID_PLAY_BOOKMARK10 )
639             {
640                 PlayBookmark( p_intf, i_action - ACTIONID_PLAY_BOOKMARK1 + 1 );
641             }
642             else if( i_action >= ACTIONID_SET_BOOKMARK1 &&
643                      i_action <= ACTIONID_SET_BOOKMARK10 )
644             {
645                 SetBookmark( p_intf, i_action - ACTIONID_SET_BOOKMARK1 + 1 );
646             }
647             /* Only makes sense with DVD */
648             else if( i_action == ACTIONID_TITLE_PREV )
649             {
650                 val.b_bool = VLC_TRUE;
651                 var_Set( p_input, "prev-title", val );
652             }
653             else if( i_action == ACTIONID_TITLE_NEXT )
654             {
655                 val.b_bool = VLC_TRUE;
656                 var_Set( p_input, "next-title", val );
657             }
658             else if( i_action == ACTIONID_CHAPTER_PREV )
659             {
660                 val.b_bool = VLC_TRUE;
661                 var_Set( p_input, "prev-chapter", val );
662             }
663             else if( i_action == ACTIONID_CHAPTER_NEXT )
664             {
665                 val.b_bool = VLC_TRUE;
666                 var_Set( p_input, "next-chapter", val );
667             }
668             else if( i_action == ACTIONID_DISC_MENU )
669             {
670                 vlc_value_t val; val.i_int = 2;
671 msg_Dbg( p_input, "set dvdmenu" );
672                 var_Set( p_input, "title  0", val);
673             }
674             else if( i_action == ACTIONID_SUBDELAY_DOWN )
675             {
676                 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
677
678                 i_delay -= 50000;    /* 50 ms */
679
680                 var_SetTime( p_input, "spu-delay", i_delay );
681                 ClearChannels( p_intf, p_vout );
682                 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
683                                  (int)(i_delay/1000) );
684             }
685             else if( i_action == ACTIONID_SUBDELAY_UP )
686             {
687                 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
688
689                 i_delay += 50000;    /* 50 ms */
690
691                 var_SetTime( p_input, "spu-delay", i_delay );
692                 ClearChannels( p_intf, p_vout );
693                 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
694                                  (int)(i_delay/1000) );
695             }
696             else if( i_action == ACTIONID_AUDIODELAY_DOWN )
697             {
698                 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
699
700                 i_delay -= 50000;    /* 50 ms */
701
702                 var_SetTime( p_input, "audio-delay", i_delay );
703                 ClearChannels( p_intf, p_vout );
704                 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
705                                  (int)(i_delay/1000) );
706             }
707             else if( i_action == ACTIONID_AUDIODELAY_UP )
708             {
709                 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
710
711                 i_delay += 50000;    /* 50 ms */
712
713                 var_SetTime( p_input, "audio-delay", i_delay );
714                 ClearChannels( p_intf, p_vout );
715                 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
716                                  (int)(i_delay/1000) );
717             }
718             else if( i_action == ACTIONID_PLAY )
719             {
720                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
721                                               FIND_ANYWHERE );
722                 if( p_playlist )
723                 {
724                     var_Get( p_input, "rate", &val );
725                     msg_Dbg( p_input, "rate %d", val.i_int );
726                     if( val.i_int != INPUT_RATE_DEFAULT )
727                     {
728                         /* Return to normal speed */
729                         val.i_int = INPUT_RATE_DEFAULT;
730                         var_Set( p_input, "rate", val );
731                     }
732                     else
733                     {
734                         ClearChannels( p_intf, p_vout );
735                         vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
736                                       OSD_PAUSE_ICON );
737                         playlist_Play( p_playlist );
738                     }
739                     vlc_object_release( p_playlist );
740                 }
741             }
742         }
743     }
744 }
745
746 static int GetKey( intf_thread_t *p_intf)
747 {
748     vlc_mutex_lock( &p_intf->p_sys->change_lock );
749     if ( p_intf->p_sys->i_size == 0 )
750     {
751         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
752         return -1;
753     }
754     else
755     {
756         int i_return = p_intf->p_sys->p_keys[ 0 ];
757         int i;
758         p_intf->p_sys->i_size--;
759         for ( i = 0; i < BUFFER_SIZE - 1; i++)
760         {
761             p_intf->p_sys->p_keys[ i ] = p_intf->p_sys->p_keys[ i + 1 ];
762         }
763         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
764         return i_return;
765     }
766 }
767
768 /*****************************************************************************
769  * KeyEvent: callback for keyboard events
770  *****************************************************************************/
771 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
772                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
773 {
774     intf_thread_t *p_intf = (intf_thread_t *)p_data;
775     vlc_mutex_lock( &p_intf->p_sys->change_lock );
776     if ( p_intf->p_sys->i_size == BUFFER_SIZE )
777     {
778         msg_Warn( p_intf, "event buffer full, dropping keypress" );
779         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
780         return VLC_EGENERIC;
781     }
782     else
783     {
784         p_intf->p_sys->p_keys[ p_intf->p_sys->i_size ] = newval.i_int;
785         p_intf->p_sys->i_size++;
786     }
787     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
788
789     return VLC_SUCCESS;
790 }
791
792 static int ActionKeyCB( vlc_object_t *p_this, char const *psz_var,
793                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
794 {
795     vlc_t *p_vlc = (vlc_t *)p_this;
796     struct hotkey *p_hotkeys = p_vlc->p_hotkeys;
797     mtime_t i_date;
798     int i;
799
800     for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
801     {
802         if( !strcmp( p_hotkeys[i].psz_action, psz_var ) )
803         {
804             p_hotkeys[i].i_key = newval.i_int;
805             /* do hotkey accounting */
806             i_date = mdate();
807             if( (p_hotkeys[i].i_delta_date > 0) &&
808                 (p_hotkeys[i].i_delta_date <= (i_date - p_hotkeys[i].i_last_date) ) )
809                 p_hotkeys[i].i_times = 0;
810             else
811                 p_hotkeys[i].i_times++;
812             p_hotkeys[i].i_last_date = i_date;
813         }
814     }
815
816     return VLC_SUCCESS;
817 }
818
819 static void PlayBookmark( intf_thread_t *p_intf, int i_num )
820 {
821     vlc_value_t val;
822     int i_position;
823     char psz_bookmark_name[11];
824     playlist_t *p_playlist =
825         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
826
827     sprintf( psz_bookmark_name, "bookmark%i", i_num );
828     var_Create( p_intf, psz_bookmark_name, VLC_VAR_STRING|VLC_VAR_DOINHERIT );
829     var_Get( p_intf, psz_bookmark_name, &val );
830
831     if( p_playlist )
832     {
833         char *psz_bookmark = strdup( val.psz_string );
834         for( i_position = 0; i_position < p_playlist->i_size; i_position++)
835         {
836             if( !strcmp( psz_bookmark,
837                          p_playlist->pp_items[i_position]->input.psz_uri ) )
838             {
839                 playlist_Goto( p_playlist, i_position );
840                 break;
841             }
842         }
843         vlc_object_release( p_playlist );
844     }
845 }
846
847 static void SetBookmark( intf_thread_t *p_intf, int i_num )
848 {
849     playlist_t *p_playlist =
850         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
851     if( p_playlist )
852     {
853         char psz_bookmark_name[11];
854         sprintf( psz_bookmark_name, "bookmark%i", i_num );
855         var_Create( p_intf, psz_bookmark_name,
856                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
857         if( p_playlist->status.p_item )
858         {
859             config_PutPsz( p_intf, psz_bookmark_name, 
860                            p_playlist->status.p_item->input.psz_uri);
861             msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num,
862                            p_playlist->status.p_item->input.psz_uri);
863             config_SaveConfigFile( p_intf, "hotkeys" );
864         }
865         vlc_object_release( p_playlist );
866     }
867 }
868
869 static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
870                              input_thread_t *p_input )
871 {
872     char psz_duration[MSTRTIME_MAX_SIZE];
873     char psz_time[MSTRTIME_MAX_SIZE];
874     vlc_value_t time, pos;
875     mtime_t i_seconds;
876
877     if( p_vout == NULL )
878     {
879         return;
880     }
881     ClearChannels( p_intf, p_vout );
882
883     var_Get( p_input, "time", &time );
884     i_seconds = time.i_time / 1000000;
885     secstotimestr ( psz_time, i_seconds );
886
887     var_Get( p_input, "length", &time );
888     if( time.i_time > 0 )
889     {
890         secstotimestr( psz_duration, time.i_time / 1000000 );
891         vout_OSDMessage( p_input, POSITION_TEXT_CHAN, "%s / %s",
892                          psz_time, psz_duration );
893     }
894     else if( i_seconds > 0 )
895     {
896         vout_OSDMessage( p_input, POSITION_TEXT_CHAN, psz_time );
897     }
898
899     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
900     {
901         var_Get( p_input, "position", &pos );
902         vout_OSDSlider( VLC_OBJECT( p_input ), POSITION_WIDGET_CHAN,
903                         pos.f_float * 100, OSD_HOR_SLIDER );
904     }
905 }
906
907 static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
908                            audio_volume_t i_vol )
909 {
910     if( p_vout == NULL )
911     {
912         return;
913     }
914     ClearChannels( p_intf, p_vout );
915
916     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
917     {
918         vout_OSDSlider( VLC_OBJECT( p_vout ), VOLUME_WIDGET_CHAN,
919             i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
920     }
921     else
922     {
923         vout_OSDMessage( p_vout, VOLUME_TEXT_CHAN, "Volume %d%%",
924                          i_vol*400/AOUT_VOLUME_MAX );
925     }
926 }
927
928 static void ClearChannels( intf_thread_t *p_intf, vout_thread_t *p_vout )
929 {
930     int i;
931
932     if( p_vout )
933     {
934         spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
935         for( i = 0; i < CHANNELS_NUMBER; i++ )
936         {
937             spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
938                          p_intf->p_sys->p_channels[ i ] );
939         }
940     }
941 }