]> git.sesse.net Git - vlc/blob - src/video_output/vout_intf.c
* src/video_output/*: moved fullscreen object var handling in vout_intf.c and disable...
[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
31 #include "vlc_video.h"
32 #include "video_output.h"
33 #include "vlc_interface.h"
34
35 #include <vlc/input.h>                                 /* for input_thread_t */
36
37 /*****************************************************************************
38  * Local prototypes
39  *****************************************************************************/
40
41 /* Object variables callbacks */
42 static int ZoomCallback( vlc_object_t *, char const *,
43                          vlc_value_t, vlc_value_t, void * );
44 static int OnTopCallback( vlc_object_t *, char const *,
45                           vlc_value_t, vlc_value_t, void * );
46 static int FullscreenCallback( vlc_object_t *, char const *,
47                                vlc_value_t, vlc_value_t, void * );
48
49 /*****************************************************************************
50  * vout_RequestWindow: Create/Get a video window if possible.
51  *****************************************************************************
52  * This function looks for the main interface and tries to request
53  * a new video window. If it fails then the vout will still need to create the
54  * window by itself.
55  *****************************************************************************/
56 void *vout_RequestWindow( vout_thread_t *p_vout,
57                           int *pi_x_hint, int *pi_y_hint,
58                           unsigned int *pi_width_hint,
59                           unsigned int *pi_height_hint )
60 {
61     intf_thread_t *p_intf;
62     void *p_window;
63     vlc_value_t val;
64
65     /* Get requested coordinates */
66     var_Get( p_vout, "video-x", &val );
67     *pi_x_hint = val.i_int ;
68     var_Get( p_vout, "video-y", &val );
69     *pi_y_hint = val.i_int;
70
71     *pi_width_hint = p_vout->i_window_width;
72     *pi_height_hint = p_vout->i_window_height;
73
74     /* Check whether someone provided us with a window ID */
75     var_Get( p_vout->p_vlc, "drawable", &val );
76     if( val.i_int ) return (void *)val.i_int;
77
78     /* Find the main interface */
79     p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
80     if( !p_intf ) return NULL;
81
82     if( !p_intf->pf_request_window )
83     {
84         vlc_object_release( p_intf );
85         return NULL;
86     }
87
88     p_window = p_intf->pf_request_window( p_intf, p_vout, pi_x_hint, pi_y_hint,
89                                           pi_width_hint, pi_height_hint );
90     vlc_object_release( p_intf );
91
92     return p_window;
93 }
94
95 void vout_ReleaseWindow( vout_thread_t *p_vout, void *p_window )
96 {
97     intf_thread_t *p_intf;
98
99     /* Find the main interface */
100     p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
101     if( !p_intf ) return;
102
103     if( !p_intf->pf_release_window )
104     {
105         msg_Err( p_vout, "no pf_release_window");
106         vlc_object_release( p_intf );
107         return;
108     }
109
110     p_intf->pf_release_window( p_intf, p_window );
111     vlc_object_release( p_intf );
112 }
113
114 int vout_ControlWindow( vout_thread_t *p_vout, void *p_window,
115                         int i_query, va_list args )
116 {
117     intf_thread_t *p_intf;
118     int i_ret;
119
120     /* Find the main interface */
121     p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE );
122     if( !p_intf ) return VLC_EGENERIC;
123
124     if( !p_intf->pf_control_window )
125     {
126         msg_Err( p_vout, "no pf_control_window");
127         vlc_object_release( p_intf );
128         return VLC_EGENERIC;
129     }
130
131     i_ret = p_intf->pf_control_window( p_intf, p_window, i_query, args );
132     vlc_object_release( p_intf );
133     return i_ret;
134 }
135
136 /*****************************************************************************
137  * vout_IntfInit: called during the vout creation to initialise misc things.
138  *****************************************************************************/
139 void vout_IntfInit( vout_thread_t *p_vout )
140 {
141     vlc_value_t val, text, old_val;
142
143     /* Create a few object variables we'll need later on */
144     var_Create( p_vout, "aspect-ratio", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
145     var_Create( p_vout, "width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
146     var_Create( p_vout, "height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
147     var_Create( p_vout, "align", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
148     var_Create( p_vout, "video-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
149     var_Create( p_vout, "video-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
150
151     var_Create( p_vout, "zoom", VLC_VAR_FLOAT | VLC_VAR_ISCOMMAND |
152                 VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT );
153
154     text.psz_string = _("Zoom");
155     var_Change( p_vout, "zoom", VLC_VAR_SETTEXT, &text, NULL );
156
157     var_Get( p_vout, "zoom", &old_val );
158     if( old_val.f_float == 0.25 ||
159         old_val.f_float == 0.5 ||
160         old_val.f_float == 1 ||
161         old_val.f_float == 2 )
162     {
163         var_Change( p_vout, "zoom", VLC_VAR_DELCHOICE, &old_val, NULL );
164     }
165
166     val.f_float = 0.25; text.psz_string = _("1:4 Quarter");
167     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
168     val.f_float = 0.5; text.psz_string = _("1:2 Half");
169     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
170     val.f_float = 1; text.psz_string = _("1:1 Original");
171     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
172     val.f_float = 2; text.psz_string = _("2:1 Double");
173     var_Change( p_vout, "zoom", VLC_VAR_ADDCHOICE, &val, &text );
174
175     var_Set( p_vout, "zoom", old_val );
176
177     var_AddCallback( p_vout, "zoom", ZoomCallback, NULL );
178
179     /* Add a variable to indicate if the window should be on top of others */
180     var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
181     text.psz_string = _("Always on top");
182     var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
183     var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
184
185     /* Add a fullscreen variable */
186     var_Create( p_vout, "fullscreen", VLC_VAR_BOOL );
187     text.psz_string = _("Fullscreen");
188     var_Change( p_vout, "fullscreen", VLC_VAR_SETTEXT, &text, NULL );
189     var_Change( p_vout, "fullscreen", VLC_VAR_INHERITVALUE, &val, NULL );
190     if( val.b_bool )
191     {
192         /* user requested fullscreen */
193         p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
194     }
195     var_AddCallback( p_vout, "fullscreen", FullscreenCallback, NULL );
196 }
197
198 /*****************************************************************************
199  * Object variables callbacks
200  *****************************************************************************/
201 static int ZoomCallback( vlc_object_t *p_this, char const *psz_cmd,
202                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
203 {
204     vout_thread_t *p_vout = (vout_thread_t *)p_this;
205     vout_Control( p_vout, VOUT_SET_ZOOM, newval.f_float );
206     return VLC_SUCCESS;
207 }
208
209 static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
210                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
211 {
212     vout_thread_t *p_vout = (vout_thread_t *)p_this;
213     vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, newval.b_bool );
214     return VLC_SUCCESS;
215 }
216
217 static int FullscreenCallback( vlc_object_t *p_this, char const *psz_cmd,
218                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
219 {
220     vout_thread_t *p_vout = (vout_thread_t *)p_this;
221     input_thread_t *p_input;
222     vlc_value_t val;
223
224     p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
225
226     p_input = (input_thread_t *)vlc_object_find( p_this, VLC_OBJECT_INPUT,
227                                                  FIND_PARENT );
228     if( p_input )
229     {
230         /* Modify input as well because the vout might have to be restarted */
231         var_Create( p_input, "fullscreen", VLC_VAR_BOOL );
232         var_Set( p_input, "fullscreen", newval );
233
234         vlc_object_release( p_input );
235     }
236
237     /* Disable "always on top" in fullscreen mode */
238     var_Get( p_vout, "video-on-top", &val );
239     if( newval.b_bool && val.b_bool )
240     {
241         val.b_bool = VLC_FALSE;
242         vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
243     }
244     else if( !newval.b_bool && val.b_bool )
245     {
246         vout_Control( p_vout, VOUT_SET_STAY_ON_TOP, val.b_bool );
247     }
248
249     val.b_bool = VLC_TRUE;
250     var_Set( p_vout, "intf-change", val );
251     return VLC_SUCCESS;
252 }