]> git.sesse.net Git - vlc/blob - src/video_output/vout_intf.c
Fixed OpenGL mouse events
[vlc] / src / video_output / vout_intf.c
1 /*****************************************************************************
2  * vout_intf.c : video output interface
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
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>                                                /* free() */
28
29 #include <vlc/vlc.h>
30 #include <vlc/intf.h>
31
32 #include "vlc_video.h"
33 #include "video_output.h"
34
35 /*****************************************************************************
36  * Local prototypes
37  *****************************************************************************/
38
39 /* Object variables callbacks */
40 static int ZoomCallback( vlc_object_t *, char const *,
41                          vlc_value_t, vlc_value_t, void * );
42 static int OnTopCallback( vlc_object_t *, char const *,
43                           vlc_value_t, vlc_value_t, void * );
44 static int FullscreenCallback( vlc_object_t *, char const *,
45                                vlc_value_t, vlc_value_t, void * );
46
47 /*****************************************************************************
48  * vout_RequestWindow: Create/Get a video window if possible.
49  *****************************************************************************
50  * This function looks for the main interface and tries to request
51  * a new video window. If it fails then the vout will still need to create the
52  * window by itself.
53  *****************************************************************************/
54 void *vout_RequestWindow( vout_thread_t *p_vout,
55                           int *pi_x_hint, int *pi_y_hint,
56                           unsigned int *pi_width_hint,
57                           unsigned int *pi_height_hint )
58 {
59     intf_thread_t *p_intf = NULL;
60     vlc_list_t *p_list;
61     void *p_window;
62     vlc_value_t val;
63     int i;
64
65     /* Small kludge */
66     if( !var_Type( p_vout, "aspect-ratio" ) ) vout_IntfInit( p_vout );
67
68     /* Get requested coordinates */
69     var_Get( p_vout, "video-x", &val );
70     *pi_x_hint = val.i_int ;
71     var_Get( p_vout, "video-y", &val );
72     *pi_y_hint = val.i_int;
73
74     *pi_width_hint = p_vout->i_window_width;
75     *pi_height_hint = p_vout->i_window_height;
76
77     /* Check whether someone provided us with a window ID */
78     var_Get( p_vout->p_vlc, "drawable", &val );
79     if( val.i_int ) return (void *)val.i_int;
80
81     /* Find if the main interface supports embedding */
82     p_list = vlc_list_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
83     if( !p_list ) return NULL;
84
85     for( i = 0; i < p_list->i_count; i++ )
86     {
87         p_intf = (intf_thread_t *)p_list->p_values[i].p_object;
88         if( p_intf->b_block && p_intf->pf_request_window ) break;
89         p_intf = NULL;
90     }
91
92     if( !p_intf )
93     {
94         vlc_list_release( p_list );
95         return NULL;
96     }
97
98     vlc_object_yield( p_intf );
99     vlc_list_release( p_list );
100
101     p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
102                                           pi_width_hint, pi_height_hint );
103
104     if( !p_window ) vlc_object_release( p_intf );
105     else p_vout->p_parent_intf = p_intf;
106
107     return p_window;
108 }
109
110 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
111 {
112     intf_thread_t *p_intf = p_vout->p_parent_intf;
113
114     if( !p_intf ) return;
115
116     vlc_mutex_lock( &p_intf->object_lock );
117     if( p_intf->b_dead )
118     {
119         vlc_mutex_unlock( &p_intf->object_lock );
120         return;
121     }
122
123     if( !p_intf->pf_release_window )
124     {
125         msg_Err( p_vout, "no pf_release_window");
126         vlc_mutex_unlock( &p_intf->object_lock );
127         vlc_object_release( p_intf );
128         return;
129     }
130
131     p_intf->pf_release_window( p_intf, p_window );
132
133     p_vout->p_parent_intf = NULL;
134     vlc_mutex_unlock( &p_intf->object_lock );
135     vlc_object_release( p_intf );
136 }
137
138 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
139                         int i_query, va_list args )
140 {
141     intf_thread_t *p_intf = p_vout->p_parent_intf;
142     int i_ret;
143
144     if( !p_intf ) return VLC_EGENERIC;
145
146     vlc_mutex_lock( &p_intf->object_lock );
147     if( p_intf->b_dead )
148     {
149         vlc_mutex_unlock( &p_intf->object_lock );
150         return VLC_EGENERIC;
151     }
152
153     if( !p_intf->pf_control_window )
154     {
155         msg_Err( p_vout, "no pf_control_window");
156         vlc_mutex_unlock( &p_intf->object_lock );
157         return VLC_EGENERIC;
158     }
159
160     i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
161     vlc_mutex_unlock( &p_intf->object_lock );
162     return i_ret;
163 }
164
165 /*****************************************************************************
166  * vout_IntfInit: called during the vout creation to initialise misc things.
167  *****************************************************************************/
168 void vout_IntfInit( vout_thread_t *p_vout )
169 {
170     vlc_value_t val, text, old_val;
171
172     /* Create a few object variables we'll need later on */
173     var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
174     var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
175     var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
176     var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
177     var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
178     var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
179
180     var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
181                 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
182
183     text.psz_string = _("Zoom");
184     var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
185
186     var_Get( p_vout, "zoom", &old_val );
187     if( old_val.f_float == 0.25 ||
188         old_val.f_float == 0.5 ||
189         old_val.f_float == 1 ||
190         old_val.f_float == 2 )
191     {
192         var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
193     }
194
195     val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
196     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
197     val.f_float = 0.5; text.psz_string = _("1:2 Half");
198     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
199     val.f_float = 1; text.psz_string = _("1:1 Original");
200     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
201     val.f_float = 2; text.psz_string = _("2:1 Double");
202     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
203
204     var_Set( p_vout, "zoom", old_val );
205
206     var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
207
208     /* Add a variable to indicate if the window should be on top of others */
209     var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
210     text.psz_string = _("Always on top");
211     var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
212     var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
213
214     /* Add a fullscreen variable */
215     var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
216     text.psz_string = _("Fullscreen");
217     var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
218     var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
219     if( val.b_bool )
220     {
221         /* user requested fullscreen */
222         p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
223     }
224     var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
225
226     var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
227     val.b_bool = VLC_TRUE;
228     var_Set( p_vout, "intf-change", val );
229 }
230
231 /*****************************************************************************
232  * vout_ControlDefault: default methods for video output control.
233  *****************************************************************************/
234 int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
235 {
236     switch( i_query )
237     {
238     case VOUT_REPARENT:
239     case VOUT_CLOSE:
240         if( p_vout->p_parent_intf )
241         {
242             vlc_object_release( p_vout->p_parent_intf );
243             p_vout->p_parent_intf = NULL;
244         }
245         return VLC_SUCCESS;
246         break;
247
248     default:
249         msg_Dbg( p_vout, "control query not supported" );
250         return VLC_EGENERIC;
251     }
252 }
253
254 /*****************************************************************************
255  * Object variables callbacks
256  *****************************************************************************/
257 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
258                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
259 {
260     vout_thread_t *p_vout = (vout_thread_t *)p_this;
261     vout_Control( p_vout, VOUT_SET_ZOOM, newval.f_float );
262     return VLC_SUCCESS;
263 }
264
265 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
266                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
267 {
268     vout_thread_t *p_vout = (vout_thread_t *)p_this;
269     playlist_t *p_playlist;
270     vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
271
272     p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
273                                                  FIND_PARENT );
274     if( p_playlist )
275     {
276         /* Modify playlist as well because the vout might have to be restarted */
277         var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL );
278         var_Set( p_playlist, "video-on-top", newval );
279
280         vlc_object_release( p_playlist );
281     }
282     return VLC_SUCCESS;
283 }
284
285 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
286                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
287 {
288     vout_thread_t *p_vout = (vout_thread_t *)p_this;
289     playlist_t *p_playlist;
290     vlc_value_t val;
291
292     p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
293
294     p_playlist = (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
295                                                  FIND_PARENT );
296     if( p_playlist )
297     {
298         /* Modify playlist as well because the vout might have to be restarted */
299         var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL );
300         var_Set( p_playlist, "fullscreen", newval );
301
302         vlc_object_release( p_playlist );
303     }
304
305     /* Disable "always on top" in fullscreen mode */
306     var_Get( p_vout, "video-on-top", &val );
307     if( newval.b_bool && val.b_bool )
308     {
309         val.b_bool = VLC_FALSE;
310         vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
311     }
312     else if( !newval.b_bool && val.b_bool )
313     {
314         vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
315     }
316
317     val.b_bool = VLC_TRUE;
318     var_Set( p_vout, "intf-change", val );
319     return VLC_SUCCESS;
320 }