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
;
48 enum vout_window_type
{
49 VOUT_WINDOW_TYPE_DUMMY
/**< Dummy window (not an actual window) */,
50 VOUT_WINDOW_TYPE_XID
/**< X11 window */,
51 VOUT_WINDOW_TYPE_HWND
/**< Win32 or OS/2 window */,
52 VOUT_WINDOW_TYPE_NSOBJECT
/**< MacOS X view */,
53 VOUT_WINDOW_TYPE_ANDROID_NATIVE
/**< Android native window */,
54 VOUT_WINDOW_TYPE_WAYLAND
/**< Wayland surface */,
58 * Window management state.
60 enum vout_window_state
{
61 VOUT_WINDOW_STATE_NORMAL
,
62 VOUT_WINDOW_STATE_ABOVE
,
63 VOUT_WINDOW_STATE_BELOW
,
67 * Window mouse event type for vout_window_mouse_event_t
69 enum vout_window_mouse_event_type
{
70 VOUT_WINDOW_MOUSE_MOVED
,
71 VOUT_WINDOW_MOUSE_PRESSED
,
72 VOUT_WINDOW_MOUSE_RELEASED
,
73 VOUT_WINDOW_MOUSE_DOUBLE_CLICK
,
79 typedef struct vout_window_mouse_event_t
81 enum vout_window_mouse_event_type type
;
85 } vout_window_mouse_event_t
;
88 * Window (desired) configuration.
90 * This structure describes the intended initial configuration
91 * of a \ref vout_window_t.
93 typedef struct vout_window_cfg_t
{
95 * Whether the window should be in full screen mode or not.
100 * Whether the window should have decorations or not.
105 /* Window position hint */
111 * Intended pixel width of the window.
116 * Intended pixel height of the window.
122 struct vout_window_callbacks
{
123 void (*resized
)(vout_window_t
*, unsigned width
, unsigned height
);
124 void (*closed
)(vout_window_t
*);
125 void (*state_changed
)(vout_window_t
*, unsigned state
);
126 void (*windowed
)(vout_window_t
*);
127 void (*fullscreened
)(vout_window_t
*, const char *id
);
129 void (*mouse_event
)(vout_window_t
*,
130 const vout_window_mouse_event_t
*mouse
);
131 void (*keyboard_event
)(vout_window_t
*, unsigned key
);
133 void (*output_event
)(vout_window_t
*, const char *id
, const char *desc
);
136 struct vout_window_operations
{
137 int (*enable
)(vout_window_t
*, const vout_window_cfg_t
*);
138 void (*disable
)(vout_window_t
*);
139 void (*resize
)(vout_window_t
*, unsigned width
, unsigned height
);
142 * Destroy the window.
144 * Destroys the window and releases all associated resources.
146 void (*destroy
)(vout_window_t
*);
148 void (*set_state
)(vout_window_t
*, unsigned state
);
149 void (*unset_fullscreen
)(vout_window_t
*);
150 void (*set_fullscreen
)(vout_window_t
*, const char *id
);
153 typedef struct vout_window_owner
{
154 const struct vout_window_callbacks
*cbs
;
156 } vout_window_owner_t
;
161 * This structure is an abstract interface to the windowing system.
162 * The window is normally used to draw video (and subpictures) into, but it
163 * can also be used for other purpose (e.g. OpenGL visualization).
165 * The window is responsible for providing a window handle, whose exact
166 * meaning depends on the windowing system. It also must report some events
167 * such as user input (keyboard, mouse) and window resize.
169 * Finally, it must support some control requests such as for fullscreen mode.
171 struct vout_window_t
{
172 struct vlc_common_members obj
;
177 * This identified the windowing system and protocol that the window
178 * needs to use. This also selects which member of the \ref handle union
179 * and the \ref display union are to be set.
181 * The possible values are defined in \ref vout_window_type.
186 * Window handle (mandatory)
188 * This must be filled by the plugin upon activation.
190 * Depending on the \ref type above, a different member of this union is
194 void *hwnd
; /**< Win32 window handle */
195 uint32_t xid
; /**< X11 windows ID */
196 void *nsobject
; /**< Mac OSX view object */
197 void *anativewindow
; /**< Android native window */
198 struct wl_surface
*wl
; /**< Wayland surface (client pointer) */
201 /** Display server (mandatory)
203 * This must be filled by the plugin upon activation.
205 * The window handle is relative to the display server. The exact meaning
206 * of the display server depends on the window handle type. Not all window
207 * handle type provide a display server field.
210 char *x11
; /**< X11 display string (NULL = use default) */
211 struct wl_display
*wl
; /**< Wayland display (client pointer) */
214 const struct vout_window_operations
*ops
;
217 bool has_double_click
; /**< Whether double click events are sent,
218 or need to be emulated */
221 /* Private place holder for the vout_window_t module (optional)
223 * A module is free to use it as it wishes.
227 vout_window_owner_t owner
;
231 * Creates a new window.
233 * @param module plugin name (usually "$window")
234 * @note don't use it inside a "vout display" module
236 VLC_API vout_window_t
* vout_window_New(vlc_object_t
*, const char *module
, const vout_window_owner_t
*);
239 * Deletes a window created by vout_window_New().
241 * @note See vout_window_New() about window recycling.
243 VLC_API
void vout_window_Delete(vout_window_t
*);
245 void vout_window_SetInhibition(vout_window_t
*window
, bool enabled
);
248 * Configures the window manager state for this window.
250 static inline void vout_window_SetState(vout_window_t
*window
, unsigned state
)
252 if (window
->ops
->set_state
!= NULL
)
253 window
->ops
->set_state(window
, state
);
257 * Requests a new window size.
259 * This requests a change of the window size.
261 * \warning The windowing system may or may not actually resize the window
262 * to the requested size. Track the resized event to determine the actual size.
264 * \note The size is expressed in terms of the "useful" area,
265 * i.e. it excludes any side decoration added by the windowing system.
267 * \param width pixel width
268 * \param height height width
270 static inline void vout_window_SetSize(vout_window_t
*window
,
271 unsigned width
, unsigned height
)
273 if (window
->ops
->resize
!= NULL
)
274 window
->ops
->resize(window
, width
, height
);
278 * Requests fullscreen mode.
280 * \param id nul-terminated output identifier, NULL for default
282 static inline void vout_window_SetFullScreen(vout_window_t
*window
,
285 if (window
->ops
->set_fullscreen
!= NULL
)
286 window
->ops
->set_fullscreen(window
, id
);
290 * Requests windowed mode.
292 static inline void vout_window_UnsetFullScreen(vout_window_t
*window
)
294 if (window
->ops
->unset_fullscreen
!= NULL
)
295 window
->ops
->unset_fullscreen(window
);
301 * This informs the window provider that the window is about to be taken into
302 * active use. A window is always initially disabled. This is so that the
303 * window provider can provide a persistent connection to the display server,
304 * and track any useful events, such as monitors hotplug.
306 * The window handle (vout_window_t.handle) and display (vout_window_t.display)
307 * must remain valid and constant while the window is enabled.
309 int vout_window_Enable(vout_window_t
*window
, const vout_window_cfg_t
*cfg
);
314 * This informs the window provider that the window is no longer needed.
316 * Note that the window may be re-enabled later by a call to
317 * vout_window_Enable().
319 void vout_window_Disable(vout_window_t
*window
);
322 * Report current window size
324 * This notifies the user of the window what the pixel dimensions of the
325 * window are (or should be, depending on the windowing system).
327 * \note This function is thread-safe. In case of concurrent call, it is
328 * undefined which one is taken into account (but at least one is).
330 static inline void vout_window_ReportSize(vout_window_t
*window
,
331 unsigned width
, unsigned height
)
333 window
->owner
.cbs
->resized(window
, width
, height
);
336 static inline void vout_window_ReportClose(vout_window_t
*window
)
338 if (window
->owner
.cbs
->closed
!= NULL
)
339 window
->owner
.cbs
->closed(window
);
343 * Reports the current window state.
345 * This notifies the owner of the window that the state of the window changed.
346 * \param state \see vout_window_state
348 static inline void vout_window_ReportState(vout_window_t
*window
,
351 if (window
->owner
.cbs
->state_changed
!= NULL
)
352 window
->owner
.cbs
->state_changed(window
, state
);
356 * Reports that the window is not in full screen.
358 * This notifies the owner of the window that the window is windowed, i.e. not
359 * in full screen mode.
361 static inline void vout_window_ReportWindowed(vout_window_t
*window
)
363 if (window
->owner
.cbs
->windowed
!= NULL
)
364 window
->owner
.cbs
->windowed(window
);
368 * Reports that the window is in full screen.
370 * \param id fullscreen output nul-terminated identifier, NULL for default
372 static inline void vout_window_ReportFullscreen(vout_window_t
*window
,
375 if (window
->owner
.cbs
->fullscreened
!= NULL
)
376 window
->owner
.cbs
->fullscreened(window
, id
);
379 static inline void vout_window_SendMouseEvent(vout_window_t
*window
,
380 const vout_window_mouse_event_t
*mouse
)
382 if (window
->owner
.cbs
->mouse_event
!= NULL
)
383 window
->owner
.cbs
->mouse_event(window
, mouse
);
387 * Send a mouse movement
389 * The mouse position must be expressed against window unit.
391 static inline void vout_window_ReportMouseMoved(vout_window_t
*window
,
394 const vout_window_mouse_event_t mouse
= {
395 VOUT_WINDOW_MOUSE_MOVED
, x
, y
, 0
397 vout_window_SendMouseEvent(window
, &mouse
);
401 * Send a mouse pressed event
403 static inline void vout_window_ReportMousePressed(vout_window_t
*window
,
406 const vout_window_mouse_event_t mouse
= {
407 VOUT_WINDOW_MOUSE_PRESSED
, 0, 0, button
,
409 vout_window_SendMouseEvent(window
, &mouse
);
413 * Send a mouse released event
415 static inline void vout_window_ReportMouseReleased(vout_window_t
*window
,
418 const vout_window_mouse_event_t mouse
= {
419 VOUT_WINDOW_MOUSE_RELEASED
, 0, 0, button
,
421 vout_window_SendMouseEvent(window
, &mouse
);
425 * Send a mouse double click event
427 static inline void vout_window_ReportMouseDoubleClick(vout_window_t
*window
,
430 const vout_window_mouse_event_t mouse
= {
431 VOUT_WINDOW_MOUSE_DOUBLE_CLICK
, 0, 0, button
,
433 vout_window_SendMouseEvent(window
, &mouse
);
436 static inline void vout_window_ReportKeyPress(vout_window_t
*window
, int key
)
438 if (window
->owner
.cbs
->keyboard_event
!= NULL
)
439 window
->owner
.cbs
->keyboard_event(window
, key
);
443 * Adds/removes a fullscreen output.
445 * This notifies the owner of the window that a usable fullscreen output has
446 * been added, changed or removed.
448 * If an output with the same identifier is already known, its name will be
449 * updated. Otherwise it will be added.
450 * If the name parameter is NULL, the output will be removed.
452 * \param id unique nul-terminated identifier for the output
453 * \param name human-readable name
455 static inline void vout_window_ReportOutputDevice(vout_window_t
*window
,
459 if (window
->owner
.cbs
->output_event
!= NULL
)
460 window
->owner
.cbs
->output_event(window
, id
, name
);
464 #endif /* VLC_VOUT_WINDOW_H */