1 /*****************************************************************************
2 * hotkeys.c: Hotkey handling for vlc
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8 * Jean-Paul Saman <jpsaman #_at_# m2x.nl>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
32 #include <vlc/input.h>
39 #define BUFFER_SIZE 10
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 *****************************************************************************/
51 vlc_mutex_t change_lock; /* mutex to keep the callback
52 * and the main loop from
53 * stepping on each others
55 int p_keys[ BUFFER_SIZE ]; /* buffer that contains
57 int i_size; /* number of events in buffer */
58 int p_channels[ CHANNELS_NUMBER ]; /* contains registered
60 input_thread_t * p_input; /* pointer to input */
61 vout_thread_t * p_vout; /* pointer to vout object */
64 /*****************************************************************************
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 * );
81 /*****************************************************************************
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_("Define playlist bookmarks.")
97 set_shortname( _("Hotkeys") );
98 set_description( _("Hotkeys management interface") );
99 set_capability( "interface", 0 );
100 set_callbacks( Open, Close );
103 /*****************************************************************************
104 * Open: initialize interface
105 *****************************************************************************/
106 static int Open( vlc_object_t *p_this )
108 intf_thread_t *p_intf = (intf_thread_t *)p_this;
110 /* Allocate instance and initialize some members */
111 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
112 if( p_intf->p_sys == NULL )
114 msg_Err( p_intf, "out of memory" );
117 vlc_mutex_init( p_intf, &p_intf->p_sys->change_lock );
118 p_intf->p_sys->i_size = 0;
119 p_intf->pf_run = Run;
121 p_intf->p_sys->p_input = NULL;
122 p_intf->p_sys->p_vout = NULL;
124 var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
128 /*****************************************************************************
129 * Close: destroy interface
130 *****************************************************************************/
131 static void Close( vlc_object_t *p_this )
133 intf_thread_t *p_intf = (intf_thread_t *)p_this;
135 var_DelCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
136 if( p_intf->p_sys->p_input )
138 vlc_object_release( p_intf->p_sys->p_input );
140 if( p_intf->p_sys->p_vout )
142 vlc_object_release( p_intf->p_sys->p_vout );
144 /* Destroy structure */
145 free( p_intf->p_sys );
148 /*****************************************************************************
150 *****************************************************************************/
151 static void Run( intf_thread_t *p_intf )
153 playlist_t *p_playlist = NULL;
154 input_thread_t *p_input = NULL;
155 vout_thread_t *p_vout = NULL;
156 vout_thread_t *p_last_vout = NULL;
157 struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
161 /* Initialize hotkey structure */
162 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
164 var_Create( p_intf->p_vlc, p_hotkeys[i].psz_action,
165 VLC_VAR_HOTKEY | VLC_VAR_DOINHERIT );
167 var_AddCallback( p_intf->p_vlc, p_hotkeys[i].psz_action,
169 var_Get( p_intf->p_vlc, p_hotkeys[i].psz_action, &val );
170 var_Set( p_intf->p_vlc, p_hotkeys[i].psz_action, val );
173 while( !p_intf->b_die )
179 msleep( INTF_IDLE_SLEEP );
181 /* Update the input */
182 if( p_intf->p_sys->p_input == NULL )
184 p_playlist = (playlist_t *)vlc_object_find( p_intf,
185 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
188 p_intf->p_sys->p_input = p_playlist->p_input;
189 if( p_intf->p_sys->p_input )
190 vlc_object_yield( p_intf->p_sys->p_input );
191 vlc_object_release( p_playlist );
194 else if( p_intf->p_sys->p_input->b_dead )
196 vlc_object_release( p_intf->p_sys->p_input );
197 p_intf->p_sys->p_input = NULL;
199 p_input = p_intf->p_sys->p_input;
201 /* Update the vout */
202 p_last_vout = p_intf->p_sys->p_vout;
205 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
206 p_intf->p_sys->p_vout = p_vout;
208 else if( p_vout->b_die )
210 vlc_object_release( p_vout );
212 p_intf->p_sys->p_vout = NULL;
215 /* Register OSD channels */
216 if( p_vout && p_vout != p_last_vout )
218 for( i = 0; i < CHANNELS_NUMBER; i++ )
220 spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER,
221 &p_intf->p_sys->p_channels[ i ] );
225 /* Find action triggered by hotkey */
227 i_key = GetKey( p_intf );
228 for( i = 0; i_key != -1 && p_hotkeys[i].psz_action != NULL; i++ )
230 if( p_hotkeys[i].i_key == i_key )
232 i_action = p_hotkeys[i].i_action;
233 i_times = p_hotkeys[i].i_times;
234 /* times key pressed within max. delta time */
235 p_hotkeys[i].i_times = 0;
241 /* No key pressed, sleep a bit more */
242 msleep( INTF_IDLE_SLEEP );
246 if( i_action == ACTIONID_QUIT )
248 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
252 playlist_Stop( p_playlist );
253 vlc_object_release( p_playlist );
255 /* Playlist is stopped now kill vlc. */
256 p_intf->p_vlc->b_die = VLC_TRUE;
257 ClearChannels( p_intf, p_vout );
258 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Quit" ) );
261 else if( i_action == ACTIONID_VOL_UP )
263 audio_volume_t i_newvol;
264 aout_VolumeUp( p_intf, 1, &i_newvol );
265 DisplayVolume( p_intf, p_vout, i_newvol );
267 else if( i_action == ACTIONID_VOL_DOWN )
269 audio_volume_t i_newvol;
270 aout_VolumeDown( p_intf, 1, &i_newvol );
271 DisplayVolume( p_intf, p_vout, i_newvol );
273 else if( i_action == ACTIONID_VOL_MUTE )
275 audio_volume_t i_newvol = -1;
276 aout_VolumeMute( p_intf, &i_newvol );
281 ClearChannels( p_intf, p_vout );
282 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
287 DisplayVolume( p_intf, p_vout, i_newvol );
291 else if( i_action == ACTIONID_INTF_SHOW )
293 val.b_bool = VLC_TRUE;
294 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
298 var_Set( p_playlist, "intf-show", val );
299 vlc_object_release( p_playlist );
302 else if( i_action == ACTIONID_INTF_HIDE )
304 val.b_bool = VLC_FALSE;
305 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
309 var_Set( p_playlist, "intf-show", val );
310 vlc_object_release( p_playlist );
313 else if( i_action == ACTIONID_SNAPSHOT )
315 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
317 else if( i_action == ACTIONID_FULLSCREEN )
321 var_Get( p_vout, "fullscreen", &val );
322 val.b_bool = !val.b_bool;
323 var_Set( p_vout, "fullscreen", val );
327 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
331 var_Get( p_playlist, "fullscreen", &val );
332 val.b_bool = !val.b_bool;
333 var_Set( p_playlist, "fullscreen", val );
334 vlc_object_release( p_playlist );
338 else if( i_action == ACTIONID_PLAY_PAUSE )
340 val.i_int = PLAYING_S;
343 var_Get( p_input, "state", &val );
345 if( p_input && val.i_int != PAUSE_S )
347 ClearChannels( p_intf, p_vout );
348 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
351 var_Set( p_input, "state", val );
355 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
359 ClearChannels( p_intf, p_vout );
360 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
362 playlist_Play( p_playlist );
363 vlc_object_release( p_playlist );
370 * How to get a valid value ?
371 * That's not that easy with some special stream
373 vlc_bool_t b_seekable = VLC_TRUE;
376 if( i_action == ACTIONID_PAUSE )
378 ClearChannels( p_intf, p_vout );
379 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
382 var_Set( p_input, "state", val );
384 else if( i_action == ACTIONID_JUMP_BACKWARD_EXTRASHORT
387 #define SET_TIME( a, b ) \
388 i_interval = config_GetInt( p_input, a "-jump-size" ); \
389 if( i_interval > 0 ) { \
390 val.i_time = ( (mtime_t)(i_interval * b) * 1000000L \
391 * ((mtime_t)(1 << i_times))); \
392 var_Set( p_input, "time-offset", val ); \
393 DisplayPosition( p_intf, p_vout, p_input ); \
395 SET_TIME( "extrashort", -1 );
397 else if( i_action == ACTIONID_JUMP_FORWARD_EXTRASHORT && b_seekable )
399 SET_TIME( "extrashort", 1 );
401 else if( i_action == ACTIONID_JUMP_BACKWARD_SHORT && b_seekable )
403 SET_TIME( "short", -1 );
405 else if( i_action == ACTIONID_JUMP_FORWARD_SHORT && b_seekable )
407 SET_TIME( "short", 1 );
409 else if( i_action == ACTIONID_JUMP_BACKWARD_MEDIUM && b_seekable )
411 SET_TIME( "medium", -1 );
413 else if( i_action == ACTIONID_JUMP_FORWARD_MEDIUM && b_seekable )
415 SET_TIME( "medium", 1 );
417 else if( i_action == ACTIONID_JUMP_BACKWARD_LONG && b_seekable )
419 SET_TIME( "long", -1 );
421 else if( i_action == ACTIONID_JUMP_FORWARD_LONG && b_seekable )
423 SET_TIME( "long", 1 );
426 else if( i_action == ACTIONID_AUDIO_TRACK )
428 vlc_value_t val, list, list2;
430 var_Get( p_input, "audio-es", &val );
431 var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
433 i_count = list.p_list->i_count;
438 for( i = 0; i < i_count; i++ )
440 if( val.i_int == list.p_list->p_values[i].i_int )
445 /* value of audio-es was not in choices list */
449 "invalid current audio track, selecting 0" );
450 var_Set( p_input, "audio-es",
451 list.p_list->p_values[0] );
454 else if( i == i_count - 1 )
456 var_Set( p_input, "audio-es",
457 list.p_list->p_values[1] );
462 var_Set( p_input, "audio-es",
463 list.p_list->p_values[i+1] );
466 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
467 _("Audio track: %s"),
468 list2.p_list->p_values[i].psz_string );
470 else if( i_action == ACTIONID_SUBTITLE_TRACK )
472 vlc_value_t val, list, list2;
474 var_Get( p_input, "spu-es", &val );
476 var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
478 i_count = list.p_list->i_count;
481 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
482 _("Subtitle track: %s"), _("N/A") );
485 for( i = 0; i < i_count; i++ )
487 if( val.i_int == list.p_list->p_values[i].i_int )
492 /* value of spu-es was not in choices list */
496 "invalid current subtitle track, selecting 0" );
497 var_Set( p_input, "spu-es", list.p_list->p_values[0] );
500 else if( i == i_count - 1 )
502 var_Set( p_input, "spu-es", list.p_list->p_values[0] );
507 var_Set( p_input, "spu-es", list.p_list->p_values[i+1] );
510 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
511 _("Subtitle track: %s"),
512 list2.p_list->p_values[i].psz_string );
514 else if( i_action == ACTIONID_ASPECT_RATIO && p_vout )
516 vlc_value_t val={0}, val_list, text_list;
517 var_Get( p_vout, "aspect-ratio", &val );
518 if( var_Change( p_vout, "aspect-ratio", VLC_VAR_GETLIST,
519 &val_list, &text_list ) >= 0 )
522 for( i = 0; i < val_list.p_list->i_count; i++ )
524 if( !strcmp( val_list.p_list->p_values[i].psz_string,
531 if( i == val_list.p_list->i_count ) i = 0;
532 var_SetString( p_vout, "aspect-ratio",
533 val_list.p_list->p_values[i].psz_string );
534 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
535 _("Aspect ratio: %s"),
536 text_list.p_list->p_values[i].psz_string );
538 free( val.psz_string );
540 else if( i_action == ACTIONID_CROP && p_vout )
542 vlc_value_t val={0}, val_list, text_list;
543 var_Get( p_vout, "crop", &val );
544 if( var_Change( p_vout, "crop", VLC_VAR_GETLIST,
545 &val_list, &text_list ) >= 0 )
548 for( i = 0; i < val_list.p_list->i_count; i++ )
550 if( !strcmp( val_list.p_list->p_values[i].psz_string,
557 if( i == val_list.p_list->i_count ) i = 0;
558 var_SetString( p_vout, "crop",
559 val_list.p_list->p_values[i].psz_string );
560 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
562 text_list.p_list->p_values[i].psz_string );
564 free( val.psz_string );
566 else if( i_action == ACTIONID_DEINTERLACE && p_vout )
568 vlc_value_t val={0}, val_list, text_list;
569 var_Get( p_vout, "deinterlace", &val );
570 if( var_Change( p_vout, "deinterlace", VLC_VAR_GETLIST,
571 &val_list, &text_list ) >= 0 )
574 for( i = 0; i < val_list.p_list->i_count; i++ )
576 if( !strcmp( val_list.p_list->p_values[i].psz_string,
583 if( i == val_list.p_list->i_count ) i = 0;
584 var_SetString( p_vout, "deinterlace",
585 val_list.p_list->p_values[i].psz_string );
586 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
587 _("Deinterlace mode: %s"),
588 text_list.p_list->p_values[i].psz_string );
590 free( val.psz_string );
592 else if( ( i_action == ACTIONID_ZOOM || i_action == ACTIONID_UNZOOM ) && p_vout )
594 vlc_value_t val={0}, val_list, text_list;
595 var_Get( p_vout, "zoom", &val );
596 if( var_Change( p_vout, "zoom", VLC_VAR_GETLIST,
597 &val_list, &text_list ) >= 0 )
600 for( i = 0; i < val_list.p_list->i_count; i++ )
602 if( val_list.p_list->p_values[i].f_float
605 if( i_action == ACTIONID_ZOOM )
607 else /* ACTIONID_UNZOOM */
612 if( i == val_list.p_list->i_count ) i = 0;
613 if( i == -1 ) i = val_list.p_list->i_count-1;
614 var_SetFloat( p_vout, "zoom",
615 val_list.p_list->p_values[i].f_float );
616 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
618 text_list.p_list->p_values[i].var.psz_name );
621 else if( i_action == ACTIONID_NEXT )
623 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
627 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
629 playlist_Next( p_playlist );
630 vlc_object_release( p_playlist );
633 else if( i_action == ACTIONID_PREV )
635 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
639 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
641 playlist_Prev( p_playlist );
642 vlc_object_release( p_playlist );
645 else if( i_action == ACTIONID_STOP )
647 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
651 playlist_Stop( p_playlist );
652 vlc_object_release( p_playlist );
655 else if( i_action == ACTIONID_FASTER )
658 val.b_bool = VLC_TRUE;
659 var_Set( p_input, "rate-faster", val );
660 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
663 else if( i_action == ACTIONID_SLOWER )
666 val.b_bool = VLC_TRUE;
667 var_Set( p_input, "rate-slower", val );
668 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
671 else if( i_action == ACTIONID_POSITION && b_seekable )
673 DisplayPosition( p_intf, p_vout, p_input );
675 else if( i_action >= ACTIONID_PLAY_BOOKMARK1 &&
676 i_action <= ACTIONID_PLAY_BOOKMARK10 )
678 PlayBookmark( p_intf, i_action - ACTIONID_PLAY_BOOKMARK1 + 1 );
680 else if( i_action >= ACTIONID_SET_BOOKMARK1 &&
681 i_action <= ACTIONID_SET_BOOKMARK10 )
683 SetBookmark( p_intf, i_action - ACTIONID_SET_BOOKMARK1 + 1 );
685 /* Only makes sense with DVD */
686 else if( i_action == ACTIONID_TITLE_PREV )
688 val.b_bool = VLC_TRUE;
689 var_Set( p_input, "prev-title", val );
691 else if( i_action == ACTIONID_TITLE_NEXT )
693 val.b_bool = VLC_TRUE;
694 var_Set( p_input, "next-title", val );
696 else if( i_action == ACTIONID_CHAPTER_PREV )
698 val.b_bool = VLC_TRUE;
699 var_Set( p_input, "prev-chapter", val );
701 else if( i_action == ACTIONID_CHAPTER_NEXT )
703 val.b_bool = VLC_TRUE;
704 var_Set( p_input, "next-chapter", val );
706 else if( i_action == ACTIONID_DISC_MENU )
708 vlc_value_t val; val.i_int = 2;
709 var_Set( p_input, "title 0", val);
711 else if( i_action == ACTIONID_SUBDELAY_DOWN )
713 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
715 i_delay -= 50000; /* 50 ms */
717 var_SetTime( p_input, "spu-delay", i_delay );
718 ClearChannels( p_intf, p_vout );
719 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
720 (int)(i_delay/1000) );
722 else if( i_action == ACTIONID_SUBDELAY_UP )
724 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
726 i_delay += 50000; /* 50 ms */
728 var_SetTime( p_input, "spu-delay", i_delay );
729 ClearChannels( p_intf, p_vout );
730 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
731 (int)(i_delay/1000) );
733 else if( i_action == ACTIONID_AUDIODELAY_DOWN )
735 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
737 i_delay -= 50000; /* 50 ms */
739 var_SetTime( p_input, "audio-delay", i_delay );
740 ClearChannels( p_intf, p_vout );
741 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
742 (int)(i_delay/1000) );
744 else if( i_action == ACTIONID_AUDIODELAY_UP )
746 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
748 i_delay += 50000; /* 50 ms */
750 var_SetTime( p_input, "audio-delay", i_delay );
751 ClearChannels( p_intf, p_vout );
752 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
753 (int)(i_delay/1000) );
755 else if( i_action == ACTIONID_PLAY )
757 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
761 var_Get( p_input, "rate", &val );
762 msg_Dbg( p_input, "rate %d", val.i_int );
763 if( val.i_int != INPUT_RATE_DEFAULT )
765 /* Return to normal speed */
766 val.i_int = INPUT_RATE_DEFAULT;
767 var_Set( p_input, "rate", val );
771 ClearChannels( p_intf, p_vout );
772 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
774 playlist_Play( p_playlist );
776 vlc_object_release( p_playlist );
783 static int GetKey( intf_thread_t *p_intf)
785 vlc_mutex_lock( &p_intf->p_sys->change_lock );
786 if ( p_intf->p_sys->i_size == 0 )
788 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
793 int i_return = p_intf->p_sys->p_keys[ 0 ];
795 p_intf->p_sys->i_size--;
796 for ( i = 0; i < BUFFER_SIZE - 1; i++)
798 p_intf->p_sys->p_keys[ i ] = p_intf->p_sys->p_keys[ i + 1 ];
800 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
805 /*****************************************************************************
806 * KeyEvent: callback for keyboard events
807 *****************************************************************************/
808 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
809 vlc_value_t oldval, vlc_value_t newval, void *p_data )
811 intf_thread_t *p_intf = (intf_thread_t *)p_data;
812 vlc_mutex_lock( &p_intf->p_sys->change_lock );
813 if ( p_intf->p_sys->i_size == BUFFER_SIZE )
815 msg_Warn( p_intf, "event buffer full, dropping keypress" );
816 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
821 p_intf->p_sys->p_keys[ p_intf->p_sys->i_size ] = newval.i_int;
822 p_intf->p_sys->i_size++;
824 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
829 static int ActionKeyCB( vlc_object_t *p_this, char const *psz_var,
830 vlc_value_t oldval, vlc_value_t newval, void *p_data )
832 vlc_t *p_vlc = (vlc_t *)p_this;
833 struct hotkey *p_hotkeys = p_vlc->p_hotkeys;
837 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
839 if( !strcmp( p_hotkeys[i].psz_action, psz_var ) )
841 p_hotkeys[i].i_key = newval.i_int;
842 /* do hotkey accounting */
844 if( (p_hotkeys[i].i_delta_date > 0) &&
845 (p_hotkeys[i].i_delta_date <= (i_date - p_hotkeys[i].i_last_date) ) )
846 p_hotkeys[i].i_times = 0;
848 p_hotkeys[i].i_times++;
849 p_hotkeys[i].i_last_date = i_date;
856 static void PlayBookmark( intf_thread_t *p_intf, int i_num )
860 char psz_bookmark_name[11];
861 playlist_t *p_playlist =
862 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
864 sprintf( psz_bookmark_name, "bookmark%i", i_num );
865 var_Create( p_intf, psz_bookmark_name, VLC_VAR_STRING|VLC_VAR_DOINHERIT );
866 var_Get( p_intf, psz_bookmark_name, &val );
870 char *psz_bookmark = strdup( val.psz_string );
871 for( i_position = 0; i_position < p_playlist->i_size; i_position++)
873 if( !strcmp( psz_bookmark,
874 p_playlist->pp_items[i_position]->input.psz_uri ) )
876 playlist_Goto( p_playlist, i_position );
880 vlc_object_release( p_playlist );
884 static void SetBookmark( intf_thread_t *p_intf, int i_num )
886 playlist_t *p_playlist =
887 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
890 char psz_bookmark_name[11];
891 sprintf( psz_bookmark_name, "bookmark%i", i_num );
892 var_Create( p_intf, psz_bookmark_name,
893 VLC_VAR_STRING|VLC_VAR_DOINHERIT );
894 if( p_playlist->status.p_item )
896 config_PutPsz( p_intf, psz_bookmark_name,
897 p_playlist->status.p_item->input.psz_uri);
898 msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num,
899 p_playlist->status.p_item->input.psz_uri);
900 config_SaveConfigFile( p_intf, "hotkeys" );
902 vlc_object_release( p_playlist );
906 static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
907 input_thread_t *p_input )
909 char psz_duration[MSTRTIME_MAX_SIZE];
910 char psz_time[MSTRTIME_MAX_SIZE];
911 vlc_value_t time, pos;
918 ClearChannels( p_intf, p_vout );
920 var_Get( p_input, "time", &time );
921 i_seconds = time.i_time / 1000000;
922 secstotimestr ( psz_time, i_seconds );
924 var_Get( p_input, "length", &time );
925 if( time.i_time > 0 )
927 secstotimestr( psz_duration, time.i_time / 1000000 );
928 vout_OSDMessage( p_input, POSITION_TEXT_CHAN, "%s / %s",
929 psz_time, psz_duration );
931 else if( i_seconds > 0 )
933 vout_OSDMessage( p_input, POSITION_TEXT_CHAN, psz_time );
936 if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
938 var_Get( p_input, "position", &pos );
939 vout_OSDSlider( VLC_OBJECT( p_input ), POSITION_WIDGET_CHAN,
940 pos.f_float * 100, OSD_HOR_SLIDER );
944 static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
945 audio_volume_t i_vol )
951 ClearChannels( p_intf, p_vout );
953 if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
955 vout_OSDSlider( VLC_OBJECT( p_vout ), VOLUME_WIDGET_CHAN,
956 i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
960 vout_OSDMessage( p_vout, VOLUME_TEXT_CHAN, "Volume %d%%",
961 i_vol*400/AOUT_VOLUME_MAX );
965 static void ClearChannels( intf_thread_t *p_intf, vout_thread_t *p_vout )
971 spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
972 for( i = 0; i < CHANNELS_NUMBER; i++ )
974 spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
975 p_intf->p_sys->p_channels[ i ] );