Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 2 | * Copyright © 2010-2011 Benjamin Franzke |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 3 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 13 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H |
| 24 | #include <config.h> |
| 25 | #endif |
| 26 | |
| 27 | #include <stddef.h> |
| 28 | #define _GNU_SOURCE |
| 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | #include <fcntl.h> |
| 33 | #include <unistd.h> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 34 | |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 35 | #include <wayland-client.h> |
| 36 | #include <wayland-egl.h> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 37 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 38 | #include <GLES2/gl2.h> |
| 39 | #include <GLES2/gl2ext.h> |
| 40 | #include <EGL/egl.h> |
| 41 | #include <EGL/eglext.h> |
| 42 | |
| 43 | #include "compositor.h" |
| 44 | |
| 45 | struct wayland_compositor { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 46 | struct weston_compositor base; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 47 | |
| 48 | struct { |
| 49 | struct wl_display *display; |
| 50 | struct wl_compositor *compositor; |
| 51 | struct wl_shell *shell; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 52 | struct wl_output *output; |
| 53 | |
| 54 | struct { |
| 55 | int32_t x, y, width, height; |
| 56 | } screen_allocation; |
| 57 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 58 | struct wl_event_source *wl_source; |
| 59 | uint32_t event_mask; |
| 60 | } parent; |
| 61 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame^] | 62 | struct { |
| 63 | int32_t top, bottom, left, right; |
| 64 | GLuint texture; |
| 65 | int32_t width, height; |
| 66 | } border; |
| 67 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 68 | struct wl_list input_list; |
| 69 | }; |
| 70 | |
| 71 | struct wayland_output { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 72 | struct weston_output base; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 73 | |
| 74 | struct { |
| 75 | struct wl_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 76 | struct wl_shell_surface *shell_surface; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 77 | struct wl_egl_window *egl_window; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 78 | } parent; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 79 | EGLSurface egl_surface; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 80 | struct weston_mode mode; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | struct wayland_input { |
| 84 | struct wayland_compositor *compositor; |
| 85 | struct wl_input_device *input_device; |
| 86 | struct wl_list link; |
| 87 | }; |
| 88 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame^] | 89 | |
| 90 | static int |
| 91 | texture_border(struct wayland_output *output) |
| 92 | { |
| 93 | struct wayland_compositor *c = |
| 94 | (struct wayland_compositor *) output->base.compositor; |
| 95 | GLfloat *d; |
| 96 | unsigned int *p; |
| 97 | int i, j, k, n; |
| 98 | GLfloat x[4], y[4], u[4], v[4]; |
| 99 | |
| 100 | x[0] = -c->border.left; |
| 101 | x[1] = 0; |
| 102 | x[2] = output->base.current->width; |
| 103 | x[3] = output->base.current->width + c->border.right; |
| 104 | |
| 105 | y[0] = -c->border.top; |
| 106 | y[1] = 0; |
| 107 | y[2] = output->base.current->height; |
| 108 | y[3] = output->base.current->height + c->border.bottom; |
| 109 | |
| 110 | u[0] = 0.0; |
| 111 | u[1] = (GLfloat) c->border.left / c->border.width; |
| 112 | u[2] = (GLfloat) (c->border.width - c->border.right) / c->border.width; |
| 113 | u[3] = 1.0; |
| 114 | |
| 115 | v[0] = 0.0; |
| 116 | v[1] = (GLfloat) c->border.top / c->border.height; |
| 117 | v[2] = (GLfloat) (c->border.height - c->border.bottom) / c->border.height; |
| 118 | v[3] = 1.0; |
| 119 | |
| 120 | n = 8; |
| 121 | d = wl_array_add(&c->base.vertices, n * 16 * sizeof *d); |
| 122 | p = wl_array_add(&c->base.indices, n * 6 * sizeof *p); |
| 123 | |
| 124 | k = 0; |
| 125 | for (i = 0; i < 3; i++) |
| 126 | for (j = 0; j < 3; j++) { |
| 127 | |
| 128 | if (i == 1 && j == 1) |
| 129 | continue; |
| 130 | |
| 131 | d[ 0] = x[i]; |
| 132 | d[ 1] = y[j]; |
| 133 | d[ 2] = u[i]; |
| 134 | d[ 3] = v[j]; |
| 135 | |
| 136 | d[ 4] = x[i]; |
| 137 | d[ 5] = y[j + 1]; |
| 138 | d[ 6] = u[i]; |
| 139 | d[ 7] = v[j + 1]; |
| 140 | |
| 141 | d[ 8] = x[i + 1]; |
| 142 | d[ 9] = y[j]; |
| 143 | d[10] = u[i + 1]; |
| 144 | d[11] = v[j]; |
| 145 | |
| 146 | d[12] = x[i + 1]; |
| 147 | d[13] = y[j + 1]; |
| 148 | d[14] = u[i + 1]; |
| 149 | d[15] = v[j + 1]; |
| 150 | |
| 151 | p[0] = k + 0; |
| 152 | p[1] = k + 1; |
| 153 | p[2] = k + 2; |
| 154 | p[3] = k + 2; |
| 155 | p[4] = k + 1; |
| 156 | p[5] = k + 3; |
| 157 | |
| 158 | d += 16; |
| 159 | p += 6; |
| 160 | k += 4; |
| 161 | } |
| 162 | |
| 163 | return k / 4; |
| 164 | } |
| 165 | |
| 166 | static void |
| 167 | draw_border(struct wayland_output *output) |
| 168 | { |
| 169 | struct wayland_compositor *c = |
| 170 | (struct wayland_compositor *) output->base.compositor; |
| 171 | struct weston_shader *shader = &c->base.texture_shader; |
| 172 | GLfloat *v; |
| 173 | int n; |
| 174 | |
| 175 | glDisable(GL_BLEND); |
| 176 | glUseProgram(shader->program); |
| 177 | c->base.current_shader = shader; |
| 178 | |
| 179 | glUniformMatrix4fv(shader->proj_uniform, |
| 180 | 1, GL_FALSE, output->base.matrix.d); |
| 181 | |
| 182 | glUniform1i(shader->tex_uniform, 0); |
| 183 | glUniform1f(shader->alpha_uniform, 1); |
| 184 | c->base.current_alpha = 255; |
| 185 | glUniform1f(shader->texwidth_uniform, 1); |
| 186 | |
| 187 | n = texture_border(output); |
| 188 | |
| 189 | glBindTexture(GL_TEXTURE_2D, c->border.texture); |
| 190 | |
| 191 | v = c->base.vertices.data; |
| 192 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[0]); |
| 193 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[2]); |
| 194 | glEnableVertexAttribArray(0); |
| 195 | glEnableVertexAttribArray(1); |
| 196 | |
| 197 | glDrawElements(GL_TRIANGLES, n * 6, |
| 198 | GL_UNSIGNED_INT, c->base.indices.data); |
| 199 | |
| 200 | glDisableVertexAttribArray(1); |
| 201 | glDisableVertexAttribArray(0); |
| 202 | |
| 203 | c->base.vertices.size = 0; |
| 204 | c->base.indices.size = 0; |
| 205 | } |
| 206 | |
| 207 | static void |
| 208 | create_border(struct wayland_compositor *c) |
| 209 | { |
| 210 | uint32_t *pixels, stride; |
| 211 | |
| 212 | pixels = weston_load_image(DATADIR "/weston/border.png", |
| 213 | &c->border.width, |
| 214 | &c->border.height, &stride); |
| 215 | if (!pixels) { |
| 216 | fprintf(stderr, "could'nt load border image\n"); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | glGenTextures(1, &c->border.texture); |
| 221 | glBindTexture(GL_TEXTURE_2D, c->border.texture); |
| 222 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 223 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 224 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 225 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 226 | |
| 227 | glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, |
| 228 | c->border.width, |
| 229 | c->border.height, |
| 230 | 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels); |
| 231 | |
| 232 | c->border.top = 25; |
| 233 | c->border.bottom = 50; |
| 234 | c->border.left = 25; |
| 235 | c->border.right = 25; |
| 236 | } |
| 237 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 238 | static int |
| 239 | wayland_input_create(struct wayland_compositor *c) |
| 240 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 241 | struct weston_input_device *input; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 242 | |
| 243 | input = malloc(sizeof *input); |
| 244 | if (input == NULL) |
| 245 | return -1; |
| 246 | |
| 247 | memset(input, 0, sizeof *input); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 248 | weston_input_device_init(input, &c->base); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 249 | |
Kristian Høgsberg | 9c3e8d7 | 2010-12-08 09:48:52 -0500 | [diff] [blame] | 250 | c->base.input_device = &input->input_device; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | static int |
| 256 | wayland_compositor_init_egl(struct wayland_compositor *c) |
| 257 | { |
| 258 | EGLint major, minor; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 259 | EGLint n; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 260 | const char *extensions; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 261 | EGLint config_attribs[] = { |
| 262 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 263 | EGL_RED_SIZE, 1, |
| 264 | EGL_GREEN_SIZE, 1, |
| 265 | EGL_BLUE_SIZE, 1, |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame^] | 266 | EGL_ALPHA_SIZE, 1, |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 267 | EGL_DEPTH_SIZE, 1, |
Kristian Høgsberg | d28ab36 | 2011-03-02 11:36:30 -0500 | [diff] [blame] | 268 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 269 | EGL_NONE |
| 270 | }; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 271 | static const EGLint context_attribs[] = { |
| 272 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 273 | EGL_NONE |
| 274 | }; |
| 275 | |
Kristian Høgsberg | 91342c6 | 2011-04-14 14:44:58 -0400 | [diff] [blame] | 276 | c->base.display = eglGetDisplay(c->parent.display); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 277 | if (c->base.display == NULL) { |
| 278 | fprintf(stderr, "failed to create display\n"); |
| 279 | return -1; |
| 280 | } |
| 281 | |
| 282 | if (!eglInitialize(c->base.display, &major, &minor)) { |
| 283 | fprintf(stderr, "failed to initialize display\n"); |
| 284 | return -1; |
| 285 | } |
| 286 | |
| 287 | extensions = eglQueryString(c->base.display, EGL_EXTENSIONS); |
Ander Conselvan de Oliveira | ef7c8d9 | 2011-11-01 16:37:41 +0200 | [diff] [blame] | 288 | if (!strstr(extensions, "EGL_KHR_surfaceless_gles2")) { |
| 289 | fprintf(stderr, "EGL_KHR_surfaceless_gles2 not available\n"); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 290 | return -1; |
| 291 | } |
| 292 | |
| 293 | if (!eglBindAPI(EGL_OPENGL_ES_API)) { |
| 294 | fprintf(stderr, "failed to bind EGL_OPENGL_ES_API\n"); |
| 295 | return -1; |
| 296 | } |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 297 | if (!eglChooseConfig(c->base.display, config_attribs, |
| 298 | &c->base.config, 1, &n) || n == 0) { |
| 299 | fprintf(stderr, "failed to choose config: %d\n", n); |
| 300 | return -1; |
| 301 | } |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 302 | |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 303 | c->base.context = eglCreateContext(c->base.display, c->base.config, |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 304 | EGL_NO_CONTEXT, context_attribs); |
| 305 | if (c->base.context == NULL) { |
| 306 | fprintf(stderr, "failed to create context\n"); |
| 307 | return -1; |
| 308 | } |
| 309 | |
| 310 | if (!eglMakeCurrent(c->base.display, EGL_NO_SURFACE, |
| 311 | EGL_NO_SURFACE, c->base.context)) { |
| 312 | fprintf(stderr, "failed to make context current\n"); |
| 313 | return -1; |
| 314 | } |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 319 | static void |
Kristian Høgsberg | cdd61d0 | 2012-02-07 09:56:15 -0500 | [diff] [blame] | 320 | frame_done(void *data, struct wl_callback *callback, uint32_t time) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 321 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 322 | struct weston_output *output = data; |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 323 | |
Kristian Høgsberg | cdd61d0 | 2012-02-07 09:56:15 -0500 | [diff] [blame] | 324 | wl_callback_destroy(callback); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 325 | weston_output_finish_frame(output, time); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static const struct wl_callback_listener frame_listener = { |
| 329 | frame_done |
| 330 | }; |
| 331 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 332 | static void |
| 333 | wayland_output_repaint(struct weston_output *output_base) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 334 | { |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 335 | struct wayland_output *output = (struct wayland_output *) output_base; |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 336 | struct wayland_compositor *compositor = |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 337 | (struct wayland_compositor *) output->base.compositor; |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 338 | struct wl_callback *callback; |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 339 | struct weston_surface *surface; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 340 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 341 | if (!eglMakeCurrent(compositor->base.display, output->egl_surface, |
| 342 | output->egl_surface, compositor->base.context)) { |
| 343 | fprintf(stderr, "failed to make current\n"); |
| 344 | return; |
| 345 | } |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 346 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 347 | wl_list_for_each_reverse(surface, &compositor->base.surface_list, link) |
| 348 | weston_surface_draw(surface, &output->base); |
| 349 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame^] | 350 | draw_border(output); |
| 351 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 352 | eglSwapBuffers(compositor->base.display, output->egl_surface); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 353 | callback = wl_surface_frame(output->parent.surface); |
| 354 | wl_callback_add_listener(callback, &frame_listener, output); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 355 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 356 | return; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 360 | wayland_output_set_cursor(struct weston_output *output_base, |
| 361 | struct weston_input_device *input) |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 362 | { |
| 363 | return -1; |
| 364 | } |
| 365 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 366 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 367 | wayland_output_destroy(struct weston_output *output_base) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 368 | { |
| 369 | struct wayland_output *output = (struct wayland_output *) output_base; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 370 | struct weston_compositor *ec = output->base.compositor; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 371 | |
| 372 | eglDestroySurface(ec->display, output->egl_surface); |
| 373 | wl_egl_window_destroy(output->parent.egl_window); |
| 374 | free(output); |
| 375 | |
| 376 | return; |
| 377 | } |
| 378 | |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 379 | static int |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 380 | wayland_compositor_create_output(struct wayland_compositor *c, |
| 381 | int width, int height) |
| 382 | { |
| 383 | struct wayland_output *output; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 384 | |
| 385 | output = malloc(sizeof *output); |
| 386 | if (output == NULL) |
| 387 | return -1; |
| 388 | memset(output, 0, sizeof *output); |
| 389 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 390 | output->mode.flags = |
| 391 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 392 | output->mode.width = width; |
| 393 | output->mode.height = height; |
| 394 | output->mode.refresh = 60; |
| 395 | wl_list_init(&output->base.mode_list); |
| 396 | wl_list_insert(&output->base.mode_list, &output->mode.link); |
| 397 | |
| 398 | output->base.current = &output->mode; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 399 | weston_output_init(&output->base, &c->base, 0, 0, width, height, |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 400 | WL_OUTPUT_FLIPPED); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 401 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame^] | 402 | output->base.border.top = c->border.top; |
| 403 | output->base.border.bottom = c->border.bottom; |
| 404 | output->base.border.left = c->border.left; |
| 405 | output->base.border.right = c->border.right; |
| 406 | |
| 407 | weston_output_move(&output->base, 0, 0); |
| 408 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 409 | output->parent.surface = |
| 410 | wl_compositor_create_surface(c->parent.compositor); |
| 411 | wl_surface_set_user_data(output->parent.surface, output); |
| 412 | |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 413 | output->parent.egl_window = |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame^] | 414 | wl_egl_window_create(output->parent.surface, |
| 415 | width + c->border.left + c->border.right, |
| 416 | height + c->border.top + c->border.bottom); |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 417 | if (!output->parent.egl_window) { |
| 418 | fprintf(stderr, "failure to create wl_egl_window\n"); |
| 419 | goto cleanup_output; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 420 | } |
| 421 | |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 422 | output->egl_surface = |
| 423 | eglCreateWindowSurface(c->base.display, c->base.config, |
| 424 | output->parent.egl_window, NULL); |
| 425 | if (!output->egl_surface) { |
| 426 | fprintf(stderr, "failed to create window surface\n"); |
| 427 | goto cleanup_window; |
| 428 | } |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 429 | |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 430 | if (!eglMakeCurrent(c->base.display, output->egl_surface, |
| 431 | output->egl_surface, c->base.context)) { |
| 432 | fprintf(stderr, "failed to make surface current\n"); |
| 433 | goto cleanup_surface; |
| 434 | return -1; |
| 435 | } |
| 436 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 437 | output->parent.shell_surface = |
| 438 | wl_shell_get_shell_surface(c->parent.shell, |
| 439 | output->parent.surface); |
| 440 | /* FIXME: add shell_surface listener for resizing */ |
| 441 | wl_shell_surface_set_toplevel(output->parent.shell_surface); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 442 | |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 443 | output->base.repaint = wayland_output_repaint; |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 444 | output->base.set_hardware_cursor = wayland_output_set_cursor; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 445 | output->base.destroy = wayland_output_destroy; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 446 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 447 | wl_list_insert(c->base.output_list.prev, &output->base.link); |
| 448 | |
| 449 | return 0; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 450 | |
| 451 | cleanup_surface: |
| 452 | eglDestroySurface(c->base.display, output->egl_surface); |
| 453 | cleanup_window: |
| 454 | wl_egl_window_destroy(output->parent.egl_window); |
| 455 | cleanup_output: |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 456 | /* FIXME: cleanup weston_output */ |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 457 | free(output); |
| 458 | |
| 459 | return -1; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 460 | } |
| 461 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 462 | /* Events received from the wayland-server this compositor is client of: */ |
| 463 | |
| 464 | /* parent output interface */ |
| 465 | static void |
| 466 | display_handle_geometry(void *data, |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 467 | struct wl_output *wl_output, |
| 468 | int x, |
| 469 | int y, |
| 470 | int physical_width, |
| 471 | int physical_height, |
| 472 | int subpixel, |
| 473 | const char *make, |
| 474 | const char *model) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 475 | { |
| 476 | struct wayland_compositor *c = data; |
| 477 | |
Kristian Høgsberg | f8fc08f | 2010-12-01 20:10:10 -0500 | [diff] [blame] | 478 | c->parent.screen_allocation.x = x; |
| 479 | c->parent.screen_allocation.y = y; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | static void |
| 483 | display_handle_mode(void *data, |
| 484 | struct wl_output *wl_output, |
| 485 | uint32_t flags, |
| 486 | int width, |
| 487 | int height, |
| 488 | int refresh) |
| 489 | { |
| 490 | struct wayland_compositor *c = data; |
| 491 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 492 | c->parent.screen_allocation.width = width; |
| 493 | c->parent.screen_allocation.height = height; |
| 494 | } |
| 495 | |
| 496 | static const struct wl_output_listener output_listener = { |
| 497 | display_handle_geometry, |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 498 | display_handle_mode |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 499 | }; |
| 500 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 501 | /* parent input interface */ |
| 502 | static void |
| 503 | input_handle_motion(void *data, struct wl_input_device *input_device, |
| 504 | uint32_t time, |
| 505 | int32_t x, int32_t y, int32_t sx, int32_t sy) |
| 506 | { |
| 507 | struct wayland_input *input = data; |
| 508 | struct wayland_compositor *c = input->compositor; |
| 509 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame^] | 510 | notify_motion(c->base.input_device, time, |
| 511 | sx - c->border.left, sy - c->border.top); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | static void |
| 515 | input_handle_button(void *data, |
| 516 | struct wl_input_device *input_device, |
| 517 | uint32_t time, uint32_t button, uint32_t state) |
| 518 | { |
| 519 | struct wayland_input *input = data; |
| 520 | struct wayland_compositor *c = input->compositor; |
| 521 | |
| 522 | notify_button(c->base.input_device, time, button, state); |
| 523 | } |
| 524 | |
| 525 | static void |
| 526 | input_handle_key(void *data, struct wl_input_device *input_device, |
| 527 | uint32_t time, uint32_t key, uint32_t state) |
| 528 | { |
| 529 | struct wayland_input *input = data; |
| 530 | struct wayland_compositor *c = input->compositor; |
| 531 | |
| 532 | notify_key(c->base.input_device, time, key, state); |
| 533 | } |
| 534 | |
| 535 | static void |
| 536 | input_handle_pointer_focus(void *data, |
| 537 | struct wl_input_device *input_device, |
| 538 | uint32_t time, struct wl_surface *surface, |
| 539 | int32_t x, int32_t y, int32_t sx, int32_t sy) |
| 540 | { |
| 541 | struct wayland_input *input = data; |
Kristian Høgsberg | af82bea | 2011-01-27 20:18:17 -0500 | [diff] [blame] | 542 | struct wayland_output *output; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 543 | struct wayland_compositor *c = input->compositor; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 544 | |
| 545 | if (surface) { |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 546 | output = wl_surface_get_user_data(surface); |
| 547 | notify_pointer_focus(c->base.input_device, |
| 548 | time, &output->base, sx, sy); |
Kristian Høgsberg | d11d944 | 2012-02-07 09:56:51 -0500 | [diff] [blame] | 549 | |
| 550 | wl_input_device_attach(input->input_device, time, NULL, 0, 0); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 551 | } else { |
Kristian Høgsberg | 93331ff | 2011-01-26 20:35:07 -0500 | [diff] [blame] | 552 | notify_pointer_focus(c->base.input_device, time, NULL, 0, 0); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
| 556 | static void |
| 557 | input_handle_keyboard_focus(void *data, |
| 558 | struct wl_input_device *input_device, |
| 559 | uint32_t time, |
| 560 | struct wl_surface *surface, |
| 561 | struct wl_array *keys) |
| 562 | { |
Kristian Høgsberg | af82bea | 2011-01-27 20:18:17 -0500 | [diff] [blame] | 563 | struct wayland_input *input = data; |
| 564 | struct wayland_compositor *c = input->compositor; |
| 565 | struct wayland_output *output; |
| 566 | |
| 567 | if (surface) { |
| 568 | output = wl_surface_get_user_data(surface); |
| 569 | notify_keyboard_focus(c->base.input_device, |
| 570 | time, &output->base, keys); |
| 571 | } else { |
| 572 | notify_keyboard_focus(c->base.input_device, time, NULL, NULL); |
| 573 | } |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | static const struct wl_input_device_listener input_device_listener = { |
| 577 | input_handle_motion, |
| 578 | input_handle_button, |
| 579 | input_handle_key, |
| 580 | input_handle_pointer_focus, |
| 581 | input_handle_keyboard_focus, |
| 582 | }; |
| 583 | |
| 584 | static void |
| 585 | display_add_input(struct wayland_compositor *c, uint32_t id) |
| 586 | { |
| 587 | struct wayland_input *input; |
| 588 | |
| 589 | input = malloc(sizeof *input); |
| 590 | if (input == NULL) |
| 591 | return; |
| 592 | |
| 593 | memset(input, 0, sizeof *input); |
| 594 | |
| 595 | input->compositor = c; |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 596 | input->input_device = wl_display_bind(c->parent.display, |
| 597 | id, &wl_input_device_interface); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 598 | wl_list_insert(c->input_list.prev, &input->link); |
| 599 | |
| 600 | wl_input_device_add_listener(input->input_device, |
| 601 | &input_device_listener, input); |
| 602 | wl_input_device_set_user_data(input->input_device, input); |
| 603 | } |
| 604 | |
| 605 | static void |
| 606 | display_handle_global(struct wl_display *display, uint32_t id, |
| 607 | const char *interface, uint32_t version, void *data) |
| 608 | { |
| 609 | struct wayland_compositor *c = data; |
| 610 | |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 611 | if (strcmp(interface, "wl_compositor") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 612 | c->parent.compositor = |
| 613 | wl_display_bind(display, id, &wl_compositor_interface); |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 614 | } else if (strcmp(interface, "wl_output") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 615 | c->parent.output = |
| 616 | wl_display_bind(display, id, &wl_output_interface); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 617 | wl_output_add_listener(c->parent.output, &output_listener, c); |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 618 | } else if (strcmp(interface, "wl_input_device") == 0) { |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 619 | display_add_input(c, id); |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 620 | } else if (strcmp(interface, "wl_shell") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 621 | c->parent.shell = |
| 622 | wl_display_bind(display, id, &wl_shell_interface); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | |
| 626 | static int |
| 627 | update_event_mask(uint32_t mask, void *data) |
| 628 | { |
| 629 | struct wayland_compositor *c = data; |
| 630 | |
| 631 | c->parent.event_mask = mask; |
| 632 | if (c->parent.wl_source) |
| 633 | wl_event_source_fd_update(c->parent.wl_source, mask); |
| 634 | |
| 635 | return 0; |
| 636 | } |
| 637 | |
Kristian Høgsberg | 95d843d | 2011-04-22 13:01:26 -0400 | [diff] [blame] | 638 | static int |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 639 | wayland_compositor_handle_event(int fd, uint32_t mask, void *data) |
| 640 | { |
| 641 | struct wayland_compositor *c = data; |
| 642 | |
| 643 | if (mask & WL_EVENT_READABLE) |
| 644 | wl_display_iterate(c->parent.display, WL_DISPLAY_READABLE); |
Kristian Høgsberg | f258a31 | 2011-12-28 22:51:20 -0500 | [diff] [blame] | 645 | if (mask & WL_EVENT_WRITABLE) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 646 | wl_display_iterate(c->parent.display, WL_DISPLAY_WRITABLE); |
Kristian Høgsberg | 95d843d | 2011-04-22 13:01:26 -0400 | [diff] [blame] | 647 | |
| 648 | return 1; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 649 | } |
| 650 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 651 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 652 | wayland_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 653 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 654 | weston_compositor_shutdown(ec); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 655 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 656 | free(ec); |
| 657 | } |
| 658 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 659 | static struct weston_compositor * |
Kristian Høgsberg | 2e28b10 | 2012-02-07 09:57:25 -0500 | [diff] [blame] | 660 | wayland_compositor_create(struct wl_display *display, |
| 661 | int width, int height, const char *display_name) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 662 | { |
| 663 | struct wayland_compositor *c; |
| 664 | struct wl_event_loop *loop; |
| 665 | int fd; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 666 | |
| 667 | c = malloc(sizeof *c); |
| 668 | if (c == NULL) |
| 669 | return NULL; |
| 670 | |
| 671 | memset(c, 0, sizeof *c); |
| 672 | |
Kristian Høgsberg | 2e28b10 | 2012-02-07 09:57:25 -0500 | [diff] [blame] | 673 | c->parent.display = wl_display_connect(display_name); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 674 | |
| 675 | if (c->parent.display == NULL) { |
| 676 | fprintf(stderr, "failed to create display: %m\n"); |
| 677 | return NULL; |
| 678 | } |
| 679 | |
| 680 | wl_list_init(&c->input_list); |
| 681 | wl_display_add_global_listener(c->parent.display, |
| 682 | display_handle_global, c); |
| 683 | |
| 684 | wl_display_iterate(c->parent.display, WL_DISPLAY_READABLE); |
| 685 | |
| 686 | c->base.wl_display = display; |
| 687 | if (wayland_compositor_init_egl(c) < 0) |
| 688 | return NULL; |
| 689 | |
Benjamin Franzke | ecfb2b9 | 2011-01-15 12:34:48 +0100 | [diff] [blame] | 690 | c->base.destroy = wayland_destroy; |
Benjamin Franzke | ecfb2b9 | 2011-01-15 12:34:48 +0100 | [diff] [blame] | 691 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 692 | /* Can't init base class until we have a current egl context */ |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 693 | if (weston_compositor_init(&c->base, display) < 0) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 694 | return NULL; |
| 695 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame^] | 696 | create_border(c); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 697 | if (wayland_compositor_create_output(c, width, height) < 0) |
| 698 | return NULL; |
| 699 | |
| 700 | if (wayland_input_create(c) < 0) |
| 701 | return NULL; |
| 702 | |
| 703 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 704 | |
| 705 | fd = wl_display_get_fd(c->parent.display, update_event_mask, c); |
| 706 | c->parent.wl_source = |
| 707 | wl_event_loop_add_fd(loop, fd, c->parent.event_mask, |
| 708 | wayland_compositor_handle_event, c); |
| 709 | if (c->parent.wl_source == NULL) |
| 710 | return NULL; |
| 711 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 712 | return &c->base; |
| 713 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 714 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 715 | struct weston_compositor * |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 716 | backend_init(struct wl_display *display, char *options); |
| 717 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 718 | WL_EXPORT struct weston_compositor * |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 719 | backend_init(struct wl_display *display, char *options) |
| 720 | { |
| 721 | int width = 1024, height = 640, i; |
Kristian Høgsberg | 2e28b10 | 2012-02-07 09:57:25 -0500 | [diff] [blame] | 722 | char *p, *value, *display_name = NULL; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 723 | |
Kristian Høgsberg | 2e28b10 | 2012-02-07 09:57:25 -0500 | [diff] [blame] | 724 | static char * const tokens[] = { "width", "height", "display", NULL }; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 725 | |
| 726 | p = options; |
| 727 | while (i = getsubopt(&p, tokens, &value), i != -1) { |
| 728 | switch (i) { |
| 729 | case 0: |
| 730 | width = strtol(value, NULL, 0); |
| 731 | break; |
| 732 | case 1: |
| 733 | height = strtol(value, NULL, 0); |
| 734 | break; |
Kristian Høgsberg | 2e28b10 | 2012-02-07 09:57:25 -0500 | [diff] [blame] | 735 | case 2: |
| 736 | display_name = strdup(value); |
| 737 | break; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
Kristian Høgsberg | 2e28b10 | 2012-02-07 09:57:25 -0500 | [diff] [blame] | 741 | return wayland_compositor_create(display, width, height, display_name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 742 | } |