]> git.sesse.net Git - vlc/blob - src/video_output/window.c
Add vout window support for OS/2
[vlc] / src / video_output / window.c
1 /*****************************************************************************
2  * window.c: "vout window" managment
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
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 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 General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 #include <assert.h>
31
32 #include <vlc_common.h>
33 #include <vlc_vout_window.h>
34 #include <vlc_modules.h>
35 #include "inhibit.h"
36 #include <libvlc.h>
37
38 typedef struct
39 {
40     vout_window_t wnd;
41     module_t *module;
42     vlc_inhibit_t *inhibit;
43 } window_t;
44
45 static int vout_window_start(void *func, va_list ap)
46 {
47     int (*activate)(vout_window_t *, const vout_window_cfg_t *) = func;
48     vout_window_t *wnd = va_arg(ap, vout_window_t *);
49     const vout_window_cfg_t *cfg = va_arg(ap, const vout_window_cfg_t *);
50
51     return activate(wnd, cfg);
52 }
53
54 vout_window_t *vout_window_New(vlc_object_t *obj,
55                                const char *module,
56                                const vout_window_cfg_t *cfg)
57 {
58     window_t *w = vlc_custom_create(obj, sizeof(*w), "window");
59     vout_window_t *window = &w->wnd;
60
61     memset(&window->handle, 0, sizeof(window->handle));
62     window->control = NULL;
63     window->sys = NULL;
64
65     const char *type;
66     switch (cfg->type) {
67 #if defined(WIN32) || defined(__OS2__)
68     case VOUT_WINDOW_TYPE_HWND:
69         type = "vout window hwnd";
70         window->handle.hwnd = NULL;
71         break;
72 #endif
73 #ifdef __APPLE__
74     case VOUT_WINDOW_TYPE_NSOBJECT:
75         type = "vout window nsobject";
76         window->handle.nsobject = NULL;
77         break;
78 #endif
79     case VOUT_WINDOW_TYPE_XID:
80         type = "vout window xid";
81         window->handle.xid = 0;
82         window->display.x11 = NULL;
83         break;
84     default:
85         assert(0);
86     }
87
88     w->module = vlc_module_load(window, type, module, module && *module,
89                                 vout_window_start, window, cfg);
90     if (!w->module) {
91         vlc_object_release(window);
92         return NULL;
93     }
94
95     /* Hook for screensaver inhibition */
96     if (var_InheritBool(obj, "disable-screensaver") &&
97         cfg->type == VOUT_WINDOW_TYPE_XID) {
98         w->inhibit = vlc_inhibit_Create(VLC_OBJECT (window),
99                                         window->handle.xid);
100         if (w->inhibit != NULL)
101             vlc_inhibit_Set(w->inhibit, true);
102             /* FIXME: ^ wait for vout activation, pause */
103     }
104     else
105         w->inhibit = NULL;
106     return window;
107 }
108
109 static void vout_window_stop(void *func, va_list ap)
110 {
111     int (*deactivate)(vout_window_t *) = func;
112     vout_window_t *wnd = va_arg(ap, vout_window_t *);
113
114     deactivate(wnd);
115 }
116
117 void vout_window_Delete(vout_window_t *window)
118 {
119     if (!window)
120         return;
121
122     window_t *w = (window_t *)window;
123     if (w->inhibit)
124     {
125         vlc_inhibit_Set (w->inhibit, false);
126         vlc_inhibit_Destroy (w->inhibit);
127     }
128
129     vlc_module_unload(w->module, vout_window_stop, window);
130     vlc_object_release(window);
131 }
132
133 int vout_window_Control(vout_window_t *window, int query, ...)
134 {
135     va_list args;
136     va_start(args, query);
137     int ret = window->control(window, query, args);
138     va_end(args);
139
140     return ret;
141 }
142