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