ASF: remove unused variables
[vlc.git] / modules / control / hotkeys.c
1 /*****************************************************************************
2  * hotkeys.c: Hotkey handling for vlc
3  *****************************************************************************
4  * Copyright (C) 2005-2009 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_interface.h>
36 #include <vlc_input.h>
37 #include <vlc_vout.h>
38 #include <vlc_aout.h>
39 #include <vlc_osd.h>
40 #include <vlc_playlist.h>
41 #include <vlc_keys.h>
42 #include "math.h"
43
44 #define CHANNELS_NUMBER 4
45 #define VOLUME_TEXT_CHAN     p_intf->p_sys->p_channels[ 0 ]
46 #define VOLUME_WIDGET_CHAN   p_intf->p_sys->p_channels[ 1 ]
47 #define POSITION_TEXT_CHAN   p_intf->p_sys->p_channels[ 2 ]
48 #define POSITION_WIDGET_CHAN p_intf->p_sys->p_channels[ 3 ]
49
50 /*****************************************************************************
51  * intf_sys_t: description and status of FB interface
52  *****************************************************************************/
53 struct intf_sys_t
54 {
55     vout_thread_t      *p_last_vout;
56     int                 p_channels[ CHANNELS_NUMBER ]; /* contains registered
57                                                         * channel IDs */
58     int                 i_mousewheel_mode;
59 };
60
61 /*****************************************************************************
62  * Local prototypes
63  *****************************************************************************/
64 static int  Open    ( vlc_object_t * );
65 static void Close   ( vlc_object_t * );
66 static int  ActionEvent( vlc_object_t *, char const *,
67                          vlc_value_t, vlc_value_t, void * );
68 static int  SpecialKeyEvent( vlc_object_t *, char const *,
69                              vlc_value_t, vlc_value_t, void * );
70 static void PlayBookmark( intf_thread_t *, int );
71 static void SetBookmark ( intf_thread_t *, int );
72 static void DisplayPosition( intf_thread_t *, vout_thread_t *, input_thread_t * );
73 static void DisplayVolume  ( intf_thread_t *, vout_thread_t *, audio_volume_t );
74 static void ClearChannels  ( intf_thread_t *, vout_thread_t * );
75
76 /*****************************************************************************
77  * Module descriptor
78  *****************************************************************************/
79
80 enum{
81     MOUSEWHEEL_VOLUME,
82     MOUSEWHEEL_POSITION,
83     NO_MOUSEWHEEL,
84 };
85
86 static const int i_mode_list[] =
87     { MOUSEWHEEL_VOLUME, MOUSEWHEEL_POSITION, NO_MOUSEWHEEL };
88
89 static const char *const psz_mode_list_text[] =
90     { N_("Volume Control"), N_("Position Control"), N_("Ignore") };
91
92 vlc_module_begin ()
93     set_shortname( N_("Hotkeys") )
94     set_description( N_("Hotkeys management interface") )
95     set_capability( "interface", 0 )
96     set_callbacks( Open, Close )
97     set_category( CAT_INTERFACE )
98     set_subcategory( SUBCAT_INTERFACE_HOTKEYS )
99
100     add_integer( "hotkeys-mousewheel-mode", MOUSEWHEEL_VOLUME, NULL,
101                  N_("MouseWheel x-axis Control"),
102                  N_("MouseWheel x-axis can control volume, position or "
103                     "mousewheel event can be ignored"), false )
104             change_integer_list( i_mode_list, psz_mode_list_text, NULL )
105
106 vlc_module_end ()
107
108 /*****************************************************************************
109  * Open: initialize interface
110  *****************************************************************************/
111 static int Open( vlc_object_t *p_this )
112 {
113     intf_thread_t *p_intf = (intf_thread_t *)p_this;
114     intf_sys_t *p_sys;
115     p_sys = malloc( sizeof( intf_sys_t ) );
116     if( !p_sys )
117         return VLC_ENOMEM;
118
119     p_intf->p_sys = p_sys;
120     p_intf->pf_run = NULL;
121
122     p_sys->p_last_vout = NULL;
123     p_intf->p_sys->i_mousewheel_mode =
124         config_GetInt( p_intf, "hotkeys-mousewheel-mode" );
125
126     var_AddCallback( p_intf->p_libvlc, "key-pressed", SpecialKeyEvent, p_intf );
127     var_AddCallback( p_intf->p_libvlc, "key-action", ActionEvent, p_intf );
128     return VLC_SUCCESS;
129 }
130
131 /*****************************************************************************
132  * Close: destroy interface
133  *****************************************************************************/
134 static void Close( vlc_object_t *p_this )
135 {
136     intf_thread_t *p_intf = (intf_thread_t *)p_this;
137     intf_sys_t *p_sys = p_intf->p_sys;
138
139     var_DelCallback( p_intf->p_libvlc, "key-action", ActionEvent, p_intf );
140     var_DelCallback( p_intf->p_libvlc, "key-pressed", SpecialKeyEvent, p_intf );
141
142     /* Destroy structure */
143     free( p_sys );
144 }
145
146 static int PutAction( intf_thread_t *p_intf, int i_action )
147 {
148     intf_sys_t *p_sys = p_intf->p_sys;
149     playlist_t *p_playlist = pl_Hold( p_intf );
150
151     /* Update the input */
152     input_thread_t *p_input = playlist_CurrentInput( p_playlist );
153
154     /* Update the vout */
155     vout_thread_t *p_vout = p_input ? input_GetVout( p_input ) : NULL;
156
157     /* Update the aout */
158     aout_instance_t *p_aout = p_input ? input_GetAout( p_input ) : NULL;
159
160     /* Register OSD channels */
161     /* FIXME: this check can fail if the new vout is reallocated at the same
162      * address as the old one... We should rather listen to vout events.
163      * Alternatively, we should keep a reference to the vout thread. */
164     if( p_vout && p_vout != p_sys->p_last_vout )
165         for( unsigned i = 0; i < CHANNELS_NUMBER; i++ )
166              spu_Control( vout_GetSpu( p_vout ), SPU_CHANNEL_REGISTER,
167                           &p_intf->p_sys->p_channels[ i ] );
168     p_sys->p_last_vout = p_vout;
169
170     /* Quit */
171     switch( i_action )
172     {
173         case ACTIONID_QUIT:
174             libvlc_Quit( p_intf->p_libvlc );
175
176             ClearChannels( p_intf, p_vout );
177             vout_OSDMessage( p_intf, DEFAULT_CHAN, "%s", _( "Quit" ) );
178             break;
179
180         /* Volume and audio actions */
181         case ACTIONID_VOL_UP:
182         {
183             audio_volume_t i_newvol;
184             aout_VolumeUp( p_playlist, 1, &i_newvol );
185             DisplayVolume( p_intf, p_vout, i_newvol );
186             break;
187         }
188
189         case ACTIONID_VOL_DOWN:
190         {
191             audio_volume_t i_newvol;
192             aout_VolumeDown( p_playlist, 1, &i_newvol );
193             DisplayVolume( p_intf, p_vout, i_newvol );
194             break;
195         }
196
197         case ACTIONID_VOL_MUTE:
198         {
199             audio_volume_t i_newvol = -1;
200             aout_ToggleMute( p_playlist, &i_newvol );
201             if( p_vout )
202             {
203                 if( i_newvol == 0 )
204                 {
205                     ClearChannels( p_intf, p_vout );
206                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
207                                   OSD_MUTE_ICON );
208                 }
209                 else
210                     DisplayVolume( p_intf, p_vout, i_newvol );
211             }
212             break;
213         }
214
215         /* Interface showing */
216         case ACTIONID_INTF_SHOW:
217             var_SetBool( p_intf->p_libvlc, "intf-show", true );
218             break;
219
220         case ACTIONID_INTF_HIDE:
221             var_SetBool( p_intf->p_libvlc, "intf-show", false );
222             break;
223
224         /* Video Output actions */
225         case ACTIONID_SNAPSHOT:
226             if( p_vout )
227                 var_TriggerCallback( p_vout, "video-snapshot" );
228             break;
229
230         case ACTIONID_TOGGLE_FULLSCREEN:
231         {
232             vlc_object_t *obj = p_vout ? VLC_OBJECT(p_vout)
233                                        : VLC_OBJECT(p_playlist);
234             var_ToggleBool( obj, "fullscreen" );
235             break;
236         }
237
238         case ACTIONID_LEAVE_FULLSCREEN:
239             if( p_vout && var_GetBool( p_vout, "fullscreen" ) )
240                 var_SetBool( p_vout, "fullscreen", false );
241             break;
242
243         case ACTIONID_ZOOM_QUARTER:
244         case ACTIONID_ZOOM_HALF:
245         case ACTIONID_ZOOM_ORIGINAL:
246         case ACTIONID_ZOOM_DOUBLE:
247             if( p_vout )
248             {
249                 float f;
250                 switch( i_action )
251                 {
252                     case ACTIONID_ZOOM_QUARTER:  f = 0.25; break;
253                     case ACTIONID_ZOOM_HALF:     f = 0.5;  break;
254                     case ACTIONID_ZOOM_ORIGINAL: f = 1.;   break;
255                      /*case ACTIONID_ZOOM_DOUBLE:*/
256                     default:                     f = 2.;   break;
257                 }
258                 var_SetFloat( p_vout, "zoom", f );
259             }
260             break;
261
262 #ifdef WIN32
263         case ACTIONID_WALLPAPER:
264         {   /* FIXME: this is invalid if not using DirectX output!!! */
265             vlc_object_t *obj = p_vout ? VLC_OBJECT(p_vout)
266                                        : VLC_OBJECT(p_playlist);
267             var_ToggleBool( obj, "directx-wallpaper" );
268             break;
269         }
270 #endif
271
272         /* Playlist actions */
273         case ACTIONID_LOOP:
274             /* Toggle Normal -> Loop -> Repeat -> Normal ... */
275             if( var_GetBool( p_playlist, "repeat" ) )
276                 var_SetBool( p_playlist, "repeat", false );
277             else
278             if( var_GetBool( p_playlist, "loop" ) )
279             { /* FIXME: this is not atomic, we should use a real tristate */
280                 var_SetBool( p_playlist, "loop", false );
281                 var_SetBool( p_playlist, "repeat", true );
282             }
283             else
284                 var_SetBool( p_playlist, "loop", true );
285             break;
286
287         case ACTIONID_RANDOM:
288         {
289             var_ToggleBool( p_playlist, "random" );
290             break;
291         }
292
293         case ACTIONID_PLAY_PAUSE:
294             if( p_input )
295             {
296                 ClearChannels( p_intf, p_vout );
297
298                 int state = var_GetInteger( p_input, "state" );
299                 if( state != PAUSE_S )
300                 {
301                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
302                                   OSD_PAUSE_ICON );
303                     state = PAUSE_S;
304                 }
305                 else
306                 {
307                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
308                                   OSD_PLAY_ICON );
309                     state = PLAYING_S;
310                 }
311                 var_SetInteger( p_input, "state", state );
312             }
313             else
314                 playlist_Play( p_playlist );
315             break;
316
317         case ACTIONID_AUDIODEVICE_CYCLE:
318         {
319             if( !p_aout )
320                 break;
321
322             vlc_value_t val, list, list2;
323             int i_count, i;
324
325             var_Get( p_aout, "audio-device", &val );
326             var_Change( p_aout, "audio-device", VLC_VAR_GETCHOICES,
327                     &list, &list2 );
328             i_count = list.p_list->i_count;
329
330             if( i_count > 1 )
331             {
332                 for( i = 0; i < i_count; i++ )
333                 {
334                     if( val.i_int == list.p_list->p_values[i].i_int )
335                     {
336                         break;
337                     }
338                 }
339                 if( i == i_count )
340                 {
341                     msg_Warn( p_aout,
342                             "invalid current audio device, selecting 0" );
343                     var_Set( p_aout, "audio-device",
344                             list.p_list->p_values[0] );
345                     i = 0;
346                 }
347                 else if( i == i_count -1 )
348                 {
349                     var_Set( p_aout, "audio-device",
350                             list.p_list->p_values[0] );
351                     i = 0;
352                 }
353                 else
354                 {
355                     var_Set( p_aout, "audio-device",
356                             list.p_list->p_values[i+1] );
357                     i++;
358                 }
359                 vout_OSDMessage( p_intf, DEFAULT_CHAN,
360                         _("Audio Device: %s"),
361                         list2.p_list->p_values[i].psz_string);
362             }
363             var_FreeList( &list, &list2 );
364             break;
365         }
366
367         /* Input options */
368         default:
369         {
370             if( !p_input )
371                 break;
372
373             bool b_seekable = var_GetBool( p_input, "can-seek" );
374             int i_interval =0;
375
376             if( i_action == ACTIONID_PAUSE )
377             {
378                 if( var_GetInteger( p_input, "state" ) != PAUSE_S )
379                 {
380                     ClearChannels( p_intf, p_vout );
381                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
382                                   OSD_PAUSE_ICON );
383                     var_SetInteger( p_input, "state", PAUSE_S );
384                 }
385             }
386             else if( i_action == ACTIONID_JUMP_BACKWARD_EXTRASHORT
387                      && b_seekable )
388             {
389 #define SET_TIME( a, b ) \
390     i_interval = config_GetInt( p_input, a "-jump-size" ); \
391     if( i_interval > 0 ) { \
392         mtime_t i_time = (mtime_t)(i_interval * b) * 1000000L; \
393         var_SetTime( p_input, "time-offset", i_time ); \
394         DisplayPosition( p_intf, p_vout, p_input ); \
395     }
396                 SET_TIME( "extrashort", -1 );
397             }
398             else if( i_action == ACTIONID_JUMP_FORWARD_EXTRASHORT && b_seekable )
399             {
400                 SET_TIME( "extrashort", 1 );
401             }
402             else if( i_action == ACTIONID_JUMP_BACKWARD_SHORT && b_seekable )
403             {
404                 SET_TIME( "short", -1 );
405             }
406             else if( i_action == ACTIONID_JUMP_FORWARD_SHORT && b_seekable )
407             {
408                 SET_TIME( "short", 1 );
409             }
410             else if( i_action == ACTIONID_JUMP_BACKWARD_MEDIUM && b_seekable )
411             {
412                 SET_TIME( "medium", -1 );
413             }
414             else if( i_action == ACTIONID_JUMP_FORWARD_MEDIUM && b_seekable )
415             {
416                 SET_TIME( "medium", 1 );
417             }
418             else if( i_action == ACTIONID_JUMP_BACKWARD_LONG && b_seekable )
419             {
420                 SET_TIME( "long", -1 );
421             }
422             else if( i_action == ACTIONID_JUMP_FORWARD_LONG && b_seekable )
423             {
424                 SET_TIME( "long", 1 );
425 #undef SET_TIME
426             }
427             else if( i_action == ACTIONID_AUDIO_TRACK )
428             {
429                 vlc_value_t val, list, list2;
430                 int i_count, i;
431                 var_Get( p_input, "audio-es", &val );
432                 var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
433                             &list, &list2 );
434                 i_count = list.p_list->i_count;
435                 if( i_count > 1 )
436                 {
437                     for( i = 0; i < i_count; i++ )
438                     {
439                         if( val.i_int == list.p_list->p_values[i].i_int )
440                         {
441                             break;
442                         }
443                     }
444                     /* value of audio-es was not in choices list */
445                     if( i == i_count )
446                     {
447                         msg_Warn( p_input,
448                                   "invalid current audio track, selecting 0" );
449                         i = 0;
450                     }
451                     else if( i == i_count - 1 )
452                         i = 1;
453                     else
454                         i++;
455                     var_Set( p_input, "audio-es", list.p_list->p_values[i] );
456                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
457                                      _("Audio track: %s"),
458                                      list2.p_list->p_values[i].psz_string );
459                 }
460                 var_FreeList( &list, &list2 );
461             }
462             else if( i_action == ACTIONID_SUBTITLE_TRACK )
463             {
464                 vlc_value_t val, list, list2;
465                 int i_count, i;
466                 var_Get( p_input, "spu-es", &val );
467
468                 var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
469                             &list, &list2 );
470                 i_count = list.p_list->i_count;
471                 if( i_count <= 1 )
472                 {
473                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
474                                      _("Subtitle track: %s"), _("N/A") );
475                     var_FreeList( &list, &list2 );
476                     goto cleanup_and_continue;
477                 }
478                 for( i = 0; i < i_count; i++ )
479                 {
480                     if( val.i_int == list.p_list->p_values[i].i_int )
481                     {
482                         break;
483                     }
484                 }
485                 /* value of spu-es was not in choices list */
486                 if( i == i_count )
487                 {
488                     msg_Warn( p_input,
489                               "invalid current subtitle track, selecting 0" );
490                     i = 0;
491                 }
492                 else if( i == i_count - 1 )
493                     i = 0;
494                 else
495                     i++;
496                 var_Set( p_input, "spu-es", list.p_list->p_values[i] );
497                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
498                                  _("Subtitle track: %s"),
499                                  list2.p_list->p_values[i].psz_string );
500                 var_FreeList( &list, &list2 );
501             }
502             else if( i_action == ACTIONID_ASPECT_RATIO && p_vout )
503             {
504                 vlc_value_t val={0}, val_list, text_list;
505                 var_Get( p_vout, "aspect-ratio", &val );
506                 if( var_Change( p_vout, "aspect-ratio", VLC_VAR_GETLIST,
507                                 &val_list, &text_list ) >= 0 )
508                 {
509                     int i;
510                     for( i = 0; i < val_list.p_list->i_count; i++ )
511                     {
512                         if( !strcmp( val_list.p_list->p_values[i].psz_string,
513                                      val.psz_string ) )
514                         {
515                             i++;
516                             break;
517                         }
518                     }
519                     if( i == val_list.p_list->i_count ) i = 0;
520                     var_SetString( p_vout, "aspect-ratio",
521                                    val_list.p_list->p_values[i].psz_string );
522                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
523                                      _("Aspect ratio: %s"),
524                                      text_list.p_list->p_values[i].psz_string );
525
526                     var_FreeList( &val_list, &text_list );
527                 }
528                 free( val.psz_string );
529             }
530             else if( i_action == ACTIONID_CROP && p_vout )
531             {
532                 vlc_value_t val={0}, val_list, text_list;
533                 var_Get( p_vout, "crop", &val );
534                 if( var_Change( p_vout, "crop", VLC_VAR_GETLIST,
535                                 &val_list, &text_list ) >= 0 )
536                 {
537                     int i;
538                     for( i = 0; i < val_list.p_list->i_count; i++ )
539                     {
540                         if( !strcmp( val_list.p_list->p_values[i].psz_string,
541                                      val.psz_string ) )
542                         {
543                             i++;
544                             break;
545                         }
546                     }
547                     if( i == val_list.p_list->i_count ) i = 0;
548                     var_SetString( p_vout, "crop",
549                                    val_list.p_list->p_values[i].psz_string );
550                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
551                                      _("Crop: %s"),
552                                      text_list.p_list->p_values[i].psz_string );
553
554                     var_FreeList( &val_list, &text_list );
555                 }
556                 free( val.psz_string );
557             }
558             else if( i_action == ACTIONID_TOGGLE_AUTOSCALE && p_vout )
559             {
560                 float f_scalefactor = var_GetFloat( p_vout, "scale" );
561                 if ( f_scalefactor != 1.0 )
562                 {
563                     var_SetFloat( p_vout, "scale", 1.0 );
564                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
565                                          "%s", _("Zooming reset") );
566                 }
567                 else
568                 {
569                     bool b_autoscale = !var_GetBool( p_vout, "autoscale" );
570                     var_SetBool( p_vout, "autoscale", b_autoscale );
571                     if( b_autoscale )
572                         vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
573                                          "%s", _("Scaled to screen") );
574                     else
575                         vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
576                                          "%s", _("Original Size") );
577                 }
578             }
579             else if( i_action == ACTIONID_SCALE_UP && p_vout )
580             {
581                float f_scalefactor;
582
583                f_scalefactor = var_GetFloat( p_vout, "scale" );
584                if( f_scalefactor < 10. )
585                    f_scalefactor += .1;
586                var_SetFloat( p_vout, "scale", f_scalefactor );
587             }
588             else if( i_action == ACTIONID_SCALE_DOWN && p_vout )
589             {
590                float f_scalefactor;
591
592                f_scalefactor = var_GetFloat( p_vout, "scale" );
593                if( f_scalefactor > .3 )
594                    f_scalefactor -= .1;
595                var_SetFloat( p_vout, "scale", f_scalefactor );
596             }
597             else if( i_action == ACTIONID_DEINTERLACE && p_vout )
598             {
599                 int i_deinterlace = var_GetInteger( p_vout, "deinterlace" );
600                 if( i_deinterlace != 0 )
601                 {
602                     var_SetInteger( p_vout, "deinterlace", 0 );
603                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
604                                      "%s", _("Deinterlace off") );
605                 }
606                 else
607                 {
608                     var_SetInteger( p_vout, "deinterlace", 1 );
609
610                     char *psz_mode = var_GetString( p_vout, "deinterlace-mode" );
611                     vlc_value_t vlist, tlist;
612                     if( psz_mode && !var_Change( p_vout, "deinterlace-mode", VLC_VAR_GETCHOICES, &vlist, &tlist ) >= 0 )
613                     {
614                         const char *psz_text = NULL;
615                         for( int i = 0; i < vlist.p_list->i_count; i++ )
616                         {
617                             if( !strcmp( vlist.p_list->p_values[i].psz_string, psz_mode ) )
618                             {
619                                 psz_text = tlist.p_list->p_values[i].psz_string;
620                                 break;
621                             }
622                         }
623                         vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
624                                          "%s (%s)", _("Deinterlace on"), psz_text ? psz_text : psz_mode );
625
626                         var_FreeList( &vlist, &tlist );
627                     }
628                     free( psz_mode );
629                 }
630             }
631             else if( ( i_action == ACTIONID_ZOOM ||
632                        i_action == ACTIONID_UNZOOM ) && p_vout )
633             {
634                 vlc_value_t val={0}, val_list, text_list;
635                 var_Get( p_vout, "zoom", &val );
636                 if( var_Change( p_vout, "zoom", VLC_VAR_GETLIST,
637                                 &val_list, &text_list ) >= 0 )
638                 {
639                     int i;
640                     for( i = 0; i < val_list.p_list->i_count; i++ )
641                     {
642                         if( val_list.p_list->p_values[i].f_float
643                            == val.f_float )
644                         {
645                             if( i_action == ACTIONID_ZOOM )
646                                 i++;
647                             else /* ACTIONID_UNZOOM */
648                                 i--;
649                             break;
650                         }
651                     }
652                     if( i == val_list.p_list->i_count ) i = 0;
653                     if( i == -1 ) i = val_list.p_list->i_count-1;
654                     var_SetFloat( p_vout, "zoom",
655                                   val_list.p_list->p_values[i].f_float );
656                     vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
657                                      _("Zoom mode: %s"),
658                                 text_list.p_list->p_values[i].var.psz_name );
659
660                     var_FreeList( &val_list, &text_list );
661                 }
662             }
663             else if( i_action == ACTIONID_CROP_TOP && p_vout )
664                 var_IncInteger( p_vout, "crop-top" );
665             else if( i_action == ACTIONID_UNCROP_TOP && p_vout )
666                 var_DecInteger( p_vout, "crop-top" );
667             else if( i_action == ACTIONID_CROP_BOTTOM && p_vout )
668                 var_IncInteger( p_vout, "crop-bottom" );
669             else if( i_action == ACTIONID_UNCROP_BOTTOM && p_vout )
670                  var_DecInteger( p_vout, "crop-bottom" );
671             else if( i_action == ACTIONID_CROP_LEFT && p_vout )
672                  var_IncInteger( p_vout, "crop-left" );
673             else if( i_action == ACTIONID_UNCROP_LEFT && p_vout )
674                  var_DecInteger( p_vout, "crop-left" );
675             else if( i_action == ACTIONID_CROP_RIGHT && p_vout )
676                  var_IncInteger( p_vout, "crop-right" );
677             else if( i_action == ACTIONID_UNCROP_RIGHT && p_vout )
678                  var_DecInteger( p_vout, "crop-right" );
679
680             else if( i_action == ACTIONID_NEXT )
681             {
682                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, "%s", _("Next") );
683                 playlist_Next( p_playlist );
684             }
685             else if( i_action == ACTIONID_PREV )
686             {
687                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, "%s",
688                                  _("Previous") );
689                 playlist_Prev( p_playlist );
690             }
691             else if( i_action == ACTIONID_STOP )
692             {
693                 playlist_Stop( p_playlist );
694             }
695             else if( i_action == ACTIONID_FRAME_NEXT )
696             {
697                 var_TriggerCallback( p_input, "frame-next" );
698                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
699                                  "%s", _("Next frame") );
700             }
701             else if( i_action == ACTIONID_FASTER )
702             {
703                 var_TriggerCallback( p_input, "rate-faster" );
704                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
705                                  "%s", _("Faster") );
706             }
707             else if( i_action == ACTIONID_SLOWER )
708             {
709                 var_TriggerCallback( p_input, "rate-slower" );
710                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
711                                  "%s", _("Slower") );
712             }
713             else if( i_action == ACTIONID_RATE_NORMAL )
714             {
715                 var_SetFloat( p_input, "rate", 1. );
716                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
717                                  "%s", _("1.00x") );
718             }
719             else if( i_action == ACTIONID_RATE_FASTER_FINE ||
720                      i_action == ACTIONID_RATE_SLOWER_FINE )
721             {
722                 const double f_rate_min = (double)INPUT_RATE_DEFAULT / INPUT_RATE_MAX;
723                 const double f_rate_max = (double)INPUT_RATE_DEFAULT / INPUT_RATE_MIN;
724                 double f_rate = var_GetFloat( p_input, "rate" );
725
726                 int i_sign = f_rate < 0 ? -1 : 1;
727                 const int i_dir = i_action == ACTIONID_RATE_FASTER_FINE ? 1 : -1;
728
729                 f_rate = floor( fabs(f_rate) / 0.1 + i_dir ) * 0.1;
730                 if( f_rate < f_rate_min )
731                     f_rate = f_rate_min;
732                 else if( f_rate > f_rate_max )
733                     f_rate = f_rate_max;
734                 f_rate *= i_sign;
735
736                 var_SetFloat( p_input, "rate", f_rate );
737
738                 char psz_msg[7+1];
739                 snprintf( psz_msg, sizeof(psz_msg), _("%.2fx"), f_rate );
740                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, "%s", psz_msg );
741             }
742             else if( i_action == ACTIONID_POSITION && b_seekable )
743             {
744                 DisplayPosition( p_intf, p_vout, p_input );
745             }
746             else if( i_action >= ACTIONID_PLAY_BOOKMARK1 &&
747                      i_action <= ACTIONID_PLAY_BOOKMARK10 )
748             {
749                 PlayBookmark( p_intf, i_action - ACTIONID_PLAY_BOOKMARK1 + 1 );
750             }
751             else if( i_action >= ACTIONID_SET_BOOKMARK1 &&
752                      i_action <= ACTIONID_SET_BOOKMARK10 )
753             {
754                 SetBookmark( p_intf, i_action - ACTIONID_SET_BOOKMARK1 + 1 );
755             }
756             /* Only makes sense with DVD */
757             else if( i_action == ACTIONID_TITLE_PREV )
758                 var_TriggerCallback( p_input, "prev-title" );
759             else if( i_action == ACTIONID_TITLE_NEXT )
760                 var_TriggerCallback( p_input, "next-title" );
761             else if( i_action == ACTIONID_CHAPTER_PREV )
762                 var_TriggerCallback( p_input, "prev-chapter" );
763             else if( i_action == ACTIONID_CHAPTER_NEXT )
764                 var_TriggerCallback( p_input, "next-chapter" );
765             else if( i_action == ACTIONID_DISC_MENU )
766                 var_SetInteger( p_input, "title  0", 2 );
767
768             else if( i_action == ACTIONID_SUBDELAY_DOWN )
769             {
770                 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
771                 i_delay -= 50000;    /* 50 ms */
772                 var_SetTime( p_input, "spu-delay", i_delay );
773                 ClearChannels( p_intf, p_vout );
774                 vout_OSDMessage( p_intf, DEFAULT_CHAN,
775                                  _( "Subtitle delay %i ms" ),
776                                  (int)(i_delay/1000) );
777             }
778             else if( i_action == ACTIONID_SUBDELAY_UP )
779             {
780                 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
781                 i_delay += 50000;    /* 50 ms */
782                 var_SetTime( p_input, "spu-delay", i_delay );
783                 ClearChannels( p_intf, p_vout );
784                 vout_OSDMessage( p_intf, DEFAULT_CHAN,
785                                 _( "Subtitle delay %i ms" ),
786                                  (int)(i_delay/1000) );
787             }
788             else if( i_action == ACTIONID_SUBPOS_DOWN )
789             {
790                 int i_pos = var_GetInteger( p_input, "sub-margin" );
791                 --i_pos;
792                 var_SetInteger( p_input, "sub-margin", i_pos );
793                 ClearChannels( p_intf, p_vout );
794                 vout_OSDMessage( p_intf, DEFAULT_CHAN,
795                                 _( "Subtitle position %i px" ),
796                                  (int)(i_pos) );
797             }
798             else if( i_action == ACTIONID_SUBPOS_UP )
799             {
800                 int i_pos = var_GetInteger( p_input, "sub-margin" );
801                 ++i_pos;
802                 var_SetInteger( p_input, "sub-margin", i_pos );
803                 ClearChannels( p_intf, p_vout );
804                 vout_OSDMessage( p_intf, DEFAULT_CHAN,
805                                 _( "Subtitle position %i px" ),
806                                  (int)(i_pos) );
807             }
808             else if( i_action == ACTIONID_AUDIODELAY_DOWN )
809             {
810                 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
811                 i_delay -= 50000;    /* 50 ms */
812                 var_SetTime( p_input, "audio-delay", i_delay );
813                 ClearChannels( p_intf, p_vout );
814                 vout_OSDMessage( p_intf, DEFAULT_CHAN,
815                                 _( "Audio delay %i ms" ),
816                                  (int)(i_delay/1000) );
817             }
818             else if( i_action == ACTIONID_AUDIODELAY_UP )
819             {
820                 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
821                 i_delay += 50000;    /* 50 ms */
822                 var_SetTime( p_input, "audio-delay", i_delay );
823                 ClearChannels( p_intf, p_vout );
824                 vout_OSDMessage( p_intf, DEFAULT_CHAN,
825                                 _( "Audio delay %i ms" ),
826                                  (int)(i_delay/1000) );
827             }
828             else if( i_action == ACTIONID_PLAY )
829             {
830                 if( var_GetFloat( p_input, "rate" ) != 1. )
831                     /* Return to normal speed */
832                     var_SetFloat( p_input, "rate", 1. );
833                 else
834                 {
835                     ClearChannels( p_intf, p_vout );
836                     vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
837                                   OSD_PLAY_ICON );
838                     playlist_Play( p_playlist );
839                 }
840             }
841             else if( i_action == ACTIONID_MENU_ON )
842             {
843                 osd_MenuShow( VLC_OBJECT(p_intf) );
844             }
845             else if( i_action == ACTIONID_MENU_OFF )
846             {
847                 osd_MenuHide( VLC_OBJECT(p_intf) );
848             }
849             else if( i_action == ACTIONID_MENU_LEFT )
850             {
851                 osd_MenuPrev( VLC_OBJECT(p_intf) );
852             }
853             else if( i_action == ACTIONID_MENU_RIGHT )
854             {
855                 osd_MenuNext( VLC_OBJECT(p_intf) );
856             }
857             else if( i_action == ACTIONID_MENU_UP )
858             {
859                 osd_MenuUp( VLC_OBJECT(p_intf) );
860             }
861             else if( i_action == ACTIONID_MENU_DOWN )
862             {
863                 osd_MenuDown( VLC_OBJECT(p_intf) );
864             }
865             else if( i_action == ACTIONID_MENU_SELECT )
866             {
867                 osd_MenuActivate( VLC_OBJECT(p_intf) );
868             }
869             else if( i_action == ACTIONID_RECORD )
870             {
871                 if( var_GetBool( p_input, "can-record" ) )
872                 {
873                     const bool b_record = !var_GetBool( p_input, "record" );
874
875                     if( b_record )
876                         vout_OSDMessage( p_intf, DEFAULT_CHAN, "%s", _("Recording") );
877                     else
878                         vout_OSDMessage( p_intf, DEFAULT_CHAN, "%s", _("Recording done") );
879                     var_SetBool( p_input, "record", b_record );
880                 }
881             }
882         }
883     }
884 cleanup_and_continue:
885     if( p_aout )
886         vlc_object_release( p_aout );
887     if( p_vout )
888         vlc_object_release( p_vout );
889     if( p_input )
890         vlc_object_release( p_input );
891     pl_Release( p_intf );
892     return VLC_SUCCESS;
893 }
894
895 /*****************************************************************************
896  * SpecialKeyEvent: callback for mouse events
897  *****************************************************************************/
898 static int SpecialKeyEvent( vlc_object_t *libvlc, char const *psz_var,
899                             vlc_value_t oldval, vlc_value_t newval,
900                             void *p_data )
901 {
902     intf_thread_t *p_intf = (intf_thread_t *)p_data;
903     int i_action = 0;
904
905     (void)psz_var;
906     (void)oldval;
907
908     int i_mode = p_intf->p_sys->i_mousewheel_mode;
909
910     /* Special action for mouse event */
911     /* FIXME: rework hotkeys handling to allow more than 1 event
912      * to trigger one same action */
913     switch (newval.i_int & ~KEY_MODIFIER)
914     {
915         case KEY_MOUSEWHEELUP:
916             i_action = (i_mode == MOUSEWHEEL_VOLUME ) ? ACTIONID_VOL_UP
917                                  : ACTIONID_JUMP_FORWARD_EXTRASHORT;
918             break;
919         case KEY_MOUSEWHEELDOWN:
920             i_action = (i_mode == MOUSEWHEEL_VOLUME ) ? ACTIONID_VOL_DOWN
921                                 : ACTIONID_JUMP_BACKWARD_EXTRASHORT;
922             break;
923         case KEY_MOUSEWHEELLEFT:
924             i_action = (i_mode == MOUSEWHEEL_VOLUME ) ?
925                         ACTIONID_JUMP_BACKWARD_EXTRASHORT : ACTIONID_VOL_DOWN;
926             break;
927         case KEY_MOUSEWHEELRIGHT:
928             i_action = (i_mode == MOUSEWHEEL_VOLUME ) ?
929                         ACTIONID_JUMP_FORWARD_EXTRASHORT : ACTIONID_VOL_UP;
930             break;
931         case KEY_MENU:
932             var_SetBool( libvlc, "intf-popupmenu", true );
933             break;
934     }
935
936     if( i_mode == NO_MOUSEWHEEL ) return VLC_SUCCESS;
937
938     if( i_action )
939         return PutAction( p_intf, i_action );
940     return VLC_SUCCESS;
941 }
942
943 /*****************************************************************************
944  * ActionEvent: callback for hotkey actions
945  *****************************************************************************/
946 static int ActionEvent( vlc_object_t *libvlc, char const *psz_var,
947                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
948 {
949     intf_thread_t *p_intf = (intf_thread_t *)p_data;
950
951     (void)libvlc;
952     (void)psz_var;
953     (void)oldval;
954
955     return PutAction( p_intf, newval.i_int );
956 }
957
958 static void PlayBookmark( intf_thread_t *p_intf, int i_num )
959 {
960     char *psz_bookmark_name;
961     if( asprintf( &psz_bookmark_name, "bookmark%i", i_num ) == -1 )
962         return;
963
964     playlist_t *p_playlist = pl_Hold( p_intf );
965     char *psz_bookmark = var_CreateGetString( p_intf, psz_bookmark_name );
966
967     PL_LOCK;
968     FOREACH_ARRAY( playlist_item_t *p_item, p_playlist->items )
969         char *psz_uri = input_item_GetURI( p_item->p_input );
970         if( !strcmp( psz_bookmark, psz_uri ) )
971         {
972             free( psz_uri );
973             playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
974                               NULL, p_item );
975             break;
976         }
977         else
978             free( psz_uri );
979     FOREACH_END();
980     PL_UNLOCK;
981
982     free( psz_bookmark );
983     free( psz_bookmark_name );
984     pl_Release( p_intf );
985 }
986
987 static void SetBookmark( intf_thread_t *p_intf, int i_num )
988 {
989     char *psz_bookmark_name;
990     if( asprintf( &psz_bookmark_name, "bookmark%i", i_num ) == -1 )
991         return;
992
993     playlist_t *p_playlist = pl_Hold( p_intf );
994     var_Create( p_intf, psz_bookmark_name,
995                 VLC_VAR_STRING|VLC_VAR_DOINHERIT );
996     playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
997     if( p_item )
998     {
999         char *psz_uri = input_item_GetURI( p_item->p_input );
1000         config_PutPsz( p_intf, psz_bookmark_name, psz_uri);
1001         msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num, psz_uri);
1002         free( psz_uri );
1003         config_SaveConfigFile( p_intf, "hotkeys" );
1004     }
1005
1006     pl_Release( p_intf );
1007     free( psz_bookmark_name );
1008 }
1009
1010 static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
1011                              input_thread_t *p_input )
1012 {
1013     char psz_duration[MSTRTIME_MAX_SIZE];
1014     char psz_time[MSTRTIME_MAX_SIZE];
1015     vlc_value_t time, pos;
1016     mtime_t i_seconds;
1017
1018     if( p_vout == NULL ) return;
1019
1020     ClearChannels( p_intf, p_vout );
1021
1022     var_Get( p_input, "time", &time );
1023     i_seconds = time.i_time / 1000000;
1024     secstotimestr ( psz_time, i_seconds );
1025
1026     var_Get( p_input, "length", &time );
1027     if( time.i_time > 0 )
1028     {
1029         secstotimestr( psz_duration, time.i_time / 1000000 );
1030         vout_OSDMessage( p_input, POSITION_TEXT_CHAN, "%s / %s",
1031                          psz_time, psz_duration );
1032     }
1033     else if( i_seconds > 0 )
1034     {
1035         vout_OSDMessage( p_input, POSITION_TEXT_CHAN, "%s", psz_time );
1036     }
1037
1038     if( var_GetBool( p_vout, "fullscreen" ) )
1039     {
1040         var_Get( p_input, "position", &pos );
1041         vout_OSDSlider( VLC_OBJECT( p_input ), POSITION_WIDGET_CHAN,
1042                         pos.f_float * 100, OSD_HOR_SLIDER );
1043     }
1044 }
1045
1046 static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
1047                            audio_volume_t i_vol )
1048 {
1049     if( p_vout == NULL )
1050     {
1051         return;
1052     }
1053     ClearChannels( p_intf, p_vout );
1054
1055     if( var_GetBool( p_vout, "fullscreen" ) )
1056     {
1057         vout_OSDSlider( VLC_OBJECT( p_vout ), VOLUME_WIDGET_CHAN,
1058             i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
1059     }
1060     else
1061     {
1062         vout_OSDMessage( p_vout, VOLUME_TEXT_CHAN, _( "Volume %d%%" ),
1063                          i_vol*400/AOUT_VOLUME_MAX );
1064     }
1065 }
1066
1067 static void ClearChannels( intf_thread_t *p_intf, vout_thread_t *p_vout )
1068 {
1069     int i;
1070
1071     if( p_vout )
1072     {
1073         spu_t *p_spu = vout_GetSpu( p_vout );
1074         spu_Control( p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
1075         for( i = 0; i < CHANNELS_NUMBER; i++ )
1076         {
1077             spu_Control( p_spu, SPU_CHANNEL_CLEAR,
1078                          p_intf->p_sys->p_channels[ i ] );
1079         }
1080     }
1081 }