]> git.sesse.net Git - vlc/blob - src/video_output/event.h
LGPL
[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     playlist_t *playlist = pl_Get(vout);
47     playlist_Stop(playlist);
48 }
49 static inline void vout_SendEventKey(vout_thread_t *vout, int key)
50 {
51     var_SetInteger(vout->p_libvlc, "key-pressed", key);
52 }
53 static inline void vout_SendEventMouseMoved(vout_thread_t *vout, int x, int y)
54 {
55     var_SetCoords(vout, "mouse-moved", x, y);
56 }
57 static inline void vout_SendEventMousePressed(vout_thread_t *vout, int button)
58 {
59     int key;
60     var_OrInteger(vout, "mouse-button-down", 1 << button);
61
62     switch (button)
63     {
64     case MOUSE_BUTTON_LEFT:
65     {
66         /* FIXME? */
67         int x, y;
68         var_GetCoords(vout, "mouse-moved", &x, &y);
69         var_SetCoords(vout, "mouse-clicked", x, y);
70         var_SetBool(vout->p_libvlc, "intf-popupmenu", false);
71         return;
72     }
73     case MOUSE_BUTTON_CENTER:
74         var_ToggleBool(vout->p_libvlc, "intf-toggle-fscontrol");
75         return;
76     case MOUSE_BUTTON_RIGHT:
77         var_SetBool(vout->p_libvlc, "intf-popupmenu", true);
78         return;
79     case MOUSE_BUTTON_WHEEL_UP:    key = KEY_MOUSEWHEELUP;    break;
80     case MOUSE_BUTTON_WHEEL_DOWN:  key = KEY_MOUSEWHEELDOWN;  break;
81     case MOUSE_BUTTON_WHEEL_LEFT:  key = KEY_MOUSEWHEELLEFT;  break;
82     case MOUSE_BUTTON_WHEEL_RIGHT: key = KEY_MOUSEWHEELRIGHT; break;
83     }
84     vout_SendEventKey(vout, key);
85 }
86 static inline void vout_SendEventMouseReleased(vout_thread_t *vout, int button)
87 {
88     var_NAndInteger(vout, "mouse-button-down", 1 << button);
89 }
90 static inline void vout_SendEventMouseDoubleClick(vout_thread_t *vout)
91 {
92     //vout_ControlSetFullscreen(vout, !var_GetBool(vout, "fullscreen"));
93     //var_ToggleBool(vout, "fullscreen");
94     var_SetInteger(vout->p_libvlc, "key-action", ACTIONID_TOGGLE_FULLSCREEN);
95 }
96 static inline void vout_SendEventMouseVisible(vout_thread_t *vout)
97 {
98     /* TODO */
99     VLC_UNUSED(vout);
100 }
101 static inline void vout_SendEventMouseHidden(vout_thread_t *vout)
102 {
103     /* TODO */
104     VLC_UNUSED(vout);
105 }
106
107 static inline void vout_SendEventFullscreen(vout_thread_t *vout, bool is_fullscreen)
108 {
109     var_SetBool(vout, "fullscreen", is_fullscreen);
110 }
111
112 static inline void vout_SendEventDisplayFilled(vout_thread_t *vout, bool is_display_filled)
113 {
114     if (!var_GetBool(vout, "autoscale") != !is_display_filled)
115         var_SetBool(vout, "autoscale", is_display_filled);
116 }
117
118 static inline void vout_SendEventZoom(vout_thread_t *vout, int num, int den)
119 {
120     VLC_UNUSED(vout);
121     VLC_UNUSED(num);
122     VLC_UNUSED(den);
123     /* FIXME deadlock problems with current vout */
124 #if 0
125     const float zoom = (float)num / (float)den;
126
127     /* XXX 0.1% is arbitrary */
128     if (fabs(zoom - var_GetFloat(vout, "scale")) > 0.001)
129         var_SetFloat(vout, "scale", zoom);
130 #endif
131 }
132
133 static inline void vout_SendEventOnTop(vout_thread_t *vout, bool is_on_top)
134 {
135     VLC_UNUSED(vout);
136     VLC_UNUSED(is_on_top);
137     /* FIXME deadlock problems with current vout */
138 #if 0
139
140     if (!var_GetBool(vout, "video-on-top") != !is_on_top)
141         var_SetBool(vout, "video-on-top", is_on_top);
142 #endif
143 }
144
145 /**
146  * It must be called on source aspect ratio changes, with the new DAR (Display
147  * Aspect Ratio) value.
148  */
149 static inline void vout_SendEventSourceAspect(vout_thread_t *vout,
150                                               unsigned num, unsigned den)
151 {
152     VLC_UNUSED(vout);
153     VLC_UNUSED(num);
154     VLC_UNUSED(den);
155     /* FIXME the value stored in "aspect-ratio" are not reduced
156      * creating a lot of problems here */
157 #if 0
158     char *ar;
159     if (num > 0 && den > 0) {
160         if (asprintf(&ar, "%u:%u", num, den) < 0)
161             return;
162     } else {
163         ar = strdup("");
164     }
165
166     char *current = var_GetString(vout, "aspect-ratio");
167     msg_Err(vout, "vout_SendEventSourceAspect %s -> %s", current, ar);
168     if (ar && current && strcmp(ar, current))
169         var_SetString(vout, "aspect-ratio", ar);
170
171     free(current);
172     free(ar);
173 #endif
174 }
175 static inline void vout_SendEventSourceCrop(vout_thread_t *vout,
176                                             unsigned num, unsigned den,
177                                             unsigned left, unsigned top,
178                                             unsigned right, unsigned bottom)
179 {
180     VLC_UNUSED(num);
181     VLC_UNUSED(den);
182
183     vlc_value_t val;
184
185     /* I cannot use var_Set here, infinite loop otherwise */
186
187     /* */
188     val.i_int = left;
189     var_Change(vout, "crop-left",   VLC_VAR_SETVALUE, &val, NULL);
190     val.i_int = top;
191     var_Change(vout, "crop-top",    VLC_VAR_SETVALUE, &val, NULL);
192     val.i_int = right;
193     var_Change(vout, "crop-right",  VLC_VAR_SETVALUE, &val, NULL);
194     val.i_int = bottom;
195     var_Change(vout, "crop-bottom", VLC_VAR_SETVALUE, &val, NULL);
196
197     /* FIXME the value stored in "crop" are not reduced
198      * creating a lot of problems here */
199 #if 0
200     char *crop;
201     if (num > 0 && den > 0) {
202         if (asprintf(&crop, "%u:%u", num, den) < 0)
203             crop = NULL;
204     } else if (left > 0 || top > 0 || right > 0 || bottom > 0) {
205         if (asprintf(&crop, "%u+%u+%u+%u", left, top, right, bottom) < 0)
206             crop = NULL;
207     } else {
208         crop = strdup("");
209     }
210     if (crop) {
211         val.psz_string = crop;
212         var_Change(vout, "crop", VLC_VAR_SETVALUE, &val, NULL);
213         free(crop);
214     }
215 #endif
216 }
217 #if 0
218 static inline void vout_SendEventSnapshot(vout_thread_t *vout, const char *filename)
219 {
220     /* signal creation of a new snapshot file */
221     var_SetString(vout->p_libvlc, "snapshot-file", filename);
222 }
223
224 #warning "FIXME clean up postproc event"
225
226 extern void vout_InstallDeprecatedPostProcessing(vout_thread_t *);
227 extern void vout_UninstallDeprecatedPostProcessing(vout_thread_t *);
228
229 static inline void vout_SendEventPostProcessing(vout_thread_t *vout, bool is_available)
230 {
231     if (is_available)
232         vout_InstallDeprecatedPostProcessing(vout);
233     else
234         vout_UninstallDeprecatedPostProcessing(vout);
235 }
236
237 static inline void vout_SendEventFilters(vout_thread_t *vout)
238 {
239     vout_filter_t **filter;
240     int           filter_count;
241
242     vout_ControlGetFilters(vout, &filter, &filter_count);
243
244     char *list = strdup("");
245     for (int i = 0; i < filter_count; i++) {
246         char *psz;
247
248         if (asprintf(&psz, "%s%s%s",
249                      list, i > 0 ? ":" : "", filter[i]->name) < 0) {
250             free(list);
251             list = NULL;
252             break;
253         }
254         free(list);
255         list = psz;
256     }
257
258     if (list) {
259         vlc_value_t val;
260         val.psz_string = list;
261         var_Change(vout, "video-filter", VLC_VAR_SETVALUE, &val, NULL);
262         free(list);
263     }
264
265     for (int i = 0; i < filter_count; i++)
266         vout_filter_Delete(filter[i]);
267     free(filter);
268 }
269 #endif