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