X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmisc%2Fnotify%2Fxosd.c;h=a7b2b9ba00bea278205d98f65a5634e05c9eaf43;hb=fa4bde0b26a6c7a2a617362ea0b17144686e39fe;hp=4dd0a94bb3ce542ce487e5b1fb17da95e5c6a6ef;hpb=e02432e597acb3511d14433ae3303ff4da3742f9;p=vlc diff --git a/modules/misc/notify/xosd.c b/modules/misc/notify/xosd.c index 4dd0a94bb3..a7b2b9ba00 100644 --- a/modules/misc/notify/xosd.c +++ b/modules/misc/notify/xosd.c @@ -10,7 +10,7 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -26,7 +26,12 @@ *****************************************************************************/ #include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include #include @@ -41,7 +46,7 @@ struct intf_sys_t { xosd * p_osd; /* libxosd handle */ - vlc_bool_t b_need_update; /* Update display ? */ + bool b_need_update; /* Update display ? */ }; #define MAX_LINE_LENGTH 256 @@ -78,23 +83,23 @@ static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable, #define COLOUR_TEXT N_("Color") #define COLOUR_LONGTEXT N_("Color used to display text in the XOSD output.") -vlc_module_begin(); - set_category( CAT_INTERFACE ); - set_subcategory( SUBCAT_INTERFACE_CONTROL ); - set_description( _("XOSD interface") ); - set_shortname( "XOSD" ); - add_bool( "xosd-position", 1, NULL, POSITION_TEXT, POSITION_LONGTEXT, VLC_TRUE ); - add_integer( "xosd-text-offset", 30, NULL, TXT_OFS_TEXT, TXT_OFS_LONGTEXT, VLC_TRUE ); +vlc_module_begin () + set_category( CAT_INTERFACE ) + set_subcategory( SUBCAT_INTERFACE_CONTROL ) + set_description( N_("XOSD interface") ) + set_shortname( "XOSD" ) + add_bool( "xosd-position", 1, NULL, POSITION_TEXT, POSITION_LONGTEXT, true ) + add_integer( "xosd-text-offset", 30, NULL, TXT_OFS_TEXT, TXT_OFS_LONGTEXT, true ) add_integer( "xosd-shadow-offset", 2, NULL, - SHD_OFS_TEXT, SHD_OFS_LONGTEXT, VLC_TRUE ); + SHD_OFS_TEXT, SHD_OFS_LONGTEXT, true ) add_string( "xosd-font", "-adobe-helvetica-bold-r-normal-*-*-160-*-*-p-*-iso8859-1", - NULL, FONT_TEXT, FONT_LONGTEXT, VLC_TRUE ); + NULL, FONT_TEXT, FONT_LONGTEXT, true ) add_string( "xosd-colour", "LawnGreen", - NULL, COLOUR_TEXT, COLOUR_LONGTEXT, VLC_TRUE ); - set_capability( "interface", 10 ); - set_callbacks( Open, Close ); -vlc_module_end(); + NULL, COLOUR_TEXT, COLOUR_LONGTEXT, true ) + set_capability( "interface", 10 ) + set_callbacks( Open, Close ) +vlc_module_end () /***************************************************************************** * Open: initialize and create stuff @@ -103,30 +108,33 @@ static int Open( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; xosd *p_osd; + char *psz_font, *psz_colour; /* Allocate instance and initialize some members */ p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) ); if( p_intf->p_sys == NULL ) - { - msg_Err( p_intf, "out of memory" ); return VLC_ENOMEM; - } if( getenv( "DISPLAY" ) == NULL ) { msg_Err( p_intf, "no display, please set the DISPLAY variable" ); + free( p_intf->p_sys ); return VLC_EGENERIC; } /* Initialize library */ #if defined(HAVE_XOSD_VERSION_0) || defined(HAVE_XOSD_VERSION_1) - p_osd = p_intf->p_sys->p_osd = - xosd_init( config_GetPsz( p_intf, "xosd-font" ), - config_GetPsz( p_intf,"xosd-colour" ), 3, - XOSD_top, 0, 1 ); + psz_font = config_GetPsz( p_intf, "xosd-font" ); + psz_colour = config_GetPsz( p_intf,"xosd-colour" ); + p_osd = p_intf->p_sys->p_osd = xosd_init( psz_font, psz_colour, 3, + XOSD_top, 0, 1 ); + free( psz_font ); + free( psz_colour ); + if( p_intf->p_sys->p_osd == NULL ) { msg_Err( p_intf, "couldn't initialize libxosd" ); + free( p_intf->p_sys ); return VLC_EGENERIC; } #else @@ -134,21 +142,26 @@ static int Open( vlc_object_t *p_this ) if( p_osd == NULL ) { msg_Err( p_intf, "couldn't initialize libxosd" ); + free( p_intf->p_sys ); return VLC_EGENERIC; } - xosd_set_colour( p_osd, config_GetPsz( p_intf,"xosd-colour" ) ); + + psz_colour = config_GetPsz( p_intf,"xosd-colour" ); + xosd_set_colour( p_osd, psz_colour ); xosd_set_timeout( p_osd, 3 ); + free( psz_colour ); #endif - playlist_t *p_playlist = pl_Yield( p_intf ); + playlist_t *p_playlist = pl_Hold( p_intf ); var_AddCallback( p_playlist, "playlist-current", PlaylistNext, p_this ); var_AddCallback( p_playlist, "item-change", PlaylistNext, p_this ); pl_Release( p_intf ); /* Set user preferences */ - xosd_set_font( p_intf->p_sys->p_osd, - config_GetPsz( p_intf, "xosd-font" ) ); + psz_font = config_GetPsz( p_intf, "xosd-font" ); + xosd_set_font( p_intf->p_sys->p_osd, psz_font ); + free( psz_font ); xosd_set_outline_colour( p_intf->p_sys->p_osd,"black" ); #ifdef HAVE_XOSD_VERSION_2 xosd_set_horizontal_offset( p_intf->p_sys->p_osd, @@ -170,7 +183,7 @@ static int Open( vlc_object_t *p_this ) p_intf->pf_run = Run; - p_intf->p_sys->b_need_update = VLC_TRUE; + p_intf->p_sys->b_need_update = true; return VLC_SUCCESS; } @@ -181,7 +194,7 @@ static int Open( vlc_object_t *p_this ) static void Close( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; - playlist_t *p_playlist = pl_Yield( p_intf ); + playlist_t *p_playlist = pl_Hold( p_intf ); var_DelCallback( p_playlist, "playlist-current", PlaylistNext, p_this ); var_DelCallback( p_playlist, "item-change", PlaylistNext, p_this ); pl_Release( p_intf ); @@ -206,44 +219,40 @@ static void Run( intf_thread_t *p_intf ) char psz_duration[MSTRTIME_MAX_SIZE+2]; char *psz_display = NULL; - while( !p_intf->b_die ) + for( ;; ) { - if( p_intf->p_sys->b_need_update == VLC_TRUE ) + int canc = vlc_savecancel(); + if( p_intf->p_sys->b_need_update == true ) { - p_intf->p_sys->b_need_update = VLC_FALSE; - p_playlist = pl_Yield( p_intf ); + p_intf->p_sys->b_need_update = false; + p_playlist = pl_Hold( p_intf ); - if( !playlist_IsEmpty( p_playlist ) ) + if( playlist_IsEmpty( p_playlist ) ) { - vlc_object_release( p_playlist ); + pl_Release( p_intf ); continue; } - if( psz_display ) - { - free( psz_display ); - psz_display = NULL; - } - if( p_playlist->status.i_status == PLAYLIST_STOPPED ) + free( psz_display ); + psz_display = NULL; + int i_status = playlist_Status( p_playlist ); + if( i_status == PLAYLIST_STOPPED ) { psz_display = strdup(_("Stop")); - vlc_object_release( p_playlist ); + pl_Release( p_intf ); } - else if( p_playlist->status.i_status == PLAYLIST_PAUSED ) + else if( i_status == PLAYLIST_PAUSED ) { psz_display = strdup(_("Pause")); - vlc_object_release( p_playlist ); + pl_Release( p_intf ); } else { - p_item = p_playlist->status.p_item; + p_item = playlist_CurrentPlayingItem( p_playlist ); p_input = p_item->p_input; + + pl_Release( p_intf ); if( !p_item ) - { - vlc_object_release( p_playlist ); continue; - } - - vlc_object_release( p_playlist ); mtime_t i_duration = input_item_GetDuration( p_input ); if( i_duration != -1 ) @@ -257,7 +266,7 @@ static void Run( intf_thread_t *p_intf ) sprintf( psz_duration," " ); } - psz_display = (char *)malloc( sizeof(char )* + psz_display = (char *)malloc( (strlen( p_input->psz_name ) + MSTRTIME_MAX_SIZE + 2+6 + 10 +10 )); sprintf( psz_display,"%s %s", @@ -271,6 +280,7 @@ static void Run( intf_thread_t *p_intf ) psz_display ); } + vlc_restorecancel( canc ); msleep( INTF_IDLE_SLEEP ); } } @@ -280,7 +290,7 @@ static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable, { intf_thread_t *p_intf = (intf_thread_t *)param; - p_intf->p_sys->b_need_update = VLC_TRUE; + p_intf->p_sys->b_need_update = true; return VLC_SUCCESS; }