blob: 805137d57da2d12667506f72c69012331e5e2930 [file] [log] [blame]
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001/*
Kristian Høgsberg96aa7da2011-09-15 15:43:14 -04002 * Copyright © 2010-2011 Benjamin Franzke
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01003 *
Kristian Høgsberg96aa7da2011-09-15 15:43:14 -04004 * 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 Franzkeec2e6422010-11-27 19:04:12 +010013 *
Kristian Høgsberg96aa7da2011-09-15 15:43:14 -040014 * 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 Franzkeec2e6422010-11-27 19:04:12 +010021 */
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 Stoneb7452fe2012-06-01 12:14:06 +010034#include <sys/mman.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010035
Benjamin Franzkebe014562011-02-18 17:04:24 +010036#include <wayland-client.h>
37#include <wayland-egl.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010038
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010039#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
46struct wayland_compositor {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050047 struct weston_compositor base;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010048
49 struct {
Kristian Høgsberg362b6722012-06-18 15:13:51 -040050 struct wl_display *wl_display;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -040051 struct wl_registry *registry;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010052 struct wl_compositor *compositor;
53 struct wl_shell *shell;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010054 struct wl_output *output;
55
56 struct {
57 int32_t x, y, width, height;
58 } screen_allocation;
59
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010060 struct wl_event_source *wl_source;
61 uint32_t event_mask;
62 } parent;
63
Kristian Høgsberg546a8122012-02-01 07:45:51 -050064 struct {
65 int32_t top, bottom, left, right;
66 GLuint texture;
67 int32_t width, height;
68 } border;
69
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010070 struct wl_list input_list;
71};
72
73struct wayland_output {
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050074 struct weston_output base;
Kristian Høgsbergd7c17262012-09-05 21:54:15 -040075 struct wl_listener frame_listener;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010076 struct {
77 struct wl_surface *surface;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +020078 struct wl_shell_surface *shell_surface;
Benjamin Franzkebe014562011-02-18 17:04:24 +010079 struct wl_egl_window *egl_window;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010080 } parent;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -050081 struct weston_mode mode;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010082};
83
84struct wayland_input {
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -040085 struct weston_seat base;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010086 struct wayland_compositor *compositor;
Daniel Stone37816df2012-05-16 18:45:18 +010087 struct wl_seat *seat;
88 struct wl_pointer *pointer;
89 struct wl_keyboard *keyboard;
90 struct wl_touch *touch;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010091 struct wl_list link;
Daniel Stone50692802012-06-22 13:21:41 +010092 uint32_t key_serial;
Kristian Høgsberg539d85f2012-08-13 23:29:53 -040093 uint32_t enter_serial;
94 int focus;
95 struct wayland_output *output;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010096};
97
Kristian Høgsberg546a8122012-02-01 07:45:51 -050098
99static int
100texture_border(struct wayland_output *output)
101{
102 struct wayland_compositor *c =
103 (struct wayland_compositor *) output->base.compositor;
104 GLfloat *d;
105 unsigned int *p;
106 int i, j, k, n;
107 GLfloat x[4], y[4], u[4], v[4];
108
109 x[0] = -c->border.left;
110 x[1] = 0;
111 x[2] = output->base.current->width;
112 x[3] = output->base.current->width + c->border.right;
113
114 y[0] = -c->border.top;
115 y[1] = 0;
116 y[2] = output->base.current->height;
117 y[3] = output->base.current->height + c->border.bottom;
118
119 u[0] = 0.0;
120 u[1] = (GLfloat) c->border.left / c->border.width;
121 u[2] = (GLfloat) (c->border.width - c->border.right) / c->border.width;
122 u[3] = 1.0;
123
124 v[0] = 0.0;
125 v[1] = (GLfloat) c->border.top / c->border.height;
126 v[2] = (GLfloat) (c->border.height - c->border.bottom) / c->border.height;
127 v[3] = 1.0;
128
129 n = 8;
130 d = wl_array_add(&c->base.vertices, n * 16 * sizeof *d);
131 p = wl_array_add(&c->base.indices, n * 6 * sizeof *p);
132
133 k = 0;
134 for (i = 0; i < 3; i++)
135 for (j = 0; j < 3; j++) {
136
137 if (i == 1 && j == 1)
138 continue;
139
140 d[ 0] = x[i];
141 d[ 1] = y[j];
142 d[ 2] = u[i];
143 d[ 3] = v[j];
144
145 d[ 4] = x[i];
146 d[ 5] = y[j + 1];
147 d[ 6] = u[i];
148 d[ 7] = v[j + 1];
149
150 d[ 8] = x[i + 1];
151 d[ 9] = y[j];
152 d[10] = u[i + 1];
153 d[11] = v[j];
154
155 d[12] = x[i + 1];
156 d[13] = y[j + 1];
157 d[14] = u[i + 1];
158 d[15] = v[j + 1];
159
160 p[0] = k + 0;
161 p[1] = k + 1;
162 p[2] = k + 2;
163 p[3] = k + 2;
164 p[4] = k + 1;
165 p[5] = k + 3;
166
167 d += 16;
168 p += 6;
169 k += 4;
170 }
171
172 return k / 4;
173}
174
175static void
176draw_border(struct wayland_output *output)
177{
178 struct wayland_compositor *c =
179 (struct wayland_compositor *) output->base.compositor;
Gwenole Beauchesne6d030492012-04-20 11:15:51 +0200180 struct weston_shader *shader = &c->base.texture_shader_rgba;
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500181 GLfloat *v;
182 int n;
183
184 glDisable(GL_BLEND);
185 glUseProgram(shader->program);
186 c->base.current_shader = shader;
187
188 glUniformMatrix4fv(shader->proj_uniform,
189 1, GL_FALSE, output->base.matrix.d);
190
Gwenole Beauchesne28f59b02012-04-20 11:44:06 +0200191 glUniform1i(shader->tex_uniforms[0], 0);
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500192 glUniform1f(shader->alpha_uniform, 1);
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500193
194 n = texture_border(output);
195
196 glBindTexture(GL_TEXTURE_2D, c->border.texture);
197
198 v = c->base.vertices.data;
199 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[0]);
200 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof *v, &v[2]);
201 glEnableVertexAttribArray(0);
202 glEnableVertexAttribArray(1);
203
204 glDrawElements(GL_TRIANGLES, n * 6,
205 GL_UNSIGNED_INT, c->base.indices.data);
206
207 glDisableVertexAttribArray(1);
208 glDisableVertexAttribArray(0);
209
210 c->base.vertices.size = 0;
211 c->base.indices.size = 0;
212}
213
214static void
215create_border(struct wayland_compositor *c)
216{
Ander Conselvan de Oliveirae2d21e82012-03-16 17:25:09 +0200217 pixman_image_t *image;
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500218
Ander Conselvan de Oliveirae2d21e82012-03-16 17:25:09 +0200219 image = load_image(DATADIR "/weston/border.png");
220 if (!image) {
Martin Minarik6d118362012-06-07 18:01:59 +0200221 weston_log("could'nt load border image\n");
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500222 return;
223 }
224
Ander Conselvan de Oliveirae2d21e82012-03-16 17:25:09 +0200225 c->border.width = pixman_image_get_width(image);
226 c->border.height = pixman_image_get_height(image);
227
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500228 glGenTextures(1, &c->border.texture);
229 glBindTexture(GL_TEXTURE_2D, c->border.texture);
230 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
231 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
232 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
233 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
234
235 glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
236 c->border.width,
237 c->border.height,
Ander Conselvan de Oliveirae2d21e82012-03-16 17:25:09 +0200238 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE,
239 pixman_image_get_data(image));
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500240
Ander Conselvan de Oliveirae2d21e82012-03-16 17:25:09 +0200241 pixman_image_unref(image);
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500242}
243
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100244static int
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100245wayland_compositor_init_egl(struct wayland_compositor *c)
246{
247 EGLint major, minor;
Benjamin Franzkebe014562011-02-18 17:04:24 +0100248 EGLint n;
Benjamin Franzkebe014562011-02-18 17:04:24 +0100249 EGLint config_attribs[] = {
250 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
251 EGL_RED_SIZE, 1,
252 EGL_GREEN_SIZE, 1,
253 EGL_BLUE_SIZE, 1,
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500254 EGL_ALPHA_SIZE, 1,
Kristian Høgsbergd28ab362011-03-02 11:36:30 -0500255 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
Benjamin Franzkebe014562011-02-18 17:04:24 +0100256 EGL_NONE
257 };
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100258
Kristian Høgsberg362b6722012-06-18 15:13:51 -0400259 c->base.egl_display = eglGetDisplay(c->parent.wl_display);
260 if (c->base.egl_display == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +0200261 weston_log("failed to create display\n");
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100262 return -1;
263 }
264
Kristian Høgsberg362b6722012-06-18 15:13:51 -0400265 if (!eglInitialize(c->base.egl_display, &major, &minor)) {
Martin Minarik6d118362012-06-07 18:01:59 +0200266 weston_log("failed to initialize display\n");
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100267 return -1;
268 }
269
Kristian Høgsberg362b6722012-06-18 15:13:51 -0400270 if (!eglChooseConfig(c->base.egl_display, config_attribs,
271 &c->base.egl_config, 1, &n) || n == 0) {
Martin Minarik6d118362012-06-07 18:01:59 +0200272 weston_log("failed to choose config: %d\n", n);
Benjamin Franzkebe014562011-02-18 17:04:24 +0100273 return -1;
274 }
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100275
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100276 return 0;
277}
278
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500279static void
Kristian Høgsbergcdd61d02012-02-07 09:56:15 -0500280frame_done(void *data, struct wl_callback *callback, uint32_t time)
Kristian Høgsberg33418202011-08-16 23:01:28 -0400281{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500282 struct weston_output *output = data;
Kristian Høgsberg33418202011-08-16 23:01:28 -0400283
Kristian Høgsbergcdd61d02012-02-07 09:56:15 -0500284 wl_callback_destroy(callback);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500285 weston_output_finish_frame(output, time);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400286}
287
288static const struct wl_callback_listener frame_listener = {
289 frame_done
290};
291
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500292static void
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400293wayland_output_frame_notify(struct wl_listener *listener, void *data)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100294{
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400295 struct wayland_output *output =
296 container_of(listener,
297 struct wayland_output, frame_listener);
Pekka Paalanen07c91f82012-08-30 16:47:21 -0500298
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500299 draw_border(output);
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400300}
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500301
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400302static void
303wayland_output_repaint(struct weston_output *output_base,
304 pixman_region32_t *damage)
305{
306 struct wayland_output *output = (struct wayland_output *) output_base;
Kristian Høgsbergfa1be022012-09-05 22:49:55 -0400307 struct weston_compositor *ec = output->base.compositor;
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400308 struct wl_callback *callback;
Scott Moreau062be7e2012-04-20 13:37:33 -0600309
Kristian Høgsbergfa1be022012-09-05 22:49:55 -0400310 ec->renderer->repaint_output(&output->base, damage);
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400311
Kristian Høgsberg33418202011-08-16 23:01:28 -0400312 callback = wl_surface_frame(output->parent.surface);
313 wl_callback_add_listener(callback, &frame_listener, output);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100314
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500315 return;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100316}
317
Matt Roper361d2ad2011-08-29 13:52:23 -0700318static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500319wayland_output_destroy(struct weston_output *output_base)
Matt Roper361d2ad2011-08-29 13:52:23 -0700320{
321 struct wayland_output *output = (struct wayland_output *) output_base;
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500322 struct weston_compositor *ec = output->base.compositor;
Matt Roper361d2ad2011-08-29 13:52:23 -0700323
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400324 eglDestroySurface(ec->egl_display, output->base.egl_surface);
Matt Roper361d2ad2011-08-29 13:52:23 -0700325 wl_egl_window_destroy(output->parent.egl_window);
326 free(output);
327
328 return;
329}
330
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300331static const struct wl_shell_surface_listener shell_surface_listener;
332
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200333static int
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100334wayland_compositor_create_output(struct wayland_compositor *c,
335 int width, int height)
336{
337 struct wayland_output *output;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100338
339 output = malloc(sizeof *output);
340 if (output == NULL)
341 return -1;
342 memset(output, 0, sizeof *output);
343
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400344 output->mode.flags =
345 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
346 output->mode.width = width;
347 output->mode.height = height;
348 output->mode.refresh = 60;
349 wl_list_init(&output->base.mode_list);
350 wl_list_insert(&output->base.mode_list, &output->mode.link);
351
352 output->base.current = &output->mode;
Scott Moreau1bad5db2012-08-18 01:04:05 -0600353 weston_output_init(&output->base, &c->base, 0, 0, width, height,
354 WL_OUTPUT_TRANSFORM_NORMAL);
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400355
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500356 output->base.border.top = c->border.top;
357 output->base.border.bottom = c->border.bottom;
358 output->base.border.left = c->border.left;
359 output->base.border.right = c->border.right;
Kristian Høgsberg90bc88c2012-08-13 23:34:04 -0400360 output->base.make = "waywayland";
361 output->base.model = "none";
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500362
363 weston_output_move(&output->base, 0, 0);
364
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100365 output->parent.surface =
366 wl_compositor_create_surface(c->parent.compositor);
367 wl_surface_set_user_data(output->parent.surface, output);
368
Benjamin Franzkebe014562011-02-18 17:04:24 +0100369 output->parent.egl_window =
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500370 wl_egl_window_create(output->parent.surface,
371 width + c->border.left + c->border.right,
372 height + c->border.top + c->border.bottom);
Benjamin Franzkebe014562011-02-18 17:04:24 +0100373 if (!output->parent.egl_window) {
Martin Minarik6d118362012-06-07 18:01:59 +0200374 weston_log("failure to create wl_egl_window\n");
Benjamin Franzkebe014562011-02-18 17:04:24 +0100375 goto cleanup_output;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100376 }
377
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400378 output->base.egl_surface =
Kristian Høgsberg362b6722012-06-18 15:13:51 -0400379 eglCreateWindowSurface(c->base.egl_display, c->base.egl_config,
Benjamin Franzkebe014562011-02-18 17:04:24 +0100380 output->parent.egl_window, NULL);
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400381 if (!output->base.egl_surface) {
Martin Minarik6d118362012-06-07 18:01:59 +0200382 weston_log("failed to create window surface\n");
Benjamin Franzkebe014562011-02-18 17:04:24 +0100383 goto cleanup_window;
384 }
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100385
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200386 output->parent.shell_surface =
387 wl_shell_get_shell_surface(c->parent.shell,
388 output->parent.surface);
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300389 wl_shell_surface_add_listener(output->parent.shell_surface,
390 &shell_surface_listener, output);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200391 wl_shell_surface_set_toplevel(output->parent.shell_surface);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100392
Alex Wubd3354b2012-04-17 17:20:49 +0800393 output->base.origin = output->base.current;
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500394 output->base.repaint = wayland_output_repaint;
Matt Roper361d2ad2011-08-29 13:52:23 -0700395 output->base.destroy = wayland_output_destroy;
Jesse Barnes5308a5e2012-02-09 13:12:57 -0800396 output->base.assign_planes = NULL;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +0200397 output->base.set_backlight = NULL;
398 output->base.set_dpms = NULL;
Alex Wu2dda6042012-04-17 17:20:47 +0800399 output->base.switch_mode = NULL;
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +0100400
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100401 wl_list_insert(c->base.output_list.prev, &output->base.link);
402
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400403 output->frame_listener.notify = wayland_output_frame_notify;
404 wl_signal_add(&output->base.frame_signal, &output->frame_listener);
405
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100406 return 0;
Benjamin Franzkebe014562011-02-18 17:04:24 +0100407
Benjamin Franzkebe014562011-02-18 17:04:24 +0100408cleanup_window:
409 wl_egl_window_destroy(output->parent.egl_window);
410cleanup_output:
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500411 /* FIXME: cleanup weston_output */
Benjamin Franzkebe014562011-02-18 17:04:24 +0100412 free(output);
413
414 return -1;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100415}
416
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300417static void
418shell_surface_ping(void *data, struct wl_shell_surface *shell_surface,
419 uint32_t serial)
420{
421 wl_shell_surface_pong(shell_surface, serial);
422}
423
424static void
425shell_surface_configure(void *data, struct wl_shell_surface *shell_surface,
426 uint32_t edges, int32_t width, int32_t height)
427{
428 /* FIXME: implement resizing */
429}
430
431static void
432shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface)
433{
434}
435
436static const struct wl_shell_surface_listener shell_surface_listener = {
437 shell_surface_ping,
438 shell_surface_configure,
439 shell_surface_popup_done
440};
441
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100442/* Events received from the wayland-server this compositor is client of: */
443
444/* parent output interface */
445static void
446display_handle_geometry(void *data,
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400447 struct wl_output *wl_output,
448 int x,
449 int y,
450 int physical_width,
451 int physical_height,
452 int subpixel,
453 const char *make,
Kristian Høgsberg0e696472012-07-22 15:49:57 -0400454 const char *model,
455 int transform)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100456{
457 struct wayland_compositor *c = data;
458
Kristian Høgsbergf8fc08f2010-12-01 20:10:10 -0500459 c->parent.screen_allocation.x = x;
460 c->parent.screen_allocation.y = y;
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400461}
462
463static void
464display_handle_mode(void *data,
465 struct wl_output *wl_output,
466 uint32_t flags,
467 int width,
468 int height,
469 int refresh)
470{
471 struct wayland_compositor *c = data;
472
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100473 c->parent.screen_allocation.width = width;
474 c->parent.screen_allocation.height = height;
475}
476
477static const struct wl_output_listener output_listener = {
478 display_handle_geometry,
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400479 display_handle_mode
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100480};
481
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400482static void
483check_focus(struct wayland_input *input, wl_fixed_t x, wl_fixed_t y)
484{
485 struct wayland_compositor *c = input->compositor;
486 int width, height, inside;
487
488 width = input->output->mode.width;
489 height = input->output->mode.height;
490
491 inside = c->border.left <= wl_fixed_to_int(x) &&
492 wl_fixed_to_int(x) < width + c->border.left &&
493 c->border.top <= wl_fixed_to_int(y) &&
494 wl_fixed_to_int(y) < height + c->border.top;
495
496 if (!input->focus && inside) {
497 notify_pointer_focus(&input->base, &input->output->base,
498 x - wl_fixed_from_int(c->border.left),
499 y = wl_fixed_from_int(c->border.top));
500 wl_pointer_set_cursor(input->pointer,
501 input->enter_serial, NULL, 0, 0);
502 } else if (input->focus && !inside) {
503 notify_pointer_focus(&input->base, NULL, 0, 0);
504 /* FIXME: Should set default cursor here. */
505 }
506
507 input->focus = inside;
508}
509
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100510/* parent input interface */
511static void
Daniel Stone37816df2012-05-16 18:45:18 +0100512input_handle_pointer_enter(void *data, struct wl_pointer *pointer,
513 uint32_t serial, struct wl_surface *surface,
Kristian Høgsberge11bbe42012-05-09 12:19:04 -0400514 wl_fixed_t x, wl_fixed_t y)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100515{
516 struct wayland_input *input = data;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100517
Daniel Stone50692802012-06-22 13:21:41 +0100518 /* XXX: If we get a modifier event immediately before the focus,
519 * we should try to keep the same serial. */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400520 input->enter_serial = serial;
521 input->output = wl_surface_get_user_data(surface);
522 check_focus(input, x, y);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100523}
524
525static void
Daniel Stone37816df2012-05-16 18:45:18 +0100526input_handle_pointer_leave(void *data, struct wl_pointer *pointer,
527 uint32_t serial, struct wl_surface *surface)
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500528{
529 struct wayland_input *input = data;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500530
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400531 notify_pointer_focus(&input->base, NULL, 0, 0);
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400532 input->output = NULL;
533 input->focus = 0;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500534}
535
536static void
Daniel Stone37816df2012-05-16 18:45:18 +0100537input_handle_motion(void *data, struct wl_pointer *pointer,
538 uint32_t time, wl_fixed_t x, wl_fixed_t y)
539{
540 struct wayland_input *input = data;
541 struct wayland_compositor *c = input->compositor;
542
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400543 check_focus(input, x, y);
544 if (input->focus)
545 notify_motion(&input->base, time,
546 x - wl_fixed_from_int(c->border.left),
547 y - wl_fixed_from_int(c->border.top));
Daniel Stone37816df2012-05-16 18:45:18 +0100548}
549
550static void
551input_handle_button(void *data, struct wl_pointer *pointer,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100552 uint32_t serial, uint32_t time, uint32_t button,
553 uint32_t state_w)
Daniel Stone37816df2012-05-16 18:45:18 +0100554{
555 struct wayland_input *input = data;
Daniel Stone4dbadb12012-05-30 16:31:51 +0100556 enum wl_pointer_button_state state = state_w;
Daniel Stone37816df2012-05-16 18:45:18 +0100557
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400558 notify_button(&input->base, time, button, state);
Daniel Stone37816df2012-05-16 18:45:18 +0100559}
560
561static void
562input_handle_axis(void *data, struct wl_pointer *pointer,
Daniel Stone2fce4022012-05-30 16:32:00 +0100563 uint32_t time, uint32_t axis, wl_fixed_t value)
Daniel Stone37816df2012-05-16 18:45:18 +0100564{
565 struct wayland_input *input = data;
Daniel Stone37816df2012-05-16 18:45:18 +0100566
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400567 notify_axis(&input->base, time, axis, value);
Daniel Stone37816df2012-05-16 18:45:18 +0100568}
569
570static const struct wl_pointer_listener pointer_listener = {
571 input_handle_pointer_enter,
572 input_handle_pointer_leave,
573 input_handle_motion,
574 input_handle_button,
575 input_handle_axis,
576};
577
578static void
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100579input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
580 int fd, uint32_t size)
581{
582 struct wayland_input *input = data;
583 struct xkb_keymap *keymap;
584 char *map_str;
585
586 if (!data) {
587 close(fd);
588 return;
589 }
590
591 if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
592 close(fd);
593 return;
594 }
595
596 map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
597 if (map_str == MAP_FAILED) {
598 close(fd);
599 return;
600 }
601
602 keymap = xkb_map_new_from_string(input->compositor->base.xkb_context,
603 map_str,
604 XKB_KEYMAP_FORMAT_TEXT_V1,
605 0);
606 munmap(map_str, size);
607 close(fd);
608
609 if (!keymap) {
Martin Minarik6d118362012-06-07 18:01:59 +0200610 weston_log("failed to compile keymap\n");
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100611 return;
612 }
613
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -0400614 weston_seat_init_keyboard(&input->base, keymap);
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100615 xkb_map_unref(keymap);
616}
617
618static void
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500619input_handle_keyboard_enter(void *data,
Daniel Stone37816df2012-05-16 18:45:18 +0100620 struct wl_keyboard *keyboard,
621 uint32_t serial,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500622 struct wl_surface *surface,
623 struct wl_array *keys)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100624{
Kristian Høgsbergaf82bea2011-01-27 20:18:17 -0500625 struct wayland_input *input = data;
Kristian Høgsbergaf82bea2011-01-27 20:18:17 -0500626
Daniel Stone50692802012-06-22 13:21:41 +0100627 /* XXX: If we get a modifier event immediately before the focus,
628 * we should try to keep the same serial. */
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400629 notify_keyboard_focus_in(&input->base, keys,
Daniel Stoned6da09e2012-06-22 13:21:29 +0100630 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500631}
632
633static void
634input_handle_keyboard_leave(void *data,
Daniel Stone37816df2012-05-16 18:45:18 +0100635 struct wl_keyboard *keyboard,
636 uint32_t serial,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500637 struct wl_surface *surface)
638{
639 struct wayland_input *input = data;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500640
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400641 notify_keyboard_focus_out(&input->base);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100642}
643
Daniel Stone37816df2012-05-16 18:45:18 +0100644static void
645input_handle_key(void *data, struct wl_keyboard *keyboard,
646 uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
647{
648 struct wayland_input *input = data;
Daniel Stone37816df2012-05-16 18:45:18 +0100649
Daniel Stone50692802012-06-22 13:21:41 +0100650 input->key_serial = serial;
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400651 notify_key(&input->base, time, key,
Daniel Stonec9785ea2012-05-30 16:31:52 +0100652 state ? WL_KEYBOARD_KEY_STATE_PRESSED :
Daniel Stone1b4e11f2012-06-22 13:21:37 +0100653 WL_KEYBOARD_KEY_STATE_RELEASED,
Daniel Stone50692802012-06-22 13:21:41 +0100654 STATE_UPDATE_NONE);
Daniel Stone37816df2012-05-16 18:45:18 +0100655}
656
Daniel Stone351eb612012-05-31 15:27:47 -0400657static void
658input_handle_modifiers(void *data, struct wl_keyboard *keyboard,
Daniel Stone50692802012-06-22 13:21:41 +0100659 uint32_t serial_in, uint32_t mods_depressed,
Daniel Stone351eb612012-05-31 15:27:47 -0400660 uint32_t mods_latched, uint32_t mods_locked,
661 uint32_t group)
662{
Daniel Stone50692802012-06-22 13:21:41 +0100663 struct wayland_input *input = data;
664 struct wayland_compositor *c = input->compositor;
665 uint32_t serial_out;
666
667 /* If we get a key event followed by a modifier event with the
668 * same serial number, then we try to preserve those semantics by
669 * reusing the same serial number on the way out too. */
670 if (serial_in == input->key_serial)
671 serial_out = wl_display_get_serial(c->base.wl_display);
672 else
673 serial_out = wl_display_next_serial(c->base.wl_display);
674
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -0400675 xkb_state_update_mask(input->base.xkb_state.state,
Daniel Stone50692802012-06-22 13:21:41 +0100676 mods_depressed, mods_latched,
677 mods_locked, 0, 0, group);
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400678 notify_modifiers(&input->base, serial_out);
Daniel Stone351eb612012-05-31 15:27:47 -0400679}
680
Daniel Stone37816df2012-05-16 18:45:18 +0100681static const struct wl_keyboard_listener keyboard_listener = {
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100682 input_handle_keymap,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500683 input_handle_keyboard_enter,
684 input_handle_keyboard_leave,
Daniel Stone37816df2012-05-16 18:45:18 +0100685 input_handle_key,
Daniel Stone351eb612012-05-31 15:27:47 -0400686 input_handle_modifiers,
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100687};
688
689static void
Daniel Stone37816df2012-05-16 18:45:18 +0100690input_handle_capabilities(void *data, struct wl_seat *seat,
691 enum wl_seat_capability caps)
692{
693 struct wayland_input *input = data;
694
695 if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
696 input->pointer = wl_seat_get_pointer(seat);
697 wl_pointer_set_user_data(input->pointer, input);
698 wl_pointer_add_listener(input->pointer, &pointer_listener,
699 input);
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -0400700 weston_seat_init_pointer(&input->base);
Daniel Stone37816df2012-05-16 18:45:18 +0100701 } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
702 wl_pointer_destroy(input->pointer);
703 input->pointer = NULL;
704 }
705
706 if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
707 input->keyboard = wl_seat_get_keyboard(seat);
708 wl_keyboard_set_user_data(input->keyboard, input);
709 wl_keyboard_add_listener(input->keyboard, &keyboard_listener,
710 input);
711 } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
712 wl_keyboard_destroy(input->keyboard);
713 input->keyboard = NULL;
714 }
715}
716
717static const struct wl_seat_listener seat_listener = {
718 input_handle_capabilities,
719};
720
721static void
722display_add_seat(struct wayland_compositor *c, uint32_t id)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100723{
724 struct wayland_input *input;
725
726 input = malloc(sizeof *input);
727 if (input == NULL)
728 return;
729
730 memset(input, 0, sizeof *input);
731
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -0400732 weston_seat_init(&input->base, &c->base);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100733 input->compositor = c;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400734 input->seat = wl_registry_bind(c->parent.registry, id,
735 &wl_seat_interface, 1);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100736 wl_list_insert(c->input_list.prev, &input->link);
737
Daniel Stone37816df2012-05-16 18:45:18 +0100738 wl_seat_add_listener(input->seat, &seat_listener, input);
739 wl_seat_set_user_data(input->seat, input);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100740}
741
742static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400743registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
744 const char *interface, uint32_t version)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100745{
746 struct wayland_compositor *c = data;
747
Benjamin Franzke080ab6c2011-04-30 10:41:27 +0200748 if (strcmp(interface, "wl_compositor") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400749 c->parent.compositor =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400750 wl_registry_bind(registry, name,
751 &wl_compositor_interface, 1);
Benjamin Franzke080ab6c2011-04-30 10:41:27 +0200752 } else if (strcmp(interface, "wl_output") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400753 c->parent.output =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400754 wl_registry_bind(registry, name,
755 &wl_output_interface, 1);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100756 wl_output_add_listener(c->parent.output, &output_listener, c);
Benjamin Franzke080ab6c2011-04-30 10:41:27 +0200757 } else if (strcmp(interface, "wl_shell") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400758 c->parent.shell =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400759 wl_registry_bind(registry, name,
760 &wl_shell_interface, 1);
Daniel Stone725c2c32012-06-22 14:04:36 +0100761 } else if (strcmp(interface, "wl_seat") == 0) {
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400762 display_add_seat(c, name);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100763 }
764}
765
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400766static const struct wl_registry_listener registry_listener = {
767 registry_handle_global
768};
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100769
Kristian Høgsberg95d843d2011-04-22 13:01:26 -0400770static int
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100771wayland_compositor_handle_event(int fd, uint32_t mask, void *data)
772{
773 struct wayland_compositor *c = data;
774
775 if (mask & WL_EVENT_READABLE)
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400776 wl_display_dispatch(c->parent.wl_display);
Kristian Høgsbergf258a312011-12-28 22:51:20 -0500777 if (mask & WL_EVENT_WRITABLE)
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400778 wl_display_flush(c->parent.wl_display);
Kristian Høgsberg95d843d2011-04-22 13:01:26 -0400779
780 return 1;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100781}
782
Kristian Høgsbergcaa64422010-12-01 16:52:15 -0500783static void
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -0400784wayland_restore(struct weston_compositor *ec)
785{
786}
787
788static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500789wayland_destroy(struct weston_compositor *ec)
Kristian Høgsbergcaa64422010-12-01 16:52:15 -0500790{
Kristian Høgsberg3a0de882012-09-06 21:44:24 -0400791 gles2_renderer_destroy(ec);
792
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500793 weston_compositor_shutdown(ec);
Matt Roper361d2ad2011-08-29 13:52:23 -0700794
Kristian Høgsbergcaa64422010-12-01 16:52:15 -0500795 free(ec);
796}
797
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500798static struct weston_compositor *
Kristian Høgsberg2e28b102012-02-07 09:57:25 -0500799wayland_compositor_create(struct wl_display *display,
Daniel Stonebaf43592012-06-01 11:11:10 -0400800 int width, int height, const char *display_name,
Daniel Stonec1be8e52012-06-01 11:14:02 -0400801 int argc, char *argv[], const char *config_file)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100802{
803 struct wayland_compositor *c;
804 struct wl_event_loop *loop;
805 int fd;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100806
807 c = malloc(sizeof *c);
808 if (c == NULL)
809 return NULL;
810
811 memset(c, 0, sizeof *c);
812
Daniel Stone725c2c32012-06-22 14:04:36 +0100813 if (weston_compositor_init(&c->base, display, argc, argv,
814 config_file) < 0)
Martin Olssonc5db50f2012-07-08 03:03:43 +0200815 goto err_free;
Daniel Stone725c2c32012-06-22 14:04:36 +0100816
Kristian Høgsberg362b6722012-06-18 15:13:51 -0400817 c->parent.wl_display = wl_display_connect(display_name);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100818
Kristian Høgsberg362b6722012-06-18 15:13:51 -0400819 if (c->parent.wl_display == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +0200820 weston_log("failed to create display: %m\n");
Martin Olssonc5db50f2012-07-08 03:03:43 +0200821 goto err_compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100822 }
823
824 wl_list_init(&c->input_list);
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400825 c->parent.registry = wl_display_get_registry(c->parent.wl_display);
826 wl_registry_add_listener(c->parent.registry, &registry_listener, c);
827 wl_display_dispatch(c->parent.wl_display);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100828
829 c->base.wl_display = display;
830 if (wayland_compositor_init_egl(c) < 0)
Martin Olssonc5db50f2012-07-08 03:03:43 +0200831 goto err_display;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100832
Benjamin Franzkeecfb2b92011-01-15 12:34:48 +0100833 c->base.destroy = wayland_destroy;
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -0400834 c->base.restore = wayland_restore;
Benjamin Franzkeecfb2b92011-01-15 12:34:48 +0100835
John Kåre Alsakerc37b32d2012-10-04 20:42:17 +0200836 c->border.top = 30;
837 c->border.bottom = 24;
John Kåre Alsakerb9b87122012-10-04 20:42:16 +0200838 c->border.left = 25;
John Kåre Alsakerc37b32d2012-10-04 20:42:17 +0200839 c->border.right = 26;
John Kåre Alsakerb9b87122012-10-04 20:42:16 +0200840
841 /* requires border fields */
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100842 if (wayland_compositor_create_output(c, width, height) < 0)
Martin Olssonc5db50f2012-07-08 03:03:43 +0200843 goto err_display;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100844
John Kåre Alsakerb9b87122012-10-04 20:42:16 +0200845 /* requires wayland_compositor_create_output */
Kristian Høgsberg2bc5e8e2012-09-06 20:51:00 -0400846 if (gles2_renderer_init(&c->base) < 0)
847 goto err_display;
848
John Kåre Alsakerb9b87122012-10-04 20:42:16 +0200849 /* requires gles2_renderer_init */
John Kåre Alsaker4b3081a2012-10-03 18:02:22 +0200850 create_border(c);
851
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100852 loop = wl_display_get_event_loop(c->base.wl_display);
853
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400854 fd = wl_display_get_fd(c->parent.wl_display);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100855 c->parent.wl_source =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400856 wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100857 wayland_compositor_handle_event, c);
858 if (c->parent.wl_source == NULL)
Martin Olssonc5db50f2012-07-08 03:03:43 +0200859 goto err_display;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100860
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100861 return &c->base;
Martin Olssonc5db50f2012-07-08 03:03:43 +0200862
863err_display:
864 wl_display_disconnect(c->parent.wl_display);
865err_compositor:
866 weston_compositor_shutdown(&c->base);
867err_free:
868 free(c);
869 return NULL;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100870}
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400871
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500872WL_EXPORT struct weston_compositor *
Daniel Stonec1be8e52012-06-01 11:14:02 -0400873backend_init(struct wl_display *display, int argc, char *argv[],
874 const char *config_file)
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400875{
Kristian Høgsbergbcacef12012-03-11 21:05:57 -0400876 int width = 1024, height = 640;
877 char *display_name = NULL;
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400878
Kristian Høgsbergbcacef12012-03-11 21:05:57 -0400879 const struct weston_option wayland_options[] = {
880 { WESTON_OPTION_INTEGER, "width", 0, &width },
881 { WESTON_OPTION_INTEGER, "height", 0, &height },
882 { WESTON_OPTION_STRING, "display", 0, &display_name },
883 };
884
885 parse_options(wayland_options,
886 ARRAY_LENGTH(wayland_options), argc, argv);
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400887
Daniel Stonebaf43592012-06-01 11:11:10 -0400888 return wayland_compositor_create(display, width, height, display_name,
Daniel Stonec1be8e52012-06-01 11:14:02 -0400889 argc, argv, config_file);
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400890}