blob: cca6ab73821cf0603b624a0997ad8941bda45eac [file] [log] [blame]
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001/*
Kristian Høgsberg96aa7da2011-09-15 15:43:14 -04002 * Copyright © 2008-2011 Kristian Høgsberg
3 * Copyright © 2010-2011 Intel Corporation
Vasily Khoruzhickb3add192013-01-07 20:39:50 +03004 * Copyright © 2013 Vasily Khoruzhick <anarsoul@gmail.com>
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04005 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -07006 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040013 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -070014 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040026 */
27
Daniel Stonec228e232013-05-22 18:03:19 +030028#include "config.h"
Chia-I Wu1b6c0ed2010-10-29 15:20:18 +080029
John Kåre Alsaker143a8982012-10-12 12:25:07 +020030#include <assert.h>
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040031#include <stddef.h>
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040032#include <stdlib.h>
33#include <string.h>
34#include <fcntl.h>
35#include <unistd.h>
36#include <errno.h>
37#include <sys/time.h>
Vasily Khoruzhickb3add192013-01-07 20:39:50 +030038#include <sys/shm.h>
Kristian Høgsbergf9112b22010-06-14 12:53:43 -040039#include <linux/input.h>
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040040
41#include <xcb/xcb.h>
Vasily Khoruzhickb3add192013-01-07 20:39:50 +030042#include <xcb/shm.h>
Daniel Stone62b33b62012-06-22 13:21:35 +010043#ifdef HAVE_XCB_XKB
44#include <xcb/xkb.h>
45#endif
46
Benjamin Franzke3b288af2011-02-20 19:58:42 +010047#include <X11/Xlib.h>
48#include <X11/Xlib-xcb.h>
49
Daniel Stone576cd152012-06-01 12:14:02 +010050#include <xkbcommon/xkbcommon.h>
51
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040052#include "compositor.h"
John Kåre Alsaker30d2b1f2012-11-13 19:10:28 +010053#include "gl-renderer.h"
Vasily Khoruzhickb3add192013-01-07 20:39:50 +030054#include "pixman-renderer.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070055#include "shared/config-parser.h"
Jon Cruz35b2eaa2015-06-15 15:37:08 -070056#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070057#include "shared/image-loader.h"
Pekka Paalanenb00c79b2016-02-18 16:53:27 +020058#include "presentation-time-server-protocol.h"
Pekka Paalanen5ffb4402014-06-12 16:52:53 +030059#include "linux-dmabuf.h"
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040060
Jonas Ådahl62efe202012-09-27 18:40:41 +020061#define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10)
62
Scott Moreau248aaec2012-08-03 14:19:52 -060063static int option_width;
64static int option_height;
Jason Ekstrandd89a0942014-03-07 15:29:14 -060065static int option_scale;
Scott Moreau248aaec2012-08-03 14:19:52 -060066static int option_count;
Scott Moreau248aaec2012-08-03 14:19:52 -060067
Giulio Camuffo954f1832014-10-11 18:27:30 +030068struct x11_backend {
69 struct weston_backend base;
70 struct weston_compositor *compositor;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040071
Benjamin Franzke3b288af2011-02-20 19:58:42 +010072 Display *dpy;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040073 xcb_connection_t *conn;
74 xcb_screen_t *screen;
75 xcb_cursor_t null_cursor;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -050076 struct wl_array keys;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040077 struct wl_event_source *xcb_source;
Daniel Stone576cd152012-06-01 12:14:02 +010078 struct xkb_keymap *xkb_keymap;
Daniel Stone62b33b62012-06-22 13:21:35 +010079 unsigned int has_xkb;
80 uint8_t xkb_event_base;
Vasily Khoruzhickd8943512013-01-07 22:36:02 +030081 int use_pixman;
Kristian Høgsberg4f92c532012-08-10 10:04:36 -040082
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -050083 int has_net_wm_state_fullscreen;
84
Kristian Høgsberg4f92c532012-08-10 10:04:36 -040085 /* We could map multi-pointer X to multiple wayland seats, but
86 * for now we only support core X input. */
Kristian Høgsberg068b61c2013-02-25 17:04:47 -050087 struct weston_seat core_seat;
Kristian Høgsberg50065962013-03-27 15:14:07 -040088 wl_fixed_t prev_x;
89 wl_fixed_t prev_y;
Kristian Høgsberg4f92c532012-08-10 10:04:36 -040090
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040091 struct {
92 xcb_atom_t wm_protocols;
93 xcb_atom_t wm_normal_hints;
94 xcb_atom_t wm_size_hints;
95 xcb_atom_t wm_delete_window;
Kristian Høgsberg24ed6212011-01-26 14:02:31 -050096 xcb_atom_t wm_class;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040097 xcb_atom_t net_wm_name;
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -050098 xcb_atom_t net_supporting_wm_check;
99 xcb_atom_t net_supported;
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500100 xcb_atom_t net_wm_icon;
Kristian Høgsberg83eeacb2011-06-18 04:20:54 -0400101 xcb_atom_t net_wm_state;
102 xcb_atom_t net_wm_state_fullscreen;
Kristian Høgsberg24ed6212011-01-26 14:02:31 -0500103 xcb_atom_t string;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400104 xcb_atom_t utf8_string;
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500105 xcb_atom_t cardinal;
Daniel Stone855028f2012-05-01 20:37:10 +0100106 xcb_atom_t xkb_names;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400107 } atom;
108};
109
110struct x11_output {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500111 struct weston_output base;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400112
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400113 xcb_window_t window;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500114 struct weston_mode mode;
Kristian Høgsberg06a670f2011-10-29 14:39:13 -0400115 struct wl_event_source *finish_frame_timer;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300116
117 xcb_gc_t gc;
118 xcb_shm_seg_t segment;
119 pixman_image_t *hw_surface;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300120 int shm_id;
121 void *buf;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300122 uint8_t depth;
Alexander Larssonedddbd12013-05-24 13:09:43 +0200123 int32_t scale;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400124};
125
Derek Foremand540f4b2015-01-27 16:26:49 -0600126struct window_delete_data {
Giulio Camuffo954f1832014-10-11 18:27:30 +0300127 struct x11_backend *backend;
Derek Foremand540f4b2015-01-27 16:26:49 -0600128 xcb_window_t window;
129};
130
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300131struct gl_renderer_interface *gl_renderer;
132
Marko61b4d3e2015-10-05 17:27:54 -0500133static xcb_screen_t *
134x11_compositor_get_default_screen(struct x11_backend *b)
135{
136 xcb_screen_iterator_t iter;
137 int i, screen_nbr = XDefaultScreen(b->dpy);
138
139 iter = xcb_setup_roots_iterator(xcb_get_setup(b->conn));
140 for (i = 0; iter.rem; xcb_screen_next(&iter), i++)
141 if (i == screen_nbr)
142 return iter.data;
143
144 return xcb_setup_roots_iterator(xcb_get_setup(b->conn)).data;
145}
146
Daniel Stone576cd152012-06-01 12:14:02 +0100147static struct xkb_keymap *
Giulio Camuffo954f1832014-10-11 18:27:30 +0300148x11_backend_get_keymap(struct x11_backend *b)
Daniel Stone576cd152012-06-01 12:14:02 +0100149{
150 xcb_get_property_cookie_t cookie;
151 xcb_get_property_reply_t *reply;
Daniel Stone576cd152012-06-01 12:14:02 +0100152 struct xkb_rule_names names;
153 struct xkb_keymap *ret;
154 const char *value_all, *value_part;
155 int length_all, length_part;
156
157 memset(&names, 0, sizeof(names));
158
Giulio Camuffo954f1832014-10-11 18:27:30 +0300159 cookie = xcb_get_property(b->conn, 0, b->screen->root,
160 b->atom.xkb_names, b->atom.string, 0, 1024);
161 reply = xcb_get_property_reply(b->conn, cookie, NULL);
Daniel Stone576cd152012-06-01 12:14:02 +0100162 if (reply == NULL)
163 return NULL;
164
165 value_all = xcb_get_property_value(reply);
166 length_all = xcb_get_property_value_length(reply);
167 value_part = value_all;
168
169#define copy_prop_value(to) \
170 length_part = strlen(value_part); \
171 if (value_part + length_part < (value_all + length_all) && \
172 length_part > 0) \
173 names.to = value_part; \
174 value_part += length_part + 1;
175
176 copy_prop_value(rules);
177 copy_prop_value(model);
178 copy_prop_value(layout);
179 copy_prop_value(variant);
180 copy_prop_value(options);
181#undef copy_prop_value
182
Giulio Camuffo954f1832014-10-11 18:27:30 +0300183 ret = xkb_keymap_new_from_names(b->compositor->xkb_context, &names, 0);
Daniel Stone576cd152012-06-01 12:14:02 +0100184
185 free(reply);
186 return ret;
187}
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400188
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400189static uint32_t
Giulio Camuffo954f1832014-10-11 18:27:30 +0300190get_xkb_mod_mask(struct x11_backend *b, uint32_t in)
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400191{
Derek Foreman1281a362015-07-31 16:55:32 -0500192 struct weston_keyboard *keyboard =
193 weston_seat_get_keyboard(&b->core_seat);
194 struct weston_xkb_info *info = keyboard->xkb_info;
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400195 uint32_t ret = 0;
196
197 if ((in & ShiftMask) && info->shift_mod != XKB_MOD_INVALID)
198 ret |= (1 << info->shift_mod);
199 if ((in & LockMask) && info->caps_mod != XKB_MOD_INVALID)
200 ret |= (1 << info->caps_mod);
201 if ((in & ControlMask) && info->ctrl_mod != XKB_MOD_INVALID)
202 ret |= (1 << info->ctrl_mod);
203 if ((in & Mod1Mask) && info->alt_mod != XKB_MOD_INVALID)
204 ret |= (1 << info->alt_mod);
205 if ((in & Mod2Mask) && info->mod2_mod != XKB_MOD_INVALID)
206 ret |= (1 << info->mod2_mod);
207 if ((in & Mod3Mask) && info->mod3_mod != XKB_MOD_INVALID)
208 ret |= (1 << info->mod3_mod);
209 if ((in & Mod4Mask) && info->super_mod != XKB_MOD_INVALID)
210 ret |= (1 << info->super_mod);
211 if ((in & Mod5Mask) && info->mod5_mod != XKB_MOD_INVALID)
212 ret |= (1 << info->mod5_mod);
213
214 return ret;
215}
216
Daniel Stone62b33b62012-06-22 13:21:35 +0100217static void
Giulio Camuffo954f1832014-10-11 18:27:30 +0300218x11_backend_setup_xkb(struct x11_backend *b)
Daniel Stone62b33b62012-06-22 13:21:35 +0100219{
220#ifndef HAVE_XCB_XKB
221 weston_log("XCB-XKB not available during build\n");
Giulio Camuffo954f1832014-10-11 18:27:30 +0300222 b->has_xkb = 0;
223 b->xkb_event_base = 0;
Daniel Stone62b33b62012-06-22 13:21:35 +0100224 return;
225#else
Derek Foreman1281a362015-07-31 16:55:32 -0500226 struct weston_keyboard *keyboard;
Daniel Stone62b33b62012-06-22 13:21:35 +0100227 const xcb_query_extension_reply_t *ext;
Daniel Stone3ee91e12012-06-22 13:21:36 +0100228 xcb_generic_error_t *error;
Daniel Stonee2faa122012-06-22 13:21:39 +0100229 xcb_void_cookie_t select;
Ran Benita6a39d872012-10-31 20:14:57 +0200230 xcb_xkb_use_extension_cookie_t use_ext;
231 xcb_xkb_use_extension_reply_t *use_ext_reply;
Daniel Stone3ee91e12012-06-22 13:21:36 +0100232 xcb_xkb_per_client_flags_cookie_t pcf;
233 xcb_xkb_per_client_flags_reply_t *pcf_reply;
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400234 xcb_xkb_get_state_cookie_t state;
235 xcb_xkb_get_state_reply_t *state_reply;
Rui Matosc6c2f8e2013-10-10 19:44:20 +0200236 uint32_t values[1] = { XCB_EVENT_MASK_PROPERTY_CHANGE };
Daniel Stone62b33b62012-06-22 13:21:35 +0100237
Giulio Camuffo954f1832014-10-11 18:27:30 +0300238 b->has_xkb = 0;
239 b->xkb_event_base = 0;
Daniel Stone62b33b62012-06-22 13:21:35 +0100240
Giulio Camuffo954f1832014-10-11 18:27:30 +0300241 ext = xcb_get_extension_data(b->conn, &xcb_xkb_id);
Daniel Stone62b33b62012-06-22 13:21:35 +0100242 if (!ext) {
243 weston_log("XKB extension not available on host X11 server\n");
244 return;
245 }
Giulio Camuffo954f1832014-10-11 18:27:30 +0300246 b->xkb_event_base = ext->first_event;
Daniel Stone62b33b62012-06-22 13:21:35 +0100247
Giulio Camuffo954f1832014-10-11 18:27:30 +0300248 select = xcb_xkb_select_events_checked(b->conn,
Ran Benita424ae012012-10-31 00:13:08 +0200249 XCB_XKB_ID_USE_CORE_KBD,
250 XCB_XKB_EVENT_TYPE_STATE_NOTIFY,
251 0,
252 XCB_XKB_EVENT_TYPE_STATE_NOTIFY,
253 0,
254 0,
255 NULL);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300256 error = xcb_request_check(b->conn, select);
Daniel Stonee2faa122012-06-22 13:21:39 +0100257 if (error) {
258 weston_log("error: failed to select for XKB state events\n");
Ran Benita7b5e3cd2012-10-31 20:14:56 +0200259 free(error);
Daniel Stonee2faa122012-06-22 13:21:39 +0100260 return;
261 }
262
Giulio Camuffo954f1832014-10-11 18:27:30 +0300263 use_ext = xcb_xkb_use_extension(b->conn,
Ran Benita6a39d872012-10-31 20:14:57 +0200264 XCB_XKB_MAJOR_VERSION,
265 XCB_XKB_MINOR_VERSION);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300266 use_ext_reply = xcb_xkb_use_extension_reply(b->conn, use_ext, NULL);
Ran Benita6a39d872012-10-31 20:14:57 +0200267 if (!use_ext_reply) {
268 weston_log("couldn't start using XKB extension\n");
269 return;
270 }
271
272 if (!use_ext_reply->supported) {
273 weston_log("XKB extension version on the server is too old "
274 "(want %d.%d, has %d.%d)\n",
275 XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION,
276 use_ext_reply->serverMajor, use_ext_reply->serverMinor);
277 free(use_ext_reply);
278 return;
279 }
280 free(use_ext_reply);
281
Giulio Camuffo954f1832014-10-11 18:27:30 +0300282 pcf = xcb_xkb_per_client_flags(b->conn,
Daniel Stone3ee91e12012-06-22 13:21:36 +0100283 XCB_XKB_ID_USE_CORE_KBD,
284 XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT,
285 XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT,
286 0,
287 0,
288 0);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300289 pcf_reply = xcb_xkb_per_client_flags_reply(b->conn, pcf, NULL);
Ran Benita7109cc82012-10-31 20:14:58 +0200290 if (!pcf_reply ||
291 !(pcf_reply->value & XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT)) {
Daniel Stone3ee91e12012-06-22 13:21:36 +0100292 weston_log("failed to set XKB per-client flags, not using "
293 "detectable repeat\n");
Ran Benita7109cc82012-10-31 20:14:58 +0200294 free(pcf_reply);
Daniel Stone3ee91e12012-06-22 13:21:36 +0100295 return;
296 }
Ran Benita7b5e3cd2012-10-31 20:14:56 +0200297 free(pcf_reply);
Daniel Stone3ee91e12012-06-22 13:21:36 +0100298
Giulio Camuffo954f1832014-10-11 18:27:30 +0300299 state = xcb_xkb_get_state(b->conn, XCB_XKB_ID_USE_CORE_KBD);
300 state_reply = xcb_xkb_get_state_reply(b->conn, state, NULL);
Ran Benita7b5e3cd2012-10-31 20:14:56 +0200301 if (!state_reply) {
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400302 weston_log("failed to get initial XKB state\n");
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400303 return;
304 }
305
Derek Foreman1281a362015-07-31 16:55:32 -0500306 keyboard = weston_seat_get_keyboard(&b->core_seat);
307 xkb_state_update_mask(keyboard->xkb_state.state,
Giulio Camuffo954f1832014-10-11 18:27:30 +0300308 get_xkb_mod_mask(b, state_reply->baseMods),
309 get_xkb_mod_mask(b, state_reply->latchedMods),
310 get_xkb_mod_mask(b, state_reply->lockedMods),
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400311 0,
312 0,
313 state_reply->group);
314
315 free(state_reply);
316
Giulio Camuffo954f1832014-10-11 18:27:30 +0300317 xcb_change_window_attributes(b->conn, b->screen->root,
Rui Matosc6c2f8e2013-10-10 19:44:20 +0200318 XCB_CW_EVENT_MASK, values);
319
Giulio Camuffo954f1832014-10-11 18:27:30 +0300320 b->has_xkb = 1;
Daniel Stone62b33b62012-06-22 13:21:35 +0100321#endif
322}
323
Jonas Ådahlf88571f2013-10-25 23:18:01 +0200324#ifdef HAVE_XCB_XKB
Rui Matosc6c2f8e2013-10-10 19:44:20 +0200325static void
Giulio Camuffo954f1832014-10-11 18:27:30 +0300326update_xkb_keymap(struct x11_backend *b)
Rui Matosc6c2f8e2013-10-10 19:44:20 +0200327{
328 struct xkb_keymap *keymap;
329
Giulio Camuffo954f1832014-10-11 18:27:30 +0300330 keymap = x11_backend_get_keymap(b);
Rui Matosc6c2f8e2013-10-10 19:44:20 +0200331 if (!keymap) {
332 weston_log("failed to get XKB keymap\n");
333 return;
334 }
Giulio Camuffo954f1832014-10-11 18:27:30 +0300335 weston_seat_update_keymap(&b->core_seat, keymap);
Rui Matosc6c2f8e2013-10-10 19:44:20 +0200336 xkb_keymap_unref(keymap);
337}
Jonas Ådahlf88571f2013-10-25 23:18:01 +0200338#endif
Rui Matosc6c2f8e2013-10-10 19:44:20 +0200339
Darxus55973f22010-11-22 21:24:39 -0500340static int
Giulio Camuffo954f1832014-10-11 18:27:30 +0300341x11_input_create(struct x11_backend *b, int no_input)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400342{
Daniel Stone576cd152012-06-01 12:14:02 +0100343 struct xkb_keymap *keymap;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400344
Giulio Camuffo954f1832014-10-11 18:27:30 +0300345 weston_seat_init(&b->core_seat, b->compositor, "default");
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300346
347 if (no_input)
348 return 0;
349
Giulio Camuffo954f1832014-10-11 18:27:30 +0300350 weston_seat_init_pointer(&b->core_seat);
Daniel Stone576cd152012-06-01 12:14:02 +0100351
Giulio Camuffo954f1832014-10-11 18:27:30 +0300352 keymap = x11_backend_get_keymap(b);
353 if (weston_seat_init_keyboard(&b->core_seat, keymap) < 0)
Kristian Høgsberg2f07ef62013-02-16 14:29:24 -0500354 return -1;
Ran Benitac9c74152014-08-19 23:59:52 +0300355 xkb_keymap_unref(keymap);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400356
Giulio Camuffo954f1832014-10-11 18:27:30 +0300357 x11_backend_setup_xkb(b);
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400358
Darxus55973f22010-11-22 21:24:39 -0500359 return 0;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400360}
361
Pekka Paalanen43c61d82012-01-03 11:58:34 +0200362static void
Giulio Camuffo954f1832014-10-11 18:27:30 +0300363x11_input_destroy(struct x11_backend *b)
Pekka Paalanen43c61d82012-01-03 11:58:34 +0200364{
Giulio Camuffo954f1832014-10-11 18:27:30 +0300365 weston_seat_release(&b->core_seat);
Pekka Paalanen43c61d82012-01-03 11:58:34 +0200366}
367
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500368static void
Jonas Ådahle5a12252013-04-05 23:07:11 +0200369x11_output_start_repaint_loop(struct weston_output *output)
370{
Pekka Paalanenb5eedad2014-09-23 22:08:45 -0400371 struct timespec ts;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200372
Pekka Paalanen662f3842015-03-18 12:17:26 +0200373 weston_compositor_read_presentation_clock(output->compositor, &ts);
Pekka Paalanenb00c79b2016-02-18 16:53:27 +0200374 weston_output_finish_frame(output, &ts, WP_PRESENTATION_FEEDBACK_INVALID);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200375}
376
David Herrmann1edf44c2013-10-22 17:11:26 +0200377static int
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300378x11_output_repaint_gl(struct weston_output *output_base,
379 pixman_region32_t *damage)
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500380{
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500381 struct x11_output *output = (struct x11_output *)output_base;
Kristian Høgsbergfa1be022012-09-05 22:49:55 -0400382 struct weston_compositor *ec = output->base.compositor;
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500383
Kristian Høgsbergfa1be022012-09-05 22:49:55 -0400384 ec->renderer->repaint_output(output_base, damage);
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500385
Ander Conselvan de Oliveira0a887722012-11-22 15:57:00 +0200386 pixman_region32_subtract(&ec->primary_plane.damage,
387 &ec->primary_plane.damage, damage);
388
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500389 wl_event_source_timer_update(output->finish_frame_timer, 10);
David Herrmann1edf44c2013-10-22 17:11:26 +0200390 return 0;
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500391}
392
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300393static void
Alexander Larsson80f91632013-05-22 14:41:38 +0200394set_clip_for_output(struct weston_output *output_base, pixman_region32_t *region)
395{
396 struct x11_output *output = (struct x11_output *)output_base;
397 struct weston_compositor *ec = output->base.compositor;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300398 struct x11_backend *b = (struct x11_backend *)ec->backend;
Jason Ekstrand33ff6362013-10-27 22:25:01 -0500399 pixman_region32_t transformed_region;
Alexander Larsson80f91632013-05-22 14:41:38 +0200400 pixman_box32_t *rects;
401 xcb_rectangle_t *output_rects;
Alexander Larsson80f91632013-05-22 14:41:38 +0200402 xcb_void_cookie_t cookie;
Jason Ekstrand33ff6362013-10-27 22:25:01 -0500403 int nrects, i;
Alexander Larsson80f91632013-05-22 14:41:38 +0200404 xcb_generic_error_t *err;
405
Jason Ekstrand33ff6362013-10-27 22:25:01 -0500406 pixman_region32_init(&transformed_region);
407 pixman_region32_copy(&transformed_region, region);
408 pixman_region32_translate(&transformed_region,
409 -output_base->x, -output_base->y);
410 weston_transformed_region(output_base->width, output_base->height,
411 output_base->transform,
412 output_base->current_scale,
413 &transformed_region, &transformed_region);
414
415 rects = pixman_region32_rectangles(&transformed_region, &nrects);
Alexander Larsson80f91632013-05-22 14:41:38 +0200416 output_rects = calloc(nrects, sizeof(xcb_rectangle_t));
417
Jason Ekstrand33ff6362013-10-27 22:25:01 -0500418 if (output_rects == NULL) {
419 pixman_region32_fini(&transformed_region);
Alexander Larsson80f91632013-05-22 14:41:38 +0200420 return;
Jason Ekstrand33ff6362013-10-27 22:25:01 -0500421 }
Alexander Larsson80f91632013-05-22 14:41:38 +0200422
423 for (i = 0; i < nrects; i++) {
Jason Ekstrand33ff6362013-10-27 22:25:01 -0500424 output_rects[i].x = rects[i].x1;
425 output_rects[i].y = rects[i].y1;
426 output_rects[i].width = rects[i].x2 - rects[i].x1;
427 output_rects[i].height = rects[i].y2 - rects[i].y1;
Alexander Larsson80f91632013-05-22 14:41:38 +0200428 }
429
Jason Ekstrand33ff6362013-10-27 22:25:01 -0500430 pixman_region32_fini(&transformed_region);
431
Giulio Camuffo954f1832014-10-11 18:27:30 +0300432 cookie = xcb_set_clip_rectangles_checked(b->conn, XCB_CLIP_ORDERING_UNSORTED,
Alexander Larsson80f91632013-05-22 14:41:38 +0200433 output->gc,
434 0, 0, nrects,
435 output_rects);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300436 err = xcb_request_check(b->conn, cookie);
Alexander Larsson80f91632013-05-22 14:41:38 +0200437 if (err != NULL) {
438 weston_log("Failed to set clip rects, err: %d\n", err->error_code);
439 free(err);
440 }
441 free(output_rects);
442}
443
444
David Herrmann1edf44c2013-10-22 17:11:26 +0200445static int
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300446x11_output_repaint_shm(struct weston_output *output_base,
447 pixman_region32_t *damage)
448{
449 struct x11_output *output = (struct x11_output *)output_base;
450 struct weston_compositor *ec = output->base.compositor;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300451 struct x11_backend *b = (struct x11_backend *)ec->backend;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300452 xcb_void_cookie_t cookie;
453 xcb_generic_error_t *err;
454
Ander Conselvan de Oliveira936effd2013-01-25 15:13:01 +0200455 pixman_renderer_output_set_buffer(output_base, output->hw_surface);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300456 ec->renderer->repaint_output(output_base, damage);
457
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300458 pixman_region32_subtract(&ec->primary_plane.damage,
459 &ec->primary_plane.damage, damage);
Alexander Larsson80f91632013-05-22 14:41:38 +0200460 set_clip_for_output(output_base, damage);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300461 cookie = xcb_shm_put_image_checked(b->conn, output->window, output->gc,
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300462 pixman_image_get_width(output->hw_surface),
463 pixman_image_get_height(output->hw_surface),
464 0, 0,
465 pixman_image_get_width(output->hw_surface),
466 pixman_image_get_height(output->hw_surface),
467 0, 0, output->depth, XCB_IMAGE_FORMAT_Z_PIXMAP,
468 0, output->segment, 0);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300469 err = xcb_request_check(b->conn, cookie);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300470 if (err != NULL) {
471 weston_log("Failed to put shm image, err: %d\n", err->error_code);
472 free(err);
473 }
474
475 wl_event_source_timer_update(output->finish_frame_timer, 10);
David Herrmann1edf44c2013-10-22 17:11:26 +0200476 return 0;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300477}
478
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100479static int
Kristian Høgsberg06a670f2011-10-29 14:39:13 -0400480finish_frame_handler(void *data)
481{
482 struct x11_output *output = data;
Pekka Paalanen363aa7b2014-12-17 16:20:40 +0200483 struct timespec ts;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200484
Pekka Paalanen662f3842015-03-18 12:17:26 +0200485 weston_compositor_read_presentation_clock(output->base.compositor, &ts);
Pekka Paalanen363aa7b2014-12-17 16:20:40 +0200486 weston_output_finish_frame(&output->base, &ts, 0);
Kristian Høgsberg06a670f2011-10-29 14:39:13 -0400487
488 return 1;
489}
490
Matt Roper361d2ad2011-08-29 13:52:23 -0700491static void
Giulio Camuffo954f1832014-10-11 18:27:30 +0300492x11_output_deinit_shm(struct x11_backend *b, struct x11_output *output)
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300493{
494 xcb_void_cookie_t cookie;
495 xcb_generic_error_t *err;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300496 xcb_free_gc(b->conn, output->gc);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300497
498 pixman_image_unref(output->hw_surface);
499 output->hw_surface = NULL;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300500 cookie = xcb_shm_detach_checked(b->conn, output->segment);
501 err = xcb_request_check(b->conn, cookie);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300502 if (err) {
503 weston_log("xcb_shm_detach failed, error %d\n", err->error_code);
504 free(err);
505 }
506 shmdt(output->buf);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300507}
508
509static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500510x11_output_destroy(struct weston_output *output_base)
Matt Roper361d2ad2011-08-29 13:52:23 -0700511{
Pekka Paalanen2de99e22012-01-03 11:51:03 +0200512 struct x11_output *output = (struct x11_output *)output_base;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300513 struct x11_backend *backend =
514 (struct x11_backend *)output->base.compositor->backend;
Pekka Paalanen2de99e22012-01-03 11:51:03 +0200515
Pekka Paalanen2de99e22012-01-03 11:51:03 +0200516 wl_event_source_remove(output->finish_frame_timer);
517
Giulio Camuffo954f1832014-10-11 18:27:30 +0300518 if (backend->use_pixman) {
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300519 pixman_renderer_output_destroy(output_base);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300520 x11_output_deinit_shm(backend, output);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300521 } else
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300522 gl_renderer->output_destroy(output_base);
Pekka Paalanen2de99e22012-01-03 11:51:03 +0200523
Giulio Camuffo954f1832014-10-11 18:27:30 +0300524 xcb_destroy_window(backend->conn, output->window);
Pekka Paalanen2de99e22012-01-03 11:51:03 +0200525
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500526 weston_output_destroy(&output->base);
Pekka Paalanen2de99e22012-01-03 11:51:03 +0200527
528 free(output);
Matt Roper361d2ad2011-08-29 13:52:23 -0700529}
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200530
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400531static void
Giulio Camuffo954f1832014-10-11 18:27:30 +0300532x11_output_set_wm_protocols(struct x11_backend *b,
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500533 struct x11_output *output)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400534{
535 xcb_atom_t list[1];
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400536
Giulio Camuffo954f1832014-10-11 18:27:30 +0300537 list[0] = b->atom.wm_delete_window;
538 xcb_change_property (b->conn,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400539 XCB_PROP_MODE_REPLACE,
540 output->window,
Giulio Camuffo954f1832014-10-11 18:27:30 +0300541 b->atom.wm_protocols,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400542 XCB_ATOM_ATOM,
543 32,
Kristian Høgsberg09e26922011-12-23 13:33:45 -0500544 ARRAY_LENGTH(list),
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400545 list);
546}
547
548struct wm_normal_hints {
549 uint32_t flags;
550 uint32_t pad[4];
551 int32_t min_width, min_height;
552 int32_t max_width, max_height;
553 int32_t width_inc, height_inc;
554 int32_t min_aspect_x, min_aspect_y;
555 int32_t max_aspect_x, max_aspect_y;
556 int32_t base_width, base_height;
557 int32_t win_gravity;
558};
559
560#define WM_NORMAL_HINTS_MIN_SIZE 16
561#define WM_NORMAL_HINTS_MAX_SIZE 32
562
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500563static void
Giulio Camuffo954f1832014-10-11 18:27:30 +0300564x11_output_set_icon(struct x11_backend *b,
Kristian Høgsbergb41d76c2011-04-23 15:03:15 -0400565 struct x11_output *output, const char *filename)
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500566{
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400567 uint32_t *icon;
Kristian Høgsbergb41d76c2011-04-23 15:03:15 -0400568 int32_t width, height;
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400569 pixman_image_t *image;
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500570
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400571 image = load_image(filename);
572 if (!image)
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500573 return;
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400574 width = pixman_image_get_width(image);
575 height = pixman_image_get_height(image);
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500576 icon = malloc(width * height * 4 + 8);
577 if (!icon) {
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400578 pixman_image_unref(image);
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500579 return;
580 }
581
582 icon[0] = width;
583 icon[1] = height;
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400584 memcpy(icon + 2, pixman_image_get_data(image), width * height * 4);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300585 xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window,
586 b->atom.net_wm_icon, b->atom.cardinal, 32,
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500587 width * height + 2, icon);
588 free(icon);
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400589 pixman_image_unref(image);
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500590}
591
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500592static void
Giulio Camuffo954f1832014-10-11 18:27:30 +0300593x11_output_wait_for_map(struct x11_backend *b, struct x11_output *output)
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500594{
595 xcb_map_notify_event_t *map_notify;
596 xcb_configure_notify_event_t *configure_notify;
597 xcb_generic_event_t *event;
Kristian Høgsberg8e7adbf2013-02-14 21:14:11 -0500598 int mapped = 0, configured = 0;
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500599 uint8_t response_type;
600
601 /* This isn't the nicest way to do this. Ideally, we could
Kristian Høgsberg8e7adbf2013-02-14 21:14:11 -0500602 * just go back to the main loop and once we get the configure
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500603 * notify, we add the output to the compositor. While we do
604 * support output hotplug, we can't start up with no outputs.
Kristian Høgsberg8e7adbf2013-02-14 21:14:11 -0500605 * We could add the output and then resize once we get the
606 * configure notify, but we don't want to start up and
607 * immediately resize the output.
608 *
609 * Also, some window managers don't give us our final
610 * fullscreen size before map_notify, so if we don't get a
611 * configure_notify before map_notify, we just wait for the
612 * first one and hope that's our size. */
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500613
Giulio Camuffo954f1832014-10-11 18:27:30 +0300614 xcb_flush(b->conn);
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500615
Kristian Høgsberg8e7adbf2013-02-14 21:14:11 -0500616 while (!mapped || !configured) {
Giulio Camuffo954f1832014-10-11 18:27:30 +0300617 event = xcb_wait_for_event(b->conn);
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500618 response_type = event->response_type & ~0x80;
619
620 switch (response_type) {
621 case XCB_MAP_NOTIFY:
622 map_notify = (xcb_map_notify_event_t *) event;
623 if (map_notify->window == output->window)
624 mapped = 1;
625 break;
626
627 case XCB_CONFIGURE_NOTIFY:
628 configure_notify =
629 (xcb_configure_notify_event_t *) event;
630
Alexander Larsson4ea95522013-05-22 14:41:37 +0200631
632 if (configure_notify->width % output->scale != 0 ||
633 configure_notify->height % output->scale != 0)
634 weston_log("Resolution is not a multiple of screen size, rounding\n");
Jason Ekstrandd89a0942014-03-07 15:29:14 -0600635 output->mode.width = configure_notify->width;
636 output->mode.height = configure_notify->height;
Kristian Høgsberg8e7adbf2013-02-14 21:14:11 -0500637 configured = 1;
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500638 break;
639 }
640 }
641}
642
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300643static xcb_visualtype_t *
644find_visual_by_id(xcb_screen_t *screen,
645 xcb_visualid_t id)
646{
647 xcb_depth_iterator_t i;
648 xcb_visualtype_iterator_t j;
649 for (i = xcb_screen_allowed_depths_iterator(screen);
650 i.rem;
651 xcb_depth_next(&i)) {
652 for (j = xcb_depth_visuals_iterator(i.data);
653 j.rem;
654 xcb_visualtype_next(&j)) {
655 if (j.data->visual_id == id)
656 return j.data;
657 }
658 }
659 return 0;
660}
661
662static uint8_t
663get_depth_of_visual(xcb_screen_t *screen,
664 xcb_visualid_t id)
665{
666 xcb_depth_iterator_t i;
667 xcb_visualtype_iterator_t j;
668 for (i = xcb_screen_allowed_depths_iterator(screen);
669 i.rem;
670 xcb_depth_next(&i)) {
671 for (j = xcb_depth_visuals_iterator(i.data);
672 j.rem;
673 xcb_visualtype_next(&j)) {
674 if (j.data->visual_id == id)
675 return i.data->depth;
676 }
677 }
678 return 0;
679}
680
681static int
Giulio Camuffo954f1832014-10-11 18:27:30 +0300682x11_output_init_shm(struct x11_backend *b, struct x11_output *output,
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300683 int width, int height)
684{
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300685 xcb_visualtype_t *visual_type;
Marko61b4d3e2015-10-05 17:27:54 -0500686 xcb_screen_t *screen;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300687 xcb_format_iterator_t fmt;
688 xcb_void_cookie_t cookie;
689 xcb_generic_error_t *err;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300690 const xcb_query_extension_reply_t *ext;
691 int bitsperpixel = 0;
692 pixman_format_code_t pixman_format;
693
694 /* Check if SHM is available */
Giulio Camuffo954f1832014-10-11 18:27:30 +0300695 ext = xcb_get_extension_data(b->conn, &xcb_shm_id);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300696 if (ext == NULL || !ext->present) {
697 /* SHM is missing */
698 weston_log("SHM extension is not available\n");
699 errno = ENOENT;
700 return -1;
701 }
702
Marko61b4d3e2015-10-05 17:27:54 -0500703 screen = x11_compositor_get_default_screen(b);
704 visual_type = find_visual_by_id(screen, screen->root_visual);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300705 if (!visual_type) {
706 weston_log("Failed to lookup visual for root window\n");
707 errno = ENOENT;
708 return -1;
709 }
710 weston_log("Found visual, bits per value: %d, red_mask: %.8x, green_mask: %.8x, blue_mask: %.8x\n",
711 visual_type->bits_per_rgb_value,
712 visual_type->red_mask,
713 visual_type->green_mask,
714 visual_type->blue_mask);
Marko61b4d3e2015-10-05 17:27:54 -0500715 output->depth = get_depth_of_visual(screen, screen->root_visual);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300716 weston_log("Visual depth is %d\n", output->depth);
717
Giulio Camuffo954f1832014-10-11 18:27:30 +0300718 for (fmt = xcb_setup_pixmap_formats_iterator(xcb_get_setup(b->conn));
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300719 fmt.rem;
720 xcb_format_next(&fmt)) {
721 if (fmt.data->depth == output->depth) {
722 bitsperpixel = fmt.data->bits_per_pixel;
723 break;
724 }
725 }
726 weston_log("Found format for depth %d, bpp: %d\n",
727 output->depth, bitsperpixel);
728
729 if (bitsperpixel == 32 &&
730 visual_type->red_mask == 0xff0000 &&
731 visual_type->green_mask == 0x00ff00 &&
732 visual_type->blue_mask == 0x0000ff) {
733 weston_log("Will use x8r8g8b8 format for SHM surfaces\n");
734 pixman_format = PIXMAN_x8r8g8b8;
MoD1b55a592013-11-28 05:24:21 +0000735 } else if (bitsperpixel == 16 &&
736 visual_type->red_mask == 0x00f800 &&
737 visual_type->green_mask == 0x0007e0 &&
738 visual_type->blue_mask == 0x00001f) {
739 weston_log("Will use r5g6b5 format for SHM surfaces\n");
740 pixman_format = PIXMAN_r5g6b5;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300741 } else {
742 weston_log("Can't find appropriate format for SHM pixmap\n");
743 errno = ENOTSUP;
744 return -1;
745 }
746
747
748 /* Create SHM segment and attach it */
749 output->shm_id = shmget(IPC_PRIVATE, width * height * (bitsperpixel / 8), IPC_CREAT | S_IRWXU);
750 if (output->shm_id == -1) {
751 weston_log("x11shm: failed to allocate SHM segment\n");
752 return -1;
753 }
754 output->buf = shmat(output->shm_id, NULL, 0 /* read/write */);
755 if (-1 == (long)output->buf) {
756 weston_log("x11shm: failed to attach SHM segment\n");
757 return -1;
758 }
Giulio Camuffo954f1832014-10-11 18:27:30 +0300759 output->segment = xcb_generate_id(b->conn);
760 cookie = xcb_shm_attach_checked(b->conn, output->segment, output->shm_id, 1);
761 err = xcb_request_check(b->conn, cookie);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300762 if (err) {
Bryce Harrington665b0252015-05-26 18:14:21 -0700763 weston_log("x11shm: xcb_shm_attach error %d, op code %d, resource id %d\n",
764 err->error_code, err->major_code, err->minor_code);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300765 free(err);
766 return -1;
767 }
768
769 shmctl(output->shm_id, IPC_RMID, NULL);
770
771 /* Now create pixman image */
772 output->hw_surface = pixman_image_create_bits(pixman_format, width, height, output->buf,
773 width * (bitsperpixel / 8));
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300774
Giulio Camuffo954f1832014-10-11 18:27:30 +0300775 output->gc = xcb_generate_id(b->conn);
776 xcb_create_gc(b->conn, output->gc, output->window, 0, NULL);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300777
778 return 0;
779}
780
Scott Moreau1bad5db2012-08-18 01:04:05 -0600781static struct x11_output *
Giulio Camuffo954f1832014-10-11 18:27:30 +0300782x11_backend_create_output(struct x11_backend *b, int x, int y,
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300783 int width, int height, int fullscreen,
Scott Moreau1bad5db2012-08-18 01:04:05 -0600784 int no_input, char *configured_name,
Alexander Larssonedddbd12013-05-24 13:09:43 +0200785 uint32_t transform, int32_t scale)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400786{
Scott Moreau1bad5db2012-08-18 01:04:05 -0600787 static const char name[] = "Weston Compositor";
Kristian Høgsberg86000402012-01-03 23:24:14 -0500788 static const char class[] = "weston-1\0Weston Compositor";
Scott Moreau1bad5db2012-08-18 01:04:05 -0600789 char title[32];
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400790 struct x11_output *output;
Marko61b4d3e2015-10-05 17:27:54 -0500791 xcb_screen_t *screen;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400792 struct wm_normal_hints normal_hints;
Kristian Høgsberg06a670f2011-10-29 14:39:13 -0400793 struct wl_event_loop *loop;
Kristian Høgsberg8404acb2014-03-18 12:15:42 -0700794 int output_width, output_height, width_mm, height_mm;
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300795 int ret;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400796 uint32_t mask = XCB_CW_EVENT_MASK | XCB_CW_CURSOR;
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500797 xcb_atom_t atom_list[1];
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300798 uint32_t values[2] = {
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400799 XCB_EVENT_MASK_EXPOSURE |
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300800 XCB_EVENT_MASK_STRUCTURE_NOTIFY,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400801 0
802 };
803
Alexander Larsson4ea95522013-05-22 14:41:37 +0200804 output_width = width * scale;
805 output_height = height * scale;
806
Scott Moreau1bad5db2012-08-18 01:04:05 -0600807 if (configured_name)
808 sprintf(title, "%s - %s", name, configured_name);
809 else
810 strcpy(title, name);
811
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300812 if (!no_input)
813 values[0] |=
814 XCB_EVENT_MASK_KEY_PRESS |
815 XCB_EVENT_MASK_KEY_RELEASE |
816 XCB_EVENT_MASK_BUTTON_PRESS |
817 XCB_EVENT_MASK_BUTTON_RELEASE |
818 XCB_EVENT_MASK_POINTER_MOTION |
819 XCB_EVENT_MASK_ENTER_WINDOW |
820 XCB_EVENT_MASK_LEAVE_WINDOW |
821 XCB_EVENT_MASK_KEYMAP_STATE |
822 XCB_EVENT_MASK_FOCUS_CHANGE;
823
Peter Huttererf3d62272013-08-08 11:57:05 +1000824 output = zalloc(sizeof *output);
Bryce Harrington665b0252015-05-26 18:14:21 -0700825 if (output == NULL) {
826 perror("zalloc");
Scott Moreau1bad5db2012-08-18 01:04:05 -0600827 return NULL;
Bryce Harrington665b0252015-05-26 18:14:21 -0700828 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400829
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400830 output->mode.flags =
831 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
Alexander Larsson4ea95522013-05-22 14:41:37 +0200832
Alexander Larsson0b135062013-05-28 16:23:36 +0200833 output->mode.width = output_width;
834 output->mode.height = output_height;
Kristian Høgsbergc4621b02012-05-10 12:23:53 -0400835 output->mode.refresh = 60000;
Alexander Larsson4ea95522013-05-22 14:41:37 +0200836 output->scale = scale;
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400837 wl_list_init(&output->base.mode_list);
838 wl_list_insert(&output->base.mode_list, &output->mode.link);
839
Giulio Camuffo954f1832014-10-11 18:27:30 +0300840 values[1] = b->null_cursor;
841 output->window = xcb_generate_id(b->conn);
Marko61b4d3e2015-10-05 17:27:54 -0500842 screen = x11_compositor_get_default_screen(b);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300843 xcb_create_window(b->conn,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400844 XCB_COPY_FROM_PARENT,
845 output->window,
Marko61b4d3e2015-10-05 17:27:54 -0500846 screen->root,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400847 0, 0,
Alexander Larsson4ea95522013-05-22 14:41:37 +0200848 output_width, output_height,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400849 0,
850 XCB_WINDOW_CLASS_INPUT_OUTPUT,
Marko61b4d3e2015-10-05 17:27:54 -0500851 screen->root_visual,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400852 mask, values);
853
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500854 if (fullscreen) {
Giulio Camuffo954f1832014-10-11 18:27:30 +0300855 atom_list[0] = b->atom.net_wm_state_fullscreen;
856 xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE,
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500857 output->window,
Giulio Camuffo954f1832014-10-11 18:27:30 +0300858 b->atom.net_wm_state,
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500859 XCB_ATOM_ATOM, 32,
860 ARRAY_LENGTH(atom_list), atom_list);
861 } else {
862 /* Don't resize me. */
863 memset(&normal_hints, 0, sizeof normal_hints);
864 normal_hints.flags =
865 WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE;
Alexander Larsson4ea95522013-05-22 14:41:37 +0200866 normal_hints.min_width = output_width;
867 normal_hints.min_height = output_height;
868 normal_hints.max_width = output_width;
869 normal_hints.max_height = output_height;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300870 xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window,
871 b->atom.wm_normal_hints,
872 b->atom.wm_size_hints, 32,
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500873 sizeof normal_hints / 4,
874 (uint8_t *) &normal_hints);
875 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400876
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400877 /* Set window name. Don't bother with non-EWMH WMs. */
Giulio Camuffo954f1832014-10-11 18:27:30 +0300878 xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window,
879 b->atom.net_wm_name, b->atom.utf8_string, 8,
Scott Moreau1bad5db2012-08-18 01:04:05 -0600880 strlen(title), title);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300881 xcb_change_property(b->conn, XCB_PROP_MODE_REPLACE, output->window,
882 b->atom.wm_class, b->atom.string, 8,
Kristian Høgsberg24ed6212011-01-26 14:02:31 -0500883 sizeof class, class);
884
Giulio Camuffo954f1832014-10-11 18:27:30 +0300885 x11_output_set_icon(b, output, DATADIR "/weston/wayland.png");
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500886
Giulio Camuffo954f1832014-10-11 18:27:30 +0300887 x11_output_set_wm_protocols(b, output);
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500888
Giulio Camuffo954f1832014-10-11 18:27:30 +0300889 xcb_map_window(b->conn, output->window);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400890
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -0500891 if (fullscreen)
Giulio Camuffo954f1832014-10-11 18:27:30 +0300892 x11_output_wait_for_map(b, output);
Kristian Høgsberg83eeacb2011-06-18 04:20:54 -0400893
Jonas Ådahle5a12252013-04-05 23:07:11 +0200894 output->base.start_repaint_loop = x11_output_start_repaint_loop;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300895 if (b->use_pixman)
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300896 output->base.repaint = x11_output_repaint_shm;
897 else
898 output->base.repaint = x11_output_repaint_gl;
Matt Roper361d2ad2011-08-29 13:52:23 -0700899 output->base.destroy = x11_output_destroy;
Jesse Barnes5308a5e2012-02-09 13:12:57 -0800900 output->base.assign_planes = NULL;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +0200901 output->base.set_backlight = NULL;
902 output->base.set_dpms = NULL;
Alex Wu2dda6042012-04-17 17:20:47 +0800903 output->base.switch_mode = NULL;
Hardeningff39efa2013-09-18 23:56:35 +0200904 output->base.current_mode = &output->mode;
Jason Ekstrand22e16b62014-09-15 12:10:27 -0700905 output->base.make = "weston-X11";
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500906 output->base.model = "none";
Ander Conselvan de Oliveirad4ea71e2013-12-18 19:51:40 +0200907
908 if (configured_name)
909 output->base.name = strdup(configured_name);
910
Giulio Camuffo954f1832014-10-11 18:27:30 +0300911 width_mm = width * b->screen->width_in_millimeters /
912 b->screen->width_in_pixels;
913 height_mm = height * b->screen->height_in_millimeters /
914 b->screen->height_in_pixels;
915 weston_output_init(&output->base, b->compositor,
Kristian Høgsberg8404acb2014-03-18 12:15:42 -0700916 x, y, width_mm, height_mm, transform, scale);
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +0100917
Giulio Camuffo954f1832014-10-11 18:27:30 +0300918 if (b->use_pixman) {
919 if (x11_output_init_shm(b, output,
Kristian Høgsbergb5a4f982013-10-23 23:38:50 -0700920 output->mode.width,
Bryce Harrington665b0252015-05-26 18:14:21 -0700921 output->mode.height) < 0) {
922 weston_log("Failed to initialize SHM for the X11 output\n");
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300923 return NULL;
Bryce Harrington665b0252015-05-26 18:14:21 -0700924 }
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300925 if (pixman_renderer_output_create(&output->base) < 0) {
Bryce Harrington665b0252015-05-26 18:14:21 -0700926 weston_log("Failed to create pixman renderer for output\n");
Giulio Camuffo954f1832014-10-11 18:27:30 +0300927 x11_output_deinit_shm(b, output);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300928 return NULL;
929 }
930 } else {
Jonny Lamb671148f2015-03-20 15:26:52 +0100931 /* eglCreatePlatformWindowSurfaceEXT takes a Window*
932 * but eglCreateWindowSurface takes a Window. */
933 Window xid = (Window) output->window;
934
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300935 ret = gl_renderer->output_create(&output->base,
Neil Roberts77c1a5b2014-03-07 18:05:50 +0000936 (EGLNativeWindowType) output->window,
Jonny Lamb671148f2015-03-20 15:26:52 +0100937 &xid,
Neil Roberts77c1a5b2014-03-07 18:05:50 +0000938 gl_renderer->opaque_attribs,
Derek Foremane76f1852015-05-15 12:12:39 -0500939 NULL,
940 0);
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300941 if (ret < 0)
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300942 return NULL;
943 }
John Kåre Alsaker94659272012-11-13 19:10:18 +0100944
Giulio Camuffo954f1832014-10-11 18:27:30 +0300945 loop = wl_display_get_event_loop(b->compositor->wl_display);
John Kåre Alsaker94659272012-11-13 19:10:18 +0100946 output->finish_frame_timer =
947 wl_event_loop_add_timer(loop, finish_frame_handler, output);
948
Giulio Camuffo954f1832014-10-11 18:27:30 +0300949 weston_compositor_add_output(b->compositor, &output->base);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400950
Kristian Høgsbergfc9c5e02012-06-08 16:45:33 -0400951 weston_log("x11 output %dx%d, window id %d\n",
952 width, height, output->window);
953
Scott Moreau1bad5db2012-08-18 01:04:05 -0600954 return output;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400955}
956
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400957static struct x11_output *
Giulio Camuffo954f1832014-10-11 18:27:30 +0300958x11_backend_find_output(struct x11_backend *b, xcb_window_t window)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400959{
960 struct x11_output *output;
961
Giulio Camuffo954f1832014-10-11 18:27:30 +0300962 wl_list_for_each(output, &b->compositor->output_list, base.link) {
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400963 if (output->window == window)
964 return output;
965 }
966
Derek Foreman99bfa642014-12-11 15:44:46 -0600967 return NULL;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400968}
969
Ander Conselvan de Oliveiraf54fa4d2013-12-13 22:10:49 +0200970static void
Giulio Camuffo954f1832014-10-11 18:27:30 +0300971x11_backend_delete_window(struct x11_backend *b, xcb_window_t window)
Ander Conselvan de Oliveiraf54fa4d2013-12-13 22:10:49 +0200972{
Zhang, Xiong Ya4b54c02013-12-13 22:10:51 +0200973 struct x11_output *output;
Ander Conselvan de Oliveiraf54fa4d2013-12-13 22:10:49 +0200974
Giulio Camuffo954f1832014-10-11 18:27:30 +0300975 output = x11_backend_find_output(b, window);
Derek Foreman99bfa642014-12-11 15:44:46 -0600976 if (output)
977 x11_output_destroy(&output->base);
Ander Conselvan de Oliveiraf54fa4d2013-12-13 22:10:49 +0200978
Giulio Camuffo954f1832014-10-11 18:27:30 +0300979 xcb_flush(b->conn);
Ander Conselvan de Oliveiraf54fa4d2013-12-13 22:10:49 +0200980
Giulio Camuffo954f1832014-10-11 18:27:30 +0300981 if (wl_list_empty(&b->compositor->output_list))
Giulio Camuffo459137b2014-10-11 23:56:24 +0300982 weston_compositor_exit(b->compositor);
Ander Conselvan de Oliveiraf54fa4d2013-12-13 22:10:49 +0200983}
984
Derek Foremand540f4b2015-01-27 16:26:49 -0600985static void delete_cb(void *data)
986{
987 struct window_delete_data *wd = data;
988
Giulio Camuffo954f1832014-10-11 18:27:30 +0300989 x11_backend_delete_window(wd->backend, wd->window);
Derek Foremand540f4b2015-01-27 16:26:49 -0600990 free(wd);
991}
992
Daniel Stone154c34c2012-06-22 13:21:40 +0100993#ifdef HAVE_XCB_XKB
Daniel Stonee2faa122012-06-22 13:21:39 +0100994static void
Giulio Camuffo954f1832014-10-11 18:27:30 +0300995update_xkb_state(struct x11_backend *b, xcb_xkb_state_notify_event_t *state)
Daniel Stonee2faa122012-06-22 13:21:39 +0100996{
Derek Foreman1281a362015-07-31 16:55:32 -0500997 struct weston_keyboard *keyboard =
998 weston_seat_get_keyboard(&b->core_seat);
999
1000 xkb_state_update_mask(keyboard->xkb_state.state,
Giulio Camuffo954f1832014-10-11 18:27:30 +03001001 get_xkb_mod_mask(b, state->baseMods),
1002 get_xkb_mod_mask(b, state->latchedMods),
1003 get_xkb_mod_mask(b, state->lockedMods),
Daniel Stonee2faa122012-06-22 13:21:39 +01001004 0,
1005 0,
1006 state->group);
1007
Giulio Camuffo954f1832014-10-11 18:27:30 +03001008 notify_modifiers(&b->core_seat,
1009 wl_display_next_serial(b->compositor->wl_display));
Daniel Stonee2faa122012-06-22 13:21:39 +01001010}
1011#endif
1012
Daniel Stone154c34c2012-06-22 13:21:40 +01001013/**
1014 * This is monumentally unpleasant. If we don't have XCB-XKB bindings,
1015 * the best we can do (given that XCB also lacks XI2 support), is to take
1016 * the state from the core key events. Unfortunately that only gives us
1017 * the effective (i.e. union of depressed/latched/locked) state, and we
1018 * need the granularity.
1019 *
1020 * So we still update the state with every key event we see, but also use
1021 * the state field from X11 events as a mask so we don't get any stuck
1022 * modifiers.
1023 */
1024static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03001025update_xkb_state_from_core(struct x11_backend *b, uint16_t x11_mask)
Daniel Stone154c34c2012-06-22 13:21:40 +01001026{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001027 uint32_t mask = get_xkb_mod_mask(b, x11_mask);
Derek Foreman1281a362015-07-31 16:55:32 -05001028 struct weston_keyboard *keyboard
1029 = weston_seat_get_keyboard(&b->core_seat);
Daniel Stone154c34c2012-06-22 13:21:40 +01001030
Derek Foreman1281a362015-07-31 16:55:32 -05001031 xkb_state_update_mask(keyboard->xkb_state.state,
Daniel Stone154c34c2012-06-22 13:21:40 +01001032 keyboard->modifiers.mods_depressed & mask,
1033 keyboard->modifiers.mods_latched & mask,
1034 keyboard->modifiers.mods_locked & mask,
1035 0,
1036 0,
1037 (x11_mask >> 13) & 3);
Giulio Camuffo954f1832014-10-11 18:27:30 +03001038 notify_modifiers(&b->core_seat,
1039 wl_display_next_serial(b->compositor->wl_display));
Daniel Stone154c34c2012-06-22 13:21:40 +01001040}
1041
Tiago Vignattia3a71622011-12-08 17:03:17 +02001042static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03001043x11_backend_deliver_button_event(struct x11_backend *b,
1044 xcb_generic_event_t *event, int state)
Tiago Vignattia3a71622011-12-08 17:03:17 +02001045{
1046 xcb_button_press_event_t *button_event =
1047 (xcb_button_press_event_t *) event;
Daniel Stone5d663712012-05-04 11:21:55 +01001048 uint32_t button;
Kristian Høgsberg73308622012-10-30 11:04:52 -04001049 struct x11_output *output;
Peter Hutterer89b6a492016-01-18 15:58:17 +10001050 struct weston_pointer_axis_event weston_event;
Kristian Høgsberg73308622012-10-30 11:04:52 -04001051
Giulio Camuffo954f1832014-10-11 18:27:30 +03001052 output = x11_backend_find_output(b, button_event->event);
Derek Foreman99bfa642014-12-11 15:44:46 -06001053 if (!output)
1054 return;
Kristian Høgsberg73308622012-10-30 11:04:52 -04001055
1056 if (state)
Giulio Camuffo954f1832014-10-11 18:27:30 +03001057 xcb_grab_pointer(b->conn, 0, output->window,
Kristian Høgsberg73308622012-10-30 11:04:52 -04001058 XCB_EVENT_MASK_BUTTON_PRESS |
1059 XCB_EVENT_MASK_BUTTON_RELEASE |
1060 XCB_EVENT_MASK_POINTER_MOTION |
1061 XCB_EVENT_MASK_ENTER_WINDOW |
1062 XCB_EVENT_MASK_LEAVE_WINDOW,
1063 XCB_GRAB_MODE_ASYNC,
1064 XCB_GRAB_MODE_ASYNC,
1065 output->window, XCB_CURSOR_NONE,
1066 button_event->time);
1067 else
Giulio Camuffo954f1832014-10-11 18:27:30 +03001068 xcb_ungrab_pointer(b->conn, button_event->time);
Tiago Vignattia3a71622011-12-08 17:03:17 +02001069
Giulio Camuffo954f1832014-10-11 18:27:30 +03001070 if (!b->has_xkb)
1071 update_xkb_state_from_core(b, button_event->state);
Daniel Stone154c34c2012-06-22 13:21:40 +01001072
Tiago Vignattia3a71622011-12-08 17:03:17 +02001073 switch (button_event->detail) {
Dima Ryazanov3e4d4bd2015-02-04 01:51:57 -08001074 case 1:
1075 button = BTN_LEFT;
Tiago Vignattia3a71622011-12-08 17:03:17 +02001076 break;
1077 case 2:
1078 button = BTN_MIDDLE;
1079 break;
1080 case 3:
1081 button = BTN_RIGHT;
1082 break;
1083 case 4:
Jonas Ådahl62efe202012-09-27 18:40:41 +02001084 /* Axis are measured in pixels, but the xcb events are discrete
1085 * steps. Therefore move the axis by some pixels every step. */
Peter Hutterer89b6a492016-01-18 15:58:17 +10001086 if (state) {
1087 weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE;
Peter Hutterer87743e92016-01-18 16:38:22 +10001088 weston_event.discrete = -1;
1089 weston_event.has_discrete = true;
Peter Hutterer89b6a492016-01-18 15:58:17 +10001090 weston_event.axis =
1091 WL_POINTER_AXIS_VERTICAL_SCROLL;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001092 notify_axis(&b->core_seat,
Jonas Ådahl62efe202012-09-27 18:40:41 +02001093 weston_compositor_get_time(),
Peter Hutterer89b6a492016-01-18 15:58:17 +10001094 &weston_event);
Marek Chalupa345b4f52016-02-03 14:03:00 +01001095 notify_pointer_frame(&b->core_seat);
Peter Hutterer89b6a492016-01-18 15:58:17 +10001096 }
Scott Moreau210d0792012-03-22 10:47:01 -06001097 return;
Tiago Vignattia3a71622011-12-08 17:03:17 +02001098 case 5:
Peter Hutterer89b6a492016-01-18 15:58:17 +10001099 if (state) {
1100 weston_event.value = DEFAULT_AXIS_STEP_DISTANCE;
Peter Hutterer87743e92016-01-18 16:38:22 +10001101 weston_event.discrete = 1;
1102 weston_event.has_discrete = true;
Peter Hutterer89b6a492016-01-18 15:58:17 +10001103 weston_event.axis =
1104 WL_POINTER_AXIS_VERTICAL_SCROLL;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001105 notify_axis(&b->core_seat,
Jonas Ådahl62efe202012-09-27 18:40:41 +02001106 weston_compositor_get_time(),
Peter Hutterer89b6a492016-01-18 15:58:17 +10001107 &weston_event);
Marek Chalupa345b4f52016-02-03 14:03:00 +01001108 notify_pointer_frame(&b->core_seat);
Peter Hutterer89b6a492016-01-18 15:58:17 +10001109 }
Scott Moreau210d0792012-03-22 10:47:01 -06001110 return;
Tiago Vignattia3a71622011-12-08 17:03:17 +02001111 case 6:
Peter Hutterer89b6a492016-01-18 15:58:17 +10001112 if (state) {
1113 weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE;
Peter Hutterer87743e92016-01-18 16:38:22 +10001114 weston_event.discrete = -1;
1115 weston_event.has_discrete = true;
Peter Hutterer89b6a492016-01-18 15:58:17 +10001116 weston_event.axis =
1117 WL_POINTER_AXIS_HORIZONTAL_SCROLL;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001118 notify_axis(&b->core_seat,
Jonas Ådahl62efe202012-09-27 18:40:41 +02001119 weston_compositor_get_time(),
Peter Hutterer89b6a492016-01-18 15:58:17 +10001120 &weston_event);
Marek Chalupa345b4f52016-02-03 14:03:00 +01001121 notify_pointer_frame(&b->core_seat);
Peter Hutterer89b6a492016-01-18 15:58:17 +10001122 }
Scott Moreau210d0792012-03-22 10:47:01 -06001123 return;
Tiago Vignattia3a71622011-12-08 17:03:17 +02001124 case 7:
Peter Hutterer89b6a492016-01-18 15:58:17 +10001125 if (state) {
1126 weston_event.value = DEFAULT_AXIS_STEP_DISTANCE;
Peter Hutterer87743e92016-01-18 16:38:22 +10001127 weston_event.discrete = 1;
1128 weston_event.has_discrete = true;
Peter Hutterer89b6a492016-01-18 15:58:17 +10001129 weston_event.axis =
1130 WL_POINTER_AXIS_HORIZONTAL_SCROLL;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001131 notify_axis(&b->core_seat,
Jonas Ådahl62efe202012-09-27 18:40:41 +02001132 weston_compositor_get_time(),
Peter Hutterer89b6a492016-01-18 15:58:17 +10001133 &weston_event);
Marek Chalupa345b4f52016-02-03 14:03:00 +01001134 notify_pointer_frame(&b->core_seat);
Peter Hutterer89b6a492016-01-18 15:58:17 +10001135 }
Tiago Vignattia3a71622011-12-08 17:03:17 +02001136 return;
Dima Ryazanov3e4d4bd2015-02-04 01:51:57 -08001137 default:
1138 button = button_event->detail + BTN_SIDE - 8;
1139 break;
Tiago Vignattia3a71622011-12-08 17:03:17 +02001140 }
1141
Giulio Camuffo954f1832014-10-11 18:27:30 +03001142 notify_button(&b->core_seat,
Daniel Stone4dbadb12012-05-30 16:31:51 +01001143 weston_compositor_get_time(), button,
1144 state ? WL_POINTER_BUTTON_STATE_PRESSED :
1145 WL_POINTER_BUTTON_STATE_RELEASED);
Peter Hutterer87743e92016-01-18 16:38:22 +10001146 notify_pointer_frame(&b->core_seat);
Tiago Vignattia3a71622011-12-08 17:03:17 +02001147}
1148
Scott Moreau1bad5db2012-08-18 01:04:05 -06001149static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03001150x11_backend_deliver_motion_event(struct x11_backend *b,
1151 xcb_generic_event_t *event)
Scott Moreau1bad5db2012-08-18 01:04:05 -06001152{
1153 struct x11_output *output;
1154 wl_fixed_t x, y;
Jonas Ådahld2510102014-10-05 21:39:14 +02001155 struct weston_pointer_motion_event motion_event = { 0 };
Scott Moreau1bad5db2012-08-18 01:04:05 -06001156 xcb_motion_notify_event_t *motion_notify =
1157 (xcb_motion_notify_event_t *) event;
1158
Giulio Camuffo954f1832014-10-11 18:27:30 +03001159 if (!b->has_xkb)
1160 update_xkb_state_from_core(b, motion_notify->state);
1161 output = x11_backend_find_output(b, motion_notify->event);
Derek Foreman99bfa642014-12-11 15:44:46 -06001162 if (!output)
1163 return;
1164
Kristian Høgsberg98c774f2013-07-22 14:33:42 -07001165 weston_output_transform_coordinate(&output->base,
Jason Ekstrandb6a3cc72013-10-27 22:25:00 -05001166 wl_fixed_from_int(motion_notify->event_x),
1167 wl_fixed_from_int(motion_notify->event_y),
1168 &x, &y);
Scott Moreau1bad5db2012-08-18 01:04:05 -06001169
Jonas Ådahld2510102014-10-05 21:39:14 +02001170 motion_event = (struct weston_pointer_motion_event) {
1171 .mask = WESTON_POINTER_MOTION_REL,
1172 .dx = wl_fixed_to_double(x - b->prev_x),
1173 .dy = wl_fixed_to_double(y - b->prev_y)
1174 };
1175
Giulio Camuffo954f1832014-10-11 18:27:30 +03001176 notify_motion(&b->core_seat, weston_compositor_get_time(),
Jonas Ådahld2510102014-10-05 21:39:14 +02001177 &motion_event);
Peter Hutterer87743e92016-01-18 16:38:22 +10001178 notify_pointer_frame(&b->core_seat);
Kristian Høgsberg50065962013-03-27 15:14:07 -04001179
Giulio Camuffo954f1832014-10-11 18:27:30 +03001180 b->prev_x = x;
1181 b->prev_y = y;
Scott Moreau1bad5db2012-08-18 01:04:05 -06001182}
1183
1184static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03001185x11_backend_deliver_enter_event(struct x11_backend *b,
1186 xcb_generic_event_t *event)
Scott Moreau1bad5db2012-08-18 01:04:05 -06001187{
1188 struct x11_output *output;
1189 wl_fixed_t x, y;
1190
1191 xcb_enter_notify_event_t *enter_notify =
1192 (xcb_enter_notify_event_t *) event;
1193 if (enter_notify->state >= Button1Mask)
1194 return;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001195 if (!b->has_xkb)
1196 update_xkb_state_from_core(b, enter_notify->state);
1197 output = x11_backend_find_output(b, enter_notify->event);
Derek Foreman99bfa642014-12-11 15:44:46 -06001198 if (!output)
1199 return;
1200
Kristian Høgsberg98c774f2013-07-22 14:33:42 -07001201 weston_output_transform_coordinate(&output->base,
Jason Ekstrandb6a3cc72013-10-27 22:25:00 -05001202 wl_fixed_from_int(enter_notify->event_x),
1203 wl_fixed_from_int(enter_notify->event_y), &x, &y);
Scott Moreau1bad5db2012-08-18 01:04:05 -06001204
Giulio Camuffo954f1832014-10-11 18:27:30 +03001205 notify_pointer_focus(&b->core_seat, &output->base, x, y);
Kristian Høgsberg50065962013-03-27 15:14:07 -04001206
Giulio Camuffo954f1832014-10-11 18:27:30 +03001207 b->prev_x = x;
1208 b->prev_y = y;
Scott Moreau1bad5db2012-08-18 01:04:05 -06001209}
1210
Kristian Høgsbergee724822011-04-21 14:51:44 -04001211static int
Giulio Camuffo954f1832014-10-11 18:27:30 +03001212x11_backend_next_event(struct x11_backend *b,
1213 xcb_generic_event_t **event, uint32_t mask)
Kristian Høgsbergee724822011-04-21 14:51:44 -04001214{
Kristian Høgsberg127d0f02011-04-22 12:18:13 -04001215 if (mask & WL_EVENT_READABLE) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001216 *event = xcb_poll_for_event(b->conn);
Kristian Høgsbergee724822011-04-21 14:51:44 -04001217 } else {
Kristian Høgsberg82ed0422011-04-25 15:41:59 -04001218#ifdef HAVE_XCB_POLL_FOR_QUEUED_EVENT
Giulio Camuffo954f1832014-10-11 18:27:30 +03001219 *event = xcb_poll_for_queued_event(b->conn);
Kristian Høgsberg82ed0422011-04-25 15:41:59 -04001220#else
Giulio Camuffo954f1832014-10-11 18:27:30 +03001221 *event = xcb_poll_for_event(b->conn);
Kristian Høgsberg82ed0422011-04-25 15:41:59 -04001222#endif
Kristian Høgsbergee724822011-04-21 14:51:44 -04001223 }
1224
1225 return *event != NULL;
1226}
1227
Kristian Høgsberg127d0f02011-04-22 12:18:13 -04001228static int
Giulio Camuffo954f1832014-10-11 18:27:30 +03001229x11_backend_handle_event(int fd, uint32_t mask, void *data)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001230{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001231 struct x11_backend *b = data;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001232 struct x11_output *output;
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001233 xcb_generic_event_t *event, *prev;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001234 xcb_client_message_event_t *client_message;
Kristian Høgsberg93331ff2011-01-26 20:35:07 -05001235 xcb_enter_notify_event_t *enter_notify;
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001236 xcb_key_press_event_t *key_press, *key_release;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001237 xcb_keymap_notify_event_t *keymap_notify;
1238 xcb_focus_in_event_t *focus_in;
Kristian Høgsberg49952d12012-06-20 00:35:59 -04001239 xcb_expose_event_t *expose;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001240 xcb_atom_t atom;
Ander Conselvan de Oliveiraf54fa4d2013-12-13 22:10:49 +02001241 xcb_window_t window;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001242 uint32_t *k;
Kristian Høgsberg875ab9e2012-03-30 11:52:39 -04001243 uint32_t i, set;
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001244 uint8_t response_type;
Bill Spitzakb715cec2012-06-05 17:08:23 -04001245 int count;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001246
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001247 prev = NULL;
Bill Spitzakb715cec2012-06-05 17:08:23 -04001248 count = 0;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001249 while (x11_backend_next_event(b, &event, mask)) {
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001250 response_type = event->response_type & ~0x80;
1251
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001252 switch (prev ? prev->response_type & ~0x80 : 0x80) {
1253 case XCB_KEY_RELEASE:
Daniel Stone3ee91e12012-06-22 13:21:36 +01001254 /* Suppress key repeat events; this is only used if we
1255 * don't have XCB XKB support. */
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001256 key_release = (xcb_key_press_event_t *) prev;
1257 key_press = (xcb_key_press_event_t *) event;
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001258 if (response_type == XCB_KEY_PRESS &&
Dima Ryazanovc2247482011-08-16 17:25:32 -07001259 key_release->time == key_press->time &&
1260 key_release->detail == key_press->detail) {
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001261 /* Don't deliver the held key release
1262 * event or the new key press event. */
1263 free(event);
1264 free(prev);
1265 prev = NULL;
1266 continue;
1267 } else {
1268 /* Deliver the held key release now
1269 * and fall through and handle the new
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001270 * event below. */
Giulio Camuffo954f1832014-10-11 18:27:30 +03001271 update_xkb_state_from_core(b, key_release->state);
1272 notify_key(&b->core_seat,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001273 weston_compositor_get_time(),
Daniel Stonec9785ea2012-05-30 16:31:52 +01001274 key_release->detail - 8,
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001275 WL_KEYBOARD_KEY_STATE_RELEASED,
1276 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001277 free(prev);
1278 prev = NULL;
1279 break;
1280 }
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001281
1282 case XCB_FOCUS_IN:
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001283 assert(response_type == XCB_KEYMAP_NOTIFY);
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001284 keymap_notify = (xcb_keymap_notify_event_t *) event;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001285 b->keys.size = 0;
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001286 for (i = 0; i < ARRAY_LENGTH(keymap_notify->keys) * 8; i++) {
1287 set = keymap_notify->keys[i >> 3] &
1288 (1 << (i & 7));
1289 if (set) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001290 k = wl_array_add(&b->keys, sizeof *k);
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001291 *k = i;
1292 }
1293 }
1294
Daniel Stoned6da09e2012-06-22 13:21:29 +01001295 /* Unfortunately the state only comes with the enter
1296 * event, rather than with the focus event. I'm not
1297 * sure of the exact semantics around it and whether
1298 * we can ensure that we get both? */
Giulio Camuffo954f1832014-10-11 18:27:30 +03001299 notify_keyboard_focus_in(&b->core_seat, &b->keys,
Daniel Stoned6da09e2012-06-22 13:21:29 +01001300 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001301
1302 free(prev);
1303 prev = NULL;
1304 break;
1305
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001306 default:
1307 /* No previous event held */
1308 break;
Kristian Høgsberg3ddd1482011-04-15 15:48:07 -04001309 }
1310
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001311 switch (response_type) {
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001312 case XCB_KEY_PRESS:
1313 key_press = (xcb_key_press_event_t *) event;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001314 if (!b->has_xkb)
1315 update_xkb_state_from_core(b, key_press->state);
1316 notify_key(&b->core_seat,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001317 weston_compositor_get_time(),
Daniel Stonec9785ea2012-05-30 16:31:52 +01001318 key_press->detail - 8,
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001319 WL_KEYBOARD_KEY_STATE_PRESSED,
Giulio Camuffo954f1832014-10-11 18:27:30 +03001320 b->has_xkb ? STATE_UPDATE_NONE :
Daniel Stonee2faa122012-06-22 13:21:39 +01001321 STATE_UPDATE_AUTOMATIC);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001322 break;
1323 case XCB_KEY_RELEASE:
Daniel Stone3ee91e12012-06-22 13:21:36 +01001324 /* If we don't have XKB, we need to use the lame
1325 * autorepeat detection above. */
Giulio Camuffo954f1832014-10-11 18:27:30 +03001326 if (!b->has_xkb) {
Daniel Stone3ee91e12012-06-22 13:21:36 +01001327 prev = event;
1328 break;
1329 }
1330 key_release = (xcb_key_press_event_t *) event;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001331 notify_key(&b->core_seat,
Daniel Stone3ee91e12012-06-22 13:21:36 +01001332 weston_compositor_get_time(),
1333 key_release->detail - 8,
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001334 WL_KEYBOARD_KEY_STATE_RELEASED,
Daniel Stonee2faa122012-06-22 13:21:39 +01001335 STATE_UPDATE_NONE);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001336 break;
1337 case XCB_BUTTON_PRESS:
Giulio Camuffo954f1832014-10-11 18:27:30 +03001338 x11_backend_deliver_button_event(b, event, 1);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001339 break;
1340 case XCB_BUTTON_RELEASE:
Giulio Camuffo954f1832014-10-11 18:27:30 +03001341 x11_backend_deliver_button_event(b, event, 0);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001342 break;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001343 case XCB_MOTION_NOTIFY:
Giulio Camuffo954f1832014-10-11 18:27:30 +03001344 x11_backend_deliver_motion_event(b, event);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001345 break;
1346
1347 case XCB_EXPOSE:
Kristian Høgsberg49952d12012-06-20 00:35:59 -04001348 expose = (xcb_expose_event_t *) event;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001349 output = x11_backend_find_output(b, expose->window);
Derek Foreman99bfa642014-12-11 15:44:46 -06001350 if (!output)
1351 break;
1352
Kristian Høgsberga98c2e12013-12-05 12:30:37 -08001353 weston_output_damage(&output->base);
Kristian Høgsberg49952d12012-06-20 00:35:59 -04001354 weston_output_schedule_repaint(&output->base);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001355 break;
Kristian Høgsberg86e09892010-07-07 09:51:11 -04001356
1357 case XCB_ENTER_NOTIFY:
Giulio Camuffo954f1832014-10-11 18:27:30 +03001358 x11_backend_deliver_enter_event(b, event);
Kristian Høgsberg86e09892010-07-07 09:51:11 -04001359 break;
1360
1361 case XCB_LEAVE_NOTIFY:
Kristian Høgsberg93331ff2011-01-26 20:35:07 -05001362 enter_notify = (xcb_enter_notify_event_t *) event;
Kristian Høgsberg2dfe6262011-02-08 11:59:53 -05001363 if (enter_notify->state >= Button1Mask)
1364 break;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001365 if (!b->has_xkb)
1366 update_xkb_state_from_core(b, enter_notify->state);
1367 notify_pointer_focus(&b->core_seat, NULL, 0, 0);
Kristian Høgsberg86e09892010-07-07 09:51:11 -04001368 break;
1369
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001370 case XCB_CLIENT_MESSAGE:
1371 client_message = (xcb_client_message_event_t *) event;
1372 atom = client_message->data.data32[0];
Ander Conselvan de Oliveiraf54fa4d2013-12-13 22:10:49 +02001373 window = client_message->window;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001374 if (atom == b->atom.wm_delete_window) {
Derek Foremand540f4b2015-01-27 16:26:49 -06001375 struct wl_event_loop *loop;
1376 struct window_delete_data *data = malloc(sizeof *data);
1377
1378 /* if malloc failed we should at least try to
1379 * delete the window, even if it may result in
1380 * a crash.
1381 */
1382 if (!data) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001383 x11_backend_delete_window(b, window);
Derek Foremand540f4b2015-01-27 16:26:49 -06001384 break;
1385 }
Giulio Camuffo954f1832014-10-11 18:27:30 +03001386 data->backend = b;
Derek Foremand540f4b2015-01-27 16:26:49 -06001387 data->window = window;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001388 loop = wl_display_get_event_loop(b->compositor->wl_display);
Derek Foremand540f4b2015-01-27 16:26:49 -06001389 wl_event_loop_add_idle(loop, delete_cb, data);
1390 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001391 break;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001392
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001393 case XCB_FOCUS_IN:
1394 focus_in = (xcb_focus_in_event_t *) event;
1395 if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED)
1396 break;
1397
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001398 prev = event;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001399 break;
1400
1401 case XCB_FOCUS_OUT:
1402 focus_in = (xcb_focus_in_event_t *) event;
Kristian Høgsberg42e40ae2011-12-19 14:36:50 -05001403 if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED ||
1404 focus_in->mode == XCB_NOTIFY_MODE_UNGRAB)
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001405 break;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001406 notify_keyboard_focus_out(&b->core_seat);
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001407 break;
1408
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001409 default:
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001410 break;
1411 }
1412
Daniel Stonee2faa122012-06-22 13:21:39 +01001413#ifdef HAVE_XCB_XKB
Giulio Camuffo954f1832014-10-11 18:27:30 +03001414 if (b->has_xkb) {
1415 if (response_type == b->xkb_event_base) {
Rui Matosc6c2f8e2013-10-10 19:44:20 +02001416 xcb_xkb_state_notify_event_t *state =
1417 (xcb_xkb_state_notify_event_t *) event;
1418 if (state->xkbType == XCB_XKB_STATE_NOTIFY)
Giulio Camuffo954f1832014-10-11 18:27:30 +03001419 update_xkb_state(b, state);
Rui Matosc6c2f8e2013-10-10 19:44:20 +02001420 } else if (response_type == XCB_PROPERTY_NOTIFY) {
1421 xcb_property_notify_event_t *prop_notify =
1422 (xcb_property_notify_event_t *) event;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001423 if (prop_notify->window == b->screen->root &&
1424 prop_notify->atom == b->atom.xkb_names &&
Rui Matosc6c2f8e2013-10-10 19:44:20 +02001425 prop_notify->state == XCB_PROPERTY_NEW_VALUE)
Giulio Camuffo954f1832014-10-11 18:27:30 +03001426 update_xkb_keymap(b);
Rui Matosc6c2f8e2013-10-10 19:44:20 +02001427 }
Daniel Stonee2faa122012-06-22 13:21:39 +01001428 }
1429#endif
1430
Bill Spitzakb715cec2012-06-05 17:08:23 -04001431 count++;
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001432 if (prev != event)
Kristian Høgsberg3ddd1482011-04-15 15:48:07 -04001433 free (event);
1434 }
1435
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001436 switch (prev ? prev->response_type & ~0x80 : 0x80) {
1437 case XCB_KEY_RELEASE:
1438 key_release = (xcb_key_press_event_t *) prev;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001439 update_xkb_state_from_core(b, key_release->state);
1440 notify_key(&b->core_seat,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001441 weston_compositor_get_time(),
Daniel Stonec9785ea2012-05-30 16:31:52 +01001442 key_release->detail - 8,
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001443 WL_KEYBOARD_KEY_STATE_RELEASED,
1444 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001445 free(prev);
1446 prev = NULL;
1447 break;
1448 default:
1449 break;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001450 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001451
Bill Spitzakb715cec2012-06-05 17:08:23 -04001452 return count;
Kristian Høgsbergee724822011-04-21 14:51:44 -04001453}
1454
Giulio Camuffo954f1832014-10-11 18:27:30 +03001455#define F(field) offsetof(struct x11_backend, field)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001456
1457static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03001458x11_backend_get_resources(struct x11_backend *b)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001459{
1460 static const struct { const char *name; int offset; } atoms[] = {
1461 { "WM_PROTOCOLS", F(atom.wm_protocols) },
1462 { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) },
1463 { "WM_SIZE_HINTS", F(atom.wm_size_hints) },
1464 { "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
Kristian Høgsberg24ed6212011-01-26 14:02:31 -05001465 { "WM_CLASS", F(atom.wm_class) },
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001466 { "_NET_WM_NAME", F(atom.net_wm_name) },
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -05001467 { "_NET_WM_ICON", F(atom.net_wm_icon) },
Kristian Høgsberg83eeacb2011-06-18 04:20:54 -04001468 { "_NET_WM_STATE", F(atom.net_wm_state) },
1469 { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) },
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -05001470 { "_NET_SUPPORTING_WM_CHECK",
1471 F(atom.net_supporting_wm_check) },
1472 { "_NET_SUPPORTED", F(atom.net_supported) },
Kristian Høgsberg24ed6212011-01-26 14:02:31 -05001473 { "STRING", F(atom.string) },
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001474 { "UTF8_STRING", F(atom.utf8_string) },
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -05001475 { "CARDINAL", F(atom.cardinal) },
Daniel Stone855028f2012-05-01 20:37:10 +01001476 { "_XKB_RULES_NAMES", F(atom.xkb_names) },
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001477 };
1478
Kristian Høgsberg09e26922011-12-23 13:33:45 -05001479 xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001480 xcb_intern_atom_reply_t *reply;
1481 xcb_pixmap_t pixmap;
1482 xcb_gc_t gc;
Kristian Høgsberg875ab9e2012-03-30 11:52:39 -04001483 unsigned int i;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001484 uint8_t data[] = { 0, 0, 0, 0 };
1485
Kristian Høgsberg09e26922011-12-23 13:33:45 -05001486 for (i = 0; i < ARRAY_LENGTH(atoms); i++)
Giulio Camuffo954f1832014-10-11 18:27:30 +03001487 cookies[i] = xcb_intern_atom (b->conn, 0,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001488 strlen(atoms[i].name),
1489 atoms[i].name);
1490
Kristian Høgsberg09e26922011-12-23 13:33:45 -05001491 for (i = 0; i < ARRAY_LENGTH(atoms); i++) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001492 reply = xcb_intern_atom_reply (b->conn, cookies[i], NULL);
1493 *(xcb_atom_t *) ((char *) b + atoms[i].offset) = reply->atom;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001494 free(reply);
1495 }
1496
Giulio Camuffo954f1832014-10-11 18:27:30 +03001497 pixmap = xcb_generate_id(b->conn);
1498 gc = xcb_generate_id(b->conn);
1499 xcb_create_pixmap(b->conn, 1, pixmap, b->screen->root, 1, 1);
1500 xcb_create_gc(b->conn, gc, pixmap, 0, NULL);
1501 xcb_put_image(b->conn, XCB_IMAGE_FORMAT_XY_PIXMAP,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001502 pixmap, gc, 1, 1, 0, 0, 0, 32, sizeof data, data);
Giulio Camuffo954f1832014-10-11 18:27:30 +03001503 b->null_cursor = xcb_generate_id(b->conn);
1504 xcb_create_cursor (b->conn, b->null_cursor,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001505 pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1);
Giulio Camuffo954f1832014-10-11 18:27:30 +03001506 xcb_free_gc(b->conn, gc);
1507 xcb_free_pixmap(b->conn, pixmap);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001508}
1509
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001510static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03001511x11_backend_get_wm_info(struct x11_backend *c)
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -05001512{
1513 xcb_get_property_cookie_t cookie;
1514 xcb_get_property_reply_t *reply;
1515 xcb_atom_t *atom;
1516 unsigned int i;
1517
1518 cookie = xcb_get_property(c->conn, 0, c->screen->root,
1519 c->atom.net_supported,
1520 XCB_ATOM_ATOM, 0, 1024);
1521 reply = xcb_get_property_reply(c->conn, cookie, NULL);
1522 if (reply == NULL)
1523 return;
1524
1525 atom = (xcb_atom_t *) xcb_get_property_value(reply);
1526
1527 for (i = 0; i < reply->value_len; i++) {
1528 if (atom[i] == c->atom.net_wm_state_fullscreen)
1529 c->has_net_wm_state_fullscreen = 1;
1530 }
Ryo Munakata76fb7ec2015-03-08 19:17:06 +09001531
1532 free(reply);
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -05001533}
1534
1535static void
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -04001536x11_restore(struct weston_compositor *ec)
1537{
1538}
1539
1540static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001541x11_destroy(struct weston_compositor *ec)
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001542{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001543 struct x11_backend *backend = (struct x11_backend *)ec->backend;
Matt Roper361d2ad2011-08-29 13:52:23 -07001544
Giulio Camuffo954f1832014-10-11 18:27:30 +03001545 wl_event_source_remove(backend->xcb_source);
1546 x11_input_destroy(backend);
Pekka Paalanen43c61d82012-01-03 11:58:34 +02001547
Ander Conselvan de Oliveira6b162142013-10-25 16:26:32 +03001548 weston_compositor_shutdown(ec); /* destroys outputs, too */
1549
Giulio Camuffo954f1832014-10-11 18:27:30 +03001550 XCloseDisplay(backend->dpy);
1551 free(backend);
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001552}
1553
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +03001554static int
Giulio Camuffo954f1832014-10-11 18:27:30 +03001555init_gl_renderer(struct x11_backend *b)
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +03001556{
1557 int ret;
1558
1559 gl_renderer = weston_load_module("gl-renderer.so",
1560 "gl_renderer_interface");
1561 if (!gl_renderer)
1562 return -1;
1563
Giulio Camuffo954f1832014-10-11 18:27:30 +03001564 ret = gl_renderer->create(b->compositor, EGL_PLATFORM_X11_KHR, (void *) b->dpy,
Derek Foremane76f1852015-05-15 12:12:39 -05001565 gl_renderer->opaque_attribs, NULL, 0);
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +03001566
1567 return ret;
1568}
Giulio Camuffo954f1832014-10-11 18:27:30 +03001569static struct x11_backend *
1570x11_backend_create(struct weston_compositor *compositor,
1571 int fullscreen,
1572 int no_input,
1573 int use_pixman,
1574 int *argc, char *argv[],
1575 struct weston_config *config)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001576{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001577 struct x11_backend *b;
Scott Moreau1bad5db2012-08-18 01:04:05 -06001578 struct x11_output *output;
Kristian Høgsberg8f6fcbf2013-05-26 21:21:23 -04001579 struct weston_config_section *section;
Scott Moreau248aaec2012-08-03 14:19:52 -06001580 int i, x = 0, output_count = 0;
Jason Ekstrandd89a0942014-03-07 15:29:14 -06001581 int width, height, scale, count;
Kristian Høgsberg8f6fcbf2013-05-26 21:21:23 -04001582 const char *section_name;
1583 char *name, *t, *mode;
1584 uint32_t transform;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001585
Kristian Høgsbergfc9c5e02012-06-08 16:45:33 -04001586 weston_log("initializing x11 backend\n");
1587
Giulio Camuffo954f1832014-10-11 18:27:30 +03001588 b = zalloc(sizeof *b);
1589 if (b == NULL)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001590 return NULL;
1591
Giulio Camuffo954f1832014-10-11 18:27:30 +03001592 b->compositor = compositor;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001593 if (weston_compositor_set_presentation_clock_software(compositor) < 0)
Pekka Paalanenb5eedad2014-09-23 22:08:45 -04001594 goto err_free;
1595
Giulio Camuffo954f1832014-10-11 18:27:30 +03001596 b->dpy = XOpenDisplay(NULL);
1597 if (b->dpy == NULL)
Martin Olsson11434bb2012-07-08 03:03:44 +02001598 goto err_free;
Cyril Brulebois20798292011-04-06 18:05:40 +02001599
Giulio Camuffo954f1832014-10-11 18:27:30 +03001600 b->conn = XGetXCBConnection(b->dpy);
1601 XSetEventQueueOwner(b->dpy, XCBOwnsEventQueue);
Benjamin Franzkee997c5f2011-03-25 14:06:37 +01001602
Giulio Camuffo954f1832014-10-11 18:27:30 +03001603 if (xcb_connection_has_error(b->conn))
Martin Olsson11434bb2012-07-08 03:03:44 +02001604 goto err_xdisplay;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001605
Marko61b4d3e2015-10-05 17:27:54 -05001606 b->screen = x11_compositor_get_default_screen(b);
Giulio Camuffo954f1832014-10-11 18:27:30 +03001607 wl_array_init(&b->keys);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001608
Giulio Camuffo954f1832014-10-11 18:27:30 +03001609 x11_backend_get_resources(b);
1610 x11_backend_get_wm_info(b);
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -05001611
Giulio Camuffo954f1832014-10-11 18:27:30 +03001612 if (!b->has_net_wm_state_fullscreen && fullscreen) {
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -05001613 weston_log("Can not fullscreen without window manager support"
1614 "(need _NET_WM_STATE_FULLSCREEN)\n");
1615 fullscreen = 0;
1616 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001617
Giulio Camuffo954f1832014-10-11 18:27:30 +03001618 b->use_pixman = use_pixman;
1619 if (b->use_pixman) {
1620 if (pixman_renderer_init(compositor) < 0) {
Bryce Harrington665b0252015-05-26 18:14:21 -07001621 weston_log("Failed to initialize pixman renderer for X11 backend\n");
Vasily Khoruzhickb3add192013-01-07 20:39:50 +03001622 goto err_xdisplay;
Bryce Harrington665b0252015-05-26 18:14:21 -07001623 }
Vasily Khoruzhickb3add192013-01-07 20:39:50 +03001624 }
Giulio Camuffo954f1832014-10-11 18:27:30 +03001625 else if (init_gl_renderer(b) < 0) {
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +03001626 goto err_xdisplay;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +03001627 }
Vasily Khoruzhickd8943512013-01-07 22:36:02 +03001628 weston_log("Using %s renderer\n", use_pixman ? "pixman" : "gl");
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001629
Giulio Camuffo954f1832014-10-11 18:27:30 +03001630 b->base.destroy = x11_destroy;
1631 b->base.restore = x11_restore;
Kristian Høgsberg8525a502011-01-14 16:20:21 -05001632
Giulio Camuffo954f1832014-10-11 18:27:30 +03001633 if (x11_input_create(b, no_input) < 0) {
Bryce Harrington665b0252015-05-26 18:14:21 -07001634 weston_log("Failed to create X11 input\n");
Vasily Khoruzhickb3add192013-01-07 20:39:50 +03001635 goto err_renderer;
Bryce Harrington665b0252015-05-26 18:14:21 -07001636 }
Daniel Stone22815f92012-06-22 13:21:34 +01001637
Scott Moreau248aaec2012-08-03 14:19:52 -06001638 width = option_width ? option_width : 1024;
1639 height = option_height ? option_height : 640;
Jason Ekstrandd89a0942014-03-07 15:29:14 -06001640 scale = option_scale ? option_scale : 1;
Scott Moreau248aaec2012-08-03 14:19:52 -06001641 count = option_count ? option_count : 1;
1642
Kristian Høgsberg8f6fcbf2013-05-26 21:21:23 -04001643 section = NULL;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001644 while (weston_config_next_section(config,
Kristian Høgsberg8f6fcbf2013-05-26 21:21:23 -04001645 &section, &section_name)) {
1646 if (strcmp(section_name, "output") != 0)
1647 continue;
1648 weston_config_section_get_string(section, "name", &name, NULL);
Rob Bradford5c4245d2013-07-26 16:29:44 +01001649 if (name == NULL || name[0] != 'X') {
1650 free(name);
Kristian Høgsberg8f6fcbf2013-05-26 21:21:23 -04001651 continue;
Rob Bradford5c4245d2013-07-26 16:29:44 +01001652 }
Kristian Høgsberg8f6fcbf2013-05-26 21:21:23 -04001653
1654 weston_config_section_get_string(section,
1655 "mode", &mode, "1024x600");
1656 if (sscanf(mode, "%dx%d", &width, &height) != 2) {
1657 weston_log("Invalid mode \"%s\" for output %s\n",
1658 mode, name);
1659 width = 1024;
1660 height = 600;
1661 }
1662 free(mode);
1663
1664 if (option_width)
1665 width = option_width;
1666 if (option_height)
1667 height = option_height;
1668
1669 weston_config_section_get_int(section, "scale", &scale, 1);
Kristian Høgsberg3c2e66b2014-03-10 13:41:35 -07001670 if (option_scale)
1671 scale = option_scale;
1672
Kristian Høgsberg8f6fcbf2013-05-26 21:21:23 -04001673 weston_config_section_get_string(section,
1674 "transform", &t, "normal");
Derek Foreman64a3df02014-10-23 12:24:18 -05001675 if (weston_parse_transform(t, &transform) < 0)
1676 weston_log("Invalid transform \"%s\" for output %s\n",
1677 t, name);
Kristian Høgsberg8f6fcbf2013-05-26 21:21:23 -04001678 free(t);
1679
Giulio Camuffo954f1832014-10-11 18:27:30 +03001680 output = x11_backend_create_output(b, x, 0,
1681 width, height,
1682 fullscreen, no_input,
1683 name, transform, scale);
Kristian Høgsberg8f6fcbf2013-05-26 21:21:23 -04001684 free(name);
Bryce Harrington665b0252015-05-26 18:14:21 -07001685 if (output == NULL) {
1686 weston_log("Failed to create configured x11 output\n");
Scott Moreau248aaec2012-08-03 14:19:52 -06001687 goto err_x11_input;
Bryce Harrington665b0252015-05-26 18:14:21 -07001688 }
Scott Moreau1bad5db2012-08-18 01:04:05 -06001689
1690 x = pixman_region32_extents(&output->base.region)->x2;
1691
Scott Moreau248aaec2012-08-03 14:19:52 -06001692 output_count++;
1693 if (option_count && output_count >= option_count)
1694 break;
1695 }
1696
1697 for (i = output_count; i < count; i++) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001698 output = x11_backend_create_output(b, x, 0, width, height,
1699 fullscreen, no_input, NULL,
1700 WL_OUTPUT_TRANSFORM_NORMAL, scale);
Bryce Harrington665b0252015-05-26 18:14:21 -07001701 if (output == NULL) {
1702 weston_log("Failed to create x11 output #%d\n", i);
Martin Olsson11434bb2012-07-08 03:03:44 +02001703 goto err_x11_input;
Bryce Harrington665b0252015-05-26 18:14:21 -07001704 }
Scott Moreau1bad5db2012-08-18 01:04:05 -06001705 x = pixman_region32_extents(&output->base.region)->x2;
Kristian Høgsberg1ccd9d22011-07-21 10:22:13 -07001706 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001707
Giulio Camuffo954f1832014-10-11 18:27:30 +03001708 b->xcb_source =
1709 wl_event_loop_add_fd(compositor->input_loop,
1710 xcb_get_file_descriptor(b->conn),
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001711 WL_EVENT_READABLE,
Giulio Camuffo954f1832014-10-11 18:27:30 +03001712 x11_backend_handle_event, b);
1713 wl_event_source_check(b->xcb_source);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001714
Pekka Paalanen5ffb4402014-06-12 16:52:53 +03001715 if (compositor->renderer->import_dmabuf) {
1716 if (linux_dmabuf_setup(compositor) < 0)
1717 weston_log("Error: initializing dmabuf "
1718 "support failed.\n");
1719 }
1720
Giulio Camuffo954f1832014-10-11 18:27:30 +03001721 compositor->backend = &b->base;
Pekka Paalanen5ffb4402014-06-12 16:52:53 +03001722
Giulio Camuffo954f1832014-10-11 18:27:30 +03001723 return b;
Martin Olsson11434bb2012-07-08 03:03:44 +02001724
1725err_x11_input:
Giulio Camuffo954f1832014-10-11 18:27:30 +03001726 x11_input_destroy(b);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +03001727err_renderer:
Giulio Camuffo954f1832014-10-11 18:27:30 +03001728 compositor->renderer->destroy(compositor);
Martin Olsson11434bb2012-07-08 03:03:44 +02001729err_xdisplay:
Giulio Camuffo954f1832014-10-11 18:27:30 +03001730 XCloseDisplay(b->dpy);
Martin Olsson11434bb2012-07-08 03:03:44 +02001731err_free:
Giulio Camuffo954f1832014-10-11 18:27:30 +03001732 free(b);
Martin Olsson11434bb2012-07-08 03:03:44 +02001733 return NULL;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001734}
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001735
Giulio Camuffo954f1832014-10-11 18:27:30 +03001736WL_EXPORT int
1737backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
Giulio Camuffo93daabb2015-10-17 19:24:14 +03001738 struct weston_config *config,
1739 struct weston_backend_config *config_base)
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001740{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001741 struct x11_backend *b;
Scott Moreau248aaec2012-08-03 14:19:52 -06001742 int fullscreen = 0;
Pekka Paalanen36f155f2012-06-07 15:07:05 +03001743 int no_input = 0;
Vasily Khoruzhickd8943512013-01-07 22:36:02 +03001744 int use_pixman = 0;
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001745
Kristian Høgsbergbcacef12012-03-11 21:05:57 -04001746 const struct weston_option x11_options[] = {
Scott Moreau248aaec2012-08-03 14:19:52 -06001747 { WESTON_OPTION_INTEGER, "width", 0, &option_width },
1748 { WESTON_OPTION_INTEGER, "height", 0, &option_height },
Jason Ekstrandd89a0942014-03-07 15:29:14 -06001749 { WESTON_OPTION_INTEGER, "scale", 0, &option_scale },
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -05001750 { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &fullscreen },
Scott Moreau248aaec2012-08-03 14:19:52 -06001751 { WESTON_OPTION_INTEGER, "output-count", 0, &option_count },
Pekka Paalanen36f155f2012-06-07 15:07:05 +03001752 { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
Vasily Khoruzhickd8943512013-01-07 22:36:02 +03001753 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
Kristian Høgsberg83eeacb2011-06-18 04:20:54 -04001754 };
Kristian Høgsbergbcacef12012-03-11 21:05:57 -04001755
1756 parse_options(x11_options, ARRAY_LENGTH(x11_options), argc, argv);
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001757
Giulio Camuffo954f1832014-10-11 18:27:30 +03001758 b = x11_backend_create(compositor,
1759 fullscreen,
1760 no_input,
1761 use_pixman,
1762 argc, argv, config);
1763 if (b == NULL)
1764 return -1;
1765 return 0;
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001766}