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