1 /*****************************************************************************
2 * vlc_vout_window.h: vout_window_t definitions
3 *****************************************************************************
4 * Copyright (C) 2008 RĂ©mi Denis-Courmont
5 * Copyright (C) 2009 Laurent Aimar
8 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifndef VLC_VOUT_WINDOW_H
26 #define VLC_VOUT_WINDOW_H 1
29 #include <vlc_common.h>
32 * \defgroup video_window Video window
33 * \ingroup video_output
34 * Video output window management
37 * Video output window modules interface
40 typedef struct vout_window_t vout_window_t
;
41 typedef struct vout_window_sys_t vout_window_sys_t
;
49 enum vout_window_type
{
50 VOUT_WINDOW_TYPE_INVALID
=0 /**< Invalid or unspecified window type */,
51 VOUT_WINDOW_TYPE_XID
/**< X11 window */,
52 VOUT_WINDOW_TYPE_HWND
/**< Win32 or OS/2 window */,
53 VOUT_WINDOW_TYPE_NSOBJECT
/**< MacOS X view */,
54 VOUT_WINDOW_TYPE_ANDROID_NATIVE
/**< Android native window */,
55 VOUT_WINDOW_TYPE_WAYLAND
/**< Wayland surface */,
59 * Control query for vout_window_t
61 enum vout_window_control
{
62 VOUT_WINDOW_SET_STATE
, /* unsigned state */
63 VOUT_WINDOW_SET_SIZE
, /* unsigned i_width, unsigned i_height */
64 VOUT_WINDOW_SET_FULLSCREEN
, /* int b_fullscreen */
65 VOUT_WINDOW_HIDE_MOUSE
, /* int b_hide */
69 * Window mouse event type for vout_window_mouse_event_t
71 enum vout_window_mouse_event_type
{
72 VOUT_WINDOW_MOUSE_STATE
,
73 VOUT_WINDOW_MOUSE_MOVED
,
74 VOUT_WINDOW_MOUSE_PRESSED
,
75 VOUT_WINDOW_MOUSE_RELEASED
,
76 VOUT_WINDOW_MOUSE_DOUBLE_CLICK
,
82 typedef struct vout_window_mouse_event_t
84 enum vout_window_mouse_event_type type
;
88 } vout_window_mouse_event_t
;
90 typedef struct vout_window_cfg_t
{
91 /* Window handle type */
94 /* If true, a standalone window is requested */
99 /* Window position hint */
104 /* Windows size hint */
110 typedef struct vout_window_owner
{
112 void (*resized
)(vout_window_t
*, unsigned width
, unsigned height
);
113 void (*closed
)(vout_window_t
*);
114 void (*mouse_event
)(vout_window_t
*, const vout_window_mouse_event_t
*mouse
);
115 } vout_window_owner_t
;
120 * This structure is an abstract interface to the windowing system.
121 * The window is normally used to draw video (and subpictures) into, but it
122 * can also be used for other purpose (e.g. OpenGL visualization).
124 * The window is responsible for providing a window handle, whose exact
125 * meaning depends on the windowing system. It also must report some events
126 * such as user input (keyboard, mouse) and window resize.
128 * Finally, it must support some control requests such as for fullscreen mode.
130 struct vout_window_t
{
136 * This identified the windowing system and protocol that the window
137 * needs to use. This also selects which member of the \ref handle union
138 * and the \ref display union are to be set.
140 * The possible values are defined in \ref vout_window_type.
142 * VOUT_WINDOW_TYPE_INVALID is a special placeholder type. It means that
143 * any windowing system is acceptable. In that case, the plugin must set
144 * its actual type during activation.
149 * Window handle (mandatory)
151 * This must be filled by the plugin upon activation.
153 * Depending on the \ref type above, a different member of this union is
157 void *hwnd
; /**< Win32 window handle */
158 uint32_t xid
; /**< X11 windows ID */
159 void *nsobject
; /**< Mac OSX view object */
160 void *anativewindow
; /**< Android native window */
161 struct wl_surface
*wl
; /**< Wayland surface (client pointer) */
164 /** Display server (mandatory)
166 * This must be filled by the plugin upon activation.
168 * The window handle is relative to the display server. The exact meaning
169 * of the display server depends on the window handle type. Not all window
170 * handle type provide a display server field.
173 char *x11
; /**< X11 display string (NULL = use default) */
174 struct wl_display
*wl
; /**< Wayland display (client pointer) */
178 * Control callback (mandatory)
180 * This callback handles some control request regarding the window.
181 * See \ref vout_window_control.
183 * This field should not be used directly when manipulating a window.
184 * vout_window_Control() should be used instead.
186 int (*control
)(vout_window_t
*, int query
, va_list);
189 bool has_double_click
; /**< Whether double click events are sent,
190 or need to be emulated */
193 /* Private place holder for the vout_window_t module (optional)
195 * A module is free to use it as it wishes.
197 vout_window_sys_t
*sys
;
199 vout_window_owner_t owner
;
203 * Creates a new window.
205 * @param module plugin name (usually "$window")
206 * @note If you are inside a "vout display", you must use
207 / vout_display_NewWindow() and vout_display_DeleteWindow() instead.
208 * This enables recycling windows.
210 VLC_API vout_window_t
* vout_window_New(vlc_object_t
*, const char *module
, const vout_window_cfg_t
*, const vout_window_owner_t
*);
213 * Deletes a window created by vout_window_New().
215 * @note See vout_window_New() about window recycling.
217 VLC_API
void vout_window_Delete(vout_window_t
*);
219 void vout_window_SetInhibition(vout_window_t
*window
, bool enabled
);
221 static inline int vout_window_vaControl(vout_window_t
*window
, int query
,
224 return window
->control(window
, query
, ap
);
228 * Reconfigures a window.
230 * @note The vout_window_* wrappers should be used instead of this function.
232 * @warning The caller must own the window, as vout_window_t is not thread safe.
234 static inline int vout_window_Control(vout_window_t
*window
, int query
, ...)
240 ret
= vout_window_vaControl(window
, query
, ap
);
246 * Configures the window manager state for this window.
248 static inline int vout_window_SetState(vout_window_t
*window
, unsigned state
)
250 return vout_window_Control(window
, VOUT_WINDOW_SET_STATE
, state
);
254 * Configures the window display (i.e. inner/useful) size.
256 static inline int vout_window_SetSize(vout_window_t
*window
,
257 unsigned width
, unsigned height
)
259 return vout_window_Control(window
, VOUT_WINDOW_SET_SIZE
, width
, height
);
263 * Sets fullscreen mode.
265 static inline int vout_window_SetFullScreen(vout_window_t
*window
, bool full
)
267 return vout_window_Control(window
, VOUT_WINDOW_SET_FULLSCREEN
, full
);
271 * Hide the mouse cursor
273 static inline int vout_window_HideMouse(vout_window_t
*window
, bool hide
)
275 return vout_window_Control(window
, VOUT_WINDOW_HIDE_MOUSE
, hide
);
279 * Report current window size
281 * This notifies the user of the window what the pixel dimensions of the
282 * window are (or should be, depending on the windowing system).
284 * \note This function is thread-safe. In case of concurrent call, it is
285 * undefined which one is taken into account (but at least one is).
287 static inline void vout_window_ReportSize(vout_window_t
*window
,
288 unsigned width
, unsigned height
)
290 if (window
->owner
.resized
!= NULL
)
291 window
->owner
.resized(window
, width
, height
);
294 static inline void vout_window_ReportClose(vout_window_t
*window
)
296 if (window
->owner
.closed
!= NULL
)
297 window
->owner
.closed(window
);
300 static inline void vout_window_SendMouseEvent(vout_window_t
*window
,
301 const vout_window_mouse_event_t
*mouse
)
303 if (window
->owner
.mouse_event
!= NULL
)
304 window
->owner
.mouse_event(window
, mouse
);
308 * Send a full mouse state
310 * The mouse position must be expressed against window unit. You can use this
311 * function of others vout_window_ReportMouse*() functions.
313 static inline void vout_window_ReportMouseState(vout_window_t
*window
,
314 int x
, int y
, int button_mask
)
316 const vout_window_mouse_event_t mouse
= {
317 VOUT_WINDOW_MOUSE_STATE
, x
, y
, button_mask
319 vout_window_SendMouseEvent(window
, &mouse
);
323 * Send a mouse movement
325 * The mouse position must be expressed against window unit.
327 static inline void vout_window_ReportMouseMoved(vout_window_t
*window
,
330 const vout_window_mouse_event_t mouse
= {
331 VOUT_WINDOW_MOUSE_MOVED
, x
, y
, 0
333 vout_window_SendMouseEvent(window
, &mouse
);
337 * Send a mouse pressed event
339 static inline void vout_window_ReportMousePressed(vout_window_t
*window
,
342 const vout_window_mouse_event_t mouse
= {
343 VOUT_WINDOW_MOUSE_PRESSED
, 0, 0, button
,
345 vout_window_SendMouseEvent(window
, &mouse
);
349 * Send a mouse released event
351 static inline void vout_window_ReportMouseReleased(vout_window_t
*window
,
354 const vout_window_mouse_event_t mouse
= {
355 VOUT_WINDOW_MOUSE_RELEASED
, 0, 0, button
,
357 vout_window_SendMouseEvent(window
, &mouse
);
361 * Send a mouse double click event
363 static inline void vout_window_ReportMouseDoubleClick(vout_window_t
*window
,
366 const vout_window_mouse_event_t mouse
= {
367 VOUT_WINDOW_MOUSE_DOUBLE_CLICK
, 0, 0, button
,
369 vout_window_SendMouseEvent(window
, &mouse
);
373 #endif /* VLC_VOUT_WINDOW_H */