]> git.sesse.net Git - vlc/blob - modules/control/hotkeys.c
* Improve strings for jumps
[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., 59 Temple Place - Suite 330, Boston, MA  02111, 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_category( CAT_INTERFACE );
101 //    set_subcategory( SUBCAT_INTERFACE_GENERAL );
102
103     add_string( "bookmark1", NULL, NULL,
104                 BOOKMARK1_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
105     add_string( "bookmark2", NULL, NULL,
106                 BOOKMARK2_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
107     add_string( "bookmark3", NULL, NULL,
108                 BOOKMARK3_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
109     add_string( "bookmark4", NULL, NULL,
110                 BOOKMARK4_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
111     add_string( "bookmark5", NULL, NULL,
112                 BOOKMARK5_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
113     add_string( "bookmark6", NULL, NULL,
114                 BOOKMARK6_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
115     add_string( "bookmark7", NULL, NULL,
116                 BOOKMARK7_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
117     add_string( "bookmark8", NULL, NULL,
118                 BOOKMARK8_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
119     add_string( "bookmark9", NULL, NULL,
120                 BOOKMARK9_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
121     add_string( "bookmark10", NULL, NULL,
122                 BOOKMARK10_TEXT, BOOKMARK_LONGTEXT, VLC_FALSE );
123
124     set_capability( "interface", 0 );
125     set_callbacks( Open, Close );
126 vlc_module_end();
127
128 /*****************************************************************************
129  * Open: initialize interface
130  *****************************************************************************/
131 static int Open( vlc_object_t *p_this )
132 {
133     intf_thread_t *p_intf = (intf_thread_t *)p_this;
134
135     /* Allocate instance and initialize some members */
136     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
137     if( p_intf->p_sys == NULL )
138     {
139         msg_Err( p_intf, "out of memory" );
140         return 1;
141     }
142     vlc_mutex_init( p_intf, &p_intf->p_sys->change_lock );
143     p_intf->p_sys->i_size = 0;
144     p_intf->pf_run = Run;
145
146     p_intf->p_sys->p_input = NULL;
147     p_intf->p_sys->p_vout = NULL;
148
149     var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
150     return 0;
151 }
152
153 /*****************************************************************************
154  * Close: destroy interface
155  *****************************************************************************/
156 static void Close( vlc_object_t *p_this )
157 {
158     intf_thread_t *p_intf = (intf_thread_t *)p_this;
159
160     var_DelCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
161     if( p_intf->p_sys->p_input )
162     {
163         vlc_object_release( p_intf->p_sys->p_input );
164     }
165     if( p_intf->p_sys->p_vout )
166     {
167         vlc_object_release( p_intf->p_sys->p_vout );
168     }
169     /* Destroy structure */
170     free( p_intf->p_sys );
171 }
172
173 /*****************************************************************************
174  * Run: main loop
175  *****************************************************************************/
176 static void Run( intf_thread_t *p_intf )
177 {
178     playlist_t *p_playlist = NULL;
179     input_thread_t *p_input = NULL;
180     vout_thread_t *p_vout = NULL;
181     vout_thread_t *p_last_vout = NULL;
182     struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
183     vlc_value_t val;
184     int i;
185
186     /* Initialize hotkey structure */
187     for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
188     {
189         var_Create( p_intf->p_vlc, p_hotkeys[i].psz_action,
190                     VLC_VAR_HOTKEY | VLC_VAR_DOINHERIT );
191
192         var_AddCallback( p_intf->p_vlc, p_hotkeys[i].psz_action,
193                          ActionKeyCB, NULL );
194         var_Get( p_intf->p_vlc, p_hotkeys[i].psz_action, &val );
195         var_Set( p_intf->p_vlc, p_hotkeys[i].psz_action, val );
196     }
197
198     while( !p_intf->b_die )
199     {
200         int i_key, i_action;
201         int i_times = 0;
202
203         /* Sleep a bit */
204         msleep( INTF_IDLE_SLEEP );
205
206         /* Update the input */
207         if( p_intf->p_sys->p_input == NULL )
208         {
209             p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
210                                                       FIND_ANYWHERE );
211         }
212         else if( p_intf->p_sys->p_input->b_dead )
213         {
214             vlc_object_release( p_intf->p_sys->p_input );
215             p_intf->p_sys->p_input = NULL;
216         }
217         p_input = p_intf->p_sys->p_input;
218
219         /* Update the vout */
220         p_last_vout = p_intf->p_sys->p_vout;
221         if( p_vout == NULL )
222         {
223             p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
224             p_intf->p_sys->p_vout = p_vout;
225         }
226         else if( p_vout->b_die )
227         {
228             vlc_object_release( p_vout );
229             p_vout = NULL;
230             p_intf->p_sys->p_vout = NULL;
231         }
232
233         /* Register OSD channels */
234         if( p_vout && p_vout != p_last_vout )
235         {
236             for( i = 0; i < CHANNELS_NUMBER; i++ )
237             {
238                 spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER,
239                              &p_intf->p_sys->p_channels[ i ] );
240             }
241         }
242
243         /* Find action triggered by hotkey */
244         i_action = 0;
245         i_key = GetKey( p_intf );
246         for( i = 0; i_key != -1 && p_hotkeys[i].psz_action != NULL; i++ )
247         {
248             if( p_hotkeys[i].i_key == i_key )
249             {
250                 i_action = p_hotkeys[i].i_action;
251                 i_times  = p_hotkeys[i].i_times; /* times key pressed within max. delta time */
252                 p_hotkeys[i].i_times = 0;
253             }
254         }
255
256         if( !i_action )
257         {
258             /* No key pressed, sleep a bit more */
259             msleep( INTF_IDLE_SLEEP );
260             continue;
261         }
262
263         if( i_action == ACTIONID_QUIT )
264         {
265             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
266                                     FIND_ANYWHERE );
267             if( p_playlist )
268             {
269                 playlist_Stop( p_playlist );
270                 vlc_object_release( p_playlist );
271             }
272             /* Playlist is stopped now kill vlc. */
273             p_intf->p_vlc->b_die = VLC_TRUE;
274             ClearChannels( p_intf, p_vout );
275             vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Quit" ) );
276             continue;
277         }
278         else if( i_action == ACTIONID_VOL_UP )
279         {
280             audio_volume_t i_newvol;
281             aout_VolumeUp( p_intf, 1, &i_newvol );
282             DisplayVolume( p_intf, p_vout, i_newvol );
283         }
284         else if( i_action == ACTIONID_VOL_DOWN )
285         {
286             audio_volume_t i_newvol;
287             aout_VolumeDown( p_intf, 1, &i_newvol );
288             DisplayVolume( p_intf, p_vout, i_newvol );
289         }
290         else if( i_action == ACTIONID_VOL_MUTE )
291         {
292             audio_volume_t i_newvol = -1;
293             aout_VolumeMute( p_intf, &i_newvol );
294             if( p_vout )
295             {
296                 if( i_newvol == 0 )
297                 {
298                     ClearChannels( p_intf, p_vout );
299                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
300                                   OSD_MUTE_ICON );
301                 }
302                 else
303                 {
304                     DisplayVolume( p_intf, p_vout, i_newvol );
305                 }
306             }
307         }
308         else if( i_action == ACTIONID_INTF_SHOW )
309         {
310             val.b_bool = VLC_TRUE;
311             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
312                                           FIND_ANYWHERE );
313             if( p_playlist )
314             {
315                 var_Set( p_playlist, "intf-show", val );
316                 vlc_object_release( p_playlist );
317             }
318         }
319         else if( i_action == ACTIONID_INTF_HIDE )
320         {
321             val.b_bool = VLC_FALSE;
322             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
323                                           FIND_ANYWHERE );
324             if( p_playlist )
325             {
326                 var_Set( p_playlist, "intf-show", val );
327                 vlc_object_release( p_playlist );
328             }
329         }
330         else if( i_action == ACTIONID_SNAPSHOT )
331         {
332             if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
333         }
334         else if( i_action == ACTIONID_FULLSCREEN )
335         {
336             if( p_vout )
337             {
338                 var_Get( p_vout, "fullscreen", &val ); val.b_bool = !val.b_bool;
339                 var_Set( p_vout, "fullscreen", val );
340             }
341             else
342             {
343                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
344                                           FIND_ANYWHERE );
345                 if( p_playlist )
346                 {
347                     var_Get( p_playlist, "fullscreen", &val ); val.b_bool = !val.b_bool;
348                     var_Set( p_playlist, "fullscreen", val );
349                     vlc_object_release( p_playlist );
350                 }
351             }
352         }
353         else if( i_action == ACTIONID_PLAY_PAUSE )
354         {
355             val.i_int = PLAYING_S;
356             if( p_input )
357             {
358                 var_Get( p_input, "state", &val );
359             }
360             if( p_input && val.i_int != PAUSE_S )
361             {
362                 ClearChannels( p_intf, p_vout );
363                 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
364                               OSD_PAUSE_ICON );
365                 val.i_int = PAUSE_S;
366                 var_Set( p_input, "state", val );
367             }
368             else
369             {
370                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
371                                               FIND_ANYWHERE );
372                 if( p_playlist )
373                 {
374                     ClearChannels( p_intf, p_vout );
375                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
376                                   OSD_PLAY_ICON );
377                     playlist_Play( p_playlist );
378                     vlc_object_release( p_playlist );
379                 }
380             }
381         }
382         else if( p_input )
383         {
384             /* FIXME --fenrir
385              * How to get a valid value ?
386              * That's not that easy with some special stream
387              */
388             vlc_bool_t b_seekable = VLC_TRUE;
389             int i_interval =0;
390
391             if( i_action == ACTIONID_PAUSE )
392             {
393                 ClearChannels( p_intf, p_vout );
394                 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
395                               OSD_PAUSE_ICON );
396                 val.i_int = PAUSE_S;
397                 var_Set( p_input, "state", val );
398             }
399             else if( i_action == ACTIONID_JUMP_BACKWARD_EXTRASHORT && b_seekable )
400             {
401 #define SET_TIME( a, b ) \
402     i_interval = config_GetInt( p_input, a "-jump-size" ); \
403     if( i_interval > 0 ) { \
404         val.i_time = ( (mtime_t)(i_interval * b) * 1000000L \
405                        * ((mtime_t)(1 << i_times))); \
406         var_Set( p_input, "time-offset", val ); \
407         DisplayPosition( p_intf, p_vout, p_input ); \
408     }
409                 SET_TIME( "extrashort", -1 );
410             }
411             else if( i_action == ACTIONID_JUMP_FORWARD_EXTRASHORT && b_seekable )
412             {
413                 SET_TIME( "extrashort", 1 );
414             }
415             else if( i_action == ACTIONID_JUMP_BACKWARD_SHORT && b_seekable )
416             {
417                 SET_TIME( "short", -1 );
418             }
419             else if( i_action == ACTIONID_JUMP_FORWARD_SHORT && b_seekable )
420             {
421                 SET_TIME( "short", 1 );
422             }
423             else if( i_action == ACTIONID_JUMP_BACKWARD_MEDIUM && b_seekable )
424             {
425                 SET_TIME( "medium", -1 );
426             }
427             else if( i_action == ACTIONID_JUMP_FORWARD_MEDIUM && b_seekable )
428             {
429                 SET_TIME( "medium", 1 );
430             }
431             else if( i_action == ACTIONID_JUMP_BACKWARD_LONG && b_seekable )
432             {
433                 SET_TIME( "long", -1 );
434             }
435             else if( i_action == ACTIONID_JUMP_FORWARD_LONG && b_seekable )
436             {
437                 SET_TIME( "long", 1 );
438 #undef SET_TIME
439             }
440             else if( i_action == ACTIONID_AUDIO_TRACK )
441             {
442                 vlc_value_t val, list, list2;
443                 int i_count, i;
444                 var_Get( p_input, "audio-es", &val );
445                 var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
446                             &list, &list2 );
447                 i_count = list.p_list->i_count;
448                 if( i_count <= 1 )
449                 {
450                     continue;
451                 }
452                 for( i = 0; i < i_count; i++ )
453                 {
454                     if( val.i_int == list.p_list->p_values[i].i_int )
455                     {
456                         break;
457                     }
458                 }
459                 /* value of audio-es was not in choices list */
460                 if( i == i_count )
461                 {
462                     msg_Warn( p_input,
463                               "invalid current audio track, selecting 0" );
464                     var_Set( p_input, "audio-es",
465                              list.p_list->p_values[0] );
466                     i = 0;
467                 }
468                 else if( i == i_count - 1 )
469                 {
470                     var_Set( p_input, "audio-es",
471                              list.p_list->p_values[1] );
472                     i = 1;
473                 }
474                 else
475                 {
476                     var_Set( p_input, "audio-es",
477                              list.p_list->p_values[i+1] );
478                     i++;
479                 }
480                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
481                                  _("Audio track: %s"),
482                                  list2.p_list->p_values[i].psz_string );
483             }
484             else if( i_action == ACTIONID_SUBTITLE_TRACK )
485             {
486                 vlc_value_t val, list, list2;
487                 int i_count, i;
488                 var_Get( p_input, "spu-es", &val );
489
490                 var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
491                             &list, &list2 );
492                 i_count = list.p_list->i_count;
493                 if( i_count <= 1 )
494                 {
495                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Subtitle track: %s"), _("N/A") );
496                     continue;
497                 }
498                 for( i = 0; i < i_count; i++ )
499                 {
500                     if( val.i_int == list.p_list->p_values[i].i_int )
501                     {
502                         break;
503                     }
504                 }
505                 /* value of spu-es was not in choices list */
506                 if( i == i_count )
507                 {
508                     msg_Warn( p_input, "invalid current subtitle track, selecting 0" );
509                     var_Set( p_input, "spu-es", list.p_list->p_values[0] );
510                     i = 0;
511                 }
512                 else if( i == i_count - 1 )
513                 {
514                     var_Set( p_input, "spu-es", list.p_list->p_values[0] );
515                     i = 0;
516                 }
517                 else
518                 {
519                     var_Set( p_input, "spu-es", list.p_list->p_values[i+1] );
520                     i = i + 1;
521                 }
522                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
523                                  _("Subtitle track: %s"),
524                                  list2.p_list->p_values[i].psz_string );
525             }
526             else if( i_action == ACTIONID_NEXT )
527             {
528                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
529                                               FIND_ANYWHERE );
530                 if( p_playlist )
531                 {
532                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Next") );
533                     playlist_Next( p_playlist );
534                     vlc_object_release( p_playlist );
535                 }
536             }
537             else if( i_action == ACTIONID_PREV )
538             {
539                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
540                                               FIND_ANYWHERE );
541                 if( p_playlist )
542                 {
543                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Previous") );
544                     playlist_Prev( p_playlist );
545                     vlc_object_release( p_playlist );
546                 }
547             }
548             else if( i_action == ACTIONID_STOP )
549             {
550                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
551                                               FIND_ANYWHERE );
552                 if( p_playlist )
553                 {
554                     playlist_Stop( p_playlist );
555                     vlc_object_release( p_playlist );
556                 }
557             }
558             else if( i_action == ACTIONID_FASTER )
559             {
560                 vlc_value_t val;
561                 val.b_bool = VLC_TRUE;
562                 var_Set( p_input, "rate-faster", val );
563                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Faster") );
564             }
565             else if( i_action == ACTIONID_SLOWER )
566             {
567                 vlc_value_t val;
568                 val.b_bool = VLC_TRUE;
569                 var_Set( p_input, "rate-slower", val );
570                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Slower") );
571             }
572             else if( i_action == ACTIONID_POSITION && b_seekable )
573             {
574                 DisplayPosition( p_intf, p_vout, p_input );
575             }
576             else if( i_action >= ACTIONID_PLAY_BOOKMARK1 &&
577                      i_action <= ACTIONID_PLAY_BOOKMARK10 )
578             {
579                 PlayBookmark( p_intf, i_action - ACTIONID_PLAY_BOOKMARK1 + 1 );
580             }
581             else if( i_action >= ACTIONID_SET_BOOKMARK1 &&
582                      i_action <= ACTIONID_SET_BOOKMARK10 )
583             {
584                 SetBookmark( p_intf, i_action - ACTIONID_SET_BOOKMARK1 + 1 );
585             }
586             /* Only makes sense with DVD */
587             else if( i_action == ACTIONID_TITLE_PREV )
588             {
589                 val.b_bool = VLC_TRUE;
590                 var_Set( p_input, "prev-title", val );
591             }
592             else if( i_action == ACTIONID_TITLE_NEXT )
593             {
594                 val.b_bool = VLC_TRUE;
595                 var_Set( p_input, "next-title", val );
596             }
597             else if( i_action == ACTIONID_CHAPTER_PREV )
598             {
599                 val.b_bool = VLC_TRUE;
600                 var_Set( p_input, "prev-chapter", val );
601             }
602             else if( i_action == ACTIONID_CHAPTER_NEXT )
603             {
604                 val.b_bool = VLC_TRUE;
605                 var_Set( p_input, "next-chapter", val );
606             }
607             else if( i_action == ACTIONID_DISC_MENU )
608             {
609                 vlc_value_t val; val.i_int = 2;
610 msg_Dbg( p_input, "set dvdmenu" );
611                 var_Set( p_input, "title  0", val);
612             }
613             else if( i_action == ACTIONID_SUBDELAY_DOWN )
614             {
615                 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
616
617                 i_delay -= 50000;    /* 50 ms */
618
619                 var_SetTime( p_input, "spu-delay", i_delay );
620                 ClearChannels( p_intf, p_vout );
621                 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
622                                  (int)(i_delay/1000) );
623             }
624             else if( i_action == ACTIONID_SUBDELAY_UP )
625             {
626                 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
627
628                 i_delay += 50000;    /* 50 ms */
629
630                 var_SetTime( p_input, "spu-delay", i_delay );
631                 ClearChannels( p_intf, p_vout );
632                 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
633                                  (int)(i_delay/1000) );
634             }
635             else if( i_action == ACTIONID_AUDIODELAY_DOWN )
636             {
637                 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
638
639                 i_delay -= 50000;    /* 50 ms */
640
641                 var_SetTime( p_input, "audio-delay", i_delay );
642                 ClearChannels( p_intf, p_vout );
643                 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
644                                  (int)(i_delay/1000) );
645             }
646             else if( i_action == ACTIONID_AUDIODELAY_UP )
647             {
648                 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
649
650                 i_delay += 50000;    /* 50 ms */
651
652                 var_SetTime( p_input, "audio-delay", i_delay );
653                 ClearChannels( p_intf, p_vout );
654                 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
655                                  (int)(i_delay/1000) );
656             }
657             else if( i_action == ACTIONID_PLAY )
658             {
659                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
660                                               FIND_ANYWHERE );
661                 if( p_playlist )
662                 {
663                     var_Get( p_input, "rate", &val );
664                     msg_Dbg( p_input, "rate %d", val.i_int );
665                     if( val.i_int != INPUT_RATE_DEFAULT )
666                     {
667                         /* Return to normal speed */
668                         val.i_int = INPUT_RATE_DEFAULT;
669                         var_Set( p_input, "rate", val );
670                     }
671                     else
672                     {
673                         ClearChannels( p_intf, p_vout );
674                         vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
675                                       OSD_PAUSE_ICON );
676                         playlist_Play( p_playlist );
677                     }
678                     vlc_object_release( p_playlist );
679                 }
680             }
681         }
682     }
683 }
684
685 static int GetKey( intf_thread_t *p_intf)
686 {
687     vlc_mutex_lock( &p_intf->p_sys->change_lock );
688     if ( p_intf->p_sys->i_size == 0 )
689     {
690         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
691         return -1;
692     }
693     else
694     {
695         int i_return = p_intf->p_sys->p_keys[ 0 ];
696         int i;
697         p_intf->p_sys->i_size--;
698         for ( i = 0; i < BUFFER_SIZE - 1; i++)
699         {
700             p_intf->p_sys->p_keys[ i ] = p_intf->p_sys->p_keys[ i + 1 ];
701         }
702         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
703         return i_return;
704     }
705 }
706
707 /*****************************************************************************
708  * KeyEvent: callback for keyboard events
709  *****************************************************************************/
710 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
711                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
712 {
713     intf_thread_t *p_intf = (intf_thread_t *)p_data;
714     vlc_mutex_lock( &p_intf->p_sys->change_lock );
715     if ( p_intf->p_sys->i_size == BUFFER_SIZE )
716     {
717         msg_Warn( p_intf, "event buffer full, dropping keypress" );
718         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
719         return VLC_EGENERIC;
720     }
721     else
722     {
723         p_intf->p_sys->p_keys[ p_intf->p_sys->i_size ] = newval.i_int;
724         p_intf->p_sys->i_size++;
725     }
726     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
727
728     return VLC_SUCCESS;
729 }
730
731 static int ActionKeyCB( vlc_object_t *p_this, char const *psz_var,
732                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
733 {
734     vlc_t *p_vlc = (vlc_t *)p_this;
735     struct hotkey *p_hotkeys = p_vlc->p_hotkeys;
736     mtime_t i_date;
737     int i;
738
739     for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
740     {
741         if( !strcmp( p_hotkeys[i].psz_action, psz_var ) )
742         {
743             p_hotkeys[i].i_key = newval.i_int;
744             /* do hotkey accounting */
745             i_date = mdate();
746             if( (p_hotkeys[i].i_delta_date > 0) &&
747                 (p_hotkeys[i].i_delta_date <= (i_date - p_hotkeys[i].i_last_date) ) )
748                 p_hotkeys[i].i_times = 0;
749             else
750                 p_hotkeys[i].i_times++;
751             p_hotkeys[i].i_last_date = i_date;
752         }
753     }
754
755     return VLC_SUCCESS;
756 }
757
758 static void PlayBookmark( intf_thread_t *p_intf, int i_num )
759 {
760     vlc_value_t val;
761     int i_position;
762     char psz_bookmark_name[11];
763     playlist_t *p_playlist =
764         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
765
766     sprintf( psz_bookmark_name, "bookmark%i", i_num );
767     var_Create( p_intf, psz_bookmark_name, VLC_VAR_STRING|VLC_VAR_DOINHERIT );
768     var_Get( p_intf, psz_bookmark_name, &val );
769
770     if( p_playlist )
771     {
772         char *psz_bookmark = strdup( val.psz_string );
773         for( i_position = 0; i_position < p_playlist->i_size; i_position++)
774         {
775             if( !strcmp( psz_bookmark,
776                          p_playlist->pp_items[i_position]->input.psz_uri ) )
777             {
778                 playlist_Goto( p_playlist, i_position );
779                 break;
780             }
781         }
782         vlc_object_release( p_playlist );
783     }
784 }
785
786 static void SetBookmark( intf_thread_t *p_intf, int i_num )
787 {
788     playlist_t *p_playlist =
789         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
790     if( p_playlist )
791     {
792         char psz_bookmark_name[11];
793         sprintf( psz_bookmark_name, "bookmark%i", i_num );
794         var_Create( p_intf, psz_bookmark_name,
795                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
796         if( p_playlist->status.p_item )
797         {
798             config_PutPsz( p_intf, psz_bookmark_name, 
799                            p_playlist->status.p_item->input.psz_uri);
800             msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num,
801                            p_playlist->status.p_item->input.psz_uri);
802             config_SaveConfigFile( p_intf, "hotkeys" );
803         }
804         vlc_object_release( p_playlist );
805     }
806 }
807
808 static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
809                              input_thread_t *p_input )
810 {
811     char psz_duration[MSTRTIME_MAX_SIZE];
812     char psz_time[MSTRTIME_MAX_SIZE];
813     vlc_value_t time, pos;
814     mtime_t i_seconds;
815
816     if( p_vout == NULL )
817     {
818         return;
819     }
820     ClearChannels( p_intf, p_vout );
821
822     var_Get( p_input, "time", &time );
823     i_seconds = time.i_time / 1000000;
824     secstotimestr ( psz_time, i_seconds );
825
826     var_Get( p_input, "length", &time );
827     if( time.i_time > 0 )
828     {
829         secstotimestr( psz_duration, time.i_time / 1000000 );
830         vout_OSDMessage( p_input, POSITION_TEXT_CHAN, "%s / %s",
831                          psz_time, psz_duration );
832     }
833     else if( i_seconds > 0 )
834     {
835         vout_OSDMessage( p_input, POSITION_TEXT_CHAN, psz_time );
836     }
837
838     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
839     {
840         var_Get( p_input, "position", &pos );
841         vout_OSDSlider( VLC_OBJECT( p_input ), POSITION_WIDGET_CHAN,
842                         pos.f_float * 100, OSD_HOR_SLIDER );
843     }
844 }
845
846 static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
847                            audio_volume_t i_vol )
848 {
849     if( p_vout == NULL )
850     {
851         return;
852     }
853     ClearChannels( p_intf, p_vout );
854
855     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
856     {
857         vout_OSDSlider( VLC_OBJECT( p_vout ), VOLUME_WIDGET_CHAN,
858             i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
859     }
860     else
861     {
862         vout_OSDMessage( p_vout, VOLUME_TEXT_CHAN, "Volume %d%%",
863                          i_vol*400/AOUT_VOLUME_MAX );
864     }
865 }
866
867 static void ClearChannels( intf_thread_t *p_intf, vout_thread_t *p_vout )
868 {
869     int i;
870
871     if( p_vout )
872     {
873         spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
874         for( i = 0; i < CHANNELS_NUMBER; i++ )
875         {
876             spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
877                          p_intf->p_sys->p_channels[ i ] );
878         }
879     }
880 }