]> git.sesse.net Git - vlc/blob - modules/video_output/xcb/window.c
Cleanup vout window handle typedef
[vlc] / modules / video_output / xcb / window.c
1 /**
2  * @file window.c
3  * @brief X C Bindings window provider module for VLC media player
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 <xcb/xcb.h>
31 #include <xcb/xcb_aux.h>
32
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_window.h>
36
37 #define DISPLAY_TEXT N_("X11 display")
38 #define DISPLAY_LONGTEXT N_( \
39     "X11 hardware display to use. By default VLC will " \
40     "use the value of the DISPLAY environment variable.")
41
42 static int  Open (vlc_object_t *);
43 static void Close (vlc_object_t *);
44
45 /*
46  * Module descriptor
47  */
48 vlc_module_begin ()
49     set_shortname (N_("XCB window"))
50     set_description (N_("(Experimental) XCB video window"))
51     set_category (CAT_VIDEO)
52     set_subcategory (SUBCAT_VIDEO_VOUT)
53     set_capability ("vout_window", 10)
54     set_callbacks (Open, Close)
55
56     add_string ("x11-display", NULL, NULL,
57                 DISPLAY_TEXT, DISPLAY_LONGTEXT, true)
58 vlc_module_end ()
59
60 static int Control (vout_window_t *, int, va_list ap);
61
62 /**
63  * Create an X11 window.
64  */
65 static int Open (vlc_object_t *obj)
66 {
67     vout_window_t *wnd = (vout_window_t *)obj;
68     xcb_generic_error_t *err;
69     xcb_void_cookie_t ck;
70
71     /* Connect to X */
72     char *display = var_CreateGetNonEmptyString (wnd, "x11-display");
73     int snum;
74
75     xcb_connection_t *conn = xcb_connect (display, &snum);
76     free (display);
77     if (xcb_connection_has_error (conn) /*== NULL*/)
78         goto error;
79
80     /* Create window */
81     xcb_screen_t *scr = xcb_aux_get_screen (conn, snum);
82
83     xcb_window_t window = xcb_generate_id (conn);
84     ck = xcb_create_window_checked (conn, scr->root_depth, window, scr->root,
85                                     0, 0, wnd->width, wnd->height, 0,
86                                     XCB_WINDOW_CLASS_INPUT_OUTPUT,
87                                     scr->root_visual, 0, NULL);
88     err = xcb_request_check (conn, ck);
89     if (err)
90     {
91         msg_Err (wnd, "creating window: X11 error %d", err->error_code);
92         goto error;
93     }
94
95     /* Make sure the window is ready */
96     xcb_map_window (conn, window);
97     xcb_flush (conn);
98
99     wnd->handle.xid = window;
100     wnd->p_sys = conn;
101     wnd->control = Control;
102     return VLC_SUCCESS;
103
104 error:
105     xcb_disconnect (conn);
106     return VLC_EGENERIC;
107 }
108
109
110 /**
111  * Destroys the X11 window.
112  */
113 static void Close (vlc_object_t *obj)
114 {
115     vout_window_t *wnd = (vout_window_t *)obj;
116     xcb_connection_t *conn = wnd->p_sys;
117     xcb_window_t window = (uintptr_t)wnd->handle;
118
119     xcb_unmap_window (conn, window);
120     xcb_destroy_window (conn, window);
121     xcb_disconnect (conn);
122 }
123
124
125 static int Control (vout_window_t *wnd, int cmd, va_list ap)
126 {
127     msg_Err (wnd, "request %d not implemented", cmd);
128     (void)ap;
129     return VLC_EGENERIC;
130 }
131