]> git.sesse.net Git - vlc/blob - modules/control/hotkeys.c
Added new hotkeys (key-intf-hide, key-jump-3sec, key-jump+3sec, key-title-next, key...
[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 <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             }
249         }
250
251         if( !i_action )
252         {
253             /* No key pressed, sleep a bit more */
254             msleep( INTF_IDLE_SLEEP );
255             continue;
256         }
257
258         if( i_action == ACTIONID_QUIT )
259         {
260             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
261                                     FIND_ANYWHERE );
262             if( p_playlist )
263             {
264                 playlist_Stop( p_playlist );
265                 vlc_object_release( p_playlist );
266             }
267             /* Playlist is stopped now kill vlc. */
268             p_intf->p_vlc->b_die = VLC_TRUE;
269             ClearChannels( p_intf, p_vout );
270             vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Quit" ) );
271             continue;
272         }
273         else if( i_action == ACTIONID_VOL_UP )
274         {
275             audio_volume_t i_newvol;
276             aout_VolumeUp( p_intf, 1, &i_newvol );
277             DisplayVolume( p_intf, p_vout, i_newvol );
278         }
279         else if( i_action == ACTIONID_VOL_DOWN )
280         {
281             audio_volume_t i_newvol;
282             aout_VolumeDown( p_intf, 1, &i_newvol );
283             DisplayVolume( p_intf, p_vout, i_newvol );
284         }
285         else if( i_action == ACTIONID_VOL_MUTE )
286         {
287             audio_volume_t i_newvol = -1;
288             aout_VolumeMute( p_intf, &i_newvol );
289             if( p_vout )
290             {
291                 if( i_newvol == 0 )
292                 {
293                     ClearChannels( p_intf, p_vout );
294                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
295                                   OSD_MUTE_ICON );
296                 }
297                 else
298                 {
299                     DisplayVolume( p_intf, p_vout, i_newvol );
300                 }
301             }
302         }
303         else if( i_action == ACTIONID_INTF_SHOW )
304         {
305             val.b_bool = VLC_TRUE;
306             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
307                                           FIND_ANYWHERE );
308             if( p_playlist )
309             {
310                 var_Set( p_playlist, "intf-show", val );
311                 vlc_object_release( p_playlist );
312             }
313         }
314         else if( i_action == ACTIONID_INTF_HIDE )
315         {
316             val.b_bool = VLC_FALSE;
317             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
318                                           FIND_ANYWHERE );
319             if( p_playlist )
320             {
321                 var_Set( p_playlist, "intf-show", val );
322                 vlc_object_release( p_playlist );
323             }
324         }
325         else if( i_action == ACTIONID_SNAPSHOT )
326         {
327             if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
328         }
329         else if( i_action == ACTIONID_SUBDELAY_DOWN )
330         {
331             int64_t i_delay = var_GetTime( p_input, "spu-delay" );
332
333             i_delay -= 50000;    /* 50 ms */
334
335             var_SetTime( p_input, "spu-delay", i_delay );
336             ClearChannels( p_intf, p_vout );
337             vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
338                                  (int)(i_delay/1000) );
339         }
340         else if( i_action == ACTIONID_SUBDELAY_UP )
341         {
342             int64_t i_delay = var_GetTime( p_input, "spu-delay" );
343
344             i_delay += 50000;    /* 50 ms */
345
346             var_SetTime( p_input, "spu-delay", i_delay );
347             ClearChannels( p_intf, p_vout );
348             vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
349                                  (int)(i_delay/1000) );
350         }
351         else if( i_action == ACTIONID_AUDIODELAY_DOWN )
352         {
353             int64_t i_delay = var_GetTime( p_input, "audio-delay" );
354
355             i_delay -= 50000;    /* 50 ms */
356
357             var_SetTime( p_input, "audio-delay", i_delay );
358             ClearChannels( p_intf, p_vout );
359             vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
360                                  (int)(i_delay/1000) );
361         }
362         else if( i_action == ACTIONID_AUDIODELAY_UP )
363         {
364             int64_t i_delay = var_GetTime( p_input, "audio-delay" );
365
366             i_delay += 50000;    /* 50 ms */
367
368             var_SetTime( p_input, "audio-delay", i_delay );
369             ClearChannels( p_intf, p_vout );
370             vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
371                                  (int)(i_delay/1000) );
372         }
373         else if( i_action == ACTIONID_FULLSCREEN )
374         {
375             if( p_vout )
376             {
377                 var_Get( p_vout, "fullscreen", &val ); val.b_bool = !val.b_bool;
378                 var_Set( p_vout, "fullscreen", val );
379             }
380             else
381             {
382                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
383                                           FIND_ANYWHERE );
384                 if( p_playlist )
385                 {
386                     var_Get( p_playlist, "fullscreen", &val ); val.b_bool = !val.b_bool;
387                     var_Set( p_playlist, "fullscreen", val );
388                     vlc_object_release( p_playlist );
389                 }
390             }
391         }
392         else if( i_action == ACTIONID_PLAY )
393         {
394             p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
395                                           FIND_ANYWHERE );
396             if( p_playlist )
397             {
398                 var_Get( p_input, "rate", &val );
399                 msg_Dbg( p_input, "rate %d", val.i_int );
400                 if( val.i_int != INPUT_RATE_DEFAULT )
401                 {
402                     /* Return to normal speed */
403                     val.i_int = INPUT_RATE_DEFAULT;
404                     var_Set( p_input, "rate", val );
405                 }
406                 else
407                 {
408                     ClearChannels( p_intf, p_vout );
409                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
410                                   OSD_PAUSE_ICON );
411                     playlist_Play( p_playlist );
412                 }
413                 vlc_object_release( p_playlist );
414             }
415
416         }
417         else if( i_action == ACTIONID_PLAY_PAUSE )
418         {
419             val.i_int = PLAYING_S;
420             if( p_input )
421             {
422                 var_Get( p_input, "state", &val );
423             }
424             if( p_input && val.i_int != PAUSE_S )
425             {
426                 ClearChannels( p_intf, p_vout );
427                 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
428                               OSD_PAUSE_ICON );
429                 val.i_int = PAUSE_S;
430                 var_Set( p_input, "state", val );
431             }
432             else
433             {
434                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
435                                               FIND_ANYWHERE );
436                 if( p_playlist )
437                 {
438                     ClearChannels( p_intf, p_vout );
439                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
440                                   OSD_PLAY_ICON );
441                     playlist_Play( p_playlist );
442                     vlc_object_release( p_playlist );
443                 }
444             }
445         }
446         else if( p_input )
447         {
448             /* FIXME --fenrir
449              * How to get a valid value ?
450              * That's not that easy with some special stream
451              */
452             vlc_bool_t b_seekable = VLC_TRUE;
453
454             if( i_action == ACTIONID_PAUSE )
455             {
456                 ClearChannels( p_intf, p_vout );
457                 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
458                               OSD_PAUSE_ICON );
459                 val.i_int = PAUSE_S;
460                 var_Set( p_input, "state", val );
461             }
462             else if( i_action == ACTIONID_JUMP_BACKWARD_3SEC && b_seekable )
463             {
464                 val.i_time = (-3000000 * 2^i_times);
465                 var_Set( p_input, "time-offset", val );
466                 DisplayPosition( p_intf, p_vout, p_input );
467             }
468             else if( i_action == ACTIONID_JUMP_FORWARD_3SEC && b_seekable )
469             {
470                 val.i_time = (3000000 * 2^i_times);
471                 var_Set( p_input, "time-offset", val );
472                 DisplayPosition( p_intf, p_vout, p_input );
473             }
474             else if( i_action == ACTIONID_JUMP_BACKWARD_10SEC && b_seekable )
475             {
476                 val.i_time = (-10000000 * 2^i_times);
477                 var_Set( p_input, "time-offset", val );
478                 DisplayPosition( p_intf, p_vout, p_input );
479             }
480             else if( i_action == ACTIONID_JUMP_FORWARD_10SEC && b_seekable )
481             {
482                 val.i_time = (10000000 * 2^i_times);
483                 var_Set( p_input, "time-offset", val );
484                 DisplayPosition( p_intf, p_vout, p_input );
485             }
486             else if( i_action == ACTIONID_JUMP_BACKWARD_1MIN && b_seekable )
487             {
488                 val.i_time = (-60000000 * 2^i_times);
489                 var_Set( p_input, "time-offset", val );
490                 DisplayPosition( p_intf, p_vout, p_input );
491             }
492             else if( i_action == ACTIONID_JUMP_FORWARD_1MIN && b_seekable )
493             {
494                 val.i_time = (60000000 * 2^i_times);
495                 var_Set( p_input, "time-offset", val );
496                 DisplayPosition( p_intf, p_vout, p_input );
497             }
498             else if( i_action == ACTIONID_JUMP_BACKWARD_5MIN && b_seekable )
499             {
500                 val.i_time = (-300000000 * 2^i_times);
501                 var_Set( p_input, "time-offset", val );
502                 DisplayPosition( p_intf, p_vout, p_input );
503             }
504             else if( i_action == ACTIONID_JUMP_FORWARD_5MIN && b_seekable )
505             {
506                 val.i_time = (300000000 * 2^i_times);
507                 var_Set( p_input, "time-offset", val );
508                 DisplayPosition( p_intf, p_vout, p_input );
509             }
510             else if( i_action == ACTIONID_AUDIO_TRACK )
511             {
512                 vlc_value_t val, list, list2;
513                 int i_count, i;
514                 var_Get( p_input, "audio-es", &val );
515                 var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
516                             &list, &list2 );
517                 i_count = list.p_list->i_count;
518                 if( i_count <= 1 )
519                 {
520                     continue;
521                 }
522                 for( i = 0; i < i_count; i++ )
523                 {
524                     if( val.i_int == list.p_list->p_values[i].i_int )
525                     {
526                         break;
527                     }
528                 }
529                 /* value of audio-es was not in choices list */
530                 if( i == i_count )
531                 {
532                     msg_Warn( p_input,
533                               "invalid current audio track, selecting 0" );
534                     var_Set( p_input, "audio-es",
535                              list.p_list->p_values[0] );
536                     i = 0;
537                 }
538                 else if( i == i_count - 1 )
539                 {
540                     var_Set( p_input, "audio-es",
541                              list.p_list->p_values[1] );
542                     i = 1;
543                 }
544                 else
545                 {
546                     var_Set( p_input, "audio-es",
547                              list.p_list->p_values[i+1] );
548                     i++;
549                 }
550                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
551                                  _("Audio track: %s"),
552                                  list2.p_list->p_values[i].psz_string );
553             }
554             else if( i_action == ACTIONID_SUBTITLE_TRACK )
555             {
556                 vlc_value_t val, list, list2;
557                 int i_count, i;
558                 var_Get( p_input, "spu-es", &val );
559                 
560                 var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
561                             &list, &list2 );
562                 i_count = list.p_list->i_count;
563                 if( i_count <= 1 )
564                 {
565                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Subtitle track: %s"), _("N/A") );
566                     continue;
567                 }
568                 for( i = 0; i < i_count; i++ )
569                 {
570                     if( val.i_int == list.p_list->p_values[i].i_int )
571                     {
572                         break;
573                     }
574                 }
575                 /* value of spu-es was not in choices list */
576                 if( i == i_count )
577                 {
578                     msg_Warn( p_input, "invalid current subtitle track, selecting 0" );
579                     var_Set( p_input, "spu-es", list.p_list->p_values[0] );
580                     i = 0;
581                 }
582                 else if( i == i_count - 1 )
583                 {
584                     var_Set( p_input, "spu-es", list.p_list->p_values[0] );
585                     i = 0;
586                 }
587                 else
588                 {
589                     var_Set( p_input, "spu-es", list.p_list->p_values[i+1] );
590                     i = i + 1;
591                 }
592                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
593                                  _("Subtitle track: %s"),
594                                  list2.p_list->p_values[i].psz_string );
595             }
596             else if( i_action == ACTIONID_NEXT )
597             {
598                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
599                                               FIND_ANYWHERE );
600                 if( p_playlist )
601                 {
602                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Next") );
603                     playlist_Next( p_playlist );
604                     vlc_object_release( p_playlist );
605                 }
606             }
607             else if( i_action == ACTIONID_PREV )
608             {
609                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
610                                               FIND_ANYWHERE );
611                 if( p_playlist )
612                 {
613                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Previous") );
614                     playlist_Prev( p_playlist );
615                     vlc_object_release( p_playlist );
616                 }
617             }
618             else if( i_action == ACTIONID_STOP )
619             {
620                 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
621                                               FIND_ANYWHERE );
622                 if( p_playlist )
623                 {
624                     playlist_Stop( p_playlist );
625                     vlc_object_release( p_playlist );
626                 }
627             }
628             else if( i_action == ACTIONID_FASTER )
629             {
630                 vlc_value_t val;
631                 val.b_bool = VLC_TRUE;
632                 var_Set( p_input, "rate-faster", val );
633                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Faster") );
634             }
635             else if( i_action == ACTIONID_SLOWER )
636             {
637                 vlc_value_t val;
638                 val.b_bool = VLC_TRUE;
639                 var_Set( p_input, "rate-slower", val );
640                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Slower") );
641             }
642             else if( i_action == ACTIONID_POSITION && b_seekable )
643             {
644                 DisplayPosition( p_intf, p_vout, p_input );
645             }
646             else if( i_action >= ACTIONID_PLAY_BOOKMARK1 &&
647                      i_action <= ACTIONID_PLAY_BOOKMARK10 )
648             {
649                 PlayBookmark( p_intf, i_action - ACTIONID_PLAY_BOOKMARK1 + 1 );
650             }
651             else if( i_action >= ACTIONID_SET_BOOKMARK1 &&
652                      i_action <= ACTIONID_SET_BOOKMARK10 )
653             {
654                 SetBookmark( p_intf, i_action - ACTIONID_SET_BOOKMARK1 + 1 );
655             }
656             /* Only makes sense with DVD */
657             else if( i_action == ACTIONID_TITLE_PREV )
658             {
659                 val.b_bool = VLC_TRUE;
660                 var_Set( p_input, "prev-title", val );
661             }
662             else if( i_action == ACTIONID_TITLE_NEXT )
663             {
664                 val.b_bool = VLC_TRUE;
665                 var_Set( p_input, "next-title", val );
666             }
667             else if( i_action == ACTIONID_CHAPTER_PREV )
668             {
669                 val.b_bool = VLC_TRUE;
670                 var_Set( p_input, "prev-chapter", val );
671             }
672             else if( i_action == ACTIONID_CHAPTER_NEXT )
673             {
674                 val.b_bool = VLC_TRUE;
675                 var_Set( p_input, "next-chapter", val );
676             }
677         }
678     }
679 }
680
681 static int GetKey( intf_thread_t *p_intf)
682 {
683     vlc_mutex_lock( &p_intf->p_sys->change_lock );
684     if ( p_intf->p_sys->i_size == 0 )
685     {
686         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
687         return -1;
688     }
689     else
690     {
691         int i_return = p_intf->p_sys->p_keys[ 0 ];
692         int i;
693         p_intf->p_sys->i_size--;
694         for ( i = 0; i < BUFFER_SIZE - 1; i++)
695         {
696             p_intf->p_sys->p_keys[ i ] = p_intf->p_sys->p_keys[ i + 1 ];
697         }
698         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
699         return i_return;
700     }
701 }
702
703 /*****************************************************************************
704  * KeyEvent: callback for keyboard events
705  *****************************************************************************/
706 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
707                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
708 {
709     intf_thread_t *p_intf = (intf_thread_t *)p_data;
710     vlc_mutex_lock( &p_intf->p_sys->change_lock );
711     if ( p_intf->p_sys->i_size == BUFFER_SIZE )
712     {
713         msg_Warn( p_intf, "event buffer full, dropping keypress" );
714         vlc_mutex_unlock( &p_intf->p_sys->change_lock );
715         return VLC_EGENERIC;
716     }
717     else
718     {
719         p_intf->p_sys->p_keys[ p_intf->p_sys->i_size ] = newval.i_int;
720         p_intf->p_sys->i_size++;
721     }
722     vlc_mutex_unlock( &p_intf->p_sys->change_lock );
723
724     return VLC_SUCCESS;
725 }
726
727 static int ActionKeyCB( vlc_object_t *p_this, char const *psz_var,
728                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
729 {
730     vlc_t *p_vlc = (vlc_t *)p_this;
731     struct hotkey *p_hotkeys = p_vlc->p_hotkeys;
732     mtime_t i_date;
733     int i;
734
735     for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
736     {
737         if( !strcmp( p_hotkeys[i].psz_action, psz_var ) )
738         {
739             p_hotkeys[i].i_key = newval.i_int;
740             /* do hotkey accounting */            
741             i_date = mdate();
742             if( (p_hotkeys[i].i_delta_date > 0) &&
743                 (p_hotkeys[i].i_delta_date <= (i_date - p_hotkeys[i].i_last_date) ) )
744                 p_hotkeys[i].i_times = 0;
745             else
746                 p_hotkeys[i].i_times++;
747             p_hotkeys[i].i_last_date = i_date;
748         }
749     }
750
751     return VLC_SUCCESS;
752 }
753
754 static void PlayBookmark( intf_thread_t *p_intf, int i_num )
755 {
756     vlc_value_t val;
757     int i_position;
758     char psz_bookmark_name[11];
759     playlist_t *p_playlist =
760         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
761
762     sprintf( psz_bookmark_name, "bookmark%i", i_num );
763     var_Create( p_intf, psz_bookmark_name, VLC_VAR_STRING|VLC_VAR_DOINHERIT );
764     var_Get( p_intf, psz_bookmark_name, &val );
765
766     if( p_playlist )
767     {
768         char *psz_bookmark = strdup( val.psz_string );
769         for( i_position = 0; i_position < p_playlist->i_size; i_position++)
770         {
771             if( !strcmp( psz_bookmark,
772                          p_playlist->pp_items[i_position]->input.psz_uri ) )
773             {
774                 playlist_Goto( p_playlist, i_position );
775                 break;
776             }
777         }
778         vlc_object_release( p_playlist );
779     }
780 }
781
782 static void SetBookmark( intf_thread_t *p_intf, int i_num )
783 {
784     playlist_t *p_playlist =
785         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
786     if( p_playlist )
787     {
788         char psz_bookmark_name[11];
789         sprintf( psz_bookmark_name, "bookmark%i", i_num );
790         var_Create( p_intf, psz_bookmark_name,
791                     VLC_VAR_STRING|VLC_VAR_DOINHERIT );
792         if( p_playlist->status.p_item )
793         {
794             config_PutPsz( p_intf, psz_bookmark_name, 
795                            p_playlist->status.p_item->input.psz_uri);
796             msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num,
797                            p_playlist->status.p_item->input.psz_uri);
798             config_SaveConfigFile( p_intf, "hotkeys" );
799         }
800         vlc_object_release( p_playlist );
801     }
802 }
803
804 static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
805                              input_thread_t *p_input )
806 {
807     char psz_duration[MSTRTIME_MAX_SIZE];
808     char psz_time[MSTRTIME_MAX_SIZE];
809     vlc_value_t time, pos;
810     mtime_t i_seconds;
811
812     if( p_vout == NULL )
813     {
814         return;
815     }
816     ClearChannels( p_intf, p_vout );
817
818     var_Get( p_input, "time", &time );
819     i_seconds = time.i_time / 1000000;
820     secstotimestr ( psz_time, i_seconds );
821
822     var_Get( p_input, "length", &time );
823     if( time.i_time > 0 )
824     {
825         secstotimestr( psz_duration, time.i_time / 1000000 );
826         vout_OSDMessage( p_input, POSITION_TEXT_CHAN, "%s / %s",
827                          psz_time, psz_duration );
828     }
829     else if( i_seconds > 0 )
830     {
831         vout_OSDMessage( p_input, POSITION_TEXT_CHAN, psz_time );
832     }
833
834     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
835     {
836         var_Get( p_input, "position", &pos );
837         vout_OSDSlider( VLC_OBJECT( p_input ), POSITION_WIDGET_CHAN,
838                         pos.f_float * 100, OSD_HOR_SLIDER );
839     }
840 }
841
842 static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
843                            audio_volume_t i_vol )
844 {
845     if( p_vout == NULL )
846     {
847         return;
848     }
849     ClearChannels( p_intf, p_vout );
850
851     if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
852     {
853         vout_OSDSlider( VLC_OBJECT( p_vout ), VOLUME_WIDGET_CHAN,
854             i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
855     }
856     else
857     {
858         vout_OSDMessage( p_vout, VOLUME_TEXT_CHAN, "Volume %d%%",
859                          i_vol*400/AOUT_VOLUME_MAX );
860     }
861 }
862
863 static void ClearChannels( intf_thread_t *p_intf, vout_thread_t *p_vout )
864 {
865     int i;
866
867     if( p_vout )
868     {
869         spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
870         for( i = 0; i < CHANNELS_NUMBER; i++ )
871         {
872             spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
873                          p_intf->p_sys->p_channels[ i ] );
874         }
875     }
876 }