]> git.sesse.net Git - vlc/blob - modules/control/showintf.c
* Still some work for playlist drag'n'drop
[vlc] / modules / control / showintf.c
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 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/intf.h>
32 #include <vlc/vout.h>
33
34 #ifdef HAVE_UNISTD_H
35 #    include <unistd.h>
36 #endif
37
38 /*****************************************************************************
39  * intf_sys_t: description and status of interface
40  *****************************************************************************/
41 struct intf_sys_t
42 {
43     vlc_object_t * p_vout;
44     vlc_bool_t     b_button_pressed;
45     vlc_bool_t     b_triggered;
46     int            i_threshold;
47 };
48
49 /*****************************************************************************
50  * Local prototypes.
51  *****************************************************************************/
52 int  E_(Open) ( vlc_object_t * );
53 void E_(Close)( vlc_object_t * );
54 static void RunIntf( intf_thread_t *p_intf );
55 static int  InitThread( intf_thread_t *p_intf );
56 static int  MouseEvent( vlc_object_t *, char const *,
57                         vlc_value_t, vlc_value_t, void * );
58
59 /*****************************************************************************
60  * Module descriptor
61  *****************************************************************************/
62 #define THRESHOLD_TEXT N_( "Threshold" )
63 #define THRESHOLD_LONGTEXT N_( "Height of the zone triggering the interface" )
64
65 vlc_module_begin();
66     set_shortname( "Showintf" );
67     set_category( CAT_INTERFACE );
68     set_subcategory( SUBCAT_INTERFACE_CONTROL );
69     add_integer( "showintf-threshold", 10, NULL, THRESHOLD_TEXT, THRESHOLD_LONGTEXT, VLC_TRUE );
70     set_description( _("Interface showing control interface") );
71
72     set_capability( "interface", 0 );
73     set_callbacks( E_(Open), E_(Close) );
74 vlc_module_end();
75
76 /*****************************************************************************
77  * Open: initialize interface
78  *****************************************************************************/
79 int E_(Open)( vlc_object_t *p_this )
80 {
81     intf_thread_t *p_intf = (intf_thread_t *)p_this;
82
83     /* Allocate instance and initialize some members */
84     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
85     if( p_intf->p_sys == NULL )
86     {
87         return( 1 );
88     };
89
90     p_intf->pf_run = RunIntf;
91
92     return( 0 );
93 }
94
95 /*****************************************************************************
96  * Close: destroy interface
97  *****************************************************************************/
98 void E_(Close)( vlc_object_t *p_this )
99 {
100     intf_thread_t *p_intf = (intf_thread_t *)p_this;
101
102     /* Destroy structure */
103     free( p_intf->p_sys );
104 }
105
106
107 /*****************************************************************************
108  * RunIntf: main loop
109  *****************************************************************************/
110 static void RunIntf( intf_thread_t *p_intf )
111 {
112     p_intf->p_sys->p_vout = NULL;
113
114     if( InitThread( p_intf ) < 0 )
115     {
116         msg_Err( p_intf, "cannot initialize intf" );
117         return;
118     }
119
120     /* Main loop */
121     while( !p_intf->b_die )
122     {
123         vlc_mutex_lock( &p_intf->change_lock );
124
125         /* Notify the interfaces */
126         if( p_intf->p_sys->b_triggered )
127         {
128             playlist_t *p_playlist =
129                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
130                                                FIND_ANYWHERE );
131
132             if( p_playlist != NULL )
133             {
134                 vlc_value_t val;
135                 val.b_bool = VLC_TRUE;
136                 var_Set( p_playlist, "intf-show", val );
137                 vlc_object_release( p_playlist );
138             }
139             p_intf->p_sys->b_triggered = VLC_FALSE;
140         }
141
142         vlc_mutex_unlock( &p_intf->change_lock );
143
144
145         /* Take care of the video output */
146         if( p_intf->p_sys->p_vout && p_intf->p_sys->p_vout->b_die )
147         {
148             var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
149                              MouseEvent, p_intf );
150             var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
151                              MouseEvent, p_intf );
152             vlc_object_release( p_intf->p_sys->p_vout );
153             p_intf->p_sys->p_vout = NULL;
154         }
155
156         if( p_intf->p_sys->p_vout == NULL )
157         {
158             p_intf->p_sys->p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
159                                                      FIND_ANYWHERE );
160             if( p_intf->p_sys->p_vout )
161             {
162                 var_AddCallback( p_intf->p_sys->p_vout, "mouse-moved",
163                                  MouseEvent, p_intf );
164                 var_AddCallback( p_intf->p_sys->p_vout, "mouse-button-down",
165                                  MouseEvent, p_intf );
166             }
167         }
168
169         /* Wait a bit */
170         msleep( INTF_IDLE_SLEEP );
171     }
172
173     if( p_intf->p_sys->p_vout )
174     {
175         var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
176                          MouseEvent, p_intf );
177         var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
178                          MouseEvent, p_intf );
179         vlc_object_release( p_intf->p_sys->p_vout );
180     }
181 }
182
183 /*****************************************************************************
184  * InitThread:
185  *****************************************************************************/
186 static int InitThread( intf_thread_t * p_intf )
187 {
188     if( !p_intf->b_die )
189     {
190         vlc_mutex_lock( &p_intf->change_lock );
191
192         p_intf->p_sys->b_triggered = VLC_FALSE;
193         p_intf->p_sys->b_button_pressed = VLC_FALSE;
194         p_intf->p_sys->i_threshold =
195             config_GetInt( p_intf, "showintf-threshold" );
196
197         vlc_mutex_unlock( &p_intf->change_lock );
198
199         return 0;
200     }
201     else
202     {
203         return -1;
204     }
205 }
206
207 /*****************************************************************************
208  * MouseEvent: callback for mouse events
209  *****************************************************************************/
210 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
211                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
212 {
213     vlc_value_t val;
214
215     int i_mouse_x, i_mouse_y;
216     intf_thread_t *p_intf = (intf_thread_t *)p_data;
217
218     /* Do nothing when the interface is already requested */
219     if( p_intf->p_sys->b_triggered )
220         return VLC_SUCCESS;
221
222     /* Nothing to do when not in fullscreen mode */
223     var_Get( p_intf->p_sys->p_vout, "fullscreen", &val );
224     if( !val.i_int )
225         return VLC_SUCCESS;
226
227     vlc_mutex_lock( &p_intf->change_lock );
228     if( !strcmp( psz_var, "mouse-moved" ) && !p_intf->p_sys->b_button_pressed )
229     {
230         var_Get( p_intf->p_sys->p_vout, "mouse-x", &val );
231         i_mouse_x = val.i_int;
232         var_Get( p_intf->p_sys->p_vout, "mouse-y", &val );
233         i_mouse_y = val.i_int;
234
235         /* Very basic test, we even ignore the x value :) */
236         if ( i_mouse_y < p_intf->p_sys->i_threshold )
237         {
238             msg_Dbg( p_intf, "interface showing requested" );
239             p_intf->p_sys->b_triggered = VLC_TRUE;
240         }
241     }
242
243     /* We keep track of the button state to avoid interferences with the
244      * gestures plugin */
245     if( !p_intf->p_sys->b_button_pressed &&
246         !strcmp( psz_var, "mouse-button-down" ) )
247     {
248         p_intf->p_sys->b_button_pressed = VLC_TRUE;
249     }
250     if( p_intf->p_sys->b_button_pressed &&
251         !strcmp( psz_var, "mouse-button-down" ) )
252     {
253         p_intf->p_sys->b_button_pressed = VLC_FALSE;
254     }
255
256     vlc_mutex_unlock( &p_intf->change_lock );
257
258     return VLC_SUCCESS;
259 }