vlc_vout_window.h 8.93 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*****************************************************************************
 * vlc_vout_window.h: vout_window_t definitions
 *****************************************************************************
 * Copyright (C) 2008 Rémi Denis-Courmont
 * Copyright (C) 2009 Laurent Aimar
 * $Id$
 *
 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
10 11 12
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
13 14 15 16
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
17 18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
19
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
20 21 22
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27
 *****************************************************************************/

#ifndef VLC_VOUT_WINDOW_H
#define VLC_VOUT_WINDOW_H 1

28 29 30
#include <stdarg.h>
#include <vlc_common.h>

31
/**
32 33 34 35
 * \defgroup video_window Video window
 * \ingroup video_output
 * Video output window management
 * @{
36
 * \file
37
 * Video output window modules interface
38 39 40 41 42
 */

typedef struct vout_window_t vout_window_t;
typedef struct vout_window_sys_t vout_window_sys_t;

43 44
struct wl_display;
struct wl_surface;
45 46 47 48 49

/**
 * Window handle type
 */
enum {
50
    VOUT_WINDOW_TYPE_INVALID=0,
51
    VOUT_WINDOW_TYPE_XID,
52
    VOUT_WINDOW_TYPE_HWND,
53
    VOUT_WINDOW_TYPE_NSOBJECT,
54
    VOUT_WINDOW_TYPE_ANDROID_NATIVE,
55
    VOUT_WINDOW_TYPE_WAYLAND,
56 57 58 59 60 61
};

/**
 * Control query for vout_window_t
 */
enum {
62
    VOUT_WINDOW_SET_STATE, /* unsigned state */
63 64
    VOUT_WINDOW_SET_SIZE,   /* unsigned i_width, unsigned i_height */
    VOUT_WINDOW_SET_FULLSCREEN, /* int b_fullscreen */
65
    VOUT_WINDOW_HIDE_MOUSE, /* bool b_hide */
66 67
};

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
/**
 * Window mouse event type for vout_window_mouse_event_t
 */
enum vout_window_mouse_event_type {
    VOUT_WINDOW_MOUSE_STATE,
    VOUT_WINDOW_MOUSE_MOVED,
    VOUT_WINDOW_MOUSE_PRESSED,
    VOUT_WINDOW_MOUSE_RELEASED,
    VOUT_WINDOW_MOUSE_DOUBLE_CLICK,
};

/**
 * Window mouse event
 */
typedef struct vout_window_mouse_event_t
{
    enum vout_window_mouse_event_type type;
    int x;
    int y;
    int button_mask;
} vout_window_mouse_event_t;

90
typedef struct vout_window_cfg_t {
91
    /* Window handle type */
92
    unsigned type;
93

94 95 96 97
    /* If true, a standalone window is requested */
    bool is_standalone;
    bool is_fullscreen;

98
#ifdef __APPLE__
99 100 101
    /* Window position hint */
    int x;
    int y;
102
#endif
103

104 105 106
    /* Windows size hint */
    unsigned width;
    unsigned height;
107 108 109

} vout_window_cfg_t;

110 111 112
typedef struct vout_window_owner {
    void *sys;
    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 116
} vout_window_owner_t;

117 118 119 120 121 122 123
/**
 * FIXME do we need an event system in the window too ?
 * or the window user will take care of it ?
 */
struct vout_window_t {
    VLC_COMMON_MEMBERS

124 125
    unsigned type; /**< Window handle type */

126 127 128 129 130
    /* window handle (mandatory)
     *
     * It must be filled in the open function.
     */
    union {
131 132 133 134
        void     *hwnd;          /* Win32 window handle */
        uint32_t xid;            /* X11 windows ID */
        void     *nsobject;      /* Mac OSX view object */
        void     *anativewindow; /* Android native window. */
135
        struct wl_surface *wl;   /* Wayland surface */
136
    } handle;
137

138 139
    /* display server (mandatory) */
    union {
140
        char     *x11; /* X11 display (NULL = use default) */
141
        struct wl_display *wl;   /* Wayland struct wl_display pointer */
142
    } display;
143

144 145
    /* Control on the module (mandatory)
     *
146
     * Do not use it directly; use vout_window_Control instead.
147 148 149 150 151
     */
    int (*control)(vout_window_t *, int query, va_list);

    /* Private place holder for the vout_window_t module (optional)
     *
152
     * A module is free to use it as it wishes.
153 154
     */
    vout_window_sys_t *sys;
155 156

    vout_window_owner_t owner;
157 158
};

159
/**
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
160 161 162
 * Creates a new window.
 *
 * @param module plugin name (usually "$window")
163
 * @note If you are inside a "vout display", you must use
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
164 165
 / vout_display_NewWindow() and vout_display_DeleteWindow() instead.
 * This enables recycling windows.
166
 */
167
VLC_API vout_window_t * vout_window_New(vlc_object_t *, const char *module, const vout_window_cfg_t *, const vout_window_owner_t *);
168 169

/**
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
170
 * Deletes a window created by vout_window_New().
171
 *
172
 * @note See vout_window_New() about window recycling.
173
 */
174
VLC_API void vout_window_Delete(vout_window_t *);
175

176 177 178 179 180
static inline int vout_window_vaControl(vout_window_t *window, int query,
                                        va_list ap)
{
    return window->control(window, query, ap);
}
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
181

182
/**
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
183 184 185
 * Reconfigures a window.
 *
 * @note The vout_window_* wrappers should be used instead of this function.
186
 *
187
 * @warning The caller must own the window, as vout_window_t is not thread safe.
188
 */
189 190 191 192 193 194 195 196 197 198
static inline int vout_window_Control(vout_window_t *window, int query, ...)
{
    va_list ap;
    int ret;

    va_start(ap, query);
    ret = vout_window_vaControl(window, query, ap);
    va_end(ap);
    return ret;
}
199 200

/**
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
201
 * Configures the window manager state for this window.
202
 */
203
static inline int vout_window_SetState(vout_window_t *window, unsigned state)
204
{
205
    return vout_window_Control(window, VOUT_WINDOW_SET_STATE, state);
206 207 208
}

/**
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
209
 * Configures the window display (i.e. inner/useful) size.
210
 */
211 212
static inline int vout_window_SetSize(vout_window_t *window,
                                      unsigned width, unsigned height)
213 214 215 216
{
    return vout_window_Control(window, VOUT_WINDOW_SET_SIZE, width, height);
}

217
/**
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
218
 * Sets fullscreen mode.
219 220 221 222 223 224
 */
static inline int vout_window_SetFullScreen(vout_window_t *window, bool full)
{
    return vout_window_Control(window, VOUT_WINDOW_SET_FULLSCREEN, full);
}

225 226 227 228 229 230 231 232
/**
 * Hide the mouse cursor
 */
static inline int vout_window_HideMouse(vout_window_t *window, bool hide)
{
    return vout_window_Control(window, VOUT_WINDOW_HIDE_MOUSE, hide);
}

233 234 235 236 237 238 239 240 241
/**
 * Report current window size
 *
 * This notifies the user of the window what the pixel dimensions of the
 * window are (or should be, depending on the windowing system).
 *
 * \note This function is thread-safe. In case of concurrent call, it is
 * undefined which one is taken into account (but at least one is).
 */
242 243 244 245 246 247 248
static inline void vout_window_ReportSize(vout_window_t *window,
                                          unsigned width, unsigned height)
{
    if (window->owner.resized != NULL)
        window->owner.resized(window, width, height);
}

249 250 251 252 253 254
static inline void vout_window_ReportClose(vout_window_t *window)
{
    if (window->owner.closed != NULL)
        window->owner.closed(window);
}

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
static inline void vout_window_SendMouseEvent(vout_window_t *window,
                                              const vout_window_mouse_event_t *mouse)
{
    if (window->owner.mouse_event != NULL)
        window->owner.mouse_event(window, mouse);
}

/**
 * Send a full mouse state
 *
 * The mouse position must be expressed against window unit. You can use this
 * function of others vout_window_ReportMouse*() functions.
 */
static inline void vout_window_ReportMouseState(vout_window_t *window,
                                                int x, int y, int button_mask)
{
    const vout_window_mouse_event_t mouse = {
        VOUT_WINDOW_MOUSE_STATE, x, y, button_mask
    };
    vout_window_SendMouseEvent(window, &mouse);
}

/**
 * Send a mouse movement
 *
 * The mouse position must be expressed against window unit.
 */
static inline void vout_window_ReportMouseMoved(vout_window_t *window,
                                                int x, int y)
{
    const vout_window_mouse_event_t mouse = {
        VOUT_WINDOW_MOUSE_MOVED, x, y, 0
    };
    vout_window_SendMouseEvent(window, &mouse);
}

/**
 * Send a mouse pressed event
 */
static inline void vout_window_ReportMousePressed(vout_window_t *window,
                                                  int button)
{
    const vout_window_mouse_event_t mouse = {
        VOUT_WINDOW_MOUSE_PRESSED, 0, 0, button,
    };
    vout_window_SendMouseEvent(window, &mouse);
}

/**
 * Send a mouse released event
 */
static inline void vout_window_ReportMouseReleased(vout_window_t *window,
                                                  int button)
{
    const vout_window_mouse_event_t mouse = {
        VOUT_WINDOW_MOUSE_RELEASED, 0, 0, button,
    };
    vout_window_SendMouseEvent(window, &mouse);
}

/**
 * Send a mouse double click event
 */
static inline void vout_window_ReportMouseDoubleClick(vout_window_t *window)
{
    const vout_window_mouse_event_t mouse = {
        VOUT_WINDOW_MOUSE_DOUBLE_CLICK, 0, 0, 0,
    };
    vout_window_SendMouseEvent(window, &mouse);
}

326
/** @} */
327
#endif /* VLC_VOUT_WINDOW_H */