Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

showintf.c

00001 /*****************************************************************************
00002  * showintf.c: control the display of the interface in fullscreen mode
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id:$
00006  *
00007  * Authors: Olivier Teuliere <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 #include <string.h>
00029 
00030 #include <vlc/vlc.h>
00031 #include <vlc/intf.h>
00032 #include <vlc/vout.h>
00033 
00034 #ifdef HAVE_UNISTD_H
00035 #    include <unistd.h>
00036 #endif
00037 
00038 /*****************************************************************************
00039  * intf_sys_t: description and status of interface
00040  *****************************************************************************/
00041 struct intf_sys_t
00042 {
00043     vlc_object_t * p_vout;
00044     vlc_bool_t     b_button_pressed;
00045     vlc_bool_t     b_triggered;
00046     int            i_threshold;
00047 };
00048 
00049 /*****************************************************************************
00050  * Local prototypes.
00051  *****************************************************************************/
00052 int  E_(Open) ( vlc_object_t * );
00053 void E_(Close)( vlc_object_t * );
00054 static void RunIntf( intf_thread_t *p_intf );
00055 static int  InitThread( intf_thread_t *p_intf );
00056 static int  MouseEvent( vlc_object_t *, char const *,
00057                         vlc_value_t, vlc_value_t, void * );
00058 
00059 /*****************************************************************************
00060  * Module descriptor
00061  *****************************************************************************/
00062 #define THRESHOLD_TEXT N_( "Threshold" )
00063 #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface" )
00064 
00065 vlc_module_begin();
00066     set_shortname( "Showintf" );
00067     set_category( CAT_INTERFACE );
00068     set_subcategory( SUBCAT_INTERFACE_CONTROL );
00069     add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, VLC_TRUE );
00070     set_description( _("Interface showing control interface") );
00071 
00072     set_capability( "interface", 0 );
00073     set_callbacks( E_(Open), E_(Close) );
00074 vlc_module_end();
00075 
00076 /*****************************************************************************
00077  * Open: initialize interface
00078  *****************************************************************************/
00079 int E_(Open)( vlc_object_t *p_this )
00080 {
00081     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00082 
00083     /* Allocate instance and initialize some members */
00084     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
00085     if( p_intf->p_sys == NULL )
00086     {
00087         return( 1 );
00088     };
00089 
00090     p_intf->pf_run = RunIntf;
00091 
00092     return( 0 );
00093 }
00094 
00095 /*****************************************************************************
00096  * Close: destroy interface
00097  *****************************************************************************/
00098 void E_(Close)( vlc_object_t *p_this )
00099 {
00100     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00101 
00102     /* Destroy structure */
00103     free( p_intf->p_sys );
00104 }
00105 
00106 
00107 /*****************************************************************************
00108  * RunIntf: main loop
00109  *****************************************************************************/
00110 static void RunIntf( intf_thread_t *p_intf )
00111 {
00112     p_intf->p_sys->p_vout = NULL;
00113 
00114     if( InitThread( p_intf ) < 0 )
00115     {
00116         msg_Err( p_intf, "cannot initialize intf" );
00117         return;
00118     }
00119 
00120     /* Main loop */
00121     while( !p_intf->b_die )
00122     {
00123         vlc_mutex_lock( &p_intf->change_lock );
00124 
00125         /* Notify the interfaces */
00126         if( p_intf->p_sys->b_triggered )
00127         {
00128             playlist_t *p_playlist =
00129                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00130                                                FIND_ANYWHERE );
00131 
00132             if( p_playlist != NULL )
00133             {
00134                 vlc_value_t val;
00135                 val.b_bool = VLC_TRUE;
00136                 var_Set( p_playlist, "intf-show", val );
00137                 vlc_object_release( p_playlist );
00138             }
00139             p_intf->p_sys->b_triggered = VLC_FALSE;
00140         }
00141 
00142         vlc_mutex_unlock( &p_intf->change_lock );
00143 
00144 
00145         /* Take care of the video output */
00146         if( p_intf->p_sys->p_vout && p_intf->p_sys->p_vout->b_die )
00147         {
00148             var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
00149                              MouseEvent, p_intf );
00150             var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
00151                              MouseEvent, p_intf );
00152             vlc_object_release( p_intf->p_sys->p_vout );
00153             p_intf->p_sys->p_vout = NULL;
00154         }
00155 
00156         if( p_intf->p_sys->p_vout == NULL )
00157         {
00158             p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
00159                                                      FIND_ANYWHERE );
00160             if( p_intf->p_sys->p_vout )
00161             {
00162                 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
00163                                  MouseEvent, p_intf );
00164                 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
00165                                  MouseEvent, p_intf );
00166             }
00167         }
00168 
00169         /* Wait a bit */
00170         msleep( INTF_IDLE_SLEEP );
00171     }
00172 
00173     if( p_intf->p_sys->p_vout )
00174     {
00175         var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
00176                          MouseEvent, p_intf );
00177         var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
00178                          MouseEvent, p_intf );
00179         vlc_object_release( p_intf->p_sys->p_vout );
00180     }
00181 }
00182 
00183 /*****************************************************************************
00184  * InitThread:
00185  *****************************************************************************/
00186 static int InitThread( intf_thread_t * p_intf )
00187 {
00188     if( !p_intf->b_die )
00189     {
00190         vlc_mutex_lock( &p_intf->change_lock );
00191 
00192         p_intf->p_sys->b_triggered = VLC_FALSE;
00193         p_intf->p_sys->b_button_pressed = VLC_FALSE;
00194         p_intf->p_sys->i_threshold =
00195             config_GetInt( p_intf, "showintf-threshold" );
00196 
00197         vlc_mutex_unlock( &p_intf->change_lock );
00198 
00199         return 0;
00200     }
00201     else
00202     {
00203         return -1;
00204     }
00205 }
00206 
00207 /*****************************************************************************
00208  * MouseEvent: callback for mouse events
00209  *****************************************************************************/
00210 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
00211                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
00212 {
00213     vlc_value_t val;
00214 
00215     int i_mouse_x, i_mouse_y;
00216     intf_thread_t *p_intf = (intf_thread_t *)p_data;
00217 
00218     /* Do nothing when the interface is already requested */
00219     if( p_intf->p_sys->b_triggered )
00220         return VLC_SUCCESS;
00221 
00222     /* Nothing to do when not in fullscreen mode */
00223     var_Get( p_intf->p_sys->p_vout, "fullscreen", &val );
00224     if( !val.i_int )
00225         return VLC_SUCCESS;
00226 
00227     vlc_mutex_lock( &p_intf->change_lock );
00228     if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
00229     {
00230         var_Get( p_intf->p_sys->p_vout, "mouse-x", &val );
00231         i_mouse_x = val.i_int;
00232         var_Get( p_intf->p_sys->p_vout, "mouse-y", &val );
00233         i_mouse_y = val.i_int;
00234 
00235         /* Very basic test, we even ignore the x value :) */
00236         if ( i_mouse_y < p_intf->p_sys->i_threshold )
00237         {
00238             msg_Dbg( p_intf, "interface showing requested" );
00239             p_intf->p_sys->b_triggered = VLC_TRUE;
00240         }
00241     }
00242 
00243     /* We keep track of the button state to avoid interferences with the
00244      * gestures plugin */
00245     if( !p_intf->p_sys->b_button_pressed &&
00246         !strcmp( psz_var, "mouse-button-down" ) )
00247     {
00248         p_intf->p_sys->b_button_pressed = VLC_TRUE;
00249     }
00250     if( p_intf->p_sys->b_button_pressed &&
00251         !strcmp( psz_var, "mouse-button-down" ) )
00252     {
00253         p_intf->p_sys->b_button_pressed = VLC_FALSE;
00254     }
00255 
00256     vlc_mutex_unlock( &p_intf->change_lock );
00257 
00258     return VLC_SUCCESS;
00259 }

Generated on Tue Dec 20 10:14:31 2005 for vlc-0.8.4a by  doxygen 1.4.2