]> git.sesse.net Git - vlc/blob - src/video_output/window.c
d79a4e21eb412869169dfed7e437b9d9e6671e04
[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 "inhibit.h"
35 #include <libvlc.h>
36
37 typedef struct
38 {
39     vout_window_t wnd;
40     module_t *module;
41     vlc_inhibit_t *inhibit;
42 } window_t;
43
44 vout_window_t *vout_window_New(vlc_object_t *obj,
45                                const char *module,
46                                const vout_window_cfg_t *cfg)
47 {
48     static char const name[] = "window";
49     window_t *w = vlc_custom_create(obj, sizeof(*w), VLC_OBJECT_GENERIC, name);
50     vout_window_t *window = &w->wnd;
51
52     window->cfg = cfg;
53     memset(&window->handle, 0, sizeof(window->handle));
54     window->control = NULL;
55     window->sys = NULL;
56
57     vlc_object_attach(window, obj);
58
59     const char *type;
60     switch (cfg->type) {
61 #ifdef WIN32
62     case VOUT_WINDOW_TYPE_HWND:
63         type = "vout window hwnd";
64         window->handle.hwnd = NULL;
65         break;
66 #endif
67 #ifdef __APPLE__
68     case VOUT_WINDOW_TYPE_NSOBJECT:
69         type = "vout window nsobject";
70         window->handle.nsobject = NULL;
71         break;
72 #endif
73     case VOUT_WINDOW_TYPE_XID:
74         type = "vout window xid";
75         window->handle.xid = 0;
76         window->display.x11 = NULL;
77         break;
78     default:
79         assert(0);
80     }
81
82     w->module = module_need(window, type, module, module && *module != '\0');
83     if (!w->module) {
84         vlc_object_release(window);
85         return NULL;
86     }
87
88     /* Hook for screensaver inhibition */
89     if ( var_InheritBool( obj, "disable-screensaver" ) && cfg->type == VOUT_WINDOW_TYPE_XID) {
90         w->inhibit = vlc_inhibit_Create (VLC_OBJECT (window),
91                                          window->handle.xid);
92         if (w->inhibit != NULL)
93             vlc_inhibit_Set (w->inhibit, true);
94             /* FIXME: ^ wait for vout activation, pause */
95     }
96     else
97         w->inhibit = NULL;
98     return window;
99 }
100
101 void vout_window_Delete(vout_window_t *window)
102 {
103     if (!window)
104         return;
105
106     window_t *w = (window_t *)window;
107     if (w->inhibit)
108         vlc_inhibit_Destroy (w->inhibit);
109
110     module_unneed(window, w->module);
111
112     vlc_object_release(window);
113 }
114
115 int vout_window_Control(vout_window_t *window, int query, ...)
116 {
117     va_list args;
118     va_start(args, query);
119     int ret = window->control(window, query, args);
120     va_end(args);
121
122     return ret;
123 }
124