3 * @brief X C Bindings window provider module for VLC media player
5 /*****************************************************************************
6 * Copyright © 2009 Rémi Denis-Courmont
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.
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.
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 ****************************************************************************/
32 #include <xcb/xcb_aux.h>
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_window.h>
40 #define DISPLAY_TEXT N_("X11 display")
41 #define DISPLAY_LONGTEXT N_( \
42 "X11 hardware display to use. By default VLC will " \
43 "use the value of the DISPLAY environment variable.")
45 static int Open (vlc_object_t *);
46 static void Close (vlc_object_t *);
52 set_shortname (N_("XCB window"))
53 set_description (N_("(Experimental) XCB video window"))
54 set_category (CAT_VIDEO)
55 set_subcategory (SUBCAT_VIDEO_VOUT)
56 set_capability ("xwindow", 10)
57 set_callbacks (Open, Close)
59 add_string ("x11-display", NULL, NULL,
60 DISPLAY_TEXT, DISPLAY_LONGTEXT, true)
63 static int Control (vout_window_t *, int, va_list ap);
64 static void *Thread (void *);
66 struct vout_window_sys_t
68 xcb_connection_t *conn;
74 * Create an X11 window.
76 static int Open (vlc_object_t *obj)
78 vout_window_t *wnd = (vout_window_t *)obj;
79 vout_window_sys_t *p_sys = malloc (sizeof (*p_sys));
80 xcb_generic_error_t *err;
87 char *display = var_CreateGetNonEmptyString (wnd, "x11-display");
90 xcb_connection_t *conn = xcb_connect (display, &snum);
92 if (xcb_connection_has_error (conn) /*== NULL*/)
96 xcb_screen_t *scr = xcb_aux_get_screen (conn, snum);
97 const uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
98 uint32_t values[2] = {
99 /* XCB_CW_BACK_PIXEL */
101 /* XCB_CW_EVENT_MASK */
102 XCB_EVENT_MASK_KEY_PRESS,
105 xcb_window_t window = xcb_generate_id (conn);
106 ck = xcb_create_window_checked (conn, scr->root_depth, window, scr->root,
107 0, 0, wnd->width, wnd->height, 0,
108 XCB_WINDOW_CLASS_INPUT_OUTPUT,
109 scr->root_visual, mask, values);
110 err = xcb_request_check (conn, ck);
113 msg_Err (wnd, "creating window: X11 error %d", err->error_code);
117 wnd->handle.xid = window;
119 wnd->control = Control;
122 p_sys->keys = CreateKeyHandler (obj, conn);
124 if ((p_sys->keys != NULL)
125 && vlc_clone (&p_sys->thread, Thread, wnd, VLC_THREAD_PRIORITY_LOW))
126 DestroyKeyHandler (p_sys->keys);
128 /* Make sure the window is ready */
129 xcb_map_window (conn, window);
135 xcb_disconnect (conn);
142 * Destroys the X11 window.
144 static void Close (vlc_object_t *obj)
146 vout_window_t *wnd = (vout_window_t *)obj;
147 vout_window_sys_t *p_sys = wnd->p_sys;
148 xcb_connection_t *conn = p_sys->conn;
149 xcb_window_t window = wnd->handle.xid;
153 vlc_cancel (p_sys->thread);
154 vlc_join (p_sys->thread, NULL);
155 DestroyKeyHandler (p_sys->keys);
157 xcb_unmap_window (conn, window);
158 xcb_destroy_window (conn, window);
159 xcb_disconnect (conn);
164 static void *Thread (void *data)
166 vout_window_t *wnd = data;
167 vout_window_sys_t *p_sys = wnd->p_sys;
168 xcb_connection_t *conn = p_sys->conn;
170 int fd = xcb_get_file_descriptor (conn);
176 xcb_generic_event_t *ev;
177 struct pollfd ufd = { .fd = fd, .events = POLLIN, };
181 int canc = vlc_savecancel ();
182 while ((ev = xcb_poll_for_event (conn)) != NULL)
184 if (ProcessKeyEvent (p_sys->keys, ev) == 0)
186 msg_Dbg (wnd, "unhandled event: %"PRIu8, ev->response_type);
189 vlc_restorecancel (canc);
191 if (xcb_connection_has_error (conn))
193 msg_Err (wnd, "X server failure");
200 #include <vlc_vout.h>
202 static int Control (vout_window_t *wnd, int cmd, va_list ap)
204 vout_window_sys_t *p_sys = wnd->p_sys;
205 xcb_connection_t *conn = p_sys->conn;
211 unsigned width = va_arg (ap, unsigned);
212 unsigned height = va_arg (ap, unsigned);
213 const uint32_t values[] = { width, height, };
215 xcb_configure_window (conn, wnd->handle.xid,
216 XCB_CONFIG_WINDOW_WIDTH |
217 XCB_CONFIG_WINDOW_HEIGHT, values);
223 msg_Err (wnd, "request %d not implemented", cmd);