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