]> git.sesse.net Git - vlc/blob - modules/video_output/drawable.c
macosx: fixed menubar appearance in fullscreen mode by partially reverting [46c93c9cc...
[vlc] / modules / video_output / drawable.c
1 /**
2  * @file drawable.c
3  * @brief Legacy monolithic LibVLC video window provider
4  */
5 /*****************************************************************************
6  * Copyright © 2009 Rémi Denis-Courmont
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2.0
11  * of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  ****************************************************************************/
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <stdarg.h>
28 #include <assert.h>
29
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
32 #include <vlc_vout.h>
33 #include <vlc_window.h>
34
35 static int  OpenXID (vlc_object_t *);
36 static int  OpenHWND (vlc_object_t *);
37 static void Close (vlc_object_t *);
38
39 #define XID_TEXT N_("ID of the video output X window")
40 #define XID_LONGTEXT N_( \
41     "VLC can embed its video output in an existing X11 window. " \
42     "This is the X identifier of that window (0 means none).")
43
44 /*
45  * Module descriptor
46  */
47 vlc_module_begin ()
48     set_shortname (N_("Drawable"))
49     set_description (N_("Embedded X window video"))
50     set_category (CAT_VIDEO)
51     set_subcategory (SUBCAT_VIDEO_VOUT)
52     set_capability ("xwindow", 70)
53     set_callbacks (OpenXID, Close)
54     add_integer ("drawable-xid", 0, NULL, XID_TEXT, XID_LONGTEXT, true)
55         change_unsaveable ()
56         /*change_integer_range (0, 0xffffffff)*/
57
58     add_submodule ()
59         set_description (N_("Embedded Windows video"))
60         set_capability ("hwnd", 70)
61         set_callbacks (OpenHWND, Close)
62
63 vlc_module_end ()
64
65 static int Control (vout_window_t *, int, va_list);
66
67 /**
68  * Find the drawable set by libvlc application.
69  */
70 static int Open (vlc_object_t *obj, const char *varname, bool ptr)
71 {
72     static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
73     vout_window_t *wnd = (vout_window_t *)obj;
74     vlc_value_t val, globval;
75
76     if (var_Create (obj->p_libvlc, "drawable-busy", VLC_VAR_BOOL)
77      || var_Create (obj, varname, VLC_VAR_DOINHERIT
78                                   | (ptr ? VLC_VAR_ADDRESS : VLC_VAR_INTEGER)))
79         return VLC_ENOMEM;
80     var_Get (obj, varname, &val);
81
82     vlc_mutex_lock (&serializer);
83     /* Note: We cannot simply clear the drawable variable.
84      * It would break libvlc_video_get_parent(). */
85     var_Get (obj->p_libvlc, varname, &globval);
86     if (ptr ? (val.p_address == globval.p_address)
87             : (val.i_int == globval.i_int))
88     {
89         if (var_GetBool (obj->p_libvlc, "drawable-busy"))
90         {   /* LibVLC-wide drawable already in use */
91             if (ptr)
92                 val.p_address = NULL;
93             else
94                 val.i_int = 0;
95         }
96         else
97             var_SetBool (obj->p_libvlc, "drawable-busy", true);
98     }
99     /* If we got a drawable _not_ from the root object (from the input?),
100      * We assume it is not busy. This is a bug. */
101     vlc_mutex_unlock (&serializer);
102
103     var_Destroy (obj, varname);
104
105     if (ptr ? (val.p_address == NULL) : (val.i_int == 0))
106     {
107         var_Destroy (obj->p_libvlc, "drawable-busy");
108         return VLC_EGENERIC;
109     }
110
111     if (ptr)
112         wnd->handle.hwnd = val.p_address;
113     else
114         wnd->handle.xid = val.i_int;
115
116     /* FIXME: check that X server matches --x11-display (if specified) */
117     /* FIXME: get window size (in platform-dependent ways) */
118
119     wnd->control = Control;
120     return VLC_SUCCESS;
121 }
122
123 static int  OpenXID (vlc_object_t *obj)
124 {
125     return Open (obj, "drawable-xid", false);
126 }
127
128 static int  OpenHWND (vlc_object_t *obj)
129 {
130     return Open (obj, "drawable-hwnd", true);
131 }
132
133
134 /**
135  * Release the drawable.
136  */
137 static void Close (vlc_object_t *obj)
138 {
139     /* This is atomic with regards to var_GetBool() in Open(): */
140     var_SetBool (obj->p_libvlc, "drawable-busy", false);
141
142     /* Variables are reference-counted... */
143     var_Destroy (obj->p_libvlc, "drawable-busy");
144 }
145
146
147 static int Control (vout_window_t *wnd, int query, va_list ap)
148 {
149     switch (query)
150     {
151         case VOUT_SET_SIZE: /* not allowed */
152         case VOUT_SET_STAY_ON_TOP: /* not allowed either, would be ugly */
153             return VLC_EGENERIC;
154     }
155
156     msg_Warn (wnd, "unsupported control query %d", query);
157     return VLC_EGENERIC;
158 }
159