qml: don't base MusicArtist to MusicAlbums, create it separately
[vlc.git] / include / vlc_vout_window.h
blobea16d4b414acf73b06b77967b8e03e4e5a4bd8a0
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
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
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.
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.
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 *****************************************************************************/
24 #ifndef VLC_VOUT_WINDOW_H
25 #define VLC_VOUT_WINDOW_H 1
27 #include <stdarg.h>
28 #include <vlc_common.h>
30 /**
31 * \defgroup video_window Video window
32 * \ingroup video_output
33 * Window management
35 * Window management provides a partial abstraction for windowing systems and
36 * rendering targets (i.e. "windows"). See \ref vout_window_t.
38 * @{
39 * \file
40 * Window modules interface
43 struct vout_window_t;
44 struct wl_display;
45 struct wl_surface;
47 /**
48 * Window handle type.
50 * The window handle type specifies the window system protocol that the
51 * window was created with. It determines which members of the
52 * vout_window_t::handle and vout_window_t::display unions are defined
53 * for the given window.
55 * It also establishes some protocol-dependent semantics such as the exact
56 * interpretation of the window state (\ref vout_window_state)
57 * and the window size.
59 enum vout_window_type {
60 VOUT_WINDOW_TYPE_DUMMY /**< Dummy window (not an actual window) */,
61 VOUT_WINDOW_TYPE_XID /**< X11 window */,
62 VOUT_WINDOW_TYPE_HWND /**< Win32 or OS/2 window */,
63 VOUT_WINDOW_TYPE_NSOBJECT /**< macOS/iOS view */,
64 VOUT_WINDOW_TYPE_ANDROID_NATIVE /**< Android native window */,
65 VOUT_WINDOW_TYPE_WAYLAND /**< Wayland surface */,
66 VOUT_WINDOW_TYPE_DCOMP /**< Win32 DirectComposition */,
69 /**
70 * Window states.
72 * Currently, this only handles different window stacking orders.
73 * See also \ref vout_window_SetState().
75 enum vout_window_state {
76 VOUT_WINDOW_STATE_NORMAL /**< Normal stacking */,
77 VOUT_WINDOW_STATE_ABOVE /**< Stacking above (a.k.a. always on top) */,
78 VOUT_WINDOW_STATE_BELOW /**< Stacking below (a.k.a. wall paper mode) */,
81 /**
82 * Window mouse event types.
84 * This enumeration defines the possible event types
85 * vout_window_mouse_event_t::type.
87 enum vout_window_mouse_event_type {
88 VOUT_WINDOW_MOUSE_MOVED /**< Pointer position change */,
89 VOUT_WINDOW_MOUSE_PRESSED /**< Pointer button press or single click */,
90 VOUT_WINDOW_MOUSE_RELEASED /**< Pointer button release */,
91 VOUT_WINDOW_MOUSE_DOUBLE_CLICK /**< Double click */,
94 /**
95 * Window mouse event.
97 * This structure describes a pointer input event on a window.
99 typedef struct vout_window_mouse_event_t
101 enum vout_window_mouse_event_type type; /**< Event type. */
104 * Pointer abscissa.
106 * The pointer abscissa is relative to the window and expressed in pixels.
107 * Abscissa goes from left to right, such that the left-most column is at 0
108 * and the right-most column is at width minus one.
110 * A negative abscissa refers to pixels to the left of the window, and
111 * an abscissa of width or larger refers to pixels to the right.
113 * This is only set if @c event equals \ref VOUT_WINDOW_MOUSE_MOVED.
115 int x;
118 * Pointer ordinate.
120 * The pointer ordinate is relative to the window and expressed in pixels.
121 * Ordinate goes from top to bottom, such that the top-most row is at 0
122 * and the bottom-most column is at height minus one.
124 * A negative ordinate refers to pixels above the window, and
125 * an ordinate of height or larger refers to pixels below the window.
127 * This is only set if @c event equals \ref VOUT_WINDOW_MOUSE_MOVED.
129 int y;
132 * Pressed button.
134 * See \ref vlc_mouse_button for possible vaules.
136 * This is set if @c event does not equal \ref VOUT_WINDOW_MOUSE_MOVED.
138 int button_mask;
139 } vout_window_mouse_event_t;
142 * Window (desired) configuration.
144 * This structure describes the intended initial configuration
145 * of a \ref vout_window_t.
147 typedef struct vout_window_cfg_t {
149 * Whether the window should be in full screen mode or not.
151 bool is_fullscreen;
154 * Whether the window should have decorations or not.
156 bool is_decorated;
158 #if defined(__APPLE__) || defined(_WIN32)
159 /* Window position hint */
160 int x;
161 int y;
162 #endif
165 * Intended pixel width of the window.
167 unsigned width;
170 * Intended pixel height of the window.
172 unsigned height;
174 } vout_window_cfg_t;
177 * Window event callbacks structure.
179 * This structure provided to vout_window_New() conveys callbacks to handle
180 * window events.
182 * As a general rule, the events can occur synchronously or asynchronously from
183 * the time that the window is (succesfully) being created by vout_window_New()
184 * until the time that the window has been deleted by vout_window_Delete().
186 * \warning
187 * Also, a window object functions are not reentrant, so the callbacks must not
188 * invoke the window object functions.
189 * Otherwise a deadlock or infinite recursion may occur.
191 struct vout_window_callbacks {
193 * Callback for window size changes.
195 * This callback function is invoked when the windowing
196 * system changes the window size.
198 * This event may occur synchronously when the window is created or a size
199 * change is requested. It may also occur asynchronously as a consequence
200 * of external events from the windowing system, or deferred processing of
201 * a size change request.
203 void (*resized)(struct vout_window_t *, unsigned width, unsigned height);
206 * Callback for window closing.
208 * This callback function (if non-NULL) is invoked upon an external request
209 * to close the window. Not all windowing systems support this.
211 * Soon after this callback, the window should be disabled with
212 * vout_window_Disable().
214 * \warning Do not disable the window within the callback.
215 * That could lead to a dead lock.
217 void (*closed)(struct vout_window_t *);
220 * Callback for window state change.
222 * This callback function (if non-NULL) is invoked when the window state
223 * as changed, either as a consequence of vout_window_SetSate() or external
224 * events.
226 * \bug Many window back-ends fail to invoke this callback when due.
228 * \param state new window state (see \ref vout_window_state).
230 void (*state_changed)(struct vout_window_t *, unsigned state);
233 * Callback for windowed mode.
235 * This callback function (if non-NULL) is invoked when the window becomes
236 * windowed. It might also occur spuriously if the window remains windowed.
238 * \bug Many window back-ends fail to invoke this callback when due.
240 void (*windowed)(struct vout_window_t *);
243 * Callback for fullscreen mode.
245 * This callback function (if non-NULL) is invoked when the window becomes
246 * fullscreen, when it changes to a different fullscreen output, or
247 * spuriously when the window remains in fullscreen mode.
249 * \bug Many window back-ends fail to invoke this callback when due.
251 * \param id fullscreen output identifier (NULL if unspecified)
253 void (*fullscreened)(struct vout_window_t *, const char *id);
256 * Callback for pointer input events.
258 * This callback function (if non-NULL) is invoked upon any pointer input
259 * event on the window. See \ref vout_window_mouse_event_t.
261 * \param mouse pointer to the input event.
263 void (*mouse_event)(struct vout_window_t *,
264 const vout_window_mouse_event_t *mouse);
267 * Callback for keyboard input events.
269 * This callback function (if non-NULL) is invoked upon any keyboard key
270 * press event, or repetition event, on the window.
272 * \note No events are delivered for keyboard key releases.
274 * \param key VLC key code
276 void (*keyboard_event)(struct vout_window_t *, unsigned key);
279 * Callback for fullscreen output enumeration.
281 * This callback function (if non-NULL) indicates that a fullscreen output
282 * becomes available, changes human-readable description, or becomes
283 * unavailable.
285 * \param id nul-terminated id fullscreen output identifier
286 * (cannot be NULL)
287 * \param desc nul-terminated human-readable description,
288 * or NULL if the output has become unavailable
290 void (*output_event)(struct vout_window_t *,
291 const char *id, const char *desc);
295 * Window callbacks and opaque data.
297 typedef struct vout_window_owner {
298 const struct vout_window_callbacks *cbs; /**< Callbacks */
299 void *sys; /**< Opaque data / private pointer for callbacks */
300 } vout_window_owner_t;
303 * Window implementation callbacks.
305 struct vout_window_operations {
306 int (*enable)(struct vout_window_t *, const vout_window_cfg_t *);
307 void (*disable)(struct vout_window_t *);
308 void (*resize)(struct vout_window_t *, unsigned width, unsigned height);
311 * Destroy the window.
313 * Destroys the window and releases all associated resources.
315 void (*destroy)(struct vout_window_t *);
317 void (*set_state)(struct vout_window_t *, unsigned state);
318 void (*unset_fullscreen)(struct vout_window_t *);
319 void (*set_fullscreen)(struct vout_window_t *, const char *id);
320 void (*set_title)(struct vout_window_t *, const char *id);
324 * Window object.
326 * This structure is an abstract interface to the windowing system.
327 * The window is normally used to draw video (and subpictures) into, but it
328 * can also be used for other purpose (e.g. OpenGL visualization).
330 * The window is responsible for providing a window handle, whose exact
331 * meaning depends on the windowing system. It also must report some events
332 * such as user input (keyboard, mouse) and window resize.
334 * Finally, it must support some control requests such as for fullscreen mode.
336 typedef struct vout_window_t {
337 struct vlc_object_t obj;
340 * Window handle type
342 * This identified the windowing system and protocol that the window
343 * needs to use. This also selects which member of the \ref handle union
344 * and the \ref display union are to be set.
346 * The possible values are defined in \ref vout_window_type.
348 unsigned type;
351 * Window handle (mandatory)
353 * This must be filled by the plugin upon succesful vout_window_Enable().
355 * Depending on the \ref type above, a different member of this union is
356 * used.
358 union {
359 void *hwnd; /**< Win32 window handle */
360 uint32_t xid; /**< X11 windows ID */
361 void *nsobject; /**< macOS/iOS view object */
362 void *anativewindow; /**< Android native window */
363 struct wl_surface *wl; /**< Wayland surface (client pointer) */
364 void *dcomp_visual; /**< Win32 direct composition visual */
365 } handle;
367 /** Display server (mandatory)
369 * This must be filled by the plugin upon activation.
371 * The window handle is relative to the display server. The exact meaning
372 * of the display server depends on the window handle type. Not all window
373 * handle type provide a display server field.
375 union {
376 char *x11; /**< X11 display string (NULL = use default) */
377 struct wl_display *wl; /**< Wayland display (client pointer) */
378 void* dcomp_device; /**< DirectComposition device */
379 } display;
381 const struct vout_window_operations *ops; /**< operations handled by the
382 window. Once this is set it MUST NOT be changed */
384 struct {
385 bool has_double_click; /**< Whether double click events are sent,
386 or need to be emulated */
387 } info;
389 /* Private place holder for the vout_window_t module (optional)
391 * A module is free to use it as it wishes.
393 void *sys;
395 vout_window_owner_t owner;
396 } vout_window_t;
399 * Creates a new window.
401 * This function creates a window, or some other kind of rectangle render
402 * target.
404 * \param obj parent VLC object
405 * \param module plugin name, NULL for default
406 * \param owner callbacks and private data
407 * \return a new window, or NULL on error.
409 VLC_API vout_window_t *vout_window_New(vlc_object_t *obj,
410 const char *module,
411 const vout_window_owner_t *owner);
414 * Deletes a window.
416 * This deletes a window created by vout_window_New().
418 * \param window window object to delete
420 VLC_API void vout_window_Delete(vout_window_t *window);
423 * Inhibits or deinhibits the screensaver.
425 * \param window window in respect to which the screensaver should be inhibited
426 * or deinhibited
427 * \param true to inhibit, false to deinhibit
429 void vout_window_SetInhibition(vout_window_t *window, bool enabled);
432 * Requests a new window state.
434 * This requests a change of the state of a window from the windowing system.
435 * See \ref vout_window_state for possible states.
437 * @param window window whose state to change
438 * @param state requested state
440 static inline void vout_window_SetState(vout_window_t *window, unsigned state)
442 if (window->ops->set_state != NULL)
443 window->ops->set_state(window, state);
447 * Requests a new window size.
449 * This requests a change of the window size. In general and unless otherwise
450 * stated, the size is expressed in pixels. However, the exact interpretation
451 * of the window size depends on the windowing system.
453 * There is no return value as the request may be processed asynchronously,
454 * ignored and/or modified by the window system. The actual size of the window
455 * is determined by the vout_window_callbacks::resized callback function that
456 * was supplied to vout_window_New().
458 * \note The size is expressed in terms of the "useful" area,
459 * i.e. it excludes any side decoration added by the windowing system.
461 * \param window window whom a size change is requested for
462 * \param width pixel width
463 * \param height height width
465 static inline void vout_window_SetSize(vout_window_t *window,
466 unsigned width, unsigned height)
468 if (window->ops->resize != NULL)
469 window->ops->resize(window, width, height);
473 * Requests fullscreen mode.
475 * \param window window to be brought to fullscreen mode.
476 * \param id nul-terminated output identifier, NULL for default
478 static inline void vout_window_SetFullScreen(vout_window_t *window,
479 const char *id)
481 if (window->ops->set_fullscreen != NULL)
482 window->ops->set_fullscreen(window, id);
486 * Requests windowed mode.
488 * \param window window to be brought into windowed mode.
490 static inline void vout_window_UnsetFullScreen(vout_window_t *window)
492 if (window->ops->unset_fullscreen != NULL)
493 window->ops->unset_fullscreen(window);
497 * Request a new window title.
499 * \param window window to change the title.
500 * \param title window title to use.
502 static inline void vout_window_SetTitle(vout_window_t *window, const char *title)
504 if (window->ops->set_title != NULL)
505 window->ops->set_title(window, title);
509 * Enables a window.
511 * This informs the window provider that the window is about to be taken into
512 * active use. A window is always initially disabled. This is so that the
513 * window provider can provide a persistent connection to the display server,
514 * and track any useful events, such as monitors hotplug.
516 * The window handle (vout_window_t.handle) must remain valid and constant
517 * while the window is enabled.
519 VLC_API
520 int vout_window_Enable(vout_window_t *window, const vout_window_cfg_t *cfg);
523 * Disables a window.
525 * This informs the window provider that the window is no longer needed.
527 * \note
528 * The window may be re-enabled later by a call to vout_window_Enable().
530 VLC_API
531 void vout_window_Disable(vout_window_t *window);
534 * Reports the current window size.
536 * This function is called by the window implementation and notifies the owner
537 * of the window what the pixel dimensions of the window are (or should be,
538 * depending on the windowing system).
540 * \note This function is thread-safe. In case of concurrent call, it is
541 * undefined which one is taken into account (but at least one is).
543 static inline void vout_window_ReportSize(vout_window_t *window,
544 unsigned width, unsigned height)
546 window->owner.cbs->resized(window, width, height);
550 * Reports a request to close the window.
552 * This function is called by the window implementation to advise that the
553 * window is being closed externally, and should be disabled by the owner.
555 static inline void vout_window_ReportClose(vout_window_t *window)
557 if (window->owner.cbs->closed != NULL)
558 window->owner.cbs->closed(window);
562 * Reports the current window state.
564 * This function is called by the window implementation to notify the owner of
565 * the window that the state of the window changed.
567 * \param state \see vout_window_state
569 static inline void vout_window_ReportState(vout_window_t *window,
570 unsigned state)
572 if (window->owner.cbs->state_changed != NULL)
573 window->owner.cbs->state_changed(window, state);
577 * Reports that the window is not in full screen.
579 * This notifies the owner of the window that the window is windowed, i.e. not
580 * in full screen mode.
582 VLC_API void vout_window_ReportWindowed(vout_window_t *wnd);
585 * Reports that the window is in full screen.
587 * \param id fullscreen output nul-terminated identifier, NULL for default
589 VLC_API void vout_window_ReportFullscreen(vout_window_t *wnd, const char *id);
591 static inline void vout_window_SendMouseEvent(vout_window_t *window,
592 const vout_window_mouse_event_t *mouse)
594 if (window->owner.cbs->mouse_event != NULL)
595 window->owner.cbs->mouse_event(window, mouse);
599 * Reports a pointer movement.
601 * The mouse position must be expressed in window pixel units.
602 * See also \ref vout_window_mouse_event_t.
604 * \param window window in focus
605 * \param x abscissa
606 * \param y ordinate
608 static inline void vout_window_ReportMouseMoved(vout_window_t *window,
609 int x, int y)
611 const vout_window_mouse_event_t mouse = {
612 VOUT_WINDOW_MOUSE_MOVED, x, y, 0
614 vout_window_SendMouseEvent(window, &mouse);
618 * Reports a mouse button press.
620 * \param window window in focus
621 * \param button pressed button (see \ref vlc_mouse_button)
623 static inline void vout_window_ReportMousePressed(vout_window_t *window,
624 int button)
626 const vout_window_mouse_event_t mouse = {
627 VOUT_WINDOW_MOUSE_PRESSED, 0, 0, button,
629 vout_window_SendMouseEvent(window, &mouse);
633 * Reports a mouse button release.
635 * \param window window in focus
636 * \param button released button (see \ref vlc_mouse_button)
638 static inline void vout_window_ReportMouseReleased(vout_window_t *window,
639 int button)
641 const vout_window_mouse_event_t mouse = {
642 VOUT_WINDOW_MOUSE_RELEASED, 0, 0, button,
644 vout_window_SendMouseEvent(window, &mouse);
648 * Reports a mouse double-click.
650 * \param window window in focus
651 * \param button double-clicked button (see \ref vlc_mouse_button)
653 static inline void vout_window_ReportMouseDoubleClick(vout_window_t *window,
654 int button)
656 const vout_window_mouse_event_t mouse = {
657 VOUT_WINDOW_MOUSE_DOUBLE_CLICK, 0, 0, button,
659 vout_window_SendMouseEvent(window, &mouse);
663 * Reports a keyboard key press.
665 * \param window window in focus
666 * \param key VLC key code
668 static inline void vout_window_ReportKeyPress(vout_window_t *window, int key)
670 if (window->owner.cbs->keyboard_event != NULL)
671 window->owner.cbs->keyboard_event(window, key);
675 * Adds/removes a fullscreen output.
677 * This notifies the owner of the window that a usable fullscreen output has
678 * been added, changed or removed.
680 * If an output with the same identifier is already known, its name will be
681 * updated. Otherwise it will be added.
682 * If the name parameter is NULL, the output will be removed.
684 * \param id unique nul-terminated identifier for the output
685 * \param name human-readable name
687 static inline void vout_window_ReportOutputDevice(vout_window_t *window,
688 const char *id,
689 const char *name)
691 if (window->owner.cbs->output_event != NULL)
692 window->owner.cbs->output_event(window, id, name);
695 /** @} */
696 #endif /* VLC_VOUT_WINDOW_H */