blob: 8d0322fe883b38255a4b2f0945380896ee01e35f [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
Daniel Stonec228e232013-05-22 18:03:19 +030023#include "config.h"
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010024
25#include <stddef.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010026#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <fcntl.h>
30#include <unistd.h>
Daniel Stoneb7452fe2012-06-01 12:14:06 +010031#include <sys/mman.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010032
Benjamin Franzkebe014562011-02-18 17:04:24 +010033#include <wayland-client.h>
34#include <wayland-egl.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010035
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010036#include "compositor.h"
John Kåre Alsaker30d2b1f2012-11-13 19:10:28 +010037#include "gl-renderer.h"
Kristian Høgsberg3c2360f2013-01-28 16:01:22 -050038#include "../shared/image-loader.h"
Jonas Ådahle5a12252013-04-05 23:07:11 +020039#include "../shared/os-compatibility.h"
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010040
41struct wayland_compositor {
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050042 struct weston_compositor base;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010043
44 struct {
Kristian Høgsberg362b6722012-06-18 15:13:51 -040045 struct wl_display *wl_display;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -040046 struct wl_registry *registry;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010047 struct wl_compositor *compositor;
48 struct wl_shell *shell;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010049 struct wl_output *output;
Jonas Ådahle5a12252013-04-05 23:07:11 +020050 struct wl_shm *shm;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010051
52 struct {
53 int32_t x, y, width, height;
54 } screen_allocation;
55
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010056 struct wl_event_source *wl_source;
57 uint32_t event_mask;
58 } parent;
59
Kristian Høgsberg546a8122012-02-01 07:45:51 -050060 struct {
61 int32_t top, bottom, left, right;
Kristian Høgsberg546a8122012-02-01 07:45:51 -050062 } border;
63
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050064 struct wl_list inputs;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010065};
66
67struct wayland_output {
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050068 struct weston_output base;
69
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010070 struct {
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050071 int draw_initial_frame;
72 struct wl_surface *surface;
73 struct wl_shell_surface *shell_surface;
74 struct wl_egl_window *egl_window;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010075 } parent;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050076
77 struct weston_mode mode;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010078};
79
80struct wayland_input {
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -040081 struct weston_seat base;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010082 struct wayland_compositor *compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010083 struct wl_list link;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050084
85 struct {
86 struct wl_seat *seat;
87 struct wl_pointer *pointer;
88 struct wl_keyboard *keyboard;
89 struct wl_touch *touch;
90 } parent;
91
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
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +030098struct gl_renderer_interface *gl_renderer;
99
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500100static void
101create_border(struct wayland_compositor *c)
102{
Ander Conselvan de Oliveirae2d21e82012-03-16 17:25:09 +0200103 pixman_image_t *image;
John Kåre Alsaker44154502012-11-13 19:10:20 +0100104 int32_t edges[4];
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500105
Ander Conselvan de Oliveirae2d21e82012-03-16 17:25:09 +0200106 image = load_image(DATADIR "/weston/border.png");
107 if (!image) {
Aaron Faanes9cefc642013-09-30 22:06:39 -0500108 weston_log("couldn't load border image\n");
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500109 return;
110 }
111
John Kåre Alsaker44154502012-11-13 19:10:20 +0100112 edges[0] = c->border.left;
113 edges[1] = c->border.right;
114 edges[2] = c->border.top;
115 edges[3] = c->border.bottom;
Ander Conselvan de Oliveirae2d21e82012-03-16 17:25:09 +0200116
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300117 gl_renderer->set_border(&c->base, pixman_image_get_width(image),
John Kåre Alsaker44154502012-11-13 19:10:20 +0100118 pixman_image_get_height(image),
119 pixman_image_get_data(image), edges);
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500120
Ander Conselvan de Oliveirae2d21e82012-03-16 17:25:09 +0200121 pixman_image_unref(image);
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500122}
123
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500124static void
Kristian Høgsbergcdd61d02012-02-07 09:56:15 -0500125frame_done(void *data, struct wl_callback *callback, uint32_t time)
Kristian Høgsberg33418202011-08-16 23:01:28 -0400126{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500127 struct weston_output *output = data;
Kristian Høgsberg33418202011-08-16 23:01:28 -0400128
Kristian Høgsbergcdd61d02012-02-07 09:56:15 -0500129 wl_callback_destroy(callback);
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500130 weston_output_finish_frame(output, time);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400131}
132
133static const struct wl_callback_listener frame_listener = {
134 frame_done
135};
136
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500137static void
Jonas Ådahle5a12252013-04-05 23:07:11 +0200138buffer_release(void *data, struct wl_buffer *buffer)
139{
140 wl_buffer_destroy(buffer);
141}
142
143static const struct wl_buffer_listener buffer_listener = {
144 buffer_release
145};
146
147static void
148draw_initial_frame(struct wayland_output *output)
149{
150 struct wayland_compositor *c =
151 (struct wayland_compositor *) output->base.compositor;
152 struct wl_shm *shm = c->parent.shm;
153 struct wl_surface *surface = output->parent.surface;
154 struct wl_shm_pool *pool;
155 struct wl_buffer *buffer;
156
157 int width, height, stride;
158 int size;
159 int fd;
160 void *data;
161
162 width = output->mode.width + c->border.left + c->border.right;
163 height = output->mode.height + c->border.top + c->border.bottom;
164 stride = width * 4;
165 size = height * stride;
166
167 fd = os_create_anonymous_file(size);
168 if (fd < 0) {
169 perror("os_create_anonymous_file");
170 return;
171 }
172
173 data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
174 if (data == MAP_FAILED) {
175 perror("mmap");
176 close(fd);
177 return;
178 }
179
180 pool = wl_shm_create_pool(shm, fd, size);
181
182 buffer = wl_shm_pool_create_buffer(pool, 0,
183 width, height,
184 stride,
185 WL_SHM_FORMAT_ARGB8888);
186 wl_buffer_add_listener(buffer, &buffer_listener, buffer);
187 wl_shm_pool_destroy(pool);
188 close(fd);
189
190 memset(data, 0, size);
191
192 wl_surface_attach(surface, buffer, 0, 0);
193
194 /* We only need to damage some part, as its only transparant
195 * pixels anyway. */
196 wl_surface_damage(surface, 0, 0, 1, 1);
197}
198
199static void
200wayland_output_start_repaint_loop(struct weston_output *output_base)
201{
202 struct wayland_output *output = (struct wayland_output *) output_base;
Jason Ekstrand286ff682013-10-27 22:24:57 -0500203 struct wayland_compositor *wc =
204 (struct wayland_compositor *)output->base.compositor;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200205 struct wl_callback *callback;
206
207 /* If this is the initial frame, we need to attach a buffer so that
208 * the compositor can map the surface and include it in its render
209 * loop. If the surface doesn't end up in the render loop, the frame
210 * callback won't be invoked. The buffer is transparent and of the
211 * same size as the future real output buffer. */
212 if (output->parent.draw_initial_frame) {
213 output->parent.draw_initial_frame = 0;
214
215 draw_initial_frame(output);
216 }
217
218 callback = wl_surface_frame(output->parent.surface);
219 wl_callback_add_listener(callback, &frame_listener, output);
220 wl_surface_commit(output->parent.surface);
Jason Ekstrand286ff682013-10-27 22:24:57 -0500221 wl_display_flush(wc->parent.wl_display);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200222}
223
David Herrmann1edf44c2013-10-22 17:11:26 +0200224static int
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400225wayland_output_repaint(struct weston_output *output_base,
226 pixman_region32_t *damage)
227{
228 struct wayland_output *output = (struct wayland_output *) output_base;
Kristian Høgsbergfa1be022012-09-05 22:49:55 -0400229 struct weston_compositor *ec = output->base.compositor;
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400230 struct wl_callback *callback;
Scott Moreau062be7e2012-04-20 13:37:33 -0600231
Kristian Høgsberg33418202011-08-16 23:01:28 -0400232 callback = wl_surface_frame(output->parent.surface);
233 wl_callback_add_listener(callback, &frame_listener, output);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100234
Pekka Paalanenbc106382012-10-10 12:49:31 +0300235 ec->renderer->repaint_output(&output->base, damage);
Ander Conselvan de Oliveira0a887722012-11-22 15:57:00 +0200236
237 pixman_region32_subtract(&ec->primary_plane.damage,
238 &ec->primary_plane.damage, damage);
David Herrmann1edf44c2013-10-22 17:11:26 +0200239 return 0;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100240}
241
Matt Roper361d2ad2011-08-29 13:52:23 -0700242static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500243wayland_output_destroy(struct weston_output *output_base)
Matt Roper361d2ad2011-08-29 13:52:23 -0700244{
245 struct wayland_output *output = (struct wayland_output *) output_base;
Matt Roper361d2ad2011-08-29 13:52:23 -0700246
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300247 gl_renderer->output_destroy(output_base);
John Kåre Alsaker94659272012-11-13 19:10:18 +0100248
Matt Roper361d2ad2011-08-29 13:52:23 -0700249 wl_egl_window_destroy(output->parent.egl_window);
250 free(output);
251
252 return;
253}
254
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300255static const struct wl_shell_surface_listener shell_surface_listener;
256
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200257static int
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100258wayland_compositor_create_output(struct wayland_compositor *c,
259 int width, int height)
260{
261 struct wayland_output *output;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100262
Peter Huttererf3d62272013-08-08 11:57:05 +1000263 output = zalloc(sizeof *output);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100264 if (output == NULL)
265 return -1;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100266
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400267 output->mode.flags =
268 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
269 output->mode.width = width;
270 output->mode.height = height;
271 output->mode.refresh = 60;
272 wl_list_init(&output->base.mode_list);
273 wl_list_insert(&output->base.mode_list, &output->mode.link);
274
Hardeningff39efa2013-09-18 23:56:35 +0200275 output->base.current_mode = &output->mode;
Scott Moreau1bad5db2012-08-18 01:04:05 -0600276 weston_output_init(&output->base, &c->base, 0, 0, width, height,
Alexander Larsson4ea95522013-05-22 14:41:37 +0200277 WL_OUTPUT_TRANSFORM_NORMAL, 1);
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400278
Kristian Høgsberg90bc88c2012-08-13 23:34:04 -0400279 output->base.make = "waywayland";
280 output->base.model = "none";
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500281
282 weston_output_move(&output->base, 0, 0);
283
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100284 output->parent.surface =
285 wl_compositor_create_surface(c->parent.compositor);
286 wl_surface_set_user_data(output->parent.surface, output);
287
Benjamin Franzkebe014562011-02-18 17:04:24 +0100288 output->parent.egl_window =
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500289 wl_egl_window_create(output->parent.surface,
290 width + c->border.left + c->border.right,
291 height + c->border.top + c->border.bottom);
Benjamin Franzkebe014562011-02-18 17:04:24 +0100292 if (!output->parent.egl_window) {
Martin Minarik6d118362012-06-07 18:01:59 +0200293 weston_log("failure to create wl_egl_window\n");
Benjamin Franzkebe014562011-02-18 17:04:24 +0100294 goto cleanup_output;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100295 }
296
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300297 if (gl_renderer->output_create(&output->base,
John Kåre Alsaker94659272012-11-13 19:10:18 +0100298 output->parent.egl_window) < 0)
Benjamin Franzkebe014562011-02-18 17:04:24 +0100299 goto cleanup_window;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100300
Jonas Ådahle5a12252013-04-05 23:07:11 +0200301 output->parent.draw_initial_frame = 1;
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200302 output->parent.shell_surface =
303 wl_shell_get_shell_surface(c->parent.shell,
304 output->parent.surface);
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300305 wl_shell_surface_add_listener(output->parent.shell_surface,
306 &shell_surface_listener, output);
Pekka Paalanen9d1613e2011-11-25 12:09:16 +0200307 wl_shell_surface_set_toplevel(output->parent.shell_surface);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100308
Jonas Ådahle5a12252013-04-05 23:07:11 +0200309 output->base.start_repaint_loop = wayland_output_start_repaint_loop;
Kristian Høgsberg68c479a2012-01-25 23:32:28 -0500310 output->base.repaint = wayland_output_repaint;
Matt Roper361d2ad2011-08-29 13:52:23 -0700311 output->base.destroy = wayland_output_destroy;
Jesse Barnes5308a5e2012-02-09 13:12:57 -0800312 output->base.assign_planes = NULL;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +0200313 output->base.set_backlight = NULL;
314 output->base.set_dpms = NULL;
Alex Wu2dda6042012-04-17 17:20:47 +0800315 output->base.switch_mode = NULL;
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +0100316
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100317 wl_list_insert(c->base.output_list.prev, &output->base.link);
318
319 return 0;
Benjamin Franzkebe014562011-02-18 17:04:24 +0100320
Benjamin Franzkebe014562011-02-18 17:04:24 +0100321cleanup_window:
322 wl_egl_window_destroy(output->parent.egl_window);
323cleanup_output:
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500324 /* FIXME: cleanup weston_output */
Benjamin Franzkebe014562011-02-18 17:04:24 +0100325 free(output);
326
327 return -1;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100328}
329
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300330static void
331shell_surface_ping(void *data, struct wl_shell_surface *shell_surface,
332 uint32_t serial)
333{
334 wl_shell_surface_pong(shell_surface, serial);
335}
336
337static void
338shell_surface_configure(void *data, struct wl_shell_surface *shell_surface,
339 uint32_t edges, int32_t width, int32_t height)
340{
341 /* FIXME: implement resizing */
342}
343
344static void
345shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface)
346{
347}
348
349static const struct wl_shell_surface_listener shell_surface_listener = {
350 shell_surface_ping,
351 shell_surface_configure,
352 shell_surface_popup_done
353};
354
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100355/* Events received from the wayland-server this compositor is client of: */
356
357/* parent output interface */
358static void
359display_handle_geometry(void *data,
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400360 struct wl_output *wl_output,
361 int x,
362 int y,
363 int physical_width,
364 int physical_height,
365 int subpixel,
366 const char *make,
Kristian Høgsberg0e696472012-07-22 15:49:57 -0400367 const char *model,
368 int transform)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100369{
370 struct wayland_compositor *c = data;
371
Kristian Høgsbergf8fc08f2010-12-01 20:10:10 -0500372 c->parent.screen_allocation.x = x;
373 c->parent.screen_allocation.y = y;
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400374}
375
376static void
377display_handle_mode(void *data,
378 struct wl_output *wl_output,
379 uint32_t flags,
380 int width,
381 int height,
382 int refresh)
383{
384 struct wayland_compositor *c = data;
385
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100386 c->parent.screen_allocation.width = width;
387 c->parent.screen_allocation.height = height;
388}
389
390static const struct wl_output_listener output_listener = {
391 display_handle_geometry,
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -0400392 display_handle_mode
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100393};
394
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400395static void
396check_focus(struct wayland_input *input, wl_fixed_t x, wl_fixed_t y)
397{
398 struct wayland_compositor *c = input->compositor;
399 int width, height, inside;
400
401 width = input->output->mode.width;
402 height = input->output->mode.height;
403
404 inside = c->border.left <= wl_fixed_to_int(x) &&
405 wl_fixed_to_int(x) < width + c->border.left &&
406 c->border.top <= wl_fixed_to_int(y) &&
407 wl_fixed_to_int(y) < height + c->border.top;
408
409 if (!input->focus && inside) {
410 notify_pointer_focus(&input->base, &input->output->base,
411 x - wl_fixed_from_int(c->border.left),
412 y = wl_fixed_from_int(c->border.top));
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500413 wl_pointer_set_cursor(input->parent.pointer,
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400414 input->enter_serial, NULL, 0, 0);
415 } else if (input->focus && !inside) {
416 notify_pointer_focus(&input->base, NULL, 0, 0);
417 /* FIXME: Should set default cursor here. */
418 }
419
420 input->focus = inside;
421}
422
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100423/* parent input interface */
424static void
Daniel Stone37816df2012-05-16 18:45:18 +0100425input_handle_pointer_enter(void *data, struct wl_pointer *pointer,
426 uint32_t serial, struct wl_surface *surface,
Kristian Høgsberge11bbe42012-05-09 12:19:04 -0400427 wl_fixed_t x, wl_fixed_t y)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100428{
429 struct wayland_input *input = data;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100430
Daniel Stone50692802012-06-22 13:21:41 +0100431 /* XXX: If we get a modifier event immediately before the focus,
432 * we should try to keep the same serial. */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400433 input->enter_serial = serial;
434 input->output = wl_surface_get_user_data(surface);
435 check_focus(input, x, y);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100436}
437
438static void
Daniel Stone37816df2012-05-16 18:45:18 +0100439input_handle_pointer_leave(void *data, struct wl_pointer *pointer,
440 uint32_t serial, struct wl_surface *surface)
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500441{
442 struct wayland_input *input = data;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500443
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400444 notify_pointer_focus(&input->base, NULL, 0, 0);
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400445 input->output = NULL;
446 input->focus = 0;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500447}
448
449static void
Daniel Stone37816df2012-05-16 18:45:18 +0100450input_handle_motion(void *data, struct wl_pointer *pointer,
451 uint32_t time, wl_fixed_t x, wl_fixed_t y)
452{
453 struct wayland_input *input = data;
454 struct wayland_compositor *c = input->compositor;
455
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400456 check_focus(input, x, y);
457 if (input->focus)
458 notify_motion(&input->base, time,
Kristian Høgsberg068b61c2013-02-25 17:04:47 -0500459 x - wl_fixed_from_int(c->border.left) -
Kristian Høgsberge3148752013-05-06 23:19:49 -0400460 input->base.pointer->x,
Kristian Høgsberg068b61c2013-02-25 17:04:47 -0500461 y - wl_fixed_from_int(c->border.top) -
Kristian Høgsberge3148752013-05-06 23:19:49 -0400462 input->base.pointer->y);
Daniel Stone37816df2012-05-16 18:45:18 +0100463}
464
465static void
466input_handle_button(void *data, struct wl_pointer *pointer,
Daniel Stone4dbadb12012-05-30 16:31:51 +0100467 uint32_t serial, uint32_t time, uint32_t button,
468 uint32_t state_w)
Daniel Stone37816df2012-05-16 18:45:18 +0100469{
470 struct wayland_input *input = data;
Daniel Stone4dbadb12012-05-30 16:31:51 +0100471 enum wl_pointer_button_state state = state_w;
Daniel Stone37816df2012-05-16 18:45:18 +0100472
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400473 notify_button(&input->base, time, button, state);
Daniel Stone37816df2012-05-16 18:45:18 +0100474}
475
476static void
477input_handle_axis(void *data, struct wl_pointer *pointer,
Daniel Stone2fce4022012-05-30 16:32:00 +0100478 uint32_t time, uint32_t axis, wl_fixed_t value)
Daniel Stone37816df2012-05-16 18:45:18 +0100479{
480 struct wayland_input *input = data;
Daniel Stone37816df2012-05-16 18:45:18 +0100481
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400482 notify_axis(&input->base, time, axis, value);
Daniel Stone37816df2012-05-16 18:45:18 +0100483}
484
485static const struct wl_pointer_listener pointer_listener = {
486 input_handle_pointer_enter,
487 input_handle_pointer_leave,
488 input_handle_motion,
489 input_handle_button,
490 input_handle_axis,
491};
492
493static void
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100494input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
495 int fd, uint32_t size)
496{
497 struct wayland_input *input = data;
498 struct xkb_keymap *keymap;
499 char *map_str;
500
501 if (!data) {
502 close(fd);
503 return;
504 }
505
506 if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
507 close(fd);
508 return;
509 }
510
511 map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
512 if (map_str == MAP_FAILED) {
513 close(fd);
514 return;
515 }
516
517 keymap = xkb_map_new_from_string(input->compositor->base.xkb_context,
518 map_str,
519 XKB_KEYMAP_FORMAT_TEXT_V1,
520 0);
521 munmap(map_str, size);
522 close(fd);
523
524 if (!keymap) {
Martin Minarik6d118362012-06-07 18:01:59 +0200525 weston_log("failed to compile keymap\n");
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100526 return;
527 }
528
Rui Matos0c194ce2013-10-10 19:44:21 +0200529 if (input->base.keyboard)
530 weston_seat_update_keymap(&input->base, keymap);
531 else
532 weston_seat_init_keyboard(&input->base, keymap);
533
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100534 xkb_map_unref(keymap);
535}
536
537static void
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500538input_handle_keyboard_enter(void *data,
Daniel Stone37816df2012-05-16 18:45:18 +0100539 struct wl_keyboard *keyboard,
540 uint32_t serial,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500541 struct wl_surface *surface,
542 struct wl_array *keys)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100543{
Kristian Høgsbergaf82bea2011-01-27 20:18:17 -0500544 struct wayland_input *input = data;
Kristian Høgsbergaf82bea2011-01-27 20:18:17 -0500545
Daniel Stone50692802012-06-22 13:21:41 +0100546 /* XXX: If we get a modifier event immediately before the focus,
547 * we should try to keep the same serial. */
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400548 notify_keyboard_focus_in(&input->base, keys,
Daniel Stoned6da09e2012-06-22 13:21:29 +0100549 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500550}
551
552static void
553input_handle_keyboard_leave(void *data,
Daniel Stone37816df2012-05-16 18:45:18 +0100554 struct wl_keyboard *keyboard,
555 uint32_t serial,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500556 struct wl_surface *surface)
557{
558 struct wayland_input *input = data;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500559
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400560 notify_keyboard_focus_out(&input->base);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100561}
562
Daniel Stone37816df2012-05-16 18:45:18 +0100563static void
564input_handle_key(void *data, struct wl_keyboard *keyboard,
565 uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
566{
567 struct wayland_input *input = data;
Daniel Stone37816df2012-05-16 18:45:18 +0100568
Daniel Stone50692802012-06-22 13:21:41 +0100569 input->key_serial = serial;
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400570 notify_key(&input->base, time, key,
Daniel Stonec9785ea2012-05-30 16:31:52 +0100571 state ? WL_KEYBOARD_KEY_STATE_PRESSED :
Daniel Stone1b4e11f2012-06-22 13:21:37 +0100572 WL_KEYBOARD_KEY_STATE_RELEASED,
Daniel Stone50692802012-06-22 13:21:41 +0100573 STATE_UPDATE_NONE);
Daniel Stone37816df2012-05-16 18:45:18 +0100574}
575
Daniel Stone351eb612012-05-31 15:27:47 -0400576static void
577input_handle_modifiers(void *data, struct wl_keyboard *keyboard,
Daniel Stone50692802012-06-22 13:21:41 +0100578 uint32_t serial_in, uint32_t mods_depressed,
Daniel Stone351eb612012-05-31 15:27:47 -0400579 uint32_t mods_latched, uint32_t mods_locked,
580 uint32_t group)
581{
Daniel Stone50692802012-06-22 13:21:41 +0100582 struct wayland_input *input = data;
583 struct wayland_compositor *c = input->compositor;
584 uint32_t serial_out;
585
586 /* If we get a key event followed by a modifier event with the
587 * same serial number, then we try to preserve those semantics by
588 * reusing the same serial number on the way out too. */
589 if (serial_in == input->key_serial)
590 serial_out = wl_display_get_serial(c->base.wl_display);
591 else
592 serial_out = wl_display_next_serial(c->base.wl_display);
593
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -0400594 xkb_state_update_mask(input->base.xkb_state.state,
Daniel Stone50692802012-06-22 13:21:41 +0100595 mods_depressed, mods_latched,
596 mods_locked, 0, 0, group);
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -0400597 notify_modifiers(&input->base, serial_out);
Daniel Stone351eb612012-05-31 15:27:47 -0400598}
599
Daniel Stone37816df2012-05-16 18:45:18 +0100600static const struct wl_keyboard_listener keyboard_listener = {
Daniel Stoneb7452fe2012-06-01 12:14:06 +0100601 input_handle_keymap,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -0500602 input_handle_keyboard_enter,
603 input_handle_keyboard_leave,
Daniel Stone37816df2012-05-16 18:45:18 +0100604 input_handle_key,
Daniel Stone351eb612012-05-31 15:27:47 -0400605 input_handle_modifiers,
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100606};
607
608static void
Daniel Stone37816df2012-05-16 18:45:18 +0100609input_handle_capabilities(void *data, struct wl_seat *seat,
610 enum wl_seat_capability caps)
611{
612 struct wayland_input *input = data;
613
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500614 if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->parent.pointer) {
615 input->parent.pointer = wl_seat_get_pointer(seat);
616 wl_pointer_set_user_data(input->parent.pointer, input);
617 wl_pointer_add_listener(input->parent.pointer,
618 &pointer_listener, input);
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -0400619 weston_seat_init_pointer(&input->base);
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500620 } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->parent.pointer) {
621 wl_pointer_destroy(input->parent.pointer);
622 input->parent.pointer = NULL;
Daniel Stone37816df2012-05-16 18:45:18 +0100623 }
624
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500625 if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->parent.keyboard) {
626 input->parent.keyboard = wl_seat_get_keyboard(seat);
627 wl_keyboard_set_user_data(input->parent.keyboard, input);
628 wl_keyboard_add_listener(input->parent.keyboard,
629 &keyboard_listener, input);
630 } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->parent.keyboard) {
631 wl_keyboard_destroy(input->parent.keyboard);
632 input->parent.keyboard = NULL;
Daniel Stone37816df2012-05-16 18:45:18 +0100633 }
634}
635
636static const struct wl_seat_listener seat_listener = {
637 input_handle_capabilities,
638};
639
640static void
641display_add_seat(struct wayland_compositor *c, uint32_t id)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100642{
643 struct wayland_input *input;
644
Peter Huttererf3d62272013-08-08 11:57:05 +1000645 input = zalloc(sizeof *input);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100646 if (input == NULL)
647 return;
648
Rob Bradford9af5f9e2013-05-31 18:09:50 +0100649 weston_seat_init(&input->base, &c->base, "default");
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100650 input->compositor = c;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500651 input->parent.seat = wl_registry_bind(c->parent.registry, id,
652 &wl_seat_interface, 1);
653 wl_list_insert(c->inputs.prev, &input->link);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100654
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500655 wl_seat_add_listener(input->parent.seat, &seat_listener, input);
656 wl_seat_set_user_data(input->parent.seat, input);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100657}
658
659static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400660registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
661 const char *interface, uint32_t version)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100662{
663 struct wayland_compositor *c = data;
664
Benjamin Franzke080ab6c2011-04-30 10:41:27 +0200665 if (strcmp(interface, "wl_compositor") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400666 c->parent.compositor =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400667 wl_registry_bind(registry, name,
668 &wl_compositor_interface, 1);
Benjamin Franzke080ab6c2011-04-30 10:41:27 +0200669 } else if (strcmp(interface, "wl_output") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400670 c->parent.output =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400671 wl_registry_bind(registry, name,
672 &wl_output_interface, 1);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100673 wl_output_add_listener(c->parent.output, &output_listener, c);
Benjamin Franzke080ab6c2011-04-30 10:41:27 +0200674 } else if (strcmp(interface, "wl_shell") == 0) {
Kristian Høgsbergf790c792011-08-19 14:41:57 -0400675 c->parent.shell =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400676 wl_registry_bind(registry, name,
677 &wl_shell_interface, 1);
Daniel Stone725c2c32012-06-22 14:04:36 +0100678 } else if (strcmp(interface, "wl_seat") == 0) {
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400679 display_add_seat(c, name);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200680 } else if (strcmp(interface, "wl_shm") == 0) {
681 c->parent.shm =
682 wl_registry_bind(registry, name, &wl_shm_interface, 1);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100683 }
684}
685
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400686static const struct wl_registry_listener registry_listener = {
687 registry_handle_global
688};
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100689
Kristian Høgsberg95d843d2011-04-22 13:01:26 -0400690static int
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100691wayland_compositor_handle_event(int fd, uint32_t mask, void *data)
692{
693 struct wayland_compositor *c = data;
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -0400694 int count = 0;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100695
Kristian Høgsberg453de7a2013-10-30 23:15:44 -0700696 if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
697 wl_display_terminate(c->base.wl_display);
698 return 0;
699 }
700
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100701 if (mask & WL_EVENT_READABLE)
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -0400702 count = wl_display_dispatch(c->parent.wl_display);
Kristian Høgsbergf258a312011-12-28 22:51:20 -0500703 if (mask & WL_EVENT_WRITABLE)
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400704 wl_display_flush(c->parent.wl_display);
Kristian Høgsberg95d843d2011-04-22 13:01:26 -0400705
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -0400706 if (mask == 0) {
707 count = wl_display_dispatch_pending(c->parent.wl_display);
708 wl_display_flush(c->parent.wl_display);
709 }
710
711 return count;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100712}
713
Kristian Høgsbergcaa64422010-12-01 16:52:15 -0500714static void
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -0400715wayland_restore(struct weston_compositor *ec)
716{
717}
718
719static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500720wayland_destroy(struct weston_compositor *ec)
Kristian Høgsbergcaa64422010-12-01 16:52:15 -0500721{
Jonas Ådahle5a12252013-04-05 23:07:11 +0200722 struct wayland_compositor *c = (struct wayland_compositor *) ec;
723
Vasily Khoruzhick52cfd612013-01-08 19:09:01 +0300724 ec->renderer->destroy(ec);
Kristian Høgsberg3a0de882012-09-06 21:44:24 -0400725
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500726 weston_compositor_shutdown(ec);
Matt Roper361d2ad2011-08-29 13:52:23 -0700727
Jonas Ådahle5a12252013-04-05 23:07:11 +0200728 if (c->parent.shm)
729 wl_shm_destroy(c->parent.shm);
730
Kristian Høgsbergcaa64422010-12-01 16:52:15 -0500731 free(ec);
732}
733
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500734static struct weston_compositor *
Kristian Høgsberg2e28b102012-02-07 09:57:25 -0500735wayland_compositor_create(struct wl_display *display,
Daniel Stonebaf43592012-06-01 11:11:10 -0400736 int width, int height, const char *display_name,
Kristian Høgsberg14e438c2013-05-26 21:48:14 -0400737 int *argc, char *argv[],
738 struct weston_config *config)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100739{
740 struct wayland_compositor *c;
741 struct wl_event_loop *loop;
742 int fd;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100743
Peter Huttererf3d62272013-08-08 11:57:05 +1000744 c = zalloc(sizeof *c);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100745 if (c == NULL)
746 return NULL;
747
Daniel Stone725c2c32012-06-22 14:04:36 +0100748 if (weston_compositor_init(&c->base, display, argc, argv,
Kristian Høgsberg14e438c2013-05-26 21:48:14 -0400749 config) < 0)
Martin Olssonc5db50f2012-07-08 03:03:43 +0200750 goto err_free;
Daniel Stone725c2c32012-06-22 14:04:36 +0100751
Kristian Høgsberg362b6722012-06-18 15:13:51 -0400752 c->parent.wl_display = wl_display_connect(display_name);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100753
Kristian Høgsberg362b6722012-06-18 15:13:51 -0400754 if (c->parent.wl_display == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +0200755 weston_log("failed to create display: %m\n");
Martin Olssonc5db50f2012-07-08 03:03:43 +0200756 goto err_compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100757 }
758
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500759 wl_list_init(&c->inputs);
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400760 c->parent.registry = wl_display_get_registry(c->parent.wl_display);
761 wl_registry_add_listener(c->parent.registry, &registry_listener, c);
762 wl_display_dispatch(c->parent.wl_display);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100763
764 c->base.wl_display = display;
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300765
766 gl_renderer = weston_load_module("gl-renderer.so",
767 "gl_renderer_interface");
768 if (!gl_renderer)
769 goto err_display;
770
771 if (gl_renderer->create(&c->base, c->parent.wl_display,
772 gl_renderer->alpha_attribs,
John Kåre Alsaker1b7ad162012-11-13 19:10:19 +0100773 NULL) < 0)
Martin Olssonc5db50f2012-07-08 03:03:43 +0200774 goto err_display;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100775
Benjamin Franzkeecfb2b92011-01-15 12:34:48 +0100776 c->base.destroy = wayland_destroy;
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -0400777 c->base.restore = wayland_restore;
Benjamin Franzkeecfb2b92011-01-15 12:34:48 +0100778
John Kåre Alsakerc37b32d2012-10-04 20:42:17 +0200779 c->border.top = 30;
780 c->border.bottom = 24;
John Kåre Alsakerb9b87122012-10-04 20:42:16 +0200781 c->border.left = 25;
John Kåre Alsakerc37b32d2012-10-04 20:42:17 +0200782 c->border.right = 26;
John Kåre Alsakerb9b87122012-10-04 20:42:16 +0200783
784 /* requires border fields */
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100785 if (wayland_compositor_create_output(c, width, height) < 0)
John Kåre Alsaker779b52a2012-11-13 19:10:29 +0100786 goto err_gl;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100787
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300788 /* requires gl_renderer->output_state_create called
John Kåre Alsaker1b7ad162012-11-13 19:10:19 +0100789 * by wayland_compositor_create_output */
John Kåre Alsaker4b3081a2012-10-03 18:02:22 +0200790 create_border(c);
791
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100792 loop = wl_display_get_event_loop(c->base.wl_display);
793
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400794 fd = wl_display_get_fd(c->parent.wl_display);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100795 c->parent.wl_source =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400796 wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100797 wayland_compositor_handle_event, c);
798 if (c->parent.wl_source == NULL)
John Kåre Alsaker779b52a2012-11-13 19:10:29 +0100799 goto err_gl;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100800
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -0400801 wl_event_source_check(c->parent.wl_source);
802
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100803 return &c->base;
Martin Olssonc5db50f2012-07-08 03:03:43 +0200804
John Kåre Alsaker779b52a2012-11-13 19:10:29 +0100805err_gl:
Vasily Khoruzhick52cfd612013-01-08 19:09:01 +0300806 c->base.renderer->destroy(&c->base);
Martin Olssonc5db50f2012-07-08 03:03:43 +0200807err_display:
808 wl_display_disconnect(c->parent.wl_display);
809err_compositor:
810 weston_compositor_shutdown(&c->base);
811err_free:
812 free(c);
813 return NULL;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100814}
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400815
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500816WL_EXPORT struct weston_compositor *
Kristian Høgsberg4172f662013-02-20 15:27:49 -0500817backend_init(struct wl_display *display, int *argc, char *argv[],
Kristian Høgsberg14e438c2013-05-26 21:48:14 -0400818 struct weston_config *config)
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400819{
Kristian Høgsbergbcacef12012-03-11 21:05:57 -0400820 int width = 1024, height = 640;
821 char *display_name = NULL;
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400822
Kristian Høgsbergbcacef12012-03-11 21:05:57 -0400823 const struct weston_option wayland_options[] = {
824 { WESTON_OPTION_INTEGER, "width", 0, &width },
825 { WESTON_OPTION_INTEGER, "height", 0, &height },
826 { WESTON_OPTION_STRING, "display", 0, &display_name },
827 };
828
829 parse_options(wayland_options,
830 ARRAY_LENGTH(wayland_options), argc, argv);
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400831
Daniel Stonebaf43592012-06-01 11:11:10 -0400832 return wayland_compositor_create(display, width, height, display_name,
Kristian Høgsberg14e438c2013-05-26 21:48:14 -0400833 argc, argv, config);
Kristian Høgsberg1c562182011-05-02 22:09:20 -0400834}