showintf.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:8k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * showintf.c: control the display of the interface in fullscreen mode
  3.  *****************************************************************************
  4.  * Copyright (C) 2004 the VideoLAN team
  5.  * $Id: 2f1149b5f4db8361ccfa73a53e1eea326b752500 $
  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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22.  *****************************************************************************/
  23. /*****************************************************************************
  24.  * Preamble
  25.  *****************************************************************************/
  26. #ifdef HAVE_CONFIG_H
  27. # include "config.h"
  28. #endif
  29. #include <vlc_common.h>
  30. #include <vlc_plugin.h>
  31. #include <vlc_interface.h>
  32. #include <vlc_vout.h>
  33. #include <vlc_playlist.h>
  34. #ifdef HAVE_UNISTD_H
  35. #    include <unistd.h>
  36. #endif
  37. /*****************************************************************************
  38.  * intf_sys_t: description and status of interface
  39.  *****************************************************************************/
  40. struct intf_sys_t
  41. {
  42.     vlc_mutex_t   lock;
  43.     vlc_object_t *p_vout;
  44.     bool          b_button_pressed;
  45.     bool          b_triggered;
  46.     int           i_threshold;
  47. };
  48. /*****************************************************************************
  49.  * Local prototypes.
  50.  *****************************************************************************/
  51. int  Open ( vlc_object_t * );
  52. void Close( vlc_object_t * );
  53. static void RunIntf( intf_thread_t *p_intf );
  54. static int  MouseEvent( vlc_object_t *, char const *,
  55.                         vlc_value_t, vlc_value_t, void * );
  56. /*****************************************************************************
  57.  * Module descriptor
  58.  *****************************************************************************/
  59. #define THRESHOLD_TEXT N_( "Threshold" )
  60. #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface." )
  61. vlc_module_begin ()
  62.     set_shortname( "Showintf" )
  63.     set_description( N_("Show interface with mouse") )
  64.     set_capability( "interface", 0 )
  65.     set_callbacks( Open, Close )
  66.     set_category( CAT_INTERFACE )
  67.     set_subcategory( SUBCAT_INTERFACE_CONTROL )
  68.     add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, true )
  69. vlc_module_end ()
  70. /*****************************************************************************
  71.  * Open: initialize interface
  72.  *****************************************************************************/
  73. int Open( vlc_object_t *p_this )
  74. {
  75.     intf_thread_t *p_intf = (intf_thread_t *)p_this;
  76.     /* Allocate instance and initialize some members */
  77.     intf_sys_t *p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
  78.     if( p_sys == NULL )
  79.         return VLC_ENOMEM;
  80.     vlc_mutex_init( &p_sys->lock );
  81.     p_sys->p_vout = NULL;
  82.     p_sys->b_button_pressed = false;
  83.     p_sys->b_triggered = false;
  84.     p_sys->i_threshold = config_GetInt( p_intf, "showintf-threshold" );
  85.     p_intf->pf_run = RunIntf;
  86.     return VLC_SUCCESS;
  87. }
  88. /*****************************************************************************
  89.  * Close: destroy interface
  90.  *****************************************************************************/
  91. void Close( vlc_object_t *p_this )
  92. {
  93.     intf_thread_t *p_intf = (intf_thread_t *)p_this;
  94.     /* Destroy structure */
  95.     vlc_mutex_destroy( &p_intf->p_sys->lock );
  96.     free( p_intf->p_sys );
  97. }
  98. /*****************************************************************************
  99.  * RunIntf: main loop
  100.  *****************************************************************************/
  101. static void RunIntf( intf_thread_t *p_intf )
  102. {
  103.     int canc = vlc_savecancel( );
  104.     /* Main loop */
  105.     while( vlc_object_alive( p_intf ) )
  106.     {
  107.         vlc_mutex_lock( &p_intf->p_sys->lock );
  108.         /* Notify the interfaces */
  109.         if( p_intf->p_sys->b_triggered )
  110.         {
  111.             var_SetBool( p_intf->p_libvlc, "intf-show", true );
  112.             p_intf->p_sys->b_triggered = false;
  113.         }
  114.         vlc_mutex_unlock( &p_intf->p_sys->lock );
  115.         /* Take care of the video output */
  116.         if( p_intf->p_sys->p_vout && !vlc_object_alive (p_intf->p_sys->p_vout) )
  117.         {
  118.             var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
  119.                              MouseEvent, p_intf );
  120.             var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
  121.                              MouseEvent, p_intf );
  122.             vlc_object_release( p_intf->p_sys->p_vout );
  123.             p_intf->p_sys->p_vout = NULL;
  124.         }
  125.         if( p_intf->p_sys->p_vout == NULL )
  126.         {
  127.             p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
  128.                                                      FIND_ANYWHERE );
  129.             if( p_intf->p_sys->p_vout )
  130.             {
  131.                 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
  132.                                  MouseEvent, p_intf );
  133.                 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
  134.                                  MouseEvent, p_intf );
  135.             }
  136.         }
  137.         /* Wait a bit */
  138.         msleep( INTF_IDLE_SLEEP );
  139.     }
  140.     if( p_intf->p_sys->p_vout )
  141.     {
  142.         var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
  143.                          MouseEvent, p_intf );
  144.         var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
  145.                          MouseEvent, p_intf );
  146.         vlc_object_release( p_intf->p_sys->p_vout );
  147.     }
  148.     vlc_restorecancel( canc );
  149. }
  150. /*****************************************************************************
  151.  * MouseEvent: callback for mouse events
  152.  *****************************************************************************/
  153. static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
  154.                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
  155. {
  156.     VLC_UNUSED(p_this); VLC_UNUSED(oldval); VLC_UNUSED(newval);
  157.     int i_mouse_x, i_mouse_y;
  158.     intf_thread_t *p_intf = (intf_thread_t *)p_data;
  159.     /* Do nothing when the interface is already requested */
  160.     if( p_intf->p_sys->b_triggered )
  161.         return VLC_SUCCESS;
  162.     /* Nothing to do when not in fullscreen mode */
  163.     if( !var_GetBool( p_intf->p_sys->p_vout, "fullscreen" ) )
  164.         return VLC_SUCCESS;
  165.     vlc_mutex_lock( &p_intf->p_sys->lock );
  166.     if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
  167.     {
  168.         i_mouse_x = var_GetInteger( p_intf->p_sys->p_vout, "mouse-x" );
  169.         i_mouse_y = var_GetInteger( p_intf->p_sys->p_vout, "mouse-y" );
  170.         /* Very basic test, we even ignore the x value :) */
  171.         if ( i_mouse_y < p_intf->p_sys->i_threshold )
  172.         {
  173.             msg_Dbg( p_intf, "interface showing requested" );
  174.             p_intf->p_sys->b_triggered = true;
  175.         }
  176.     }
  177.     /* We keep track of the button state to avoid interferences with the
  178.      * gestures plugin */
  179.     if( !p_intf->p_sys->b_button_pressed &&
  180.         !strcmp( psz_var, "mouse-button-down" ) )
  181.     {
  182.         p_intf->p_sys->b_button_pressed = true;
  183.     }
  184.     if( p_intf->p_sys->b_button_pressed &&
  185.         !strcmp( psz_var, "mouse-button-down" ) )
  186.     {
  187.         p_intf->p_sys->b_button_pressed = false;
  188.     }
  189.     vlc_mutex_unlock( &p_intf->p_sys->lock );
  190.     return VLC_SUCCESS;
  191. }