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> |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 34 | #include <sys/mman.h> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 35 | |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 36 | #include <wayland-client.h> |
| 37 | #include <wayland-egl.h> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 38 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 39 | #include <GLES2/gl2.h> |
| 40 | #include <GLES2/gl2ext.h> |
| 41 | #include <EGL/egl.h> |
| 42 | #include <EGL/eglext.h> |
| 43 | |
| 44 | #include "compositor.h" |
| 45 | |
| 46 | struct wayland_compositor { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 47 | struct weston_compositor base; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 48 | |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 49 | struct wl_egl_pixmap *dummy_pixmap; |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 50 | EGLSurface dummy_egl_surface; |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 51 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 52 | struct { |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 53 | struct wl_display *wl_display; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 54 | struct wl_compositor *compositor; |
| 55 | struct wl_shell *shell; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 56 | struct wl_output *output; |
| 57 | |
| 58 | struct { |
| 59 | int32_t x, y, width, height; |
| 60 | } screen_allocation; |
| 61 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 62 | struct wl_event_source *wl_source; |
| 63 | uint32_t event_mask; |
| 64 | } parent; |
| 65 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 66 | struct { |
| 67 | int32_t top, bottom, left, right; |
| 68 | GLuint texture; |
| 69 | int32_t width, height; |
| 70 | } border; |
| 71 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 72 | struct wl_list input_list; |
| 73 | }; |
| 74 | |
| 75 | struct wayland_output { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 76 | struct weston_output base; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 77 | |
| 78 | struct { |
| 79 | struct wl_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 80 | struct wl_shell_surface *shell_surface; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 81 | struct wl_egl_window *egl_window; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 82 | } parent; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 83 | EGLSurface egl_surface; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 84 | struct weston_mode mode; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | struct wayland_input { |
Kristian Høgsberg | 7af7ced | 2012-08-10 10:01:33 -0400 | [diff] [blame] | 88 | struct weston_seat base; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 89 | struct wayland_compositor *compositor; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 90 | struct wl_seat *seat; |
| 91 | struct wl_pointer *pointer; |
| 92 | struct wl_keyboard *keyboard; |
| 93 | struct wl_touch *touch; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 94 | struct wl_list link; |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 95 | uint32_t key_serial; |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 96 | uint32_t enter_serial; |
| 97 | int focus; |
| 98 | struct wayland_output *output; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 99 | }; |
| 100 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 101 | |
| 102 | static int |
| 103 | texture_border(struct wayland_output *output) |
| 104 | { |
| 105 | struct wayland_compositor *c = |
| 106 | (struct wayland_compositor *) output->base.compositor; |
| 107 | GLfloat *d; |
| 108 | unsigned int *p; |
| 109 | int i, j, k, n; |
| 110 | GLfloat x[4], y[4], u[4], v[4]; |
| 111 | |
| 112 | x[0] = -c->border.left; |
| 113 | x[1] = 0; |
| 114 | x[2] = output->base.current->width; |
| 115 | x[3] = output->base.current->width + c->border.right; |
| 116 | |
| 117 | y[0] = -c->border.top; |
| 118 | y[1] = 0; |
| 119 | y[2] = output->base.current->height; |
| 120 | y[3] = output->base.current->height + c->border.bottom; |
| 121 | |
| 122 | u[0] = 0.0; |
| 123 | u[1] = (GLfloat) c->border.left / c->border.width; |
| 124 | u[2] = (GLfloat) (c->border.width - c->border.right) / c->border.width; |
| 125 | u[3] = 1.0; |
| 126 | |
| 127 | v[0] = 0.0; |
| 128 | v[1] = (GLfloat) c->border.top / c->border.height; |
| 129 | v[2] = (GLfloat) (c->border.height - c->border.bottom) / c->border.height; |
| 130 | v[3] = 1.0; |
| 131 | |
| 132 | n = 8; |
| 133 | d = wl_array_add(&c->base.vertices, n * 16 * sizeof *d); |
| 134 | p = wl_array_add(&c->base.indices, n * 6 * sizeof *p); |
| 135 | |
| 136 | k = 0; |
| 137 | for (i = 0; i < 3; i++) |
| 138 | for (j = 0; j < 3; j++) { |
| 139 | |
| 140 | if (i == 1 && j == 1) |
| 141 | continue; |
| 142 | |
| 143 | d[ 0] = x[i]; |
| 144 | d[ 1] = y[j]; |
| 145 | d[ 2] = u[i]; |
| 146 | d[ 3] = v[j]; |
| 147 | |
| 148 | d[ 4] = x[i]; |
| 149 | d[ 5] = y[j + 1]; |
| 150 | d[ 6] = u[i]; |
| 151 | d[ 7] = v[j + 1]; |
| 152 | |
| 153 | d[ 8] = x[i + 1]; |
| 154 | d[ 9] = y[j]; |
| 155 | d[10] = u[i + 1]; |
| 156 | d[11] = v[j]; |
| 157 | |
| 158 | d[12] = x[i + 1]; |
| 159 | d[13] = y[j + 1]; |
| 160 | d[14] = u[i + 1]; |
| 161 | d[15] = v[j + 1]; |
| 162 | |
| 163 | p[0] = k + 0; |
| 164 | p[1] = k + 1; |
| 165 | p[2] = k + 2; |
| 166 | p[3] = k + 2; |
| 167 | p[4] = k + 1; |
| 168 | p[5] = k + 3; |
| 169 | |
| 170 | d += 16; |
| 171 | p += 6; |
| 172 | k += 4; |
| 173 | } |
| 174 | |
| 175 | return k / 4; |
| 176 | } |
| 177 | |
| 178 | static void |
| 179 | draw_border(struct wayland_output *output) |
| 180 | { |
| 181 | struct wayland_compositor *c = |
| 182 | (struct wayland_compositor *) output->base.compositor; |
Gwenole Beauchesne | 6d03049 | 2012-04-20 11:15:51 +0200 | [diff] [blame] | 183 | struct weston_shader *shader = &c->base.texture_shader_rgba; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 184 | GLfloat *v; |
| 185 | int n; |
| 186 | |
| 187 | glDisable(GL_BLEND); |
| 188 | glUseProgram(shader->program); |
| 189 | c->base.current_shader = shader; |
| 190 | |
| 191 | glUniformMatrix4fv(shader->proj_uniform, |
| 192 | 1, GL_FALSE, output->base.matrix.d); |
| 193 | |
Gwenole Beauchesne | 28f59b0 | 2012-04-20 11:44:06 +0200 | [diff] [blame] | 194 | glUniform1i(shader->tex_uniforms[0], 0); |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 195 | glUniform1f(shader->alpha_uniform, 1); |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 196 | glUniform1f(shader->texwidth_uniform, 1); |
| 197 | |
| 198 | n = texture_border(output); |
| 199 | |
| 200 | glBindTexture(GL_TEXTURE_2D, c->border.texture); |
| 201 | |
| 202 | v = c->base.vertices.data; |
| 203 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[0]); |
| 204 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[2]); |
| 205 | glEnableVertexAttribArray(0); |
| 206 | glEnableVertexAttribArray(1); |
| 207 | |
| 208 | glDrawElements(GL_TRIANGLES, n * 6, |
| 209 | GL_UNSIGNED_INT, c->base.indices.data); |
| 210 | |
| 211 | glDisableVertexAttribArray(1); |
| 212 | glDisableVertexAttribArray(0); |
| 213 | |
| 214 | c->base.vertices.size = 0; |
| 215 | c->base.indices.size = 0; |
| 216 | } |
| 217 | |
| 218 | static void |
| 219 | create_border(struct wayland_compositor *c) |
| 220 | { |
Ander Conselvan de Oliveira | e2d21e8 | 2012-03-16 17:25:09 +0200 | [diff] [blame] | 221 | pixman_image_t *image; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 222 | |
Ander Conselvan de Oliveira | e2d21e8 | 2012-03-16 17:25:09 +0200 | [diff] [blame] | 223 | image = load_image(DATADIR "/weston/border.png"); |
| 224 | if (!image) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 225 | weston_log("could'nt load border image\n"); |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 226 | return; |
| 227 | } |
| 228 | |
Ander Conselvan de Oliveira | e2d21e8 | 2012-03-16 17:25:09 +0200 | [diff] [blame] | 229 | c->border.width = pixman_image_get_width(image); |
| 230 | c->border.height = pixman_image_get_height(image); |
| 231 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 232 | glGenTextures(1, &c->border.texture); |
| 233 | glBindTexture(GL_TEXTURE_2D, c->border.texture); |
| 234 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 235 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 236 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 237 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 238 | |
| 239 | glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, |
| 240 | c->border.width, |
| 241 | c->border.height, |
Ander Conselvan de Oliveira | e2d21e8 | 2012-03-16 17:25:09 +0200 | [diff] [blame] | 242 | 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, |
| 243 | pixman_image_get_data(image)); |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 244 | |
| 245 | c->border.top = 25; |
| 246 | c->border.bottom = 50; |
| 247 | c->border.left = 25; |
| 248 | c->border.right = 25; |
Ander Conselvan de Oliveira | e2d21e8 | 2012-03-16 17:25:09 +0200 | [diff] [blame] | 249 | |
| 250 | pixman_image_unref(image); |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 251 | } |
| 252 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 253 | static int |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 254 | wayland_compositor_init_egl(struct wayland_compositor *c) |
| 255 | { |
| 256 | EGLint major, minor; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 257 | EGLint n; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 258 | EGLint config_attribs[] = { |
| 259 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 260 | EGL_RED_SIZE, 1, |
| 261 | EGL_GREEN_SIZE, 1, |
| 262 | EGL_BLUE_SIZE, 1, |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 263 | EGL_ALPHA_SIZE, 1, |
Kristian Høgsberg | d28ab36 | 2011-03-02 11:36:30 -0500 | [diff] [blame] | 264 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 265 | EGL_NONE |
| 266 | }; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 267 | static const EGLint context_attribs[] = { |
| 268 | EGL_CONTEXT_CLIENT_VERSION, 2, |
| 269 | EGL_NONE |
| 270 | }; |
| 271 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 272 | c->base.egl_display = eglGetDisplay(c->parent.wl_display); |
| 273 | if (c->base.egl_display == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 274 | weston_log("failed to create display\n"); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 275 | return -1; |
| 276 | } |
| 277 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 278 | if (!eglInitialize(c->base.egl_display, &major, &minor)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 279 | weston_log("failed to initialize display\n"); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 280 | return -1; |
| 281 | } |
| 282 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 283 | if (!eglBindAPI(EGL_OPENGL_ES_API)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 284 | weston_log("failed to bind EGL_OPENGL_ES_API\n"); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 285 | return -1; |
| 286 | } |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 287 | if (!eglChooseConfig(c->base.egl_display, config_attribs, |
| 288 | &c->base.egl_config, 1, &n) || n == 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 289 | weston_log("failed to choose config: %d\n", n); |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 290 | return -1; |
| 291 | } |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 292 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 293 | c->base.egl_context = |
| 294 | eglCreateContext(c->base.egl_display, c->base.egl_config, |
| 295 | EGL_NO_CONTEXT, context_attribs); |
| 296 | if (c->base.egl_context == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 297 | weston_log("failed to create context\n"); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 298 | return -1; |
| 299 | } |
| 300 | |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 301 | c->dummy_pixmap = wl_egl_pixmap_create(10, 10, 0); |
| 302 | if (!c->dummy_pixmap) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 303 | weston_log("failure to create dummy_pixmap\n"); |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 304 | return -1; |
| 305 | } |
| 306 | |
| 307 | c->dummy_egl_surface = |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 308 | eglCreatePixmapSurface(c->base.egl_display, c->base.egl_config, |
Kristian Høgsberg | b5ef591 | 2012-03-28 22:53:49 -0400 | [diff] [blame] | 309 | c->dummy_pixmap, NULL); |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 310 | if (!eglMakeCurrent(c->base.egl_display, c->dummy_egl_surface, |
| 311 | c->dummy_egl_surface, c->base.egl_context)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 312 | weston_log("failed to make context current\n"); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 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 |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 333 | wayland_output_repaint(struct weston_output *output_base, |
| 334 | pixman_region32_t *damage) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 335 | { |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 336 | struct wayland_output *output = (struct wayland_output *) output_base; |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 337 | struct wayland_compositor *compositor = |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 338 | (struct wayland_compositor *) output->base.compositor; |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 339 | struct wl_callback *callback; |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 340 | struct weston_surface *surface; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 341 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 342 | if (!eglMakeCurrent(compositor->base.egl_display, output->egl_surface, |
| 343 | output->egl_surface, |
| 344 | compositor->base.egl_context)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 345 | weston_log("failed to make current\n"); |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 346 | return; |
| 347 | } |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 348 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 349 | wl_list_for_each_reverse(surface, &compositor->base.surface_list, link) |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 350 | weston_surface_draw(surface, &output->base, damage); |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 351 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 352 | draw_border(output); |
| 353 | |
Kristian Høgsberg | e0f832b | 2012-06-20 00:13:18 -0400 | [diff] [blame] | 354 | wl_signal_emit(&output->base.frame_signal, output); |
Scott Moreau | 062be7e | 2012-04-20 13:37:33 -0600 | [diff] [blame] | 355 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 356 | eglSwapBuffers(compositor->base.egl_display, output->egl_surface); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 357 | callback = wl_surface_frame(output->parent.surface); |
| 358 | wl_callback_add_listener(callback, &frame_listener, output); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 359 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 360 | return; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 361 | } |
| 362 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 363 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 364 | wayland_output_destroy(struct weston_output *output_base) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 365 | { |
| 366 | struct wayland_output *output = (struct wayland_output *) output_base; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 367 | struct weston_compositor *ec = output->base.compositor; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 368 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 369 | eglDestroySurface(ec->egl_display, output->egl_surface); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 370 | wl_egl_window_destroy(output->parent.egl_window); |
| 371 | free(output); |
| 372 | |
| 373 | return; |
| 374 | } |
| 375 | |
Ander Conselvan de Oliveira | 563c5b8 | 2012-06-18 17:36:21 +0300 | [diff] [blame] | 376 | static const struct wl_shell_surface_listener shell_surface_listener; |
| 377 | |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 378 | static int |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 379 | wayland_compositor_create_output(struct wayland_compositor *c, |
| 380 | int width, int height) |
| 381 | { |
| 382 | struct wayland_output *output; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 383 | |
| 384 | output = malloc(sizeof *output); |
| 385 | if (output == NULL) |
| 386 | return -1; |
| 387 | memset(output, 0, sizeof *output); |
| 388 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 389 | output->mode.flags = |
| 390 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 391 | output->mode.width = width; |
| 392 | output->mode.height = height; |
| 393 | output->mode.refresh = 60; |
| 394 | wl_list_init(&output->base.mode_list); |
| 395 | wl_list_insert(&output->base.mode_list, &output->mode.link); |
| 396 | |
| 397 | output->base.current = &output->mode; |
Kristian Høgsberg | 99fd101 | 2012-08-10 09:57:56 -0400 | [diff] [blame] | 398 | weston_output_init(&output->base, &c->base, 0, 0, width, height); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 399 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 400 | output->base.border.top = c->border.top; |
| 401 | output->base.border.bottom = c->border.bottom; |
| 402 | output->base.border.left = c->border.left; |
| 403 | output->base.border.right = c->border.right; |
Kristian Høgsberg | 90bc88c | 2012-08-13 23:34:04 -0400 | [diff] [blame^] | 404 | output->base.make = "waywayland"; |
| 405 | output->base.model = "none"; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 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) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 418 | weston_log("failure to create wl_egl_window\n"); |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 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 = |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 423 | eglCreateWindowSurface(c->base.egl_display, c->base.egl_config, |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 424 | output->parent.egl_window, NULL); |
| 425 | if (!output->egl_surface) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 426 | weston_log("failed to create window surface\n"); |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 427 | goto cleanup_window; |
| 428 | } |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 429 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 430 | if (!eglMakeCurrent(c->base.egl_display, output->egl_surface, |
| 431 | output->egl_surface, c->base.egl_context)) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 432 | weston_log("failed to make surface current\n"); |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 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); |
Ander Conselvan de Oliveira | 563c5b8 | 2012-06-18 17:36:21 +0300 | [diff] [blame] | 440 | wl_shell_surface_add_listener(output->parent.shell_surface, |
| 441 | &shell_surface_listener, output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 442 | wl_shell_surface_set_toplevel(output->parent.shell_surface); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 443 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 444 | output->base.origin = output->base.current; |
Kristian Høgsberg | 68c479a | 2012-01-25 23:32:28 -0500 | [diff] [blame] | 445 | output->base.repaint = wayland_output_repaint; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 446 | output->base.destroy = wayland_output_destroy; |
Jesse Barnes | 5308a5e | 2012-02-09 13:12:57 -0800 | [diff] [blame] | 447 | output->base.assign_planes = NULL; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 448 | output->base.set_backlight = NULL; |
| 449 | output->base.set_dpms = NULL; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 450 | output->base.switch_mode = NULL; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 451 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 452 | wl_list_insert(c->base.output_list.prev, &output->base.link); |
| 453 | |
| 454 | return 0; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 455 | |
| 456 | cleanup_surface: |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 457 | eglDestroySurface(c->base.egl_display, output->egl_surface); |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 458 | cleanup_window: |
| 459 | wl_egl_window_destroy(output->parent.egl_window); |
| 460 | cleanup_output: |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 461 | /* FIXME: cleanup weston_output */ |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 462 | free(output); |
| 463 | |
| 464 | return -1; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 465 | } |
| 466 | |
Ander Conselvan de Oliveira | 563c5b8 | 2012-06-18 17:36:21 +0300 | [diff] [blame] | 467 | static void |
| 468 | shell_surface_ping(void *data, struct wl_shell_surface *shell_surface, |
| 469 | uint32_t serial) |
| 470 | { |
| 471 | wl_shell_surface_pong(shell_surface, serial); |
| 472 | } |
| 473 | |
| 474 | static void |
| 475 | shell_surface_configure(void *data, struct wl_shell_surface *shell_surface, |
| 476 | uint32_t edges, int32_t width, int32_t height) |
| 477 | { |
| 478 | /* FIXME: implement resizing */ |
| 479 | } |
| 480 | |
| 481 | static void |
| 482 | shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface) |
| 483 | { |
| 484 | } |
| 485 | |
| 486 | static const struct wl_shell_surface_listener shell_surface_listener = { |
| 487 | shell_surface_ping, |
| 488 | shell_surface_configure, |
| 489 | shell_surface_popup_done |
| 490 | }; |
| 491 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 492 | /* Events received from the wayland-server this compositor is client of: */ |
| 493 | |
| 494 | /* parent output interface */ |
| 495 | static void |
| 496 | display_handle_geometry(void *data, |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 497 | struct wl_output *wl_output, |
| 498 | int x, |
| 499 | int y, |
| 500 | int physical_width, |
| 501 | int physical_height, |
| 502 | int subpixel, |
| 503 | const char *make, |
Kristian Høgsberg | 0e69647 | 2012-07-22 15:49:57 -0400 | [diff] [blame] | 504 | const char *model, |
| 505 | int transform) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 506 | { |
| 507 | struct wayland_compositor *c = data; |
| 508 | |
Kristian Høgsberg | f8fc08f | 2010-12-01 20:10:10 -0500 | [diff] [blame] | 509 | c->parent.screen_allocation.x = x; |
| 510 | c->parent.screen_allocation.y = y; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | static void |
| 514 | display_handle_mode(void *data, |
| 515 | struct wl_output *wl_output, |
| 516 | uint32_t flags, |
| 517 | int width, |
| 518 | int height, |
| 519 | int refresh) |
| 520 | { |
| 521 | struct wayland_compositor *c = data; |
| 522 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 523 | c->parent.screen_allocation.width = width; |
| 524 | c->parent.screen_allocation.height = height; |
| 525 | } |
| 526 | |
| 527 | static const struct wl_output_listener output_listener = { |
| 528 | display_handle_geometry, |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 529 | display_handle_mode |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 530 | }; |
| 531 | |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 532 | static void |
| 533 | check_focus(struct wayland_input *input, wl_fixed_t x, wl_fixed_t y) |
| 534 | { |
| 535 | struct wayland_compositor *c = input->compositor; |
| 536 | int width, height, inside; |
| 537 | |
| 538 | width = input->output->mode.width; |
| 539 | height = input->output->mode.height; |
| 540 | |
| 541 | inside = c->border.left <= wl_fixed_to_int(x) && |
| 542 | wl_fixed_to_int(x) < width + c->border.left && |
| 543 | c->border.top <= wl_fixed_to_int(y) && |
| 544 | wl_fixed_to_int(y) < height + c->border.top; |
| 545 | |
| 546 | if (!input->focus && inside) { |
| 547 | notify_pointer_focus(&input->base, &input->output->base, |
| 548 | x - wl_fixed_from_int(c->border.left), |
| 549 | y = wl_fixed_from_int(c->border.top)); |
| 550 | wl_pointer_set_cursor(input->pointer, |
| 551 | input->enter_serial, NULL, 0, 0); |
| 552 | } else if (input->focus && !inside) { |
| 553 | notify_pointer_focus(&input->base, NULL, 0, 0); |
| 554 | /* FIXME: Should set default cursor here. */ |
| 555 | } |
| 556 | |
| 557 | input->focus = inside; |
| 558 | } |
| 559 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 560 | /* parent input interface */ |
| 561 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 562 | input_handle_pointer_enter(void *data, struct wl_pointer *pointer, |
| 563 | uint32_t serial, struct wl_surface *surface, |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 564 | wl_fixed_t x, wl_fixed_t y) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 565 | { |
| 566 | struct wayland_input *input = data; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 567 | |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 568 | /* XXX: If we get a modifier event immediately before the focus, |
| 569 | * we should try to keep the same serial. */ |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 570 | input->enter_serial = serial; |
| 571 | input->output = wl_surface_get_user_data(surface); |
| 572 | check_focus(input, x, y); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 576 | input_handle_pointer_leave(void *data, struct wl_pointer *pointer, |
| 577 | uint32_t serial, struct wl_surface *surface) |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 578 | { |
| 579 | struct wayland_input *input = data; |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 580 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 581 | notify_pointer_focus(&input->base, NULL, 0, 0); |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 582 | input->output = NULL; |
| 583 | input->focus = 0; |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 587 | input_handle_motion(void *data, struct wl_pointer *pointer, |
| 588 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
| 589 | { |
| 590 | struct wayland_input *input = data; |
| 591 | struct wayland_compositor *c = input->compositor; |
| 592 | |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 593 | check_focus(input, x, y); |
| 594 | if (input->focus) |
| 595 | notify_motion(&input->base, time, |
| 596 | x - wl_fixed_from_int(c->border.left), |
| 597 | y - wl_fixed_from_int(c->border.top)); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static void |
| 601 | input_handle_button(void *data, struct wl_pointer *pointer, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 602 | uint32_t serial, uint32_t time, uint32_t button, |
| 603 | uint32_t state_w) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 604 | { |
| 605 | struct wayland_input *input = data; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 606 | enum wl_pointer_button_state state = state_w; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 607 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 608 | notify_button(&input->base, time, button, state); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | static void |
| 612 | input_handle_axis(void *data, struct wl_pointer *pointer, |
Daniel Stone | 2fce402 | 2012-05-30 16:32:00 +0100 | [diff] [blame] | 613 | uint32_t time, uint32_t axis, wl_fixed_t value) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 614 | { |
| 615 | struct wayland_input *input = data; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 616 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 617 | notify_axis(&input->base, time, axis, value); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static const struct wl_pointer_listener pointer_listener = { |
| 621 | input_handle_pointer_enter, |
| 622 | input_handle_pointer_leave, |
| 623 | input_handle_motion, |
| 624 | input_handle_button, |
| 625 | input_handle_axis, |
| 626 | }; |
| 627 | |
| 628 | static void |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 629 | input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format, |
| 630 | int fd, uint32_t size) |
| 631 | { |
| 632 | struct wayland_input *input = data; |
| 633 | struct xkb_keymap *keymap; |
| 634 | char *map_str; |
| 635 | |
| 636 | if (!data) { |
| 637 | close(fd); |
| 638 | return; |
| 639 | } |
| 640 | |
| 641 | if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { |
| 642 | close(fd); |
| 643 | return; |
| 644 | } |
| 645 | |
| 646 | map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); |
| 647 | if (map_str == MAP_FAILED) { |
| 648 | close(fd); |
| 649 | return; |
| 650 | } |
| 651 | |
| 652 | keymap = xkb_map_new_from_string(input->compositor->base.xkb_context, |
| 653 | map_str, |
| 654 | XKB_KEYMAP_FORMAT_TEXT_V1, |
| 655 | 0); |
| 656 | munmap(map_str, size); |
| 657 | close(fd); |
| 658 | |
| 659 | if (!keymap) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 660 | weston_log("failed to compile keymap\n"); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 661 | return; |
| 662 | } |
| 663 | |
Kristian Høgsberg | 7af7ced | 2012-08-10 10:01:33 -0400 | [diff] [blame] | 664 | weston_seat_init_keyboard(&input->base, keymap); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 665 | xkb_map_unref(keymap); |
| 666 | } |
| 667 | |
| 668 | static void |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 669 | input_handle_keyboard_enter(void *data, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 670 | struct wl_keyboard *keyboard, |
| 671 | uint32_t serial, |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 672 | struct wl_surface *surface, |
| 673 | struct wl_array *keys) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 674 | { |
Kristian Høgsberg | af82bea | 2011-01-27 20:18:17 -0500 | [diff] [blame] | 675 | struct wayland_input *input = data; |
Kristian Høgsberg | af82bea | 2011-01-27 20:18:17 -0500 | [diff] [blame] | 676 | |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 677 | /* XXX: If we get a modifier event immediately before the focus, |
| 678 | * we should try to keep the same serial. */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 679 | notify_keyboard_focus_in(&input->base, keys, |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 680 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | static void |
| 684 | input_handle_keyboard_leave(void *data, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 685 | struct wl_keyboard *keyboard, |
| 686 | uint32_t serial, |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 687 | struct wl_surface *surface) |
| 688 | { |
| 689 | struct wayland_input *input = data; |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 690 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 691 | notify_keyboard_focus_out(&input->base); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 692 | } |
| 693 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 694 | static void |
| 695 | input_handle_key(void *data, struct wl_keyboard *keyboard, |
| 696 | uint32_t serial, uint32_t time, uint32_t key, uint32_t state) |
| 697 | { |
| 698 | struct wayland_input *input = data; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 699 | |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 700 | input->key_serial = serial; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 701 | notify_key(&input->base, time, key, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 702 | state ? WL_KEYBOARD_KEY_STATE_PRESSED : |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 703 | WL_KEYBOARD_KEY_STATE_RELEASED, |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 704 | STATE_UPDATE_NONE); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 705 | } |
| 706 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 707 | static void |
| 708 | input_handle_modifiers(void *data, struct wl_keyboard *keyboard, |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 709 | uint32_t serial_in, uint32_t mods_depressed, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 710 | uint32_t mods_latched, uint32_t mods_locked, |
| 711 | uint32_t group) |
| 712 | { |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 713 | struct wayland_input *input = data; |
| 714 | struct wayland_compositor *c = input->compositor; |
| 715 | uint32_t serial_out; |
| 716 | |
| 717 | /* If we get a key event followed by a modifier event with the |
| 718 | * same serial number, then we try to preserve those semantics by |
| 719 | * reusing the same serial number on the way out too. */ |
| 720 | if (serial_in == input->key_serial) |
| 721 | serial_out = wl_display_get_serial(c->base.wl_display); |
| 722 | else |
| 723 | serial_out = wl_display_next_serial(c->base.wl_display); |
| 724 | |
Kristian Høgsberg | 7af7ced | 2012-08-10 10:01:33 -0400 | [diff] [blame] | 725 | xkb_state_update_mask(input->base.xkb_state.state, |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 726 | mods_depressed, mods_latched, |
| 727 | mods_locked, 0, 0, group); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 728 | notify_modifiers(&input->base, serial_out); |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 729 | } |
| 730 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 731 | static const struct wl_keyboard_listener keyboard_listener = { |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 732 | input_handle_keymap, |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 733 | input_handle_keyboard_enter, |
| 734 | input_handle_keyboard_leave, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 735 | input_handle_key, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 736 | input_handle_modifiers, |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 737 | }; |
| 738 | |
| 739 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 740 | input_handle_capabilities(void *data, struct wl_seat *seat, |
| 741 | enum wl_seat_capability caps) |
| 742 | { |
| 743 | struct wayland_input *input = data; |
| 744 | |
| 745 | if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) { |
| 746 | input->pointer = wl_seat_get_pointer(seat); |
| 747 | wl_pointer_set_user_data(input->pointer, input); |
| 748 | wl_pointer_add_listener(input->pointer, &pointer_listener, |
| 749 | input); |
Kristian Høgsberg | 7af7ced | 2012-08-10 10:01:33 -0400 | [diff] [blame] | 750 | weston_seat_init_pointer(&input->base); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 751 | } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) { |
| 752 | wl_pointer_destroy(input->pointer); |
| 753 | input->pointer = NULL; |
| 754 | } |
| 755 | |
| 756 | if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) { |
| 757 | input->keyboard = wl_seat_get_keyboard(seat); |
| 758 | wl_keyboard_set_user_data(input->keyboard, input); |
| 759 | wl_keyboard_add_listener(input->keyboard, &keyboard_listener, |
| 760 | input); |
| 761 | } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) { |
| 762 | wl_keyboard_destroy(input->keyboard); |
| 763 | input->keyboard = NULL; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | static const struct wl_seat_listener seat_listener = { |
| 768 | input_handle_capabilities, |
| 769 | }; |
| 770 | |
| 771 | static void |
| 772 | display_add_seat(struct wayland_compositor *c, uint32_t id) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 773 | { |
| 774 | struct wayland_input *input; |
| 775 | |
| 776 | input = malloc(sizeof *input); |
| 777 | if (input == NULL) |
| 778 | return; |
| 779 | |
| 780 | memset(input, 0, sizeof *input); |
| 781 | |
Kristian Høgsberg | 7af7ced | 2012-08-10 10:01:33 -0400 | [diff] [blame] | 782 | weston_seat_init(&input->base, &c->base); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 783 | input->compositor = c; |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 784 | input->seat = wl_display_bind(c->parent.wl_display, id, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 785 | &wl_seat_interface); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 786 | wl_list_insert(c->input_list.prev, &input->link); |
| 787 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 788 | wl_seat_add_listener(input->seat, &seat_listener, input); |
| 789 | wl_seat_set_user_data(input->seat, input); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | static void |
| 793 | display_handle_global(struct wl_display *display, uint32_t id, |
| 794 | const char *interface, uint32_t version, void *data) |
| 795 | { |
| 796 | struct wayland_compositor *c = data; |
| 797 | |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 798 | if (strcmp(interface, "wl_compositor") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 799 | c->parent.compositor = |
| 800 | wl_display_bind(display, id, &wl_compositor_interface); |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 801 | } else if (strcmp(interface, "wl_output") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 802 | c->parent.output = |
| 803 | wl_display_bind(display, id, &wl_output_interface); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 804 | wl_output_add_listener(c->parent.output, &output_listener, c); |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 805 | } else if (strcmp(interface, "wl_shell") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 806 | c->parent.shell = |
| 807 | wl_display_bind(display, id, &wl_shell_interface); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 808 | } else if (strcmp(interface, "wl_seat") == 0) { |
| 809 | display_add_seat(c, id); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | |
| 813 | static int |
| 814 | update_event_mask(uint32_t mask, void *data) |
| 815 | { |
| 816 | struct wayland_compositor *c = data; |
| 817 | |
| 818 | c->parent.event_mask = mask; |
| 819 | if (c->parent.wl_source) |
| 820 | wl_event_source_fd_update(c->parent.wl_source, mask); |
| 821 | |
| 822 | return 0; |
| 823 | } |
| 824 | |
Kristian Høgsberg | 95d843d | 2011-04-22 13:01:26 -0400 | [diff] [blame] | 825 | static int |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 826 | wayland_compositor_handle_event(int fd, uint32_t mask, void *data) |
| 827 | { |
| 828 | struct wayland_compositor *c = data; |
| 829 | |
| 830 | if (mask & WL_EVENT_READABLE) |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 831 | wl_display_iterate(c->parent.wl_display, WL_DISPLAY_READABLE); |
Kristian Høgsberg | f258a31 | 2011-12-28 22:51:20 -0500 | [diff] [blame] | 832 | if (mask & WL_EVENT_WRITABLE) |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 833 | wl_display_iterate(c->parent.wl_display, WL_DISPLAY_WRITABLE); |
Kristian Høgsberg | 95d843d | 2011-04-22 13:01:26 -0400 | [diff] [blame] | 834 | |
| 835 | return 1; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 836 | } |
| 837 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 838 | static void |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 839 | wayland_restore(struct weston_compositor *ec) |
| 840 | { |
| 841 | } |
| 842 | |
| 843 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 844 | wayland_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 845 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 846 | weston_compositor_shutdown(ec); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 847 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 848 | free(ec); |
| 849 | } |
| 850 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 851 | static struct weston_compositor * |
Kristian Høgsberg | 2e28b10 | 2012-02-07 09:57:25 -0500 | [diff] [blame] | 852 | wayland_compositor_create(struct wl_display *display, |
Daniel Stone | baf4359 | 2012-06-01 11:11:10 -0400 | [diff] [blame] | 853 | int width, int height, const char *display_name, |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 854 | int argc, char *argv[], const char *config_file) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 855 | { |
| 856 | struct wayland_compositor *c; |
| 857 | struct wl_event_loop *loop; |
| 858 | int fd; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 859 | |
| 860 | c = malloc(sizeof *c); |
| 861 | if (c == NULL) |
| 862 | return NULL; |
| 863 | |
| 864 | memset(c, 0, sizeof *c); |
| 865 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 866 | if (weston_compositor_init(&c->base, display, argc, argv, |
| 867 | config_file) < 0) |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 868 | goto err_free; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 869 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 870 | c->parent.wl_display = wl_display_connect(display_name); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 871 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 872 | if (c->parent.wl_display == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 873 | weston_log("failed to create display: %m\n"); |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 874 | goto err_compositor; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | wl_list_init(&c->input_list); |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 878 | wl_display_add_global_listener(c->parent.wl_display, |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 879 | display_handle_global, c); |
| 880 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 881 | wl_display_iterate(c->parent.wl_display, WL_DISPLAY_READABLE); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 882 | |
| 883 | c->base.wl_display = display; |
| 884 | if (wayland_compositor_init_egl(c) < 0) |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 885 | goto err_display; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 886 | |
Benjamin Franzke | ecfb2b9 | 2011-01-15 12:34:48 +0100 | [diff] [blame] | 887 | c->base.destroy = wayland_destroy; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 888 | c->base.restore = wayland_restore; |
Benjamin Franzke | ecfb2b9 | 2011-01-15 12:34:48 +0100 | [diff] [blame] | 889 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 890 | if (weston_compositor_init_gl(&c->base) < 0) |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 891 | goto err_display; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 892 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 893 | create_border(c); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 894 | if (wayland_compositor_create_output(c, width, height) < 0) |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 895 | goto err_display; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 896 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 897 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 898 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 899 | fd = wl_display_get_fd(c->parent.wl_display, update_event_mask, c); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 900 | c->parent.wl_source = |
| 901 | wl_event_loop_add_fd(loop, fd, c->parent.event_mask, |
| 902 | wayland_compositor_handle_event, c); |
| 903 | if (c->parent.wl_source == NULL) |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 904 | goto err_display; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 905 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 906 | return &c->base; |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 907 | |
| 908 | err_display: |
| 909 | wl_display_disconnect(c->parent.wl_display); |
| 910 | err_compositor: |
| 911 | weston_compositor_shutdown(&c->base); |
| 912 | err_free: |
| 913 | free(c); |
| 914 | return NULL; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 915 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 916 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 917 | WL_EXPORT struct weston_compositor * |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 918 | backend_init(struct wl_display *display, int argc, char *argv[], |
| 919 | const char *config_file) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 920 | { |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 921 | int width = 1024, height = 640; |
| 922 | char *display_name = NULL; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 923 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 924 | const struct weston_option wayland_options[] = { |
| 925 | { WESTON_OPTION_INTEGER, "width", 0, &width }, |
| 926 | { WESTON_OPTION_INTEGER, "height", 0, &height }, |
| 927 | { WESTON_OPTION_STRING, "display", 0, &display_name }, |
| 928 | }; |
| 929 | |
| 930 | parse_options(wayland_options, |
| 931 | ARRAY_LENGTH(wayland_options), argc, argv); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 932 | |
Daniel Stone | baf4359 | 2012-06-01 11:11:10 -0400 | [diff] [blame] | 933 | return wayland_compositor_create(display, width, height, display_name, |
Daniel Stone | c1be8e5 | 2012-06-01 11:14:02 -0400 | [diff] [blame] | 934 | argc, argv, config_file); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 935 | } |