showintf.c
上传用户:riyaled888
上传日期:2009-03-27
资源大小:7338k
文件大小:8k
源码类别:

多媒体

开发平台:

MultiPlatform

  1. /*****************************************************************************
  2.  * showintf.c: control the display of the interface in fullscreen mode
  3.  *****************************************************************************
  4.  * Copyright (C) 2004 VideoLAN
  5.  * $Id:$
  6.  *
  7.  * Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  22.  *****************************************************************************/
  23. /*****************************************************************************
  24.  * Preamble
  25.  *****************************************************************************/
  26. #include <stdlib.h>                                      /* malloc(), free() */
  27. #include <string.h>
  28. #include <vlc/vlc.h>
  29. #include <vlc/intf.h>
  30. #include <vlc/vout.h>
  31. #ifdef HAVE_UNISTD_H
  32. #    include <unistd.h>
  33. #endif
  34. /*****************************************************************************
  35.  * intf_sys_t: description and status of interface
  36.  *****************************************************************************/
  37. struct intf_sys_t
  38. {
  39.     vlc_object_t * p_vout;
  40.     vlc_bool_t     b_button_pressed;
  41.     vlc_bool_t     b_triggered;
  42.     int            i_threshold;
  43. };
  44. /*****************************************************************************
  45.  * Local prototypes.
  46.  *****************************************************************************/
  47. int  E_(Open) ( vlc_object_t * );
  48. void E_(Close)( vlc_object_t * );
  49. static void RunIntf( intf_thread_t *p_intf );
  50. static int  InitThread( intf_thread_t *p_intf );
  51. static int  MouseEvent( vlc_object_t *, char const *,
  52.                         vlc_value_t, vlc_value_t, void * );
  53. /*****************************************************************************
  54.  * Module descriptor
  55.  *****************************************************************************/
  56. #define THRESHOLD_TEXT N_( "Threshold" )
  57. #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface" )
  58. vlc_module_begin();
  59.     add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, VLC_TRUE );
  60.     set_description( _("Interface showing control interface") );
  61.     set_capability( "interface", 0 );
  62.     set_callbacks( E_(Open), E_(Close) );
  63. vlc_module_end();
  64. /*****************************************************************************
  65.  * Open: initialize interface
  66.  *****************************************************************************/
  67. int E_(Open)( vlc_object_t *p_this )
  68. {
  69.     intf_thread_t *p_intf = (intf_thread_t *)p_this;
  70.     /* Allocate instance and initialize some members */
  71.     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
  72.     if( p_intf->p_sys == NULL )
  73.     {
  74.         return( 1 );
  75.     };
  76.     p_intf->pf_run = RunIntf;
  77.     return( 0 );
  78. }
  79. /*****************************************************************************
  80.  * Close: destroy interface
  81.  *****************************************************************************/
  82. void E_(Close)( vlc_object_t *p_this )
  83. {
  84.     intf_thread_t *p_intf = (intf_thread_t *)p_this;
  85.     /* Destroy structure */
  86.     free( p_intf->p_sys );
  87. }
  88. /*****************************************************************************
  89.  * RunIntf: main loop
  90.  *****************************************************************************/
  91. static void RunIntf( intf_thread_t *p_intf )
  92. {
  93.     p_intf->p_sys->p_vout = NULL;
  94.     if( InitThread( p_intf ) < 0 )
  95.     {
  96.         msg_Err( p_intf, "cannot initialize intf" );
  97.         return;
  98.     }
  99.     /* Main loop */
  100.     while( !p_intf->b_die )
  101.     {
  102.         vlc_mutex_lock( &p_intf->change_lock );
  103.         /* Notify the interfaces */
  104.         if( p_intf->p_sys->b_triggered )
  105.         {
  106.             playlist_t *p_playlist =
  107.                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
  108.                                                FIND_ANYWHERE );
  109.             if( p_playlist != NULL )
  110.             {
  111.                 vlc_value_t val;
  112.                 val.b_bool = VLC_TRUE;
  113.                 var_Set( p_playlist, "intf-show", val );
  114.                 vlc_object_release( p_playlist );
  115.             }
  116.             p_intf->p_sys->b_triggered = VLC_FALSE;
  117.         }
  118.         vlc_mutex_unlock( &p_intf->change_lock );
  119.         /* Take care of the video output */
  120.         if( p_intf->p_sys->p_vout && p_intf->p_sys->p_vout->b_die )
  121.         {
  122.             var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
  123.                              MouseEvent, p_intf );
  124.             var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
  125.                              MouseEvent, p_intf );
  126.             vlc_object_release( p_intf->p_sys->p_vout );
  127.             p_intf->p_sys->p_vout = NULL;
  128.         }
  129.         if( p_intf->p_sys->p_vout == NULL )
  130.         {
  131.             p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
  132.                                                      FIND_ANYWHERE );
  133.             if( p_intf->p_sys->p_vout )
  134.             {
  135.                 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
  136.                                  MouseEvent, p_intf );
  137.                 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
  138.                                  MouseEvent, p_intf );
  139.             }
  140.         }
  141.         /* Wait a bit */
  142.         msleep( INTF_IDLE_SLEEP );
  143.     }
  144.     if( p_intf->p_sys->p_vout )
  145.     {
  146.         var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
  147.                          MouseEvent, p_intf );
  148.         var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
  149.                          MouseEvent, p_intf );
  150.         vlc_object_release( p_intf->p_sys->p_vout );
  151.     }
  152. }
  153. /*****************************************************************************
  154.  * InitThread:
  155.  *****************************************************************************/
  156. static int InitThread( intf_thread_t * p_intf )
  157. {
  158.     if( !p_intf->b_die )
  159.     {
  160.         vlc_mutex_lock( &p_intf->change_lock );
  161.         p_intf->p_sys->b_triggered = VLC_FALSE;
  162.         p_intf->p_sys->b_button_pressed = VLC_FALSE;
  163.         p_intf->p_sys->i_threshold =
  164.             config_GetInt( p_intf, "showintf-threshold" );
  165.         vlc_mutex_unlock( &p_intf->change_lock );
  166.         return 0;
  167.     }
  168.     else
  169.     {
  170.         return -1;
  171.     }
  172. }
  173. /*****************************************************************************
  174.  * MouseEvent: callback for mouse events
  175.  *****************************************************************************/
  176. static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
  177.                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
  178. {
  179.     vlc_value_t val;
  180.     int i_mouse_x, i_mouse_y;
  181.     intf_thread_t *p_intf = (intf_thread_t *)p_data;
  182.     /* Do nothing when the interface is already requested */
  183.     if( p_intf->p_sys->b_triggered )
  184.         return VLC_SUCCESS;
  185.     /* Nothing to do when not in fullscreen mode */
  186.     var_Get( p_intf->p_sys->p_vout, "fullscreen", &val );
  187.     if( !val.i_int )
  188.         return VLC_SUCCESS;
  189.     vlc_mutex_lock( &p_intf->change_lock );
  190.     if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
  191.     {
  192.         var_Get( p_intf->p_sys->p_vout, "mouse-x", &val );
  193.         i_mouse_x = val.i_int;
  194.         var_Get( p_intf->p_sys->p_vout, "mouse-y", &val );
  195.         i_mouse_y = val.i_int;
  196.         /* Very basic test, we even ignore the x value :) */
  197.         if ( i_mouse_y < p_intf->p_sys->i_threshold )
  198.         {
  199.             msg_Dbg( p_intf, "interface showing requested" );
  200.             p_intf->p_sys->b_triggered = VLC_TRUE;
  201.         }
  202.     }
  203.     /* We keep track of the button state to avoid interferences with the
  204.      * gestures plugin */
  205.     if( !p_intf->p_sys->b_button_pressed &&
  206.         !strcmp( psz_var, "mouse-button-down" ) )
  207.     {
  208.         p_intf->p_sys->b_button_pressed = VLC_TRUE;
  209.     }
  210.     if( p_intf->p_sys->b_button_pressed &&
  211.         !strcmp( psz_var, "mouse-button-down" ) )
  212.     {
  213.         p_intf->p_sys->b_button_pressed = VLC_FALSE;
  214.     }
  215.     vlc_mutex_unlock( &p_intf->change_lock );
  216.     return VLC_SUCCESS;
  217. }