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;
109 MALLOC_ERR( p_intf->p_sys, intf_sys_t );
111 vlc_mutex_init( p_intf, &p_intf->p_sys->change_lock );
112 p_intf->p_sys->i_size = 0;
113 p_intf->pf_run = Run;
115 p_intf->p_sys->p_input = NULL;
116 p_intf->p_sys->p_vout = NULL;
118 var_AddCallback( p_intf->p_libvlc, "key-pressed", KeyEvent, p_intf );
122 /*****************************************************************************
123 * Close: destroy interface
124 *****************************************************************************/
125 static void Close( vlc_object_t *p_this )
127 intf_thread_t *p_intf = (intf_thread_t *)p_this;
129 var_DelCallback( p_intf->p_libvlc, "key-pressed", KeyEvent, p_intf );
130 if( p_intf->p_sys->p_input )
132 vlc_object_release( p_intf->p_sys->p_input );
134 if( p_intf->p_sys->p_vout )
136 vlc_object_release( p_intf->p_sys->p_vout );
138 /* Destroy structure */
139 free( p_intf->p_sys );
142 /*****************************************************************************
144 *****************************************************************************/
145 static void Run( intf_thread_t *p_intf )
147 input_thread_t *p_input = NULL;
148 vout_thread_t *p_vout = NULL;
149 vout_thread_t *p_last_vout = NULL;
150 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
153 playlist_t *p_playlist = pl_Yield( p_intf );
155 /* Initialize hotkey structure */
156 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
158 var_Create( p_intf->p_libvlc, p_hotkeys[i].psz_action,
159 VLC_VAR_HOTKEY | VLC_VAR_DOINHERIT );
161 var_AddCallback( p_intf->p_libvlc, p_hotkeys[i].psz_action,
163 var_Get( p_intf->p_libvlc, p_hotkeys[i].psz_action, &val );
164 var_Set( p_intf->p_libvlc, p_hotkeys[i].psz_action, val );
167 while( !intf_ShouldDie( p_intf ) )
173 // msleep( INTF_IDLE_SLEEP );
175 /* Update the input */
176 if( p_intf->p_sys->p_input == NULL )
179 p_intf->p_sys->p_input = p_playlist->p_input;
180 if( p_intf->p_sys->p_input )
181 vlc_object_yield( p_intf->p_sys->p_input );
184 else if( p_intf->p_sys->p_input->b_dead )
186 vlc_object_release( p_intf->p_sys->p_input );
187 p_intf->p_sys->p_input = NULL;
189 p_input = p_intf->p_sys->p_input;
191 /* Update the vout */
192 p_last_vout = p_intf->p_sys->p_vout;
195 p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
196 p_intf->p_sys->p_vout = p_vout;
198 else if( p_vout->b_die )
200 vlc_object_release( p_vout );
202 p_intf->p_sys->p_vout = NULL;
205 /* Register OSD channels */
206 if( p_vout && p_vout != p_last_vout )
208 for( i = 0; i < CHANNELS_NUMBER; i++ )
210 spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER,
211 &p_intf->p_sys->p_channels[ i ] );
215 /* Find action triggered by hotkey */
217 i_key = GetKey( p_intf );
218 for( i = 0; i_key != -1 && p_hotkeys[i].psz_action != NULL; i++ )
220 if( p_hotkeys[i].i_key == i_key )
222 i_action = p_hotkeys[i].i_action;
223 i_times = p_hotkeys[i].i_times;
224 /* times key pressed within max. delta time */
225 p_hotkeys[i].i_times = 0;
231 vlc_mutex_lock( &p_intf->object_lock );
232 vlc_cond_wait( &p_intf->object_wait, &p_intf->object_lock );
233 vlc_mutex_unlock( &p_intf->object_lock );
234 /* No key pressed, sleep a bit more */
235 // msleep( INTF_IDLE_SLEEP );
239 if( i_action == ACTIONID_QUIT )
241 p_intf->p_libvlc->b_die = VLC_TRUE;
242 ClearChannels( p_intf, p_vout );
243 vout_OSDMessage( p_intf, DEFAULT_CHAN, _( "Quit" ) );
246 else if( i_action == ACTIONID_VOL_UP )
248 audio_volume_t i_newvol;
249 aout_VolumeUp( p_intf, 1, &i_newvol );
250 DisplayVolume( p_intf, p_vout, i_newvol );
252 else if( i_action == ACTIONID_VOL_DOWN )
254 audio_volume_t i_newvol;
255 aout_VolumeDown( p_intf, 1, &i_newvol );
256 DisplayVolume( p_intf, p_vout, i_newvol );
258 else if( i_action == ACTIONID_VOL_MUTE )
260 audio_volume_t i_newvol = -1;
261 aout_VolumeMute( p_intf, &i_newvol );
266 ClearChannels( p_intf, p_vout );
267 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
272 DisplayVolume( p_intf, p_vout, i_newvol );
276 else if( i_action == ACTIONID_INTF_SHOW )
277 var_SetBool( p_playlist, "intf-show", VLC_TRUE );
278 else if( i_action == ACTIONID_INTF_HIDE )
279 var_SetBool( p_playlist, "intf-show", VLC_FALSE );
280 else if( i_action == ACTIONID_SNAPSHOT )
282 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
284 else if( i_action == ACTIONID_FULLSCREEN )
288 var_Get( p_vout, "fullscreen", &val );
289 val.b_bool = !val.b_bool;
290 var_Set( p_vout, "fullscreen", val );
294 var_Get( p_playlist, "fullscreen", &val );
295 val.b_bool = !val.b_bool;
296 var_Set( p_playlist, "fullscreen", val );
299 else if( i_action == ACTIONID_PLAY_PAUSE )
301 val.i_int = PLAYING_S;
304 ClearChannels( p_intf, p_vout );
306 var_Get( p_input, "state", &val );
307 if( val.i_int != PAUSE_S )
309 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
315 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
317 val.i_int = PLAYING_S;
319 var_Set( p_input, "state", val );
323 playlist_Play( p_playlist );
329 * How to get a valid value ?
330 * That's not that easy with some special stream
332 vlc_bool_t b_seekable = VLC_TRUE;
335 if( i_action == ACTIONID_PAUSE )
337 var_Get( p_input, "state", &val );
338 if( val.i_int != PAUSE_S )
340 ClearChannels( p_intf, p_vout );
341 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
344 var_Set( p_input, "state", val );
347 else if( i_action == ACTIONID_JUMP_BACKWARD_EXTRASHORT
350 #define SET_TIME( a, b ) \
351 i_interval = config_GetInt( p_input, a "-jump-size" ); \
352 if( i_interval > 0 ) { \
353 val.i_time = ( (mtime_t)(i_interval * b) * 1000000L \
354 * ((mtime_t)(1 << i_times))); \
355 var_Set( p_input, "time-offset", val ); \
356 DisplayPosition( p_intf, p_vout, p_input ); \
358 SET_TIME( "extrashort", -1 );
360 else if( i_action == ACTIONID_JUMP_FORWARD_EXTRASHORT && b_seekable )
362 SET_TIME( "extrashort", 1 );
364 else if( i_action == ACTIONID_JUMP_BACKWARD_SHORT && b_seekable )
366 SET_TIME( "short", -1 );
368 else if( i_action == ACTIONID_JUMP_FORWARD_SHORT && b_seekable )
370 SET_TIME( "short", 1 );
372 else if( i_action == ACTIONID_JUMP_BACKWARD_MEDIUM && b_seekable )
374 SET_TIME( "medium", -1 );
376 else if( i_action == ACTIONID_JUMP_FORWARD_MEDIUM && b_seekable )
378 SET_TIME( "medium", 1 );
380 else if( i_action == ACTIONID_JUMP_BACKWARD_LONG && b_seekable )
382 SET_TIME( "long", -1 );
384 else if( i_action == ACTIONID_JUMP_FORWARD_LONG && b_seekable )
386 SET_TIME( "long", 1 );
389 else if( i_action == ACTIONID_AUDIO_TRACK )
391 vlc_value_t val, list, list2;
393 var_Get( p_input, "audio-es", &val );
394 var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
396 i_count = list.p_list->i_count;
401 for( i = 0; i < i_count; i++ )
403 if( val.i_int == list.p_list->p_values[i].i_int )
408 /* value of audio-es was not in choices list */
412 "invalid current audio track, selecting 0" );
413 var_Set( p_input, "audio-es",
414 list.p_list->p_values[0] );
417 else if( i == i_count - 1 )
419 var_Set( p_input, "audio-es",
420 list.p_list->p_values[1] );
425 var_Set( p_input, "audio-es",
426 list.p_list->p_values[i+1] );
429 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
430 _("Audio track: %s"),
431 list2.p_list->p_values[i].psz_string );
433 else if( i_action == ACTIONID_SUBTITLE_TRACK )
435 vlc_value_t val, list, list2;
437 var_Get( p_input, "spu-es", &val );
439 var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
441 i_count = list.p_list->i_count;
444 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
445 _("Subtitle track: %s"), _("N/A") );
448 for( i = 0; i < i_count; i++ )
450 if( val.i_int == list.p_list->p_values[i].i_int )
455 /* value of spu-es was not in choices list */
459 "invalid current subtitle track, selecting 0" );
460 var_Set( p_input, "spu-es", list.p_list->p_values[0] );
463 else if( i == i_count - 1 )
465 var_Set( p_input, "spu-es", list.p_list->p_values[0] );
470 var_Set( p_input, "spu-es", list.p_list->p_values[i+1] );
473 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
474 _("Subtitle track: %s"),
475 list2.p_list->p_values[i].psz_string );
477 else if( i_action == ACTIONID_ASPECT_RATIO && p_vout )
479 vlc_value_t val={0}, val_list, text_list;
480 var_Get( p_vout, "aspect-ratio", &val );
481 if( var_Change( p_vout, "aspect-ratio", VLC_VAR_GETLIST,
482 &val_list, &text_list ) >= 0 )
485 for( i = 0; i < val_list.p_list->i_count; i++ )
487 if( !strcmp( val_list.p_list->p_values[i].psz_string,
494 if( i == val_list.p_list->i_count ) i = 0;
495 var_SetString( p_vout, "aspect-ratio",
496 val_list.p_list->p_values[i].psz_string );
497 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
498 _("Aspect ratio: %s"),
499 text_list.p_list->p_values[i].psz_string );
501 free( val.psz_string );
503 else if( i_action == ACTIONID_CROP && p_vout )
505 vlc_value_t val={0}, val_list, text_list;
506 var_Get( p_vout, "crop", &val );
507 if( var_Change( p_vout, "crop", VLC_VAR_GETLIST,
508 &val_list, &text_list ) >= 0 )
511 for( i = 0; i < val_list.p_list->i_count; i++ )
513 if( !strcmp( val_list.p_list->p_values[i].psz_string,
520 if( i == val_list.p_list->i_count ) i = 0;
521 var_SetString( p_vout, "crop",
522 val_list.p_list->p_values[i].psz_string );
523 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
525 text_list.p_list->p_values[i].psz_string );
527 free( val.psz_string );
529 else if( i_action == ACTIONID_DEINTERLACE && p_vout )
531 vlc_value_t val={0}, val_list, text_list;
532 var_Get( p_vout, "deinterlace", &val );
533 if( var_Change( p_vout, "deinterlace", VLC_VAR_GETLIST,
534 &val_list, &text_list ) >= 0 )
537 for( i = 0; i < val_list.p_list->i_count; i++ )
539 if( !strcmp( val_list.p_list->p_values[i].psz_string,
546 if( i == val_list.p_list->i_count ) i = 0;
547 var_SetString( p_vout, "deinterlace",
548 val_list.p_list->p_values[i].psz_string );
549 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
550 _("Deinterlace mode: %s"),
551 text_list.p_list->p_values[i].psz_string );
553 free( val.psz_string );
555 else if( ( i_action == ACTIONID_ZOOM || i_action == ACTIONID_UNZOOM ) && p_vout )
557 vlc_value_t val={0}, val_list, text_list;
558 var_Get( p_vout, "zoom", &val );
559 if( var_Change( p_vout, "zoom", VLC_VAR_GETLIST,
560 &val_list, &text_list ) >= 0 )
563 for( i = 0; i < val_list.p_list->i_count; i++ )
565 if( val_list.p_list->p_values[i].f_float
568 if( i_action == ACTIONID_ZOOM )
570 else /* ACTIONID_UNZOOM */
575 if( i == val_list.p_list->i_count ) i = 0;
576 if( i == -1 ) i = val_list.p_list->i_count-1;
577 var_SetFloat( p_vout, "zoom",
578 val_list.p_list->p_values[i].f_float );
579 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
581 text_list.p_list->p_values[i].var.psz_name );
584 else if( i_action == ACTIONID_CROP_TOP && p_vout )
585 var_IncInteger( p_vout, "crop-top" );
586 else if( i_action == ACTIONID_UNCROP_TOP && p_vout )
587 var_DecInteger( p_vout, "crop-top" );
588 else if( i_action == ACTIONID_CROP_BOTTOM && p_vout )
589 var_IncInteger( p_vout, "crop-bottom" );
590 else if( i_action == ACTIONID_UNCROP_BOTTOM && p_vout )
591 var_DecInteger( p_vout, "crop-bottom" );
592 else if( i_action == ACTIONID_CROP_LEFT && p_vout )
593 var_IncInteger( p_vout, "crop-left" );
594 else if( i_action == ACTIONID_UNCROP_LEFT && p_vout )
595 var_DecInteger( p_vout, "crop-left" );
596 else if( i_action == ACTIONID_CROP_RIGHT && p_vout )
597 var_IncInteger( p_vout, "crop-right" );
598 else if( i_action == ACTIONID_UNCROP_RIGHT && p_vout )
599 var_DecInteger( p_vout, "crop-right" );
601 else if( i_action == ACTIONID_NEXT )
603 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN, _("Next") );
604 playlist_Next( p_playlist );
606 else if( i_action == ACTIONID_PREV )
608 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
610 playlist_Prev( p_playlist );
612 else if( i_action == ACTIONID_STOP )
614 playlist_Stop( p_playlist );
616 else if( i_action == ACTIONID_FASTER )
618 var_SetVoid( p_input, "rate-faster" );
619 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
622 else if( i_action == ACTIONID_SLOWER )
624 var_SetVoid( p_input, "rate-slower" );
625 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
628 else if( i_action == ACTIONID_POSITION && b_seekable )
630 DisplayPosition( p_intf, p_vout, p_input );
632 else if( i_action >= ACTIONID_PLAY_BOOKMARK1 &&
633 i_action <= ACTIONID_PLAY_BOOKMARK10 )
635 PlayBookmark( p_intf, i_action - ACTIONID_PLAY_BOOKMARK1 + 1 );
637 else if( i_action >= ACTIONID_SET_BOOKMARK1 &&
638 i_action <= ACTIONID_SET_BOOKMARK10 )
640 SetBookmark( p_intf, i_action - ACTIONID_SET_BOOKMARK1 + 1 );
642 /* Only makes sense with DVD */
643 else if( i_action == ACTIONID_TITLE_PREV )
644 var_SetVoid( p_input, "prev-title" );
645 else if( i_action == ACTIONID_TITLE_NEXT )
646 var_SetVoid( p_input, "next-title" );
647 else if( i_action == ACTIONID_CHAPTER_PREV )
648 var_SetVoid( p_input, "prev-chapter" );
649 else if( i_action == ACTIONID_CHAPTER_NEXT )
650 var_SetVoid( p_input, "next-chapter" );
651 else if( i_action == ACTIONID_DISC_MENU )
652 var_SetInteger( p_input, "title 0", 2 );
654 else if( i_action == ACTIONID_SUBDELAY_DOWN )
656 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
657 i_delay -= 50000; /* 50 ms */
658 var_SetTime( p_input, "spu-delay", i_delay );
659 ClearChannels( p_intf, p_vout );
660 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
661 (int)(i_delay/1000) );
663 else if( i_action == ACTIONID_SUBDELAY_UP )
665 int64_t i_delay = var_GetTime( p_input, "spu-delay" );
666 i_delay += 50000; /* 50 ms */
667 var_SetTime( p_input, "spu-delay", i_delay );
668 ClearChannels( p_intf, p_vout );
669 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Subtitle delay %i ms",
670 (int)(i_delay/1000) );
672 else if( i_action == ACTIONID_AUDIODELAY_DOWN )
674 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
675 i_delay -= 50000; /* 50 ms */
676 var_SetTime( p_input, "audio-delay", i_delay );
677 ClearChannels( p_intf, p_vout );
678 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
679 (int)(i_delay/1000) );
681 else if( i_action == ACTIONID_AUDIODELAY_UP )
683 int64_t i_delay = var_GetTime( p_input, "audio-delay" );
684 i_delay += 50000; /* 50 ms */
685 var_SetTime( p_input, "audio-delay", i_delay );
686 ClearChannels( p_intf, p_vout );
687 vout_OSDMessage( p_intf, DEFAULT_CHAN, "Audio delay %i ms",
688 (int)(i_delay/1000) );
690 else if( i_action == ACTIONID_PLAY )
692 var_Get( p_input, "rate", &val );
693 if( val.i_int != INPUT_RATE_DEFAULT )
695 /* Return to normal speed */
696 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
700 ClearChannels( p_intf, p_vout );
701 vout_OSDIcon( VLC_OBJECT( p_intf ), DEFAULT_CHAN,
703 playlist_Play( p_playlist );
708 pl_Release( p_intf );
711 static int GetKey( intf_thread_t *p_intf)
713 vlc_mutex_lock( &p_intf->p_sys->change_lock );
714 if ( p_intf->p_sys->i_size == 0 )
716 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
721 int i_return = p_intf->p_sys->p_keys[ 0 ];
723 p_intf->p_sys->i_size--;
724 for ( i = 0; i < BUFFER_SIZE - 1; i++)
726 p_intf->p_sys->p_keys[ i ] = p_intf->p_sys->p_keys[ i + 1 ];
728 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
733 /*****************************************************************************
734 * KeyEvent: callback for keyboard events
735 *****************************************************************************/
736 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
737 vlc_value_t oldval, vlc_value_t newval, void *p_data )
739 intf_thread_t *p_intf = (intf_thread_t *)p_data;
740 vlc_mutex_lock( &p_intf->p_sys->change_lock );
741 if ( p_intf->p_sys->i_size == BUFFER_SIZE )
743 msg_Warn( p_intf, "event buffer full, dropping keypress" );
744 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
749 p_intf->p_sys->p_keys[ p_intf->p_sys->i_size ] = newval.i_int;
750 p_intf->p_sys->i_size++;
752 vlc_mutex_lock( &p_intf->object_lock );
753 vlc_cond_signal( &p_intf->object_wait );
754 vlc_mutex_unlock( &p_intf->object_lock );
755 vlc_mutex_unlock( &p_intf->p_sys->change_lock );
760 static int ActionKeyCB( vlc_object_t *p_this, char const *psz_var,
761 vlc_value_t oldval, vlc_value_t newval, void *p_data )
763 libvlc_int_t *p_libvlc = (libvlc_int_t *)p_this;
764 struct hotkey *p_hotkeys = p_libvlc->p_hotkeys;
768 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
770 if( !strcmp( p_hotkeys[i].psz_action, psz_var ) )
772 p_hotkeys[i].i_key = newval.i_int;
773 /* do hotkey accounting */
775 if( (p_hotkeys[i].i_delta_date > 0) &&
776 (p_hotkeys[i].i_delta_date <= (i_date - p_hotkeys[i].i_last_date) ) )
777 p_hotkeys[i].i_times = 0;
779 p_hotkeys[i].i_times++;
780 p_hotkeys[i].i_last_date = i_date;
787 static void PlayBookmark( intf_thread_t *p_intf, int i_num )
791 char psz_bookmark_name[11];
792 playlist_t *p_playlist = pl_Yield( p_intf );
794 sprintf( psz_bookmark_name, "bookmark%i", i_num );
795 var_Create( p_intf, psz_bookmark_name, VLC_VAR_STRING|VLC_VAR_DOINHERIT );
796 var_Get( p_intf, psz_bookmark_name, &val );
798 char *psz_bookmark = strdup( val.psz_string );
799 for( i = 0; i < p_playlist->i_size; i++)
801 if( !strcmp( psz_bookmark,
802 p_playlist->pp_items[i]->p_input->psz_uri ) )
804 playlist_LockControl( p_playlist, PLAYLIST_VIEWPLAY, NULL,
805 p_playlist->pp_items[i] );
809 vlc_object_release( p_playlist );
812 static void SetBookmark( intf_thread_t *p_intf, int i_num )
814 playlist_t *p_playlist = pl_Yield( p_intf );
815 char psz_bookmark_name[11];
816 sprintf( psz_bookmark_name, "bookmark%i", i_num );
817 var_Create( p_intf, psz_bookmark_name,
818 VLC_VAR_STRING|VLC_VAR_DOINHERIT );
819 if( p_playlist->status.p_item )
821 config_PutPsz( p_intf, psz_bookmark_name,
822 p_playlist->status.p_item->p_input->psz_uri);
823 msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num,
824 p_playlist->status.p_item->p_input->psz_uri);
825 config_SaveConfigFile( p_intf, "hotkeys" );
827 pl_Release( p_intf );
830 static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
831 input_thread_t *p_input )
833 char psz_duration[MSTRTIME_MAX_SIZE];
834 char psz_time[MSTRTIME_MAX_SIZE];
835 vlc_value_t time, pos;
838 if( p_vout == NULL ) return;
840 ClearChannels( p_intf, p_vout );
842 var_Get( p_input, "time", &time );
843 i_seconds = time.i_time / 1000000;
844 secstotimestr ( psz_time, i_seconds );
846 var_Get( p_input, "length", &time );
847 if( time.i_time > 0 )
849 secstotimestr( psz_duration, time.i_time / 1000000 );
850 vout_OSDMessage( p_input, POSITION_TEXT_CHAN, "%s / %s",
851 psz_time, psz_duration );
853 else if( i_seconds > 0 )
855 vout_OSDMessage( p_input, POSITION_TEXT_CHAN, psz_time );
858 if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
860 var_Get( p_input, "position", &pos );
861 vout_OSDSlider( VLC_OBJECT( p_input ), POSITION_WIDGET_CHAN,
862 pos.f_float * 100, OSD_HOR_SLIDER );
866 static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
867 audio_volume_t i_vol )
873 ClearChannels( p_intf, p_vout );
875 if( !p_vout->p_parent_intf || p_vout->b_fullscreen )
877 vout_OSDSlider( VLC_OBJECT( p_vout ), VOLUME_WIDGET_CHAN,
878 i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
882 vout_OSDMessage( p_vout, VOLUME_TEXT_CHAN, "Volume %d%%",
883 i_vol*400/AOUT_VOLUME_MAX );
887 static void ClearChannels( intf_thread_t *p_intf, vout_thread_t *p_vout )
893 spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
894 for( i = 0; i < CHANNELS_NUMBER; i++ )
896 spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR,
897 p_intf->p_sys->p_channels[ i ] );