blob: 58ccc1626cf5372c6c022398309aa4eb62c52b12 [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 *
Kristian Høgsberg96aa7da2011-09-15 15:43:14 -04006 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the copyright holders not be used in
11 * advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. The copyright holders make
13 * no representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040015 *
Kristian Høgsberg96aa7da2011-09-15 15:43:14 -040016 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040023 */
24
Chia-I Wu1b6c0ed2010-10-29 15:20:18 +080025#ifdef HAVE_CONFIG_H
26#include <config.h>
27#endif
28
John Kåre Alsaker143a8982012-10-12 12:25:07 +020029#include <assert.h>
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040030#include <stddef.h>
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040031#include <stdlib.h>
32#include <string.h>
33#include <fcntl.h>
34#include <unistd.h>
35#include <errno.h>
36#include <sys/time.h>
Vasily Khoruzhickb3add192013-01-07 20:39:50 +030037#include <sys/shm.h>
Kristian Høgsbergf9112b22010-06-14 12:53:43 -040038#include <linux/input.h>
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040039
40#include <xcb/xcb.h>
Vasily Khoruzhickb3add192013-01-07 20:39:50 +030041#include <xcb/shm.h>
Daniel Stone62b33b62012-06-22 13:21:35 +010042#ifdef HAVE_XCB_XKB
43#include <xcb/xkb.h>
44#endif
45
Benjamin Franzke3b288af2011-02-20 19:58:42 +010046#include <X11/Xlib.h>
47#include <X11/Xlib-xcb.h>
48
Daniel Stone576cd152012-06-01 12:14:02 +010049#include <xkbcommon/xkbcommon.h>
50
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040051#include "compositor.h"
John Kåre Alsaker30d2b1f2012-11-13 19:10:28 +010052#include "gl-renderer.h"
Vasily Khoruzhickb3add192013-01-07 20:39:50 +030053#include "pixman-renderer.h"
Kristian Høgsbergf02a6492012-03-12 01:05:25 -040054#include "../shared/config-parser.h"
Kristian Høgsberg3c2360f2013-01-28 16:01:22 -050055#include "../shared/image-loader.h"
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040056
Jonas Ådahl62efe202012-09-27 18:40:41 +020057#define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10)
58
Scott Moreau248aaec2012-08-03 14:19:52 -060059static char *output_name;
60static char *output_mode;
Scott Moreau1bad5db2012-08-18 01:04:05 -060061static char *output_transform;
Alexander Larsson4ea95522013-05-22 14:41:37 +020062static char *output_scale;
Scott Moreau248aaec2012-08-03 14:19:52 -060063static int option_width;
64static int option_height;
65static int option_count;
66static struct wl_list configured_output_list;
67
68struct x11_configured_output {
69 char *name;
70 int width, height;
Scott Moreau1bad5db2012-08-18 01:04:05 -060071 uint32_t transform;
Alexander Larsson4ea95522013-05-22 14:41:37 +020072 unsigned int scale;
Scott Moreau248aaec2012-08-03 14:19:52 -060073 struct wl_list link;
74};
75
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040076struct x11_compositor {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050077 struct weston_compositor base;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040078
Benjamin Franzke3b288af2011-02-20 19:58:42 +010079 Display *dpy;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040080 xcb_connection_t *conn;
81 xcb_screen_t *screen;
82 xcb_cursor_t null_cursor;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -050083 struct wl_array keys;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040084 struct wl_event_source *xcb_source;
Daniel Stone576cd152012-06-01 12:14:02 +010085 struct xkb_keymap *xkb_keymap;
Daniel Stone62b33b62012-06-22 13:21:35 +010086 unsigned int has_xkb;
87 uint8_t xkb_event_base;
Vasily Khoruzhickd8943512013-01-07 22:36:02 +030088 int use_pixman;
Kristian Høgsberg4f92c532012-08-10 10:04:36 -040089
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -050090 int has_net_wm_state_fullscreen;
91
Kristian Høgsberg4f92c532012-08-10 10:04:36 -040092 /* We could map multi-pointer X to multiple wayland seats, but
93 * for now we only support core X input. */
Kristian Høgsberg068b61c2013-02-25 17:04:47 -050094 struct weston_seat core_seat;
Kristian Høgsberg50065962013-03-27 15:14:07 -040095 wl_fixed_t prev_x;
96 wl_fixed_t prev_y;
Kristian Høgsberg4f92c532012-08-10 10:04:36 -040097
Kristian Høgsbergce5325d2010-06-14 11:54:00 -040098 struct {
99 xcb_atom_t wm_protocols;
100 xcb_atom_t wm_normal_hints;
101 xcb_atom_t wm_size_hints;
102 xcb_atom_t wm_delete_window;
Kristian Høgsberg24ed6212011-01-26 14:02:31 -0500103 xcb_atom_t wm_class;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400104 xcb_atom_t net_wm_name;
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -0500105 xcb_atom_t net_supporting_wm_check;
106 xcb_atom_t net_supported;
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500107 xcb_atom_t net_wm_icon;
Kristian Høgsberg83eeacb2011-06-18 04:20:54 -0400108 xcb_atom_t net_wm_state;
109 xcb_atom_t net_wm_state_fullscreen;
Kristian Høgsberg24ed6212011-01-26 14:02:31 -0500110 xcb_atom_t string;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400111 xcb_atom_t utf8_string;
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500112 xcb_atom_t cardinal;
Daniel Stone855028f2012-05-01 20:37:10 +0100113 xcb_atom_t xkb_names;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400114 } atom;
115};
116
117struct x11_output {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500118 struct weston_output base;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400119
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400120 xcb_window_t window;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500121 struct weston_mode mode;
Kristian Høgsberg06a670f2011-10-29 14:39:13 -0400122 struct wl_event_source *finish_frame_timer;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300123
124 xcb_gc_t gc;
125 xcb_shm_seg_t segment;
126 pixman_image_t *hw_surface;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300127 int shm_id;
128 void *buf;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300129 uint8_t depth;
Alexander Larsson4ea95522013-05-22 14:41:37 +0200130 uint32_t scale;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400131};
132
Daniel Stone576cd152012-06-01 12:14:02 +0100133static struct xkb_keymap *
134x11_compositor_get_keymap(struct x11_compositor *c)
135{
136 xcb_get_property_cookie_t cookie;
137 xcb_get_property_reply_t *reply;
Daniel Stone576cd152012-06-01 12:14:02 +0100138 struct xkb_rule_names names;
139 struct xkb_keymap *ret;
140 const char *value_all, *value_part;
141 int length_all, length_part;
142
143 memset(&names, 0, sizeof(names));
144
145 cookie = xcb_get_property(c->conn, 0, c->screen->root,
146 c->atom.xkb_names, c->atom.string, 0, 1024);
Ran Benita7b5e3cd2012-10-31 20:14:56 +0200147 reply = xcb_get_property_reply(c->conn, cookie, NULL);
Daniel Stone576cd152012-06-01 12:14:02 +0100148 if (reply == NULL)
149 return NULL;
150
151 value_all = xcb_get_property_value(reply);
152 length_all = xcb_get_property_value_length(reply);
153 value_part = value_all;
154
155#define copy_prop_value(to) \
156 length_part = strlen(value_part); \
157 if (value_part + length_part < (value_all + length_all) && \
158 length_part > 0) \
159 names.to = value_part; \
160 value_part += length_part + 1;
161
162 copy_prop_value(rules);
163 copy_prop_value(model);
164 copy_prop_value(layout);
165 copy_prop_value(variant);
166 copy_prop_value(options);
167#undef copy_prop_value
168
169 ret = xkb_map_new_from_names(c->base.xkb_context, &names, 0);
170
171 free(reply);
172 return ret;
173}
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400174
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400175static uint32_t
176get_xkb_mod_mask(struct x11_compositor *c, uint32_t in)
177{
178 struct weston_xkb_info *info = &c->core_seat.xkb_info;
179 uint32_t ret = 0;
180
181 if ((in & ShiftMask) && info->shift_mod != XKB_MOD_INVALID)
182 ret |= (1 << info->shift_mod);
183 if ((in & LockMask) && info->caps_mod != XKB_MOD_INVALID)
184 ret |= (1 << info->caps_mod);
185 if ((in & ControlMask) && info->ctrl_mod != XKB_MOD_INVALID)
186 ret |= (1 << info->ctrl_mod);
187 if ((in & Mod1Mask) && info->alt_mod != XKB_MOD_INVALID)
188 ret |= (1 << info->alt_mod);
189 if ((in & Mod2Mask) && info->mod2_mod != XKB_MOD_INVALID)
190 ret |= (1 << info->mod2_mod);
191 if ((in & Mod3Mask) && info->mod3_mod != XKB_MOD_INVALID)
192 ret |= (1 << info->mod3_mod);
193 if ((in & Mod4Mask) && info->super_mod != XKB_MOD_INVALID)
194 ret |= (1 << info->super_mod);
195 if ((in & Mod5Mask) && info->mod5_mod != XKB_MOD_INVALID)
196 ret |= (1 << info->mod5_mod);
197
198 return ret;
199}
200
Daniel Stone62b33b62012-06-22 13:21:35 +0100201static void
202x11_compositor_setup_xkb(struct x11_compositor *c)
203{
204#ifndef HAVE_XCB_XKB
205 weston_log("XCB-XKB not available during build\n");
206 c->has_xkb = 0;
207 c->xkb_event_base = 0;
208 return;
209#else
210 const xcb_query_extension_reply_t *ext;
Daniel Stone3ee91e12012-06-22 13:21:36 +0100211 xcb_generic_error_t *error;
Daniel Stonee2faa122012-06-22 13:21:39 +0100212 xcb_void_cookie_t select;
Ran Benita6a39d872012-10-31 20:14:57 +0200213 xcb_xkb_use_extension_cookie_t use_ext;
214 xcb_xkb_use_extension_reply_t *use_ext_reply;
Daniel Stone3ee91e12012-06-22 13:21:36 +0100215 xcb_xkb_per_client_flags_cookie_t pcf;
216 xcb_xkb_per_client_flags_reply_t *pcf_reply;
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400217 xcb_xkb_get_state_cookie_t state;
218 xcb_xkb_get_state_reply_t *state_reply;
Daniel Stone62b33b62012-06-22 13:21:35 +0100219
220 c->has_xkb = 0;
221 c->xkb_event_base = 0;
222
223 ext = xcb_get_extension_data(c->conn, &xcb_xkb_id);
224 if (!ext) {
225 weston_log("XKB extension not available on host X11 server\n");
226 return;
227 }
228 c->xkb_event_base = ext->first_event;
229
Ran Benita424ae012012-10-31 00:13:08 +0200230 select = xcb_xkb_select_events_checked(c->conn,
231 XCB_XKB_ID_USE_CORE_KBD,
232 XCB_XKB_EVENT_TYPE_STATE_NOTIFY,
233 0,
234 XCB_XKB_EVENT_TYPE_STATE_NOTIFY,
235 0,
236 0,
237 NULL);
Daniel Stonee2faa122012-06-22 13:21:39 +0100238 error = xcb_request_check(c->conn, select);
239 if (error) {
240 weston_log("error: failed to select for XKB state events\n");
Ran Benita7b5e3cd2012-10-31 20:14:56 +0200241 free(error);
Daniel Stonee2faa122012-06-22 13:21:39 +0100242 return;
243 }
244
Ran Benita6a39d872012-10-31 20:14:57 +0200245 use_ext = xcb_xkb_use_extension(c->conn,
246 XCB_XKB_MAJOR_VERSION,
247 XCB_XKB_MINOR_VERSION);
248 use_ext_reply = xcb_xkb_use_extension_reply(c->conn, use_ext, NULL);
249 if (!use_ext_reply) {
250 weston_log("couldn't start using XKB extension\n");
251 return;
252 }
253
254 if (!use_ext_reply->supported) {
255 weston_log("XKB extension version on the server is too old "
256 "(want %d.%d, has %d.%d)\n",
257 XCB_XKB_MAJOR_VERSION, XCB_XKB_MINOR_VERSION,
258 use_ext_reply->serverMajor, use_ext_reply->serverMinor);
259 free(use_ext_reply);
260 return;
261 }
262 free(use_ext_reply);
263
Daniel Stone3ee91e12012-06-22 13:21:36 +0100264 pcf = xcb_xkb_per_client_flags(c->conn,
265 XCB_XKB_ID_USE_CORE_KBD,
266 XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT,
267 XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT,
268 0,
269 0,
270 0);
Ran Benita7b5e3cd2012-10-31 20:14:56 +0200271 pcf_reply = xcb_xkb_per_client_flags_reply(c->conn, pcf, NULL);
Ran Benita7109cc82012-10-31 20:14:58 +0200272 if (!pcf_reply ||
273 !(pcf_reply->value & XCB_XKB_PER_CLIENT_FLAG_DETECTABLE_AUTO_REPEAT)) {
Daniel Stone3ee91e12012-06-22 13:21:36 +0100274 weston_log("failed to set XKB per-client flags, not using "
275 "detectable repeat\n");
Ran Benita7109cc82012-10-31 20:14:58 +0200276 free(pcf_reply);
Daniel Stone3ee91e12012-06-22 13:21:36 +0100277 return;
278 }
Ran Benita7b5e3cd2012-10-31 20:14:56 +0200279 free(pcf_reply);
Daniel Stone3ee91e12012-06-22 13:21:36 +0100280
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400281 state = xcb_xkb_get_state(c->conn, XCB_XKB_ID_USE_CORE_KBD);
Ran Benita7b5e3cd2012-10-31 20:14:56 +0200282 state_reply = xcb_xkb_get_state_reply(c->conn, state, NULL);
283 if (!state_reply) {
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400284 weston_log("failed to get initial XKB state\n");
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400285 return;
286 }
287
288 xkb_state_update_mask(c->core_seat.xkb_state.state,
289 get_xkb_mod_mask(c, state_reply->baseMods),
290 get_xkb_mod_mask(c, state_reply->latchedMods),
291 get_xkb_mod_mask(c, state_reply->lockedMods),
292 0,
293 0,
294 state_reply->group);
295
296 free(state_reply);
297
Daniel Stone62b33b62012-06-22 13:21:35 +0100298 c->has_xkb = 1;
299#endif
300}
301
Darxus55973f22010-11-22 21:24:39 -0500302static int
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300303x11_input_create(struct x11_compositor *c, int no_input)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400304{
Daniel Stone576cd152012-06-01 12:14:02 +0100305 struct xkb_keymap *keymap;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400306
Kristian Høgsberg4f92c532012-08-10 10:04:36 -0400307 weston_seat_init(&c->core_seat, &c->base);
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300308
309 if (no_input)
310 return 0;
311
Kristian Høgsberg4f92c532012-08-10 10:04:36 -0400312 weston_seat_init_pointer(&c->core_seat);
Daniel Stone576cd152012-06-01 12:14:02 +0100313
314 keymap = x11_compositor_get_keymap(c);
Kristian Høgsberg2f07ef62013-02-16 14:29:24 -0500315 if (weston_seat_init_keyboard(&c->core_seat, keymap) < 0)
316 return -1;
Daniel Stone576cd152012-06-01 12:14:02 +0100317 if (keymap)
318 xkb_map_unref(keymap);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400319
Kristian Høgsbergaac86932012-10-29 14:15:40 -0400320 x11_compositor_setup_xkb(c);
321
Darxus55973f22010-11-22 21:24:39 -0500322 return 0;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400323}
324
Pekka Paalanen43c61d82012-01-03 11:58:34 +0200325static void
326x11_input_destroy(struct x11_compositor *compositor)
327{
Kristian Høgsberg4f92c532012-08-10 10:04:36 -0400328 weston_seat_release(&compositor->core_seat);
Pekka Paalanen43c61d82012-01-03 11:58:34 +0200329}
330
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500331static void
Jonas Ådahle5a12252013-04-05 23:07:11 +0200332x11_output_start_repaint_loop(struct weston_output *output)
333{
334 uint32_t msec;
335 struct timeval tv;
336
337 gettimeofday(&tv, NULL);
338 msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
339 weston_output_finish_frame(output, msec);
340}
341
342static void
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300343x11_output_repaint_gl(struct weston_output *output_base,
344 pixman_region32_t *damage)
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500345{
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500346 struct x11_output *output = (struct x11_output *)output_base;
Kristian Høgsbergfa1be022012-09-05 22:49:55 -0400347 struct weston_compositor *ec = output->base.compositor;
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500348
Kristian Høgsbergfa1be022012-09-05 22:49:55 -0400349 ec->renderer->repaint_output(output_base, damage);
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500350
Ander Conselvan de Oliveira0a887722012-11-22 15:57:00 +0200351 pixman_region32_subtract(&ec->primary_plane.damage,
352 &ec->primary_plane.damage, damage);
353
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500354 wl_event_source_timer_update(output->finish_frame_timer, 10);
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500355}
356
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300357static void
358x11_output_repaint_shm(struct weston_output *output_base,
359 pixman_region32_t *damage)
360{
361 struct x11_output *output = (struct x11_output *)output_base;
362 struct weston_compositor *ec = output->base.compositor;
363 struct x11_compositor *c = (struct x11_compositor *)ec;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300364 xcb_void_cookie_t cookie;
365 xcb_generic_error_t *err;
366
Ander Conselvan de Oliveira936effd2013-01-25 15:13:01 +0200367 pixman_renderer_output_set_buffer(output_base, output->hw_surface);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300368 ec->renderer->repaint_output(output_base, damage);
369
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300370 pixman_region32_subtract(&ec->primary_plane.damage,
371 &ec->primary_plane.damage, damage);
372 cookie = xcb_shm_put_image_checked(c->conn, output->window, output->gc,
373 pixman_image_get_width(output->hw_surface),
374 pixman_image_get_height(output->hw_surface),
375 0, 0,
376 pixman_image_get_width(output->hw_surface),
377 pixman_image_get_height(output->hw_surface),
378 0, 0, output->depth, XCB_IMAGE_FORMAT_Z_PIXMAP,
379 0, output->segment, 0);
380 err = xcb_request_check(c->conn, cookie);
381 if (err != NULL) {
382 weston_log("Failed to put shm image, err: %d\n", err->error_code);
383 free(err);
384 }
385
386 wl_event_source_timer_update(output->finish_frame_timer, 10);
387}
388
Benjamin Franzkeec4d3422011-03-14 12:07:26 +0100389static int
Kristian Høgsberg06a670f2011-10-29 14:39:13 -0400390finish_frame_handler(void *data)
391{
392 struct x11_output *output = data;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200393
394 x11_output_start_repaint_loop(&output->base);
Kristian Høgsberg06a670f2011-10-29 14:39:13 -0400395
396 return 1;
397}
398
Matt Roper361d2ad2011-08-29 13:52:23 -0700399static void
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300400x11_output_deinit_shm(struct x11_compositor *c, struct x11_output *output)
401{
402 xcb_void_cookie_t cookie;
403 xcb_generic_error_t *err;
404 xcb_free_gc(c->conn, output->gc);
405
406 pixman_image_unref(output->hw_surface);
407 output->hw_surface = NULL;
408 cookie = xcb_shm_detach_checked(c->conn, output->segment);
409 err = xcb_request_check(c->conn, cookie);
410 if (err) {
411 weston_log("xcb_shm_detach failed, error %d\n", err->error_code);
412 free(err);
413 }
414 shmdt(output->buf);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300415}
416
417static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500418x11_output_destroy(struct weston_output *output_base)
Matt Roper361d2ad2011-08-29 13:52:23 -0700419{
Pekka Paalanen2de99e22012-01-03 11:51:03 +0200420 struct x11_output *output = (struct x11_output *)output_base;
421 struct x11_compositor *compositor =
422 (struct x11_compositor *)output->base.compositor;
423
424 wl_list_remove(&output->base.link);
425 wl_event_source_remove(output->finish_frame_timer);
426
Vasily Khoruzhickd8943512013-01-07 22:36:02 +0300427 if (compositor->use_pixman) {
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300428 pixman_renderer_output_destroy(output_base);
429 x11_output_deinit_shm(compositor, output);
430 } else
431 gl_renderer_output_destroy(output_base);
Pekka Paalanen2de99e22012-01-03 11:51:03 +0200432
433 xcb_destroy_window(compositor->conn, output->window);
434
Kristian Høgsberg3466bc82012-01-03 11:29:15 -0500435 weston_output_destroy(&output->base);
Pekka Paalanen2de99e22012-01-03 11:51:03 +0200436
437 free(output);
Matt Roper361d2ad2011-08-29 13:52:23 -0700438}
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200439
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400440static void
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500441x11_output_set_wm_protocols(struct x11_compositor *c,
442 struct x11_output *output)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400443{
444 xcb_atom_t list[1];
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400445
446 list[0] = c->atom.wm_delete_window;
447 xcb_change_property (c->conn,
448 XCB_PROP_MODE_REPLACE,
449 output->window,
450 c->atom.wm_protocols,
451 XCB_ATOM_ATOM,
452 32,
Kristian Høgsberg09e26922011-12-23 13:33:45 -0500453 ARRAY_LENGTH(list),
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400454 list);
455}
456
457struct wm_normal_hints {
458 uint32_t flags;
459 uint32_t pad[4];
460 int32_t min_width, min_height;
461 int32_t max_width, max_height;
462 int32_t width_inc, height_inc;
463 int32_t min_aspect_x, min_aspect_y;
464 int32_t max_aspect_x, max_aspect_y;
465 int32_t base_width, base_height;
466 int32_t win_gravity;
467};
468
469#define WM_NORMAL_HINTS_MIN_SIZE 16
470#define WM_NORMAL_HINTS_MAX_SIZE 32
471
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500472static void
Kristian Høgsbergb41d76c2011-04-23 15:03:15 -0400473x11_output_set_icon(struct x11_compositor *c,
474 struct x11_output *output, const char *filename)
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500475{
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400476 uint32_t *icon;
Kristian Høgsbergb41d76c2011-04-23 15:03:15 -0400477 int32_t width, height;
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400478 pixman_image_t *image;
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500479
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400480 image = load_image(filename);
481 if (!image)
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500482 return;
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400483 width = pixman_image_get_width(image);
484 height = pixman_image_get_height(image);
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500485 icon = malloc(width * height * 4 + 8);
486 if (!icon) {
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400487 pixman_image_unref(image);
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500488 return;
489 }
490
491 icon[0] = width;
492 icon[1] = height;
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400493 memcpy(icon + 2, pixman_image_get_data(image), width * height * 4);
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500494 xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window,
495 c->atom.net_wm_icon, c->atom.cardinal, 32,
496 width * height + 2, icon);
497 free(icon);
Kristian Høgsbergf02a6492012-03-12 01:05:25 -0400498 pixman_image_unref(image);
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500499}
500
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500501static void
502x11_output_wait_for_map(struct x11_compositor *c, struct x11_output *output)
503{
504 xcb_map_notify_event_t *map_notify;
505 xcb_configure_notify_event_t *configure_notify;
506 xcb_generic_event_t *event;
Kristian Høgsberg8e7adbf2013-02-14 21:14:11 -0500507 int mapped = 0, configured = 0;
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500508 uint8_t response_type;
509
510 /* This isn't the nicest way to do this. Ideally, we could
Kristian Høgsberg8e7adbf2013-02-14 21:14:11 -0500511 * just go back to the main loop and once we get the configure
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500512 * notify, we add the output to the compositor. While we do
513 * support output hotplug, we can't start up with no outputs.
Kristian Høgsberg8e7adbf2013-02-14 21:14:11 -0500514 * We could add the output and then resize once we get the
515 * configure notify, but we don't want to start up and
516 * immediately resize the output.
517 *
518 * Also, some window managers don't give us our final
519 * fullscreen size before map_notify, so if we don't get a
520 * configure_notify before map_notify, we just wait for the
521 * first one and hope that's our size. */
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500522
523 xcb_flush(c->conn);
524
Kristian Høgsberg8e7adbf2013-02-14 21:14:11 -0500525 while (!mapped || !configured) {
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500526 event = xcb_wait_for_event(c->conn);
527 response_type = event->response_type & ~0x80;
528
529 switch (response_type) {
530 case XCB_MAP_NOTIFY:
531 map_notify = (xcb_map_notify_event_t *) event;
532 if (map_notify->window == output->window)
533 mapped = 1;
534 break;
535
536 case XCB_CONFIGURE_NOTIFY:
537 configure_notify =
538 (xcb_configure_notify_event_t *) event;
539
Alexander Larsson4ea95522013-05-22 14:41:37 +0200540
541 if (configure_notify->width % output->scale != 0 ||
542 configure_notify->height % output->scale != 0)
543 weston_log("Resolution is not a multiple of screen size, rounding\n");
544 output->mode.width = configure_notify->width / output->scale;
545 output->mode.height = configure_notify->height / output->scale;
Kristian Høgsberg8e7adbf2013-02-14 21:14:11 -0500546 configured = 1;
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500547 break;
548 }
549 }
550}
551
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300552static xcb_visualtype_t *
553find_visual_by_id(xcb_screen_t *screen,
554 xcb_visualid_t id)
555{
556 xcb_depth_iterator_t i;
557 xcb_visualtype_iterator_t j;
558 for (i = xcb_screen_allowed_depths_iterator(screen);
559 i.rem;
560 xcb_depth_next(&i)) {
561 for (j = xcb_depth_visuals_iterator(i.data);
562 j.rem;
563 xcb_visualtype_next(&j)) {
564 if (j.data->visual_id == id)
565 return j.data;
566 }
567 }
568 return 0;
569}
570
571static uint8_t
572get_depth_of_visual(xcb_screen_t *screen,
573 xcb_visualid_t id)
574{
575 xcb_depth_iterator_t i;
576 xcb_visualtype_iterator_t j;
577 for (i = xcb_screen_allowed_depths_iterator(screen);
578 i.rem;
579 xcb_depth_next(&i)) {
580 for (j = xcb_depth_visuals_iterator(i.data);
581 j.rem;
582 xcb_visualtype_next(&j)) {
583 if (j.data->visual_id == id)
584 return i.data->depth;
585 }
586 }
587 return 0;
588}
589
590static int
591x11_output_init_shm(struct x11_compositor *c, struct x11_output *output,
592 int width, int height)
593{
594 xcb_screen_iterator_t iter;
595 xcb_visualtype_t *visual_type;
596 xcb_format_iterator_t fmt;
597 xcb_void_cookie_t cookie;
598 xcb_generic_error_t *err;
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300599 const xcb_query_extension_reply_t *ext;
600 int bitsperpixel = 0;
601 pixman_format_code_t pixman_format;
602
603 /* Check if SHM is available */
604 ext = xcb_get_extension_data(c->conn, &xcb_shm_id);
605 if (ext == NULL || !ext->present) {
606 /* SHM is missing */
607 weston_log("SHM extension is not available\n");
608 errno = ENOENT;
609 return -1;
610 }
611
612 iter = xcb_setup_roots_iterator(xcb_get_setup(c->conn));
613 visual_type = find_visual_by_id(iter.data, iter.data->root_visual);
614 if (!visual_type) {
615 weston_log("Failed to lookup visual for root window\n");
616 errno = ENOENT;
617 return -1;
618 }
619 weston_log("Found visual, bits per value: %d, red_mask: %.8x, green_mask: %.8x, blue_mask: %.8x\n",
620 visual_type->bits_per_rgb_value,
621 visual_type->red_mask,
622 visual_type->green_mask,
623 visual_type->blue_mask);
624 output->depth = get_depth_of_visual(iter.data, iter.data->root_visual);
625 weston_log("Visual depth is %d\n", output->depth);
626
627 for (fmt = xcb_setup_pixmap_formats_iterator(xcb_get_setup(c->conn));
628 fmt.rem;
629 xcb_format_next(&fmt)) {
630 if (fmt.data->depth == output->depth) {
631 bitsperpixel = fmt.data->bits_per_pixel;
632 break;
633 }
634 }
635 weston_log("Found format for depth %d, bpp: %d\n",
636 output->depth, bitsperpixel);
637
638 if (bitsperpixel == 32 &&
639 visual_type->red_mask == 0xff0000 &&
640 visual_type->green_mask == 0x00ff00 &&
641 visual_type->blue_mask == 0x0000ff) {
642 weston_log("Will use x8r8g8b8 format for SHM surfaces\n");
643 pixman_format = PIXMAN_x8r8g8b8;
644 } else {
645 weston_log("Can't find appropriate format for SHM pixmap\n");
646 errno = ENOTSUP;
647 return -1;
648 }
649
650
651 /* Create SHM segment and attach it */
652 output->shm_id = shmget(IPC_PRIVATE, width * height * (bitsperpixel / 8), IPC_CREAT | S_IRWXU);
653 if (output->shm_id == -1) {
654 weston_log("x11shm: failed to allocate SHM segment\n");
655 return -1;
656 }
657 output->buf = shmat(output->shm_id, NULL, 0 /* read/write */);
658 if (-1 == (long)output->buf) {
659 weston_log("x11shm: failed to attach SHM segment\n");
660 return -1;
661 }
662 output->segment = xcb_generate_id(c->conn);
663 cookie = xcb_shm_attach_checked(c->conn, output->segment, output->shm_id, 1);
664 err = xcb_request_check(c->conn, cookie);
665 if (err) {
666 weston_log("x11shm: xcb_shm_attach error %d\n", err->error_code);
667 free(err);
668 return -1;
669 }
670
671 shmctl(output->shm_id, IPC_RMID, NULL);
672
673 /* Now create pixman image */
674 output->hw_surface = pixman_image_create_bits(pixman_format, width, height, output->buf,
675 width * (bitsperpixel / 8));
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300676
677 output->gc = xcb_generate_id(c->conn);
678 xcb_create_gc(c->conn, output->gc, output->window, 0, NULL);
679
680 return 0;
681}
682
Scott Moreau1bad5db2012-08-18 01:04:05 -0600683static struct x11_output *
Kristian Høgsberg1ccd9d22011-07-21 10:22:13 -0700684x11_compositor_create_output(struct x11_compositor *c, int x, int y,
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300685 int width, int height, int fullscreen,
Scott Moreau1bad5db2012-08-18 01:04:05 -0600686 int no_input, char *configured_name,
Alexander Larsson4ea95522013-05-22 14:41:37 +0200687 uint32_t transform, uint32_t scale)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400688{
Scott Moreau1bad5db2012-08-18 01:04:05 -0600689 static const char name[] = "Weston Compositor";
Kristian Høgsberg86000402012-01-03 23:24:14 -0500690 static const char class[] = "weston-1\0Weston Compositor";
Scott Moreau1bad5db2012-08-18 01:04:05 -0600691 char title[32];
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400692 struct x11_output *output;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400693 xcb_screen_iterator_t iter;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400694 struct wm_normal_hints normal_hints;
Kristian Høgsberg06a670f2011-10-29 14:39:13 -0400695 struct wl_event_loop *loop;
Alexander Larsson4ea95522013-05-22 14:41:37 +0200696 int output_width, output_height;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400697 uint32_t mask = XCB_CW_EVENT_MASK | XCB_CW_CURSOR;
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500698 xcb_atom_t atom_list[1];
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300699 uint32_t values[2] = {
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400700 XCB_EVENT_MASK_EXPOSURE |
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300701 XCB_EVENT_MASK_STRUCTURE_NOTIFY,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400702 0
703 };
704
Alexander Larsson4ea95522013-05-22 14:41:37 +0200705 output_width = width * scale;
706 output_height = height * scale;
707
Scott Moreau1bad5db2012-08-18 01:04:05 -0600708 if (configured_name)
709 sprintf(title, "%s - %s", name, configured_name);
710 else
711 strcpy(title, name);
712
Pekka Paalanen36f155f2012-06-07 15:07:05 +0300713 if (!no_input)
714 values[0] |=
715 XCB_EVENT_MASK_KEY_PRESS |
716 XCB_EVENT_MASK_KEY_RELEASE |
717 XCB_EVENT_MASK_BUTTON_PRESS |
718 XCB_EVENT_MASK_BUTTON_RELEASE |
719 XCB_EVENT_MASK_POINTER_MOTION |
720 XCB_EVENT_MASK_ENTER_WINDOW |
721 XCB_EVENT_MASK_LEAVE_WINDOW |
722 XCB_EVENT_MASK_KEYMAP_STATE |
723 XCB_EVENT_MASK_FOCUS_CHANGE;
724
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400725 output = malloc(sizeof *output);
726 if (output == NULL)
Scott Moreau1bad5db2012-08-18 01:04:05 -0600727 return NULL;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400728
729 memset(output, 0, sizeof *output);
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400730
731 output->mode.flags =
732 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
Alexander Larsson4ea95522013-05-22 14:41:37 +0200733 if (output->scale != 1)
734 output->mode.flags |= WL_OUTPUT_MODE_SCALED;
735
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400736 output->mode.width = width;
737 output->mode.height = height;
Kristian Høgsbergc4621b02012-05-10 12:23:53 -0400738 output->mode.refresh = 60000;
Alexander Larsson4ea95522013-05-22 14:41:37 +0200739 output->scale = scale;
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400740 wl_list_init(&output->base.mode_list);
741 wl_list_insert(&output->base.mode_list, &output->mode.link);
742
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400743 values[1] = c->null_cursor;
744 output->window = xcb_generate_id(c->conn);
745 iter = xcb_setup_roots_iterator(xcb_get_setup(c->conn));
746 xcb_create_window(c->conn,
747 XCB_COPY_FROM_PARENT,
748 output->window,
749 iter.data->root,
750 0, 0,
Alexander Larsson4ea95522013-05-22 14:41:37 +0200751 output_width, output_height,
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400752 0,
753 XCB_WINDOW_CLASS_INPUT_OUTPUT,
754 iter.data->root_visual,
755 mask, values);
756
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500757 if (fullscreen) {
758 atom_list[0] = c->atom.net_wm_state_fullscreen;
759 xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE,
760 output->window,
761 c->atom.net_wm_state,
762 XCB_ATOM_ATOM, 32,
763 ARRAY_LENGTH(atom_list), atom_list);
764 } else {
765 /* Don't resize me. */
766 memset(&normal_hints, 0, sizeof normal_hints);
767 normal_hints.flags =
768 WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE;
Alexander Larsson4ea95522013-05-22 14:41:37 +0200769 normal_hints.min_width = output_width;
770 normal_hints.min_height = output_height;
771 normal_hints.max_width = output_width;
772 normal_hints.max_height = output_height;
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500773 xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window,
774 c->atom.wm_normal_hints,
775 c->atom.wm_size_hints, 32,
776 sizeof normal_hints / 4,
777 (uint8_t *) &normal_hints);
778 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400779
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400780 /* Set window name. Don't bother with non-EWMH WMs. */
781 xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window,
782 c->atom.net_wm_name, c->atom.utf8_string, 8,
Scott Moreau1bad5db2012-08-18 01:04:05 -0600783 strlen(title), title);
Kristian Høgsberg24ed6212011-01-26 14:02:31 -0500784 xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window,
785 c->atom.wm_class, c->atom.string, 8,
786 sizeof class, class);
787
Kristian Høgsberg86000402012-01-03 23:24:14 -0500788 x11_output_set_icon(c, output, DATADIR "/weston/wayland.png");
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -0500789
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500790 x11_output_set_wm_protocols(c, output);
791
Kristian Høgsberg24ed6212011-01-26 14:02:31 -0500792 xcb_map_window(c->conn, output->window);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400793
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -0500794 if (fullscreen)
795 x11_output_wait_for_map(c, output);
Kristian Høgsberg83eeacb2011-06-18 04:20:54 -0400796
Alex Wubd3354b2012-04-17 17:20:49 +0800797 output->base.origin = output->base.current;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200798 output->base.start_repaint_loop = x11_output_start_repaint_loop;
Vasily Khoruzhickd8943512013-01-07 22:36:02 +0300799 if (c->use_pixman)
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300800 output->base.repaint = x11_output_repaint_shm;
801 else
802 output->base.repaint = x11_output_repaint_gl;
Matt Roper361d2ad2011-08-29 13:52:23 -0700803 output->base.destroy = x11_output_destroy;
Jesse Barnes5308a5e2012-02-09 13:12:57 -0800804 output->base.assign_planes = NULL;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +0200805 output->base.set_backlight = NULL;
806 output->base.set_dpms = NULL;
Alex Wu2dda6042012-04-17 17:20:47 +0800807 output->base.switch_mode = NULL;
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -0500808 output->base.current = &output->mode;
809 output->base.make = "xwayland";
810 output->base.model = "none";
811 weston_output_init(&output->base, &c->base,
Alexander Larsson4ea95522013-05-22 14:41:37 +0200812 x, y, width, height, transform, scale);
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +0100813
Vasily Khoruzhickd8943512013-01-07 22:36:02 +0300814 if (c->use_pixman) {
Alexander Larsson4ea95522013-05-22 14:41:37 +0200815 if (x11_output_init_shm(c, output, output_width, output_height) < 0)
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300816 return NULL;
817 if (pixman_renderer_output_create(&output->base) < 0) {
818 x11_output_deinit_shm(c, output);
819 return NULL;
820 }
821 } else {
Vasily Khoruzhick1bfe2e62013-01-08 19:09:02 +0300822 if (gl_renderer_output_create(&output->base, (EGLNativeWindowType)output->window) < 0)
Vasily Khoruzhickb3add192013-01-07 20:39:50 +0300823 return NULL;
824 }
John Kåre Alsaker94659272012-11-13 19:10:18 +0100825
826 loop = wl_display_get_event_loop(c->base.wl_display);
827 output->finish_frame_timer =
828 wl_event_loop_add_timer(loop, finish_frame_handler, output);
829
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400830 wl_list_insert(c->base.output_list.prev, &output->base.link);
831
Kristian Høgsbergfc9c5e02012-06-08 16:45:33 -0400832 weston_log("x11 output %dx%d, window id %d\n",
833 width, height, output->window);
834
Scott Moreau1bad5db2012-08-18 01:04:05 -0600835 return output;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400836}
837
Kristian Høgsbergce5325d2010-06-14 11:54:00 -0400838static struct x11_output *
839x11_compositor_find_output(struct x11_compositor *c, xcb_window_t window)
840{
841 struct x11_output *output;
842
843 wl_list_for_each(output, &c->base.output_list, base.link) {
844 if (output->window == window)
845 return output;
846 }
847
848 return NULL;
849}
850
Daniel Stone154c34c2012-06-22 13:21:40 +0100851#ifdef HAVE_XCB_XKB
Daniel Stonee2faa122012-06-22 13:21:39 +0100852static void
853update_xkb_state(struct x11_compositor *c, xcb_xkb_state_notify_event_t *state)
854{
Kristian Høgsberg4f92c532012-08-10 10:04:36 -0400855 xkb_state_update_mask(c->core_seat.xkb_state.state,
Daniel Stonee2faa122012-06-22 13:21:39 +0100856 get_xkb_mod_mask(c, state->baseMods),
857 get_xkb_mod_mask(c, state->latchedMods),
858 get_xkb_mod_mask(c, state->lockedMods),
859 0,
860 0,
861 state->group);
862
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400863 notify_modifiers(&c->core_seat,
864 wl_display_next_serial(c->base.wl_display));
Daniel Stonee2faa122012-06-22 13:21:39 +0100865}
866#endif
867
Daniel Stone154c34c2012-06-22 13:21:40 +0100868/**
869 * This is monumentally unpleasant. If we don't have XCB-XKB bindings,
870 * the best we can do (given that XCB also lacks XI2 support), is to take
871 * the state from the core key events. Unfortunately that only gives us
872 * the effective (i.e. union of depressed/latched/locked) state, and we
873 * need the granularity.
874 *
875 * So we still update the state with every key event we see, but also use
876 * the state field from X11 events as a mask so we don't get any stuck
877 * modifiers.
878 */
879static void
880update_xkb_state_from_core(struct x11_compositor *c, uint16_t x11_mask)
881{
882 uint32_t mask = get_xkb_mod_mask(c, x11_mask);
Kristian Høgsberga4036bb2013-05-07 23:52:07 -0400883 struct weston_keyboard *keyboard = c->core_seat.keyboard;
Daniel Stone154c34c2012-06-22 13:21:40 +0100884
Kristian Høgsberg4f92c532012-08-10 10:04:36 -0400885 xkb_state_update_mask(c->core_seat.xkb_state.state,
Daniel Stone154c34c2012-06-22 13:21:40 +0100886 keyboard->modifiers.mods_depressed & mask,
887 keyboard->modifiers.mods_latched & mask,
888 keyboard->modifiers.mods_locked & mask,
889 0,
890 0,
891 (x11_mask >> 13) & 3);
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400892 notify_modifiers(&c->core_seat,
Daniel Stone154c34c2012-06-22 13:21:40 +0100893 wl_display_next_serial(c->base.wl_display));
894}
895
Tiago Vignattia3a71622011-12-08 17:03:17 +0200896static void
897x11_compositor_deliver_button_event(struct x11_compositor *c,
898 xcb_generic_event_t *event, int state)
899{
900 xcb_button_press_event_t *button_event =
901 (xcb_button_press_event_t *) event;
Daniel Stone5d663712012-05-04 11:21:55 +0100902 uint32_t button;
Kristian Høgsberg73308622012-10-30 11:04:52 -0400903 struct x11_output *output;
904
905 output = x11_compositor_find_output(c, button_event->event);
906
907 if (state)
908 xcb_grab_pointer(c->conn, 0, output->window,
909 XCB_EVENT_MASK_BUTTON_PRESS |
910 XCB_EVENT_MASK_BUTTON_RELEASE |
911 XCB_EVENT_MASK_POINTER_MOTION |
912 XCB_EVENT_MASK_ENTER_WINDOW |
913 XCB_EVENT_MASK_LEAVE_WINDOW,
914 XCB_GRAB_MODE_ASYNC,
915 XCB_GRAB_MODE_ASYNC,
916 output->window, XCB_CURSOR_NONE,
917 button_event->time);
918 else
919 xcb_ungrab_pointer(c->conn, button_event->time);
Tiago Vignattia3a71622011-12-08 17:03:17 +0200920
Daniel Stone154c34c2012-06-22 13:21:40 +0100921 if (!c->has_xkb)
922 update_xkb_state_from_core(c, button_event->state);
923
Tiago Vignattia3a71622011-12-08 17:03:17 +0200924 switch (button_event->detail) {
925 default:
926 button = button_event->detail + BTN_LEFT - 1;
927 break;
928 case 2:
929 button = BTN_MIDDLE;
930 break;
931 case 3:
932 button = BTN_RIGHT;
933 break;
934 case 4:
Jonas Ådahl62efe202012-09-27 18:40:41 +0200935 /* Axis are measured in pixels, but the xcb events are discrete
936 * steps. Therefore move the axis by some pixels every step. */
Scott Moreau210d0792012-03-22 10:47:01 -0600937 if (state)
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400938 notify_axis(&c->core_seat,
Jonas Ådahl62efe202012-09-27 18:40:41 +0200939 weston_compositor_get_time(),
940 WL_POINTER_AXIS_VERTICAL_SCROLL,
941 -DEFAULT_AXIS_STEP_DISTANCE);
Scott Moreau210d0792012-03-22 10:47:01 -0600942 return;
Tiago Vignattia3a71622011-12-08 17:03:17 +0200943 case 5:
Scott Moreau210d0792012-03-22 10:47:01 -0600944 if (state)
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400945 notify_axis(&c->core_seat,
Jonas Ådahl62efe202012-09-27 18:40:41 +0200946 weston_compositor_get_time(),
947 WL_POINTER_AXIS_VERTICAL_SCROLL,
948 DEFAULT_AXIS_STEP_DISTANCE);
Scott Moreau210d0792012-03-22 10:47:01 -0600949 return;
Tiago Vignattia3a71622011-12-08 17:03:17 +0200950 case 6:
Scott Moreau210d0792012-03-22 10:47:01 -0600951 if (state)
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400952 notify_axis(&c->core_seat,
Jonas Ådahl62efe202012-09-27 18:40:41 +0200953 weston_compositor_get_time(),
954 WL_POINTER_AXIS_HORIZONTAL_SCROLL,
955 -DEFAULT_AXIS_STEP_DISTANCE);
Scott Moreau210d0792012-03-22 10:47:01 -0600956 return;
Tiago Vignattia3a71622011-12-08 17:03:17 +0200957 case 7:
Scott Moreau210d0792012-03-22 10:47:01 -0600958 if (state)
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400959 notify_axis(&c->core_seat,
Jonas Ådahl62efe202012-09-27 18:40:41 +0200960 weston_compositor_get_time(),
961 WL_POINTER_AXIS_HORIZONTAL_SCROLL,
962 DEFAULT_AXIS_STEP_DISTANCE);
Tiago Vignattia3a71622011-12-08 17:03:17 +0200963 return;
964 }
965
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400966 notify_button(&c->core_seat,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100967 weston_compositor_get_time(), button,
968 state ? WL_POINTER_BUTTON_STATE_PRESSED :
969 WL_POINTER_BUTTON_STATE_RELEASED);
Tiago Vignattia3a71622011-12-08 17:03:17 +0200970}
971
Scott Moreau1bad5db2012-08-18 01:04:05 -0600972static void
973x11_output_transform_coordinate(struct x11_output *x11_output,
974 wl_fixed_t *x, wl_fixed_t *y)
975{
976 struct weston_output *output = &x11_output->base;
977 wl_fixed_t tx, ty;
Alexander Larsson4ea95522013-05-22 14:41:37 +0200978 wl_fixed_t width = wl_fixed_from_int(output->width * output->scale - 1);
979 wl_fixed_t height = wl_fixed_from_int(output->height * output->scale - 1);
Scott Moreau1bad5db2012-08-18 01:04:05 -0600980
981 switch(output->transform) {
982 case WL_OUTPUT_TRANSFORM_NORMAL:
983 default:
984 tx = *x;
985 ty = *y;
986 break;
987 case WL_OUTPUT_TRANSFORM_90:
988 tx = *y;
989 ty = height - *x;
990 break;
991 case WL_OUTPUT_TRANSFORM_180:
992 tx = width - *x;
993 ty = height - *y;
994 break;
995 case WL_OUTPUT_TRANSFORM_270:
996 tx = width - *y;
997 ty = *x;
998 break;
999 case WL_OUTPUT_TRANSFORM_FLIPPED:
1000 tx = width - *x;
1001 ty = *y;
1002 break;
1003 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
1004 tx = width - *y;
1005 ty = height - *x;
1006 break;
1007 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
1008 tx = *x;
1009 ty = height - *y;
1010 break;
1011 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
1012 tx = *y;
1013 ty = *x;
1014 break;
1015 }
1016
Alexander Larsson4ea95522013-05-22 14:41:37 +02001017 tx /= output->scale;
1018 ty /= output->scale;
1019
Scott Moreau1bad5db2012-08-18 01:04:05 -06001020 tx += wl_fixed_from_int(output->x);
1021 ty += wl_fixed_from_int(output->y);
1022
1023 *x = tx;
1024 *y = ty;
1025}
1026
1027static void
1028x11_compositor_deliver_motion_event(struct x11_compositor *c,
1029 xcb_generic_event_t *event)
1030{
1031 struct x11_output *output;
1032 wl_fixed_t x, y;
1033 xcb_motion_notify_event_t *motion_notify =
1034 (xcb_motion_notify_event_t *) event;
1035
1036 if (!c->has_xkb)
1037 update_xkb_state_from_core(c, motion_notify->state);
1038 output = x11_compositor_find_output(c, motion_notify->event);
Kristian Høgsberg50065962013-03-27 15:14:07 -04001039 x = wl_fixed_from_int(motion_notify->event_x);
1040 y = wl_fixed_from_int(motion_notify->event_y);
Scott Moreau1bad5db2012-08-18 01:04:05 -06001041 x11_output_transform_coordinate(output, &x, &y);
1042
Kristian Høgsberg50065962013-03-27 15:14:07 -04001043 notify_motion(&c->core_seat, weston_compositor_get_time(),
1044 x - c->prev_x, y - c->prev_y);
1045
1046 c->prev_x = x;
1047 c->prev_y = y;
Scott Moreau1bad5db2012-08-18 01:04:05 -06001048}
1049
1050static void
1051x11_compositor_deliver_enter_event(struct x11_compositor *c,
1052 xcb_generic_event_t *event)
1053{
1054 struct x11_output *output;
1055 wl_fixed_t x, y;
1056
1057 xcb_enter_notify_event_t *enter_notify =
1058 (xcb_enter_notify_event_t *) event;
1059 if (enter_notify->state >= Button1Mask)
1060 return;
1061 if (!c->has_xkb)
1062 update_xkb_state_from_core(c, enter_notify->state);
1063 output = x11_compositor_find_output(c, enter_notify->event);
1064 x = wl_fixed_from_int(enter_notify->event_x);
1065 y = wl_fixed_from_int(enter_notify->event_y);
1066 x11_output_transform_coordinate(output, &x, &y);
1067
1068 notify_pointer_focus(&c->core_seat, &output->base, x, y);
Kristian Høgsberg50065962013-03-27 15:14:07 -04001069
1070 c->prev_x = x;
1071 c->prev_y = y;
Scott Moreau1bad5db2012-08-18 01:04:05 -06001072}
1073
Kristian Høgsbergee724822011-04-21 14:51:44 -04001074static int
1075x11_compositor_next_event(struct x11_compositor *c,
Kristian Høgsberg127d0f02011-04-22 12:18:13 -04001076 xcb_generic_event_t **event, uint32_t mask)
Kristian Høgsbergee724822011-04-21 14:51:44 -04001077{
Kristian Høgsberg127d0f02011-04-22 12:18:13 -04001078 if (mask & WL_EVENT_READABLE) {
1079 *event = xcb_poll_for_event(c->conn);
Kristian Høgsbergee724822011-04-21 14:51:44 -04001080 } else {
Kristian Høgsberg82ed0422011-04-25 15:41:59 -04001081#ifdef HAVE_XCB_POLL_FOR_QUEUED_EVENT
Kristian Høgsberg127d0f02011-04-22 12:18:13 -04001082 *event = xcb_poll_for_queued_event(c->conn);
Kristian Høgsberg82ed0422011-04-25 15:41:59 -04001083#else
1084 *event = xcb_poll_for_event(c->conn);
1085#endif
Kristian Høgsbergee724822011-04-21 14:51:44 -04001086 }
1087
1088 return *event != NULL;
1089}
1090
Kristian Høgsberg127d0f02011-04-22 12:18:13 -04001091static int
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001092x11_compositor_handle_event(int fd, uint32_t mask, void *data)
1093{
1094 struct x11_compositor *c = data;
1095 struct x11_output *output;
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001096 xcb_generic_event_t *event, *prev;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001097 xcb_client_message_event_t *client_message;
Kristian Høgsberg93331ff2011-01-26 20:35:07 -05001098 xcb_enter_notify_event_t *enter_notify;
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001099 xcb_key_press_event_t *key_press, *key_release;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001100 xcb_keymap_notify_event_t *keymap_notify;
1101 xcb_focus_in_event_t *focus_in;
Kristian Høgsberg49952d12012-06-20 00:35:59 -04001102 xcb_expose_event_t *expose;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001103 xcb_atom_t atom;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001104 uint32_t *k;
Kristian Høgsberg875ab9e2012-03-30 11:52:39 -04001105 uint32_t i, set;
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001106 uint8_t response_type;
Bill Spitzakb715cec2012-06-05 17:08:23 -04001107 int count;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001108
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001109 prev = NULL;
Bill Spitzakb715cec2012-06-05 17:08:23 -04001110 count = 0;
Kristian Høgsberg127d0f02011-04-22 12:18:13 -04001111 while (x11_compositor_next_event(c, &event, mask)) {
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001112 response_type = event->response_type & ~0x80;
1113
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001114 switch (prev ? prev->response_type & ~0x80 : 0x80) {
1115 case XCB_KEY_RELEASE:
Daniel Stone3ee91e12012-06-22 13:21:36 +01001116 /* Suppress key repeat events; this is only used if we
1117 * don't have XCB XKB support. */
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001118 key_release = (xcb_key_press_event_t *) prev;
1119 key_press = (xcb_key_press_event_t *) event;
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001120 if (response_type == XCB_KEY_PRESS &&
Dima Ryazanovc2247482011-08-16 17:25:32 -07001121 key_release->time == key_press->time &&
1122 key_release->detail == key_press->detail) {
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001123 /* Don't deliver the held key release
1124 * event or the new key press event. */
1125 free(event);
1126 free(prev);
1127 prev = NULL;
1128 continue;
1129 } else {
1130 /* Deliver the held key release now
1131 * and fall through and handle the new
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001132 * event below. */
Daniel Stone154c34c2012-06-22 13:21:40 +01001133 update_xkb_state_from_core(c, key_release->state);
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001134 notify_key(&c->core_seat,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001135 weston_compositor_get_time(),
Daniel Stonec9785ea2012-05-30 16:31:52 +01001136 key_release->detail - 8,
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001137 WL_KEYBOARD_KEY_STATE_RELEASED,
1138 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001139 free(prev);
1140 prev = NULL;
1141 break;
1142 }
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001143
1144 case XCB_FOCUS_IN:
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001145 assert(response_type == XCB_KEYMAP_NOTIFY);
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001146 keymap_notify = (xcb_keymap_notify_event_t *) event;
1147 c->keys.size = 0;
1148 for (i = 0; i < ARRAY_LENGTH(keymap_notify->keys) * 8; i++) {
1149 set = keymap_notify->keys[i >> 3] &
1150 (1 << (i & 7));
1151 if (set) {
1152 k = wl_array_add(&c->keys, sizeof *k);
1153 *k = i;
1154 }
1155 }
1156
Daniel Stoned6da09e2012-06-22 13:21:29 +01001157 /* Unfortunately the state only comes with the enter
1158 * event, rather than with the focus event. I'm not
1159 * sure of the exact semantics around it and whether
1160 * we can ensure that we get both? */
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001161 notify_keyboard_focus_in(&c->core_seat, &c->keys,
Daniel Stoned6da09e2012-06-22 13:21:29 +01001162 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001163
1164 free(prev);
1165 prev = NULL;
1166 break;
1167
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001168 default:
1169 /* No previous event held */
1170 break;
Kristian Høgsberg3ddd1482011-04-15 15:48:07 -04001171 }
1172
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001173 switch (response_type) {
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001174 case XCB_KEY_PRESS:
1175 key_press = (xcb_key_press_event_t *) event;
Daniel Stone154c34c2012-06-22 13:21:40 +01001176 if (!c->has_xkb)
1177 update_xkb_state_from_core(c, key_press->state);
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001178 notify_key(&c->core_seat,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001179 weston_compositor_get_time(),
Daniel Stonec9785ea2012-05-30 16:31:52 +01001180 key_press->detail - 8,
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001181 WL_KEYBOARD_KEY_STATE_PRESSED,
Daniel Stonee2faa122012-06-22 13:21:39 +01001182 c->has_xkb ? STATE_UPDATE_NONE :
1183 STATE_UPDATE_AUTOMATIC);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001184 break;
1185 case XCB_KEY_RELEASE:
Daniel Stone3ee91e12012-06-22 13:21:36 +01001186 /* If we don't have XKB, we need to use the lame
1187 * autorepeat detection above. */
1188 if (!c->has_xkb) {
1189 prev = event;
1190 break;
1191 }
1192 key_release = (xcb_key_press_event_t *) event;
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001193 notify_key(&c->core_seat,
Daniel Stone3ee91e12012-06-22 13:21:36 +01001194 weston_compositor_get_time(),
1195 key_release->detail - 8,
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001196 WL_KEYBOARD_KEY_STATE_RELEASED,
Daniel Stonee2faa122012-06-22 13:21:39 +01001197 STATE_UPDATE_NONE);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001198 break;
1199 case XCB_BUTTON_PRESS:
Tiago Vignattia3a71622011-12-08 17:03:17 +02001200 x11_compositor_deliver_button_event(c, event, 1);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001201 break;
1202 case XCB_BUTTON_RELEASE:
Tiago Vignattia3a71622011-12-08 17:03:17 +02001203 x11_compositor_deliver_button_event(c, event, 0);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001204 break;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001205 case XCB_MOTION_NOTIFY:
Scott Moreau1bad5db2012-08-18 01:04:05 -06001206 x11_compositor_deliver_motion_event(c, event);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001207 break;
1208
1209 case XCB_EXPOSE:
Kristian Høgsberg49952d12012-06-20 00:35:59 -04001210 expose = (xcb_expose_event_t *) event;
1211 output = x11_compositor_find_output(c, expose->window);
1212 weston_output_schedule_repaint(&output->base);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001213 break;
Kristian Høgsberg86e09892010-07-07 09:51:11 -04001214
1215 case XCB_ENTER_NOTIFY:
Scott Moreau1bad5db2012-08-18 01:04:05 -06001216 x11_compositor_deliver_enter_event(c, event);
Kristian Høgsberg86e09892010-07-07 09:51:11 -04001217 break;
1218
1219 case XCB_LEAVE_NOTIFY:
Kristian Høgsberg93331ff2011-01-26 20:35:07 -05001220 enter_notify = (xcb_enter_notify_event_t *) event;
Kristian Høgsberg2dfe6262011-02-08 11:59:53 -05001221 if (enter_notify->state >= Button1Mask)
1222 break;
Daniel Stone154c34c2012-06-22 13:21:40 +01001223 if (!c->has_xkb)
1224 update_xkb_state_from_core(c, enter_notify->state);
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001225 notify_pointer_focus(&c->core_seat, NULL, 0, 0);
Kristian Høgsberg86e09892010-07-07 09:51:11 -04001226 break;
1227
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001228 case XCB_CLIENT_MESSAGE:
1229 client_message = (xcb_client_message_event_t *) event;
1230 atom = client_message->data.data32[0];
1231 if (atom == c->atom.wm_delete_window)
Kristian Høgsberg50dc6982010-12-01 16:43:56 -05001232 wl_display_terminate(c->base.wl_display);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001233 break;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001234
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001235 case XCB_FOCUS_IN:
1236 focus_in = (xcb_focus_in_event_t *) event;
1237 if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED)
1238 break;
1239
Kristian Høgsberg025f7b82011-04-19 12:38:22 -04001240 prev = event;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001241 break;
1242
1243 case XCB_FOCUS_OUT:
1244 focus_in = (xcb_focus_in_event_t *) event;
Kristian Høgsberg42e40ae2011-12-19 14:36:50 -05001245 if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED ||
1246 focus_in->mode == XCB_NOTIFY_MODE_UNGRAB)
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001247 break;
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001248 notify_keyboard_focus_out(&c->core_seat);
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001249 break;
1250
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001251 default:
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001252 break;
1253 }
1254
Daniel Stonee2faa122012-06-22 13:21:39 +01001255#ifdef HAVE_XCB_XKB
1256 if (c->has_xkb &&
John Kåre Alsaker143a8982012-10-12 12:25:07 +02001257 response_type == c->xkb_event_base) {
Daniel Stonee2faa122012-06-22 13:21:39 +01001258 xcb_xkb_state_notify_event_t *state =
1259 (xcb_xkb_state_notify_event_t *) event;
1260 if (state->xkbType == XCB_XKB_STATE_NOTIFY)
1261 update_xkb_state(c, state);
1262 }
1263#endif
1264
Bill Spitzakb715cec2012-06-05 17:08:23 -04001265 count++;
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001266 if (prev != event)
Kristian Høgsberg3ddd1482011-04-15 15:48:07 -04001267 free (event);
1268 }
1269
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001270 switch (prev ? prev->response_type & ~0x80 : 0x80) {
1271 case XCB_KEY_RELEASE:
1272 key_release = (xcb_key_press_event_t *) prev;
Daniel Stone154c34c2012-06-22 13:21:40 +01001273 update_xkb_state_from_core(c, key_release->state);
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001274 notify_key(&c->core_seat,
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001275 weston_compositor_get_time(),
Daniel Stonec9785ea2012-05-30 16:31:52 +01001276 key_release->detail - 8,
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001277 WL_KEYBOARD_KEY_STATE_RELEASED,
1278 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg94da7e12011-04-19 09:23:29 -04001279 free(prev);
1280 prev = NULL;
1281 break;
1282 default:
1283 break;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001284 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001285
Bill Spitzakb715cec2012-06-05 17:08:23 -04001286 return count;
Kristian Høgsbergee724822011-04-21 14:51:44 -04001287}
1288
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001289#define F(field) offsetof(struct x11_compositor, field)
1290
1291static void
1292x11_compositor_get_resources(struct x11_compositor *c)
1293{
1294 static const struct { const char *name; int offset; } atoms[] = {
1295 { "WM_PROTOCOLS", F(atom.wm_protocols) },
1296 { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) },
1297 { "WM_SIZE_HINTS", F(atom.wm_size_hints) },
1298 { "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
Kristian Høgsberg24ed6212011-01-26 14:02:31 -05001299 { "WM_CLASS", F(atom.wm_class) },
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001300 { "_NET_WM_NAME", F(atom.net_wm_name) },
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -05001301 { "_NET_WM_ICON", F(atom.net_wm_icon) },
Kristian Høgsberg83eeacb2011-06-18 04:20:54 -04001302 { "_NET_WM_STATE", F(atom.net_wm_state) },
1303 { "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) },
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -05001304 { "_NET_SUPPORTING_WM_CHECK",
1305 F(atom.net_supporting_wm_check) },
1306 { "_NET_SUPPORTED", F(atom.net_supported) },
Kristian Høgsberg24ed6212011-01-26 14:02:31 -05001307 { "STRING", F(atom.string) },
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001308 { "UTF8_STRING", F(atom.utf8_string) },
Kristian Høgsbergf58d8ca2011-01-26 14:37:07 -05001309 { "CARDINAL", F(atom.cardinal) },
Daniel Stone855028f2012-05-01 20:37:10 +01001310 { "_XKB_RULES_NAMES", F(atom.xkb_names) },
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001311 };
1312
Kristian Høgsberg09e26922011-12-23 13:33:45 -05001313 xcb_intern_atom_cookie_t cookies[ARRAY_LENGTH(atoms)];
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001314 xcb_intern_atom_reply_t *reply;
1315 xcb_pixmap_t pixmap;
1316 xcb_gc_t gc;
Kristian Høgsberg875ab9e2012-03-30 11:52:39 -04001317 unsigned int i;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001318 uint8_t data[] = { 0, 0, 0, 0 };
1319
Kristian Høgsberg09e26922011-12-23 13:33:45 -05001320 for (i = 0; i < ARRAY_LENGTH(atoms); i++)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001321 cookies[i] = xcb_intern_atom (c->conn, 0,
1322 strlen(atoms[i].name),
1323 atoms[i].name);
1324
Kristian Høgsberg09e26922011-12-23 13:33:45 -05001325 for (i = 0; i < ARRAY_LENGTH(atoms); i++) {
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001326 reply = xcb_intern_atom_reply (c->conn, cookies[i], NULL);
1327 *(xcb_atom_t *) ((char *) c + atoms[i].offset) = reply->atom;
1328 free(reply);
1329 }
1330
1331 pixmap = xcb_generate_id(c->conn);
1332 gc = xcb_generate_id(c->conn);
1333 xcb_create_pixmap(c->conn, 1, pixmap, c->screen->root, 1, 1);
1334 xcb_create_gc(c->conn, gc, pixmap, 0, NULL);
1335 xcb_put_image(c->conn, XCB_IMAGE_FORMAT_XY_PIXMAP,
1336 pixmap, gc, 1, 1, 0, 0, 0, 32, sizeof data, data);
1337 c->null_cursor = xcb_generate_id(c->conn);
1338 xcb_create_cursor (c->conn, c->null_cursor,
1339 pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1);
1340 xcb_free_gc(c->conn, gc);
1341 xcb_free_pixmap(c->conn, pixmap);
1342}
1343
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001344static void
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -05001345x11_compositor_get_wm_info(struct x11_compositor *c)
1346{
1347 xcb_get_property_cookie_t cookie;
1348 xcb_get_property_reply_t *reply;
1349 xcb_atom_t *atom;
1350 unsigned int i;
1351
1352 cookie = xcb_get_property(c->conn, 0, c->screen->root,
1353 c->atom.net_supported,
1354 XCB_ATOM_ATOM, 0, 1024);
1355 reply = xcb_get_property_reply(c->conn, cookie, NULL);
1356 if (reply == NULL)
1357 return;
1358
1359 atom = (xcb_atom_t *) xcb_get_property_value(reply);
1360
1361 for (i = 0; i < reply->value_len; i++) {
1362 if (atom[i] == c->atom.net_wm_state_fullscreen)
1363 c->has_net_wm_state_fullscreen = 1;
1364 }
1365}
1366
1367static void
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -04001368x11_restore(struct weston_compositor *ec)
1369{
1370}
1371
1372static void
Scott Moreau248aaec2012-08-03 14:19:52 -06001373x11_free_configured_output(struct x11_configured_output *output)
1374{
1375 free(output->name);
1376 free(output);
1377}
1378
1379static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001380x11_destroy(struct weston_compositor *ec)
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001381{
Pekka Paalanen43c61d82012-01-03 11:58:34 +02001382 struct x11_compositor *compositor = (struct x11_compositor *)ec;
Scott Moreau248aaec2012-08-03 14:19:52 -06001383 struct x11_configured_output *o, *n;
1384
1385 wl_list_for_each_safe(o, n, &configured_output_list, link)
1386 x11_free_configured_output(o);
Matt Roper361d2ad2011-08-29 13:52:23 -07001387
Pekka Paalanen43c61d82012-01-03 11:58:34 +02001388 wl_event_source_remove(compositor->xcb_source);
1389 x11_input_destroy(compositor);
1390
Kristian Høgsberg3466bc82012-01-03 11:29:15 -05001391 weston_compositor_shutdown(ec); /* destroys outputs, too */
Pekka Paalanen43c61d82012-01-03 11:58:34 +02001392
Vasily Khoruzhick52cfd612013-01-08 19:09:01 +03001393 ec->renderer->destroy(ec);
Pekka Paalanen43c61d82012-01-03 11:58:34 +02001394
1395 XCloseDisplay(compositor->dpy);
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001396 free(ec);
1397}
1398
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001399static struct weston_compositor *
Kristian Høgsberg83eeacb2011-06-18 04:20:54 -04001400x11_compositor_create(struct wl_display *display,
Scott Moreau248aaec2012-08-03 14:19:52 -06001401 int fullscreen,
Pekka Paalanen36f155f2012-06-07 15:07:05 +03001402 int no_input,
Vasily Khoruzhickd8943512013-01-07 22:36:02 +03001403 int use_pixman,
Ossama Othmana50e6e42013-05-14 09:48:26 -07001404 int *argc, char *argv[], int config_fd)
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001405{
1406 struct x11_compositor *c;
Scott Moreau248aaec2012-08-03 14:19:52 -06001407 struct x11_configured_output *o;
Scott Moreau1bad5db2012-08-18 01:04:05 -06001408 struct x11_output *output;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001409 xcb_screen_iterator_t s;
Scott Moreau248aaec2012-08-03 14:19:52 -06001410 int i, x = 0, output_count = 0;
1411 int width, height, count;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001412
Kristian Høgsbergfc9c5e02012-06-08 16:45:33 -04001413 weston_log("initializing x11 backend\n");
1414
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001415 c = malloc(sizeof *c);
1416 if (c == NULL)
1417 return NULL;
1418
1419 memset(c, 0, sizeof *c);
Benjamin Franzke3b288af2011-02-20 19:58:42 +01001420
Daniel Stone725c2c32012-06-22 14:04:36 +01001421 if (weston_compositor_init(&c->base, display, argc, argv,
Ossama Othmana50e6e42013-05-14 09:48:26 -07001422 config_fd) < 0)
Martin Olsson11434bb2012-07-08 03:03:44 +02001423 goto err_free;
Daniel Stone725c2c32012-06-22 14:04:36 +01001424
Benjamin Franzke3b288af2011-02-20 19:58:42 +01001425 c->dpy = XOpenDisplay(NULL);
Cyril Brulebois20798292011-04-06 18:05:40 +02001426 if (c->dpy == NULL)
Martin Olsson11434bb2012-07-08 03:03:44 +02001427 goto err_free;
Cyril Brulebois20798292011-04-06 18:05:40 +02001428
Benjamin Franzke3b288af2011-02-20 19:58:42 +01001429 c->conn = XGetXCBConnection(c->dpy);
Benjamin Franzkee997c5f2011-03-25 14:06:37 +01001430 XSetEventQueueOwner(c->dpy, XCBOwnsEventQueue);
1431
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001432 if (xcb_connection_has_error(c->conn))
Martin Olsson11434bb2012-07-08 03:03:44 +02001433 goto err_xdisplay;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001434
1435 s = xcb_setup_roots_iterator(xcb_get_setup(c->conn));
1436 c->screen = s.data;
Kristian Høgsberg3ba48582011-01-27 11:57:19 -05001437 wl_array_init(&c->keys);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001438
1439 x11_compositor_get_resources(c);
Kristian Høgsberg7cc3d842013-02-19 21:19:04 -05001440 x11_compositor_get_wm_info(c);
1441
1442 if (!c->has_net_wm_state_fullscreen && fullscreen) {
1443 weston_log("Can not fullscreen without window manager support"
1444 "(need _NET_WM_STATE_FULLSCREEN)\n");
1445 fullscreen = 0;
1446 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001447
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001448 c->base.wl_display = display;
Vasily Khoruzhickd8943512013-01-07 22:36:02 +03001449 c->use_pixman = use_pixman;
1450 if (c->use_pixman) {
Vasily Khoruzhickb3add192013-01-07 20:39:50 +03001451 if (pixman_renderer_init(&c->base) < 0)
1452 goto err_xdisplay;
1453 }
1454 else {
Vasily Khoruzhick1bfe2e62013-01-08 19:09:02 +03001455 if (gl_renderer_create(&c->base, (EGLNativeDisplayType)c->dpy, gl_renderer_opaque_attribs,
Vasily Khoruzhickb3add192013-01-07 20:39:50 +03001456 NULL) < 0)
1457 goto err_xdisplay;
1458 }
Vasily Khoruzhickd8943512013-01-07 22:36:02 +03001459 weston_log("Using %s renderer\n", use_pixman ? "pixman" : "gl");
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001460
Kristian Høgsberg8525a502011-01-14 16:20:21 -05001461 c->base.destroy = x11_destroy;
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -04001462 c->base.restore = x11_restore;
Kristian Høgsberg8525a502011-01-14 16:20:21 -05001463
Daniel Stone22815f92012-06-22 13:21:34 +01001464 if (x11_input_create(c, no_input) < 0)
Vasily Khoruzhickb3add192013-01-07 20:39:50 +03001465 goto err_renderer;
Daniel Stone22815f92012-06-22 13:21:34 +01001466
Scott Moreau248aaec2012-08-03 14:19:52 -06001467 width = option_width ? option_width : 1024;
1468 height = option_height ? option_height : 640;
1469 count = option_count ? option_count : 1;
1470
1471 wl_list_for_each(o, &configured_output_list, link) {
Scott Moreau1bad5db2012-08-18 01:04:05 -06001472 output = x11_compositor_create_output(c, x, 0,
1473 option_width ? width :
1474 o->width,
1475 option_height ? height :
1476 o->height,
1477 fullscreen, no_input,
Alexander Larsson4ea95522013-05-22 14:41:37 +02001478 o->name, o->transform, o->scale);
Scott Moreau1bad5db2012-08-18 01:04:05 -06001479 if (output == NULL)
Scott Moreau248aaec2012-08-03 14:19:52 -06001480 goto err_x11_input;
Scott Moreau1bad5db2012-08-18 01:04:05 -06001481
1482 x = pixman_region32_extents(&output->base.region)->x2;
1483
Scott Moreau248aaec2012-08-03 14:19:52 -06001484 output_count++;
1485 if (option_count && output_count >= option_count)
1486 break;
1487 }
1488
1489 for (i = output_count; i < count; i++) {
Scott Moreau1bad5db2012-08-18 01:04:05 -06001490 output = x11_compositor_create_output(c, x, 0, width, height,
1491 fullscreen, no_input, NULL,
Alexander Larsson4ea95522013-05-22 14:41:37 +02001492 WL_OUTPUT_TRANSFORM_NORMAL, wl_fixed_from_int(1));
Scott Moreau1bad5db2012-08-18 01:04:05 -06001493 if (output == NULL)
Martin Olsson11434bb2012-07-08 03:03:44 +02001494 goto err_x11_input;
Scott Moreau1bad5db2012-08-18 01:04:05 -06001495 x = pixman_region32_extents(&output->base.region)->x2;
Kristian Høgsberg1ccd9d22011-07-21 10:22:13 -07001496 }
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001497
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001498 c->xcb_source =
Kristian Høgsberg22ba60e2012-03-12 01:18:24 -04001499 wl_event_loop_add_fd(c->base.input_loop,
1500 xcb_get_file_descriptor(c->conn),
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001501 WL_EVENT_READABLE,
1502 x11_compositor_handle_event, c);
Kristian Høgsberg127d0f02011-04-22 12:18:13 -04001503 wl_event_source_check(c->xcb_source);
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001504
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001505 return &c->base;
Martin Olsson11434bb2012-07-08 03:03:44 +02001506
1507err_x11_input:
1508 x11_input_destroy(c);
Vasily Khoruzhickb3add192013-01-07 20:39:50 +03001509err_renderer:
Vasily Khoruzhick52cfd612013-01-08 19:09:01 +03001510 c->base.renderer->destroy(&c->base);
Martin Olsson11434bb2012-07-08 03:03:44 +02001511err_xdisplay:
1512 XCloseDisplay(c->dpy);
1513err_free:
1514 free(c);
1515 return NULL;
Kristian Høgsbergce5325d2010-06-14 11:54:00 -04001516}
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001517
Scott Moreau248aaec2012-08-03 14:19:52 -06001518static void
Scott Moreau1bad5db2012-08-18 01:04:05 -06001519x11_output_set_transform(struct x11_configured_output *output)
1520{
1521 if (!output_transform) {
1522 output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
1523 return;
1524 }
1525
1526 if (!strcmp(output_transform, "normal"))
1527 output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
1528 else if (!strcmp(output_transform, "90"))
1529 output->transform = WL_OUTPUT_TRANSFORM_90;
1530 else if (!strcmp(output_transform, "180"))
1531 output->transform = WL_OUTPUT_TRANSFORM_180;
1532 else if (!strcmp(output_transform, "270"))
1533 output->transform = WL_OUTPUT_TRANSFORM_270;
1534 else if (!strcmp(output_transform, "flipped"))
1535 output->transform = WL_OUTPUT_TRANSFORM_FLIPPED;
1536 else if (!strcmp(output_transform, "flipped-90"))
1537 output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_90;
1538 else if (!strcmp(output_transform, "flipped-180"))
1539 output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_180;
1540 else if (!strcmp(output_transform, "flipped-270"))
1541 output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_270;
1542 else {
1543 weston_log("Invalid transform \"%s\" for output %s\n",
1544 output_transform, output_name);
1545 output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
1546 }
1547}
1548
1549static void
Scott Moreau248aaec2012-08-03 14:19:52 -06001550output_section_done(void *data)
1551{
1552 struct x11_configured_output *output;
1553
1554 output = malloc(sizeof *output);
1555
Scott Moreau1bad5db2012-08-18 01:04:05 -06001556 if (!output || !output_name || (output_name[0] != 'X') ||
Alexander Larsson4ea95522013-05-22 14:41:37 +02001557 (!output_mode && !output_transform && !output_scale)) {
Scott Moreau1bad5db2012-08-18 01:04:05 -06001558 if (output_name)
1559 free(output_name);
Scott Moreau248aaec2012-08-03 14:19:52 -06001560 output_name = NULL;
John Kåre Alsaker5e48a852012-10-12 12:25:11 +02001561 free(output);
Scott Moreauca9b09d2012-08-06 01:27:06 -06001562 goto err_free;
Scott Moreau248aaec2012-08-03 14:19:52 -06001563 }
1564
1565 output->name = output_name;
1566
Scott Moreau1bad5db2012-08-18 01:04:05 -06001567 if (output_mode) {
1568 if (sscanf(output_mode, "%dx%d", &output->width,
1569 &output->height) != 2) {
1570 weston_log("Invalid mode \"%s\" for output %s\n",
1571 output_mode, output_name);
1572 x11_free_configured_output(output);
1573 goto err_free;
1574 }
1575 } else {
1576 output->width = 1024;
1577 output->height = 640;
Scott Moreau248aaec2012-08-03 14:19:52 -06001578 }
1579
Alexander Larsson4ea95522013-05-22 14:41:37 +02001580 output->scale = 1;
1581 if (output_scale) {
1582 if (sscanf(output_scale, "%d", &output->scale) != 1) {
1583 weston_log("Invalid scale \"%s\" for output %s\n",
1584 output_scale, output_name);
1585 x11_free_configured_output(output);
1586 goto err_free;
1587 }
1588 }
1589
Scott Moreau1bad5db2012-08-18 01:04:05 -06001590 x11_output_set_transform(output);
Scott Moreau248aaec2012-08-03 14:19:52 -06001591
Scott Moreauca9b09d2012-08-06 01:27:06 -06001592 wl_list_insert(configured_output_list.prev, &output->link);
1593
1594err_free:
Scott Moreau1bad5db2012-08-18 01:04:05 -06001595 if (output_mode)
1596 free(output_mode);
1597 if (output_transform)
1598 free(output_transform);
Scott Moreau248aaec2012-08-03 14:19:52 -06001599 output_mode = NULL;
Scott Moreau1bad5db2012-08-18 01:04:05 -06001600 output_transform = NULL;
Alexander Larsson4ea95522013-05-22 14:41:37 +02001601 output_scale = NULL;
Scott Moreau248aaec2012-08-03 14:19:52 -06001602}
1603
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001604WL_EXPORT struct weston_compositor *
Kristian Høgsberg4172f662013-02-20 15:27:49 -05001605backend_init(struct wl_display *display, int *argc, char *argv[],
Ossama Othmana50e6e42013-05-14 09:48:26 -07001606 int config_fd)
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001607{
Scott Moreau248aaec2012-08-03 14:19:52 -06001608 int fullscreen = 0;
Pekka Paalanen36f155f2012-06-07 15:07:05 +03001609 int no_input = 0;
Vasily Khoruzhickd8943512013-01-07 22:36:02 +03001610 int use_pixman = 0;
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001611
Kristian Høgsbergbcacef12012-03-11 21:05:57 -04001612 const struct weston_option x11_options[] = {
Scott Moreau248aaec2012-08-03 14:19:52 -06001613 { WESTON_OPTION_INTEGER, "width", 0, &option_width },
1614 { WESTON_OPTION_INTEGER, "height", 0, &option_height },
Kristian Høgsbergd6f09a72012-11-09 11:12:21 -05001615 { WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &fullscreen },
Scott Moreau248aaec2012-08-03 14:19:52 -06001616 { WESTON_OPTION_INTEGER, "output-count", 0, &option_count },
Pekka Paalanen36f155f2012-06-07 15:07:05 +03001617 { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
Vasily Khoruzhickd8943512013-01-07 22:36:02 +03001618 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
Kristian Høgsberg83eeacb2011-06-18 04:20:54 -04001619 };
Kristian Høgsbergbcacef12012-03-11 21:05:57 -04001620
1621 parse_options(x11_options, ARRAY_LENGTH(x11_options), argc, argv);
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001622
Scott Moreau248aaec2012-08-03 14:19:52 -06001623 wl_list_init(&configured_output_list);
1624
1625 const struct config_key x11_config_keys[] = {
1626 { "name", CONFIG_KEY_STRING, &output_name },
1627 { "mode", CONFIG_KEY_STRING, &output_mode },
Scott Moreau1bad5db2012-08-18 01:04:05 -06001628 { "transform", CONFIG_KEY_STRING, &output_transform },
Alexander Larsson4ea95522013-05-22 14:41:37 +02001629 { "scale", CONFIG_KEY_STRING, &output_scale },
Scott Moreau248aaec2012-08-03 14:19:52 -06001630 };
1631
1632 const struct config_section config_section[] = {
1633 { "output", x11_config_keys,
1634 ARRAY_LENGTH(x11_config_keys), output_section_done },
1635 };
1636
Ossama Othmana50e6e42013-05-14 09:48:26 -07001637 parse_config_file(config_fd, config_section,
Scott Moreau248aaec2012-08-03 14:19:52 -06001638 ARRAY_LENGTH(config_section), NULL);
1639
Kristian Høgsberg1ccd9d22011-07-21 10:22:13 -07001640 return x11_compositor_create(display,
Scott Moreau248aaec2012-08-03 14:19:52 -06001641 fullscreen,
Pekka Paalanen36f155f2012-06-07 15:07:05 +03001642 no_input,
Vasily Khoruzhickd8943512013-01-07 22:36:02 +03001643 use_pixman,
Ossama Othmana50e6e42013-05-14 09:48:26 -07001644 argc, argv, config_fd);
Kristian Høgsberg1c562182011-05-02 22:09:20 -04001645}