Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008-2010 Kristian Høgsberg |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software Foundation, |
| 16 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
Chia-I Wu | 1b6c0ed | 2010-10-29 15:20:18 +0800 | [diff] [blame] | 19 | #ifdef HAVE_CONFIG_H |
| 20 | #include <config.h> |
| 21 | #endif |
| 22 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 23 | #include <stddef.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <unistd.h> |
| 29 | #include <errno.h> |
| 30 | #include <sys/time.h> |
Kristian Høgsberg | f9112b2 | 2010-06-14 12:53:43 -0400 | [diff] [blame] | 31 | #include <linux/input.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 32 | |
| 33 | #include <xcb/xcb.h> |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 34 | #include <X11/Xlib.h> |
| 35 | #include <X11/Xlib-xcb.h> |
| 36 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 37 | #include <GLES2/gl2.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 38 | #include <EGL/egl.h> |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 39 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 40 | #include "compositor.h" |
| 41 | |
| 42 | #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) |
| 43 | |
| 44 | struct x11_compositor { |
| 45 | struct wlsc_compositor base; |
| 46 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 47 | Display *dpy; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 48 | xcb_connection_t *conn; |
| 49 | xcb_screen_t *screen; |
| 50 | xcb_cursor_t null_cursor; |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 51 | xcb_generic_event_t *next_event; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 52 | struct wl_array keys; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 53 | struct wl_event_source *xcb_source; |
| 54 | struct { |
| 55 | xcb_atom_t wm_protocols; |
| 56 | xcb_atom_t wm_normal_hints; |
| 57 | xcb_atom_t wm_size_hints; |
| 58 | xcb_atom_t wm_delete_window; |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 59 | xcb_atom_t wm_class; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 60 | xcb_atom_t net_wm_name; |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 61 | xcb_atom_t net_wm_icon; |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 62 | xcb_atom_t string; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 63 | xcb_atom_t utf8_string; |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 64 | xcb_atom_t cardinal; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 65 | } atom; |
| 66 | }; |
| 67 | |
| 68 | struct x11_output { |
| 69 | struct wlsc_output base; |
| 70 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 71 | xcb_window_t window; |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 72 | EGLSurface egl_surface; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | struct x11_input { |
| 76 | struct wlsc_input_device base; |
| 77 | }; |
| 78 | |
| 79 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 80 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 81 | x11_input_create(struct x11_compositor *c) |
| 82 | { |
| 83 | struct x11_input *input; |
| 84 | |
| 85 | input = malloc(sizeof *input); |
| 86 | if (input == NULL) |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 87 | return -1; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 88 | |
| 89 | memset(input, 0, sizeof *input); |
| 90 | wlsc_input_device_init(&input->base, &c->base); |
| 91 | |
Kristian Høgsberg | 9c3e8d7 | 2010-12-08 09:48:52 -0500 | [diff] [blame] | 92 | c->base.input_device = &input->base.input_device; |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 93 | |
| 94 | return 0; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 97 | static int |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 98 | x11_compositor_init_egl(struct x11_compositor *c) |
| 99 | { |
Kristian Høgsberg | 379b678 | 2010-07-28 22:52:28 -0400 | [diff] [blame] | 100 | EGLint major, minor; |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 101 | EGLint n; |
Kristian Høgsberg | 379b678 | 2010-07-28 22:52:28 -0400 | [diff] [blame] | 102 | const char *extensions; |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 103 | EGLint config_attribs[] = { |
| 104 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 105 | EGL_RED_SIZE, 1, |
| 106 | EGL_GREEN_SIZE, 1, |
| 107 | EGL_BLUE_SIZE, 1, |
| 108 | EGL_DEPTH_SIZE, 1, |
| 109 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 110 | EGL_NONE |
| 111 | }; |
Kristian Høgsberg | 2c28aa5 | 2010-07-28 23:47:54 -0400 | [diff] [blame] | 112 | static const EGLint context_attribs[] = { |
| 113 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 114 | EGL_NONE |
| 115 | }; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 116 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 117 | c->base.display = eglGetDisplay(c->dpy); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 118 | if (c->base.display == NULL) { |
| 119 | fprintf(stderr, "failed to create display\n"); |
| 120 | return -1; |
| 121 | } |
| 122 | |
| 123 | if (!eglInitialize(c->base.display, &major, &minor)) { |
| 124 | fprintf(stderr, "failed to initialize display\n"); |
| 125 | return -1; |
| 126 | } |
| 127 | |
Kristian Høgsberg | 379b678 | 2010-07-28 22:52:28 -0400 | [diff] [blame] | 128 | extensions = eglQueryString(c->base.display, EGL_EXTENSIONS); |
| 129 | if (!strstr(extensions, "EGL_KHR_surfaceless_opengl")) { |
| 130 | fprintf(stderr, "EGL_KHR_surfaceless_opengl not available\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 131 | return -1; |
| 132 | } |
| 133 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 134 | if (!eglBindAPI(EGL_OPENGL_ES_API)) { |
| 135 | fprintf(stderr, "failed to bind EGL_OPENGL_ES_API\n"); |
| 136 | return -1; |
| 137 | } |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 138 | if (!eglChooseConfig(c->base.display, config_attribs, |
| 139 | &c->base.config, 1, &n) || n == 0) { |
| 140 | fprintf(stderr, "failed to choose config: %d\n", n); |
| 141 | return -1; |
| 142 | } |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 143 | |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 144 | c->base.context = eglCreateContext(c->base.display, c->base.config, |
Kristian Høgsberg | 2c28aa5 | 2010-07-28 23:47:54 -0400 | [diff] [blame] | 145 | EGL_NO_CONTEXT, context_attribs); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 146 | if (c->base.context == NULL) { |
| 147 | fprintf(stderr, "failed to create context\n"); |
| 148 | return -1; |
| 149 | } |
| 150 | |
| 151 | if (!eglMakeCurrent(c->base.display, EGL_NO_SURFACE, |
| 152 | EGL_NO_SURFACE, c->base.context)) { |
| 153 | fprintf(stderr, "failed to make context current\n"); |
| 154 | return -1; |
| 155 | } |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 160 | static int |
| 161 | x11_output_prepare_render(struct wlsc_output *output_base) |
| 162 | { |
| 163 | struct x11_output *output = (struct x11_output *) output_base; |
| 164 | struct wlsc_compositor *ec = output->base.compositor; |
| 165 | |
| 166 | if (!eglMakeCurrent(ec->display, output->egl_surface, |
| 167 | output->egl_surface, ec->context)) { |
| 168 | fprintf(stderr, "failed to make current\n"); |
| 169 | return -1; |
| 170 | } |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 175 | static int |
| 176 | x11_output_present(struct wlsc_output *output_base) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 177 | { |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 178 | struct x11_output *output = (struct x11_output *) output_base; |
| 179 | struct wlsc_compositor *ec = output->base.compositor; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 180 | struct timeval tv; |
| 181 | uint32_t msec; |
| 182 | |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 183 | if (x11_output_prepare_render(&output->base)) |
| 184 | return -1; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 185 | |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 186 | eglSwapBuffers(ec->display, output->egl_surface); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 187 | |
| 188 | gettimeofday(&tv, NULL); |
| 189 | msec = tv.tv_sec * 1000 + tv.tv_usec / 1000; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 190 | wlsc_output_finish_frame(&output->base, msec); |
| 191 | |
| 192 | return 0; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 193 | } |
| 194 | |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 195 | static int |
Benjamin Franzke | 66aa235 | 2011-04-20 17:06:13 +0200 | [diff] [blame] | 196 | x11_output_prepare_scanout_surface(struct wlsc_output *output_base, |
| 197 | struct wlsc_surface *es) |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 198 | { |
Benjamin Franzke | 66aa235 | 2011-04-20 17:06:13 +0200 | [diff] [blame] | 199 | return -1; |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 200 | } |
| 201 | |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 202 | static int |
| 203 | x11_output_set_cursor(struct wlsc_output *output_base, |
| 204 | struct wl_input_device *input) |
| 205 | { |
| 206 | return -1; |
| 207 | } |
| 208 | |
| 209 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 210 | static void |
| 211 | x11_output_set_wm_protocols(struct x11_output *output) |
| 212 | { |
| 213 | xcb_atom_t list[1]; |
| 214 | struct x11_compositor *c = |
| 215 | (struct x11_compositor *) output->base.compositor; |
| 216 | |
| 217 | list[0] = c->atom.wm_delete_window; |
| 218 | xcb_change_property (c->conn, |
| 219 | XCB_PROP_MODE_REPLACE, |
| 220 | output->window, |
| 221 | c->atom.wm_protocols, |
| 222 | XCB_ATOM_ATOM, |
| 223 | 32, |
| 224 | ARRAY_SIZE(list), |
| 225 | list); |
| 226 | } |
| 227 | |
| 228 | struct wm_normal_hints { |
| 229 | uint32_t flags; |
| 230 | uint32_t pad[4]; |
| 231 | int32_t min_width, min_height; |
| 232 | int32_t max_width, max_height; |
| 233 | int32_t width_inc, height_inc; |
| 234 | int32_t min_aspect_x, min_aspect_y; |
| 235 | int32_t max_aspect_x, max_aspect_y; |
| 236 | int32_t base_width, base_height; |
| 237 | int32_t win_gravity; |
| 238 | }; |
| 239 | |
| 240 | #define WM_NORMAL_HINTS_MIN_SIZE 16 |
| 241 | #define WM_NORMAL_HINTS_MAX_SIZE 32 |
| 242 | |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 243 | static void |
| 244 | x11_output_set_icon(struct x11_compositor *c, struct x11_output *output, |
| 245 | const char *filename, int width, int height) |
| 246 | { |
| 247 | uint32_t *icon, *pixels; |
| 248 | |
| 249 | pixels = wlsc_load_image(filename, width, height); |
| 250 | if (!pixels) |
| 251 | return; |
| 252 | icon = malloc(width * height * 4 + 8); |
| 253 | if (!icon) { |
| 254 | free(pixels); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | icon[0] = width; |
| 259 | icon[1] = height; |
| 260 | memcpy(icon + 2, pixels, width * height * 4); |
| 261 | xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 262 | c->atom.net_wm_icon, c->atom.cardinal, 32, |
| 263 | width * height + 2, icon); |
| 264 | free(icon); |
| 265 | free(pixels); |
| 266 | } |
| 267 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 268 | static int |
| 269 | x11_compositor_create_output(struct x11_compositor *c, int width, int height) |
| 270 | { |
| 271 | static const char name[] = "Wayland Compositor"; |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 272 | static const char class[] = "wayland-1\0Wayland Compositor"; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 273 | struct x11_output *output; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 274 | xcb_screen_iterator_t iter; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 275 | struct wm_normal_hints normal_hints; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 276 | uint32_t mask = XCB_CW_EVENT_MASK | XCB_CW_CURSOR; |
| 277 | uint32_t values[2] = { |
| 278 | XCB_EVENT_MASK_KEY_PRESS | |
| 279 | XCB_EVENT_MASK_KEY_RELEASE | |
| 280 | XCB_EVENT_MASK_BUTTON_PRESS | |
| 281 | XCB_EVENT_MASK_BUTTON_RELEASE | |
| 282 | XCB_EVENT_MASK_POINTER_MOTION | |
| 283 | XCB_EVENT_MASK_EXPOSURE | |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 284 | XCB_EVENT_MASK_STRUCTURE_NOTIFY | |
| 285 | XCB_EVENT_MASK_ENTER_WINDOW | |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 286 | XCB_EVENT_MASK_LEAVE_WINDOW | |
| 287 | XCB_EVENT_MASK_KEYMAP_STATE | |
| 288 | XCB_EVENT_MASK_FOCUS_CHANGE, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 289 | 0 |
| 290 | }; |
| 291 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 292 | output = malloc(sizeof *output); |
| 293 | if (output == NULL) |
| 294 | return -1; |
| 295 | |
| 296 | memset(output, 0, sizeof *output); |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 297 | wlsc_output_init(&output->base, &c->base, 0, 0, width, height, |
| 298 | WL_OUTPUT_FLIPPED); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 299 | |
| 300 | values[1] = c->null_cursor; |
| 301 | output->window = xcb_generate_id(c->conn); |
| 302 | iter = xcb_setup_roots_iterator(xcb_get_setup(c->conn)); |
| 303 | xcb_create_window(c->conn, |
| 304 | XCB_COPY_FROM_PARENT, |
| 305 | output->window, |
| 306 | iter.data->root, |
| 307 | 0, 0, |
| 308 | width, height, |
| 309 | 0, |
| 310 | XCB_WINDOW_CLASS_INPUT_OUTPUT, |
| 311 | iter.data->root_visual, |
| 312 | mask, values); |
| 313 | |
| 314 | /* Don't resize me. */ |
| 315 | memset(&normal_hints, 0, sizeof normal_hints); |
| 316 | normal_hints.flags = |
| 317 | WM_NORMAL_HINTS_MAX_SIZE | WM_NORMAL_HINTS_MIN_SIZE; |
| 318 | normal_hints.min_width = width; |
| 319 | normal_hints.min_height = height; |
| 320 | normal_hints.max_width = width; |
| 321 | normal_hints.max_height = height; |
| 322 | xcb_change_property (c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 323 | c->atom.wm_normal_hints, |
| 324 | c->atom.wm_size_hints, 32, |
| 325 | sizeof normal_hints / 4, |
| 326 | (uint8_t *) &normal_hints); |
| 327 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 328 | /* Set window name. Don't bother with non-EWMH WMs. */ |
| 329 | xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 330 | c->atom.net_wm_name, c->atom.utf8_string, 8, |
| 331 | strlen(name), name); |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 332 | xcb_change_property(c->conn, XCB_PROP_MODE_REPLACE, output->window, |
| 333 | c->atom.wm_class, c->atom.string, 8, |
| 334 | sizeof class, class); |
| 335 | |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 336 | x11_output_set_icon(c, output, |
| 337 | DATADIR "/wayland/wayland.png", 128, 128); |
| 338 | |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 339 | xcb_map_window(c->conn, output->window); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 340 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 341 | x11_output_set_wm_protocols(output); |
| 342 | |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 343 | output->egl_surface = |
| 344 | eglCreateWindowSurface(c->base.display, c->base.config, |
| 345 | output->window, NULL); |
| 346 | if (!output->egl_surface) { |
| 347 | fprintf(stderr, "failed to create window surface\n"); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 348 | return -1; |
| 349 | } |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 350 | if (!eglMakeCurrent(c->base.display, output->egl_surface, |
| 351 | output->egl_surface, c->base.context)) { |
| 352 | fprintf(stderr, "failed to make surface current\n"); |
| 353 | return -1; |
| 354 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 355 | |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 356 | output->base.prepare_render = x11_output_prepare_render; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 357 | output->base.present = x11_output_present; |
Benjamin Franzke | 66aa235 | 2011-04-20 17:06:13 +0200 | [diff] [blame] | 358 | output->base.prepare_scanout_surface = |
| 359 | x11_output_prepare_scanout_surface; |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 360 | output->base.set_hardware_cursor = x11_output_set_cursor; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 361 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 362 | wl_list_insert(c->base.output_list.prev, &output->base.link); |
| 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 367 | static struct x11_output * |
| 368 | x11_compositor_find_output(struct x11_compositor *c, xcb_window_t window) |
| 369 | { |
| 370 | struct x11_output *output; |
| 371 | |
| 372 | wl_list_for_each(output, &c->base.output_list, base.link) { |
| 373 | if (output->window == window) |
| 374 | return output; |
| 375 | } |
| 376 | |
| 377 | return NULL; |
| 378 | } |
| 379 | |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 380 | static int |
| 381 | x11_compositor_next_event(struct x11_compositor *c, |
| 382 | xcb_generic_event_t **event) |
| 383 | { |
| 384 | if (c->next_event) { |
| 385 | *event = c->next_event; |
| 386 | c->next_event = NULL; |
| 387 | } else { |
| 388 | *event = xcb_poll_for_event (c->conn); |
| 389 | } |
| 390 | |
| 391 | return *event != NULL; |
| 392 | } |
| 393 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 394 | static void |
| 395 | x11_compositor_handle_event(int fd, uint32_t mask, void *data) |
| 396 | { |
| 397 | struct x11_compositor *c = data; |
| 398 | struct x11_output *output; |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 399 | xcb_generic_event_t *event, *prev; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 400 | xcb_client_message_event_t *client_message; |
| 401 | xcb_motion_notify_event_t *motion_notify; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 402 | xcb_enter_notify_event_t *enter_notify; |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 403 | xcb_key_press_event_t *key_press, *key_release; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 404 | xcb_button_press_event_t *button_press; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 405 | xcb_keymap_notify_event_t *keymap_notify; |
| 406 | xcb_focus_in_event_t *focus_in; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 407 | xcb_atom_t atom; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 408 | uint32_t *k; |
| 409 | int i, set; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 410 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 411 | prev = NULL; |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 412 | while (x11_compositor_next_event(c, &event)) { |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 413 | switch (prev ? prev->response_type & ~0x80 : 0x80) { |
| 414 | case XCB_KEY_RELEASE: |
| 415 | key_release = (xcb_key_press_event_t *) prev; |
| 416 | key_press = (xcb_key_press_event_t *) event; |
| 417 | if ((event->response_type & ~0x80) == XCB_KEY_PRESS && |
| 418 | key_release->time == key_press->time) { |
| 419 | /* Don't deliver the held key release |
| 420 | * event or the new key press event. */ |
| 421 | free(event); |
| 422 | free(prev); |
| 423 | prev = NULL; |
| 424 | continue; |
| 425 | } else { |
| 426 | /* Deliver the held key release now |
| 427 | * and fall through and handle the new |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 428 | * event below. */ |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 429 | notify_key(c->base.input_device, |
| 430 | key_release->time, |
| 431 | key_release->detail - 8, 0); |
| 432 | free(prev); |
| 433 | prev = NULL; |
| 434 | break; |
| 435 | } |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 436 | |
| 437 | case XCB_FOCUS_IN: |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 438 | /* assert event is keymap_notify */ |
| 439 | focus_in = (xcb_focus_in_event_t *) prev; |
| 440 | keymap_notify = (xcb_keymap_notify_event_t *) event; |
| 441 | c->keys.size = 0; |
| 442 | for (i = 0; i < ARRAY_LENGTH(keymap_notify->keys) * 8; i++) { |
| 443 | set = keymap_notify->keys[i >> 3] & |
| 444 | (1 << (i & 7)); |
| 445 | if (set) { |
| 446 | k = wl_array_add(&c->keys, sizeof *k); |
| 447 | *k = i; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | output = x11_compositor_find_output(c, focus_in->event); |
| 452 | notify_keyboard_focus(c->base.input_device, |
| 453 | get_time(), |
| 454 | &output->base, &c->keys); |
| 455 | |
| 456 | free(prev); |
| 457 | prev = NULL; |
| 458 | break; |
| 459 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 460 | default: |
| 461 | /* No previous event held */ |
| 462 | break; |
Kristian Høgsberg | 3ddd148 | 2011-04-15 15:48:07 -0400 | [diff] [blame] | 463 | } |
| 464 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 465 | switch (event->response_type & ~0x80) { |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 466 | case XCB_KEY_PRESS: |
| 467 | key_press = (xcb_key_press_event_t *) event; |
| 468 | notify_key(c->base.input_device, |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 469 | key_press->time, key_press->detail - 8, 1); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 470 | break; |
| 471 | case XCB_KEY_RELEASE: |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 472 | prev = event; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 473 | break; |
| 474 | case XCB_BUTTON_PRESS: |
| 475 | button_press = (xcb_button_press_event_t *) event; |
| 476 | notify_button(c->base.input_device, |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 477 | button_press->time, |
Kristian Høgsberg | f9112b2 | 2010-06-14 12:53:43 -0400 | [diff] [blame] | 478 | button_press->detail + BTN_LEFT - 1, 1); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 479 | break; |
| 480 | case XCB_BUTTON_RELEASE: |
| 481 | button_press = (xcb_button_press_event_t *) event; |
| 482 | notify_button(c->base.input_device, |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 483 | button_press->time, |
Kristian Høgsberg | f9112b2 | 2010-06-14 12:53:43 -0400 | [diff] [blame] | 484 | button_press->detail + BTN_LEFT - 1, 0); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 485 | break; |
| 486 | |
| 487 | case XCB_MOTION_NOTIFY: |
| 488 | motion_notify = (xcb_motion_notify_event_t *) event; |
| 489 | notify_motion(c->base.input_device, |
Kristian Høgsberg | 808fd41 | 2010-07-20 17:06:19 -0400 | [diff] [blame] | 490 | motion_notify->time, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 491 | motion_notify->event_x, |
| 492 | motion_notify->event_y); |
| 493 | break; |
| 494 | |
| 495 | case XCB_EXPOSE: |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 496 | /* FIXME: schedule output repaint */ |
| 497 | /* output = x11_compositor_find_output(c, expose->window); */ |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 498 | |
Benjamin Franzke | 84290d0 | 2011-03-02 10:07:59 +0100 | [diff] [blame] | 499 | wlsc_compositor_schedule_repaint(&c->base); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 500 | break; |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 501 | |
| 502 | case XCB_ENTER_NOTIFY: |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 503 | enter_notify = (xcb_enter_notify_event_t *) event; |
Kristian Høgsberg | 2dfe626 | 2011-02-08 11:59:53 -0500 | [diff] [blame] | 504 | if (enter_notify->state >= Button1Mask) |
| 505 | break; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 506 | output = x11_compositor_find_output(c, enter_notify->event); |
| 507 | notify_pointer_focus(c->base.input_device, |
| 508 | enter_notify->time, |
| 509 | &output->base, |
| 510 | enter_notify->event_x, |
| 511 | enter_notify->event_y); |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 512 | break; |
| 513 | |
| 514 | case XCB_LEAVE_NOTIFY: |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 515 | enter_notify = (xcb_enter_notify_event_t *) event; |
Kristian Høgsberg | 2dfe626 | 2011-02-08 11:59:53 -0500 | [diff] [blame] | 516 | if (enter_notify->state >= Button1Mask) |
| 517 | break; |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 518 | notify_pointer_focus(c->base.input_device, |
| 519 | enter_notify->time, |
| 520 | NULL, |
| 521 | enter_notify->event_x, |
| 522 | enter_notify->event_y); |
Kristian Høgsberg | 86e0989 | 2010-07-07 09:51:11 -0400 | [diff] [blame] | 523 | break; |
| 524 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 525 | case XCB_CLIENT_MESSAGE: |
| 526 | client_message = (xcb_client_message_event_t *) event; |
| 527 | atom = client_message->data.data32[0]; |
| 528 | if (atom == c->atom.wm_delete_window) |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 529 | wl_display_terminate(c->base.wl_display); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 530 | break; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 531 | |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 532 | case XCB_FOCUS_IN: |
| 533 | focus_in = (xcb_focus_in_event_t *) event; |
| 534 | if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED) |
| 535 | break; |
| 536 | |
Kristian Høgsberg | 025f7b8 | 2011-04-19 12:38:22 -0400 | [diff] [blame] | 537 | prev = event; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 538 | break; |
| 539 | |
| 540 | case XCB_FOCUS_OUT: |
| 541 | focus_in = (xcb_focus_in_event_t *) event; |
| 542 | if (focus_in->mode == XCB_NOTIFY_MODE_WHILE_GRABBED) |
| 543 | break; |
| 544 | notify_keyboard_focus(c->base.input_device, |
| 545 | get_time(), NULL, NULL); |
| 546 | break; |
| 547 | |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 548 | default: |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 549 | break; |
| 550 | } |
| 551 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 552 | if (prev != event) |
Kristian Høgsberg | 3ddd148 | 2011-04-15 15:48:07 -0400 | [diff] [blame] | 553 | free (event); |
| 554 | } |
| 555 | |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 556 | switch (prev ? prev->response_type & ~0x80 : 0x80) { |
| 557 | case XCB_KEY_RELEASE: |
| 558 | key_release = (xcb_key_press_event_t *) prev; |
Kristian Høgsberg | 3ddd148 | 2011-04-15 15:48:07 -0400 | [diff] [blame] | 559 | notify_key(c->base.input_device, |
Kristian Høgsberg | 94da7e1 | 2011-04-19 09:23:29 -0400 | [diff] [blame] | 560 | key_release->time, key_release->detail - 8, 0); |
| 561 | free(prev); |
| 562 | prev = NULL; |
| 563 | break; |
| 564 | default: |
| 565 | break; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 566 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 567 | } |
| 568 | |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 569 | static int |
| 570 | x11_compositor_check_source(struct wl_event_source *source, void *data) |
| 571 | { |
| 572 | struct x11_compositor *c = data; |
| 573 | |
| 574 | /* Really? xcb doesn't have a "get queue length" function that |
| 575 | * doesn't pop an event? */ |
| 576 | c->next_event = xcb_poll_for_queued_event(c->conn); |
| 577 | |
| 578 | return c->next_event != NULL; |
| 579 | } |
| 580 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 581 | #define F(field) offsetof(struct x11_compositor, field) |
| 582 | |
| 583 | static void |
| 584 | x11_compositor_get_resources(struct x11_compositor *c) |
| 585 | { |
| 586 | static const struct { const char *name; int offset; } atoms[] = { |
| 587 | { "WM_PROTOCOLS", F(atom.wm_protocols) }, |
| 588 | { "WM_NORMAL_HINTS", F(atom.wm_normal_hints) }, |
| 589 | { "WM_SIZE_HINTS", F(atom.wm_size_hints) }, |
| 590 | { "WM_DELETE_WINDOW", F(atom.wm_delete_window) }, |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 591 | { "WM_CLASS", F(atom.wm_class) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 592 | { "_NET_WM_NAME", F(atom.net_wm_name) }, |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 593 | { "_NET_WM_ICON", F(atom.net_wm_icon) }, |
Kristian Høgsberg | 24ed621 | 2011-01-26 14:02:31 -0500 | [diff] [blame] | 594 | { "STRING", F(atom.string) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 595 | { "UTF8_STRING", F(atom.utf8_string) }, |
Kristian Høgsberg | f58d8ca | 2011-01-26 14:37:07 -0500 | [diff] [blame] | 596 | { "CARDINAL", F(atom.cardinal) }, |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 597 | }; |
| 598 | |
| 599 | xcb_intern_atom_cookie_t cookies[ARRAY_SIZE(atoms)]; |
| 600 | xcb_intern_atom_reply_t *reply; |
| 601 | xcb_pixmap_t pixmap; |
| 602 | xcb_gc_t gc; |
| 603 | int i; |
| 604 | uint8_t data[] = { 0, 0, 0, 0 }; |
| 605 | |
| 606 | for (i = 0; i < ARRAY_SIZE(atoms); i++) |
| 607 | cookies[i] = xcb_intern_atom (c->conn, 0, |
| 608 | strlen(atoms[i].name), |
| 609 | atoms[i].name); |
| 610 | |
| 611 | for (i = 0; i < ARRAY_SIZE(atoms); i++) { |
| 612 | reply = xcb_intern_atom_reply (c->conn, cookies[i], NULL); |
| 613 | *(xcb_atom_t *) ((char *) c + atoms[i].offset) = reply->atom; |
| 614 | free(reply); |
| 615 | } |
| 616 | |
| 617 | pixmap = xcb_generate_id(c->conn); |
| 618 | gc = xcb_generate_id(c->conn); |
| 619 | xcb_create_pixmap(c->conn, 1, pixmap, c->screen->root, 1, 1); |
| 620 | xcb_create_gc(c->conn, gc, pixmap, 0, NULL); |
| 621 | xcb_put_image(c->conn, XCB_IMAGE_FORMAT_XY_PIXMAP, |
| 622 | pixmap, gc, 1, 1, 0, 0, 0, 32, sizeof data, data); |
| 623 | c->null_cursor = xcb_generate_id(c->conn); |
| 624 | xcb_create_cursor (c->conn, c->null_cursor, |
| 625 | pixmap, pixmap, 0, 0, 0, 0, 0, 0, 1, 1); |
| 626 | xcb_free_gc(c->conn, gc); |
| 627 | xcb_free_pixmap(c->conn, pixmap); |
| 628 | } |
| 629 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 630 | static void |
| 631 | x11_destroy(struct wlsc_compositor *ec) |
| 632 | { |
| 633 | free(ec); |
| 634 | } |
| 635 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 636 | struct wlsc_compositor * |
Kristian Høgsberg | 61a8251 | 2010-10-26 11:26:44 -0400 | [diff] [blame] | 637 | x11_compositor_create(struct wl_display *display, int width, int height) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 638 | { |
| 639 | struct x11_compositor *c; |
| 640 | struct wl_event_loop *loop; |
| 641 | xcb_screen_iterator_t s; |
| 642 | |
| 643 | c = malloc(sizeof *c); |
| 644 | if (c == NULL) |
| 645 | return NULL; |
| 646 | |
| 647 | memset(c, 0, sizeof *c); |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 648 | |
| 649 | c->dpy = XOpenDisplay(NULL); |
Cyril Brulebois | 2079829 | 2011-04-06 18:05:40 +0200 | [diff] [blame] | 650 | if (c->dpy == NULL) |
| 651 | return NULL; |
| 652 | |
Benjamin Franzke | 3b288af | 2011-02-20 19:58:42 +0100 | [diff] [blame] | 653 | c->conn = XGetXCBConnection(c->dpy); |
Benjamin Franzke | e997c5f | 2011-03-25 14:06:37 +0100 | [diff] [blame] | 654 | XSetEventQueueOwner(c->dpy, XCBOwnsEventQueue); |
| 655 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 656 | if (xcb_connection_has_error(c->conn)) |
| 657 | return NULL; |
| 658 | |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 659 | c->next_event = NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 660 | s = xcb_setup_roots_iterator(xcb_get_setup(c->conn)); |
| 661 | c->screen = s.data; |
Kristian Høgsberg | 3ba4858 | 2011-01-27 11:57:19 -0500 | [diff] [blame] | 662 | wl_array_init(&c->keys); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 663 | |
| 664 | x11_compositor_get_resources(c); |
| 665 | |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 666 | c->base.wl_display = display; |
Tiago Vignatti | 997ce64 | 2010-11-10 02:42:35 +0200 | [diff] [blame] | 667 | if (x11_compositor_init_egl(c) < 0) |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 668 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 669 | |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 670 | c->base.destroy = x11_destroy; |
Kristian Høgsberg | 8525a50 | 2011-01-14 16:20:21 -0500 | [diff] [blame] | 671 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 672 | /* Can't init base class until we have a current egl context */ |
Kristian Høgsberg | a946821 | 2010-06-14 21:03:11 -0400 | [diff] [blame] | 673 | if (wlsc_compositor_init(&c->base, display) < 0) |
| 674 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 675 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 676 | if (x11_compositor_create_output(c, width, height) < 0) |
| 677 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 678 | |
Darxus | 55973f2 | 2010-11-22 21:24:39 -0500 | [diff] [blame] | 679 | if (x11_input_create(c) < 0) |
| 680 | return NULL; |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 681 | |
| 682 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 683 | |
| 684 | c->xcb_source = |
| 685 | wl_event_loop_add_fd(loop, xcb_get_file_descriptor(c->conn), |
| 686 | WL_EVENT_READABLE, |
| 687 | x11_compositor_handle_event, c); |
Kristian Høgsberg | ee72482 | 2011-04-21 14:51:44 -0400 | [diff] [blame] | 688 | wl_event_source_check(c->xcb_source, x11_compositor_check_source); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 689 | |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 690 | return &c->base; |
| 691 | } |