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