]> git.sesse.net Git - vlc/blob - src/video_output/event.h
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / video_output / event.h
1 /*****************************************************************************
2  * event.h: vout event
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__)
25 # error This header file can only be included from LibVLC.
26 #endif
27
28 #include <vlc_common.h>
29 #include <vlc_playlist.h>
30 #include <math.h>
31
32 #include "vout_control.h"
33
34 /* TODO/FIXME
35  *
36  * It should be converted to something like input_thread_t:
37  * one intf-event can be grabbed by a callback, all others
38  * variable only var_Change
39  *
40  * Maybe a intf-mouse can be used too (don't like it).
41  *
42  * (Some case may infinite loop otherwise here)
43  */
44
45 static inline void vout_SendEventClose(vout_thread_t *vout)
46 {
47     /* Ask to stop
48      * FIXME works only for input handled by the playlist
49      */
50     playlist_t *playlist = pl_Get(vout);
51     playlist_Stop(playlist);
52 }
53 static inline void vout_SendEventKey(vout_thread_t *vout, int key)
54 {
55     var_SetInteger(vout->p_libvlc, "key-pressed", key);
56 }
57 static inline void vout_SendEventMouseMoved(vout_thread_t *vout, int x, int y)
58 {
59     var_SetCoords(vout, "mouse-moved", x, y);
60 }
61 static inline void vout_SendEventMousePressed(vout_thread_t *vout, int button)
62 {
63     var_OrInteger(vout, "mouse-button-down", 1 << button);
64
65     switch (button)
66     {
67     case MOUSE_BUTTON_LEFT:
68     {
69         /* FIXME? */
70         int x, y;
71         var_GetCoords(vout, "mouse-moved", &x, &y);
72         var_SetCoords(vout, "mouse-clicked", x, y);
73         var_SetBool(vout->p_libvlc, "intf-popupmenu", false);
74         break;
75     }
76     case MOUSE_BUTTON_CENTER:
77         var_ToggleBool(vout->p_libvlc, "intf-show");
78         break;
79     case MOUSE_BUTTON_RIGHT:
80         var_SetBool(vout->p_libvlc, "intf-popupmenu", true);
81         break;
82     case MOUSE_BUTTON_WHEEL_UP:
83         vout_SendEventKey(vout, KEY_MOUSEWHEELUP);
84         break;
85     case MOUSE_BUTTON_WHEEL_DOWN:
86         vout_SendEventKey(vout, KEY_MOUSEWHEELDOWN);
87         break;
88     }
89 }
90 static inline void vout_SendEventMouseReleased(vout_thread_t *vout, int button)
91 {
92     var_NAndInteger(vout, "mouse-button-down", 1 << button);
93 }
94 static inline void vout_SendEventMouseDoubleClick(vout_thread_t *vout)
95 {
96     //vout_ControlSetFullscreen(vout, !var_GetBool(vout, "fullscreen"));
97     //var_ToggleBool(vout, "fullscreen");
98     var_SetInteger(vout->p_libvlc, "key-action", ACTIONID_TOGGLE_FULLSCREEN);
99 }
100 static inline void vout_SendEventMouseVisible(vout_thread_t *vout)
101 {
102     /* TODO */
103     VLC_UNUSED(vout);
104 }
105 static inline void vout_SendEventMouseHidden(vout_thread_t *vout)
106 {
107     /* TODO */
108     VLC_UNUSED(vout);
109 }
110
111 static inline void vout_SendEventFullscreen(vout_thread_t *vout, bool is_fullscreen)
112 {
113     var_SetBool(vout, "fullscreen", is_fullscreen);
114 }
115
116 static inline void vout_SendEventDisplayFilled(vout_thread_t *vout, bool is_display_filled)
117 {
118     if (!var_GetBool(vout, "autoscale") != !is_display_filled)
119         var_SetBool(vout, "autoscale", is_display_filled);
120 }
121
122 static inline void vout_SendEventZoom(vout_thread_t *vout, int num, int den)
123 {
124     VLC_UNUSED(vout);
125     VLC_UNUSED(num);
126     VLC_UNUSED(den);
127     /* FIXME deadlock problems with current vout */
128 #if 0
129     const float zoom = (float)num / (float)den;
130
131     /* XXX 0.1% is arbitrary */
132     if (fabs(zoom - var_GetFloat(vout, "scale")) > 0.001)
133         var_SetFloat(vout, "scale", zoom);
134 #endif
135 }
136
137 static inline void vout_SendEventOnTop(vout_thread_t *vout, bool is_on_top)
138 {
139     VLC_UNUSED(vout);
140     VLC_UNUSED(is_on_top);
141     /* FIXME deadlock problems with current vout */
142 #if 0
143
144     if (!var_GetBool(vout, "video-on-top") != !is_on_top)
145         var_SetBool(vout, "video-on-top", is_on_top);
146 #endif
147 }
148
149 /**
150  * It must be called on source aspect ratio changes, with the new DAR (Display
151  * Aspect Ratio) value.
152  */
153 static inline void vout_SendEventSourceAspect(vout_thread_t *vout,
154                                               unsigned num, unsigned den)
155 {
156     VLC_UNUSED(vout);
157     VLC_UNUSED(num);
158     VLC_UNUSED(den);
159     /* FIXME the value stored in "aspect-ratio" are not reduced
160      * creating a lot of problems here */
161 #if 0
162     char *ar;
163     if (num > 0 && den > 0) {
164         if (asprintf(&ar, "%u:%u", num, den) < 0)
165             return;
166     } else {
167         ar = strdup("");
168     }
169
170     char *current = var_GetString(vout, "aspect-ratio");
171     msg_Err(vout, "vout_SendEventSourceAspect %s -> %s", current, ar);
172     if (ar && current && strcmp(ar, current))
173         var_SetString(vout, "aspect-ratio", ar);
174
175     free(current);
176     free(ar);
177 #endif
178 }
179 static inline void vout_SendEventSourceCrop(vout_thread_t *vout,
180                                             unsigned num, unsigned den,
181                                             unsigned left, unsigned top,
182                                             unsigned right, unsigned bottom)
183 {
184     VLC_UNUSED(num);
185     VLC_UNUSED(den);
186
187     vlc_value_t val;
188
189     /* I cannot use var_Set here, infinite loop otherwise */
190
191     /* */
192     val.i_int = left;
193     var_Change(vout, "crop-left",   VLC_VAR_SETVALUE, &val, NULL);
194     val.i_int = top;
195     var_Change(vout, "crop-top",    VLC_VAR_SETVALUE, &val, NULL);
196     val.i_int = right;
197     var_Change(vout, "crop-right",  VLC_VAR_SETVALUE, &val, NULL);
198     val.i_int = bottom;
199     var_Change(vout, "crop-bottom", VLC_VAR_SETVALUE, &val, NULL);
200
201     /* FIXME the value stored in "crop" are not reduced
202      * creating a lot of problems here */
203 #if 0
204     char *crop;
205     if (num > 0 && den > 0) {
206         if (asprintf(&crop, "%u:%u", num, den) < 0)
207             crop = NULL;
208     } else if (left > 0 || top > 0 || right > 0 || bottom > 0) {
209         if (asprintf(&crop, "%u+%u+%u+%u", left, top, right, bottom) < 0)
210             crop = NULL;
211     } else {
212         crop = strdup("");
213     }
214     if (crop) {
215         val.psz_string = crop;
216         var_Change(vout, "crop", VLC_VAR_SETVALUE, &val, NULL);
217         free(crop);
218     }
219 #endif
220 }
221 #if 0
222 static inline void vout_SendEventSnapshot(vout_thread_t *vout, const char *filename)
223 {
224     /* signal creation of a new snapshot file */
225     var_SetString(vout->p_libvlc, "snapshot-file", filename);
226 }
227
228 #warning "FIXME clean up postproc event"
229
230 extern void vout_InstallDeprecatedPostProcessing(vout_thread_t *);
231 extern void vout_UninstallDeprecatedPostProcessing(vout_thread_t *);
232
233 static inline void vout_SendEventPostProcessing(vout_thread_t *vout, bool is_available)
234 {
235     if (is_available)
236         vout_InstallDeprecatedPostProcessing(vout);
237     else
238         vout_UninstallDeprecatedPostProcessing(vout);
239 }
240
241 static inline void vout_SendEventFilters(vout_thread_t *vout)
242 {
243     vout_filter_t **filter;
244     int           filter_count;
245
246     vout_ControlGetFilters(vout, &filter, &filter_count);
247
248     char *list = strdup("");
249     for (int i = 0; i < filter_count; i++) {
250         char *psz;
251
252         if (asprintf(&psz, "%s%s%s",
253                      list, i > 0 ? ":" : "", filter[i]->name) < 0) {
254             free(list);
255             list = NULL;
256             break;
257         }
258         free(list);
259         list = psz;
260     }
261
262     if (list) {
263         vlc_value_t val;
264         val.psz_string = list;
265         var_Change(vout, "video-filter", VLC_VAR_SETVALUE, &val, NULL);
266         free(list);
267     }
268
269     for (int i = 0; i < filter_count; i++)
270         vout_filter_Delete(filter[i]);
271     free(filter);
272 }
273 #endif