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