blob: 6f88ffabaa78daa70778c628163a5d82de32fec1 [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
Jason Ekstrandff2fd462013-10-27 22:24:58 -05003 * Copyright © 2013 Jason Ekstrand
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01004 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -07005 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010012 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -070013 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010025 */
26
Daniel Stonec228e232013-05-22 18:03:19 +030027#include "config.h"
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010028
29#include <stddef.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010030#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <fcntl.h>
34#include <unistd.h>
Daniel Stoneb7452fe2012-06-01 12:14:06 +010035#include <sys/mman.h>
Jason Ekstrand5ea04802013-11-07 20:13:33 -060036#include <linux/input.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010037
Benjamin Franzkebe014562011-02-18 17:04:24 +010038#include <wayland-client.h>
39#include <wayland-egl.h>
Jason Ekstrand7744f712013-10-27 22:24:55 -050040#include <wayland-cursor.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010041
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010042#include "compositor.h"
John Kåre Alsaker30d2b1f2012-11-13 19:10:28 +010043#include "gl-renderer.h"
Jason Ekstrandff2fd462013-10-27 22:24:58 -050044#include "pixman-renderer.h"
Jon Cruz35b2eaa2015-06-15 15:37:08 -070045#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070046#include "shared/image-loader.h"
47#include "shared/os-compatibility.h"
48#include "shared/cairo-util.h"
Jonas Ådahl496adb32015-11-17 16:00:27 +080049#include "fullscreen-shell-unstable-v1-client-protocol.h"
Pekka Paalanen363aa7b2014-12-17 16:20:40 +020050#include "presentation_timing-server-protocol.h"
Emmanuel Gil Peyrotc59f18e2015-09-25 11:58:40 +020051#include "linux-dmabuf.h"
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010052
Jason Ekstrand48ce4212013-10-27 22:25:02 -050053#define WINDOW_TITLE "Weston Compositor"
54
Giulio Camuffo954f1832014-10-11 18:27:30 +030055struct wayland_backend {
56 struct weston_backend base;
57 struct weston_compositor *compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010058
59 struct {
Kristian Høgsberg362b6722012-06-18 15:13:51 -040060 struct wl_display *wl_display;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -040061 struct wl_registry *registry;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010062 struct wl_compositor *compositor;
63 struct wl_shell *shell;
Jonas Ådahl496adb32015-11-17 16:00:27 +080064 struct zwp_fullscreen_shell_v1 *fshell;
Jonas Ådahle5a12252013-04-05 23:07:11 +020065 struct wl_shm *shm;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010066
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -050067 struct wl_list output_list;
68
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010069 struct wl_event_source *wl_source;
70 uint32_t event_mask;
71 } parent;
72
Jason Ekstrandff2fd462013-10-27 22:24:58 -050073 int use_pixman;
Jason Ekstrande4ca8b02014-04-02 19:53:55 -050074 int sprawl_across_outputs;
Jason Ekstrandff2fd462013-10-27 22:24:58 -050075
Jason Ekstrand7744f712013-10-27 22:24:55 -050076 struct theme *theme;
77 cairo_device_t *frame_device;
78 struct wl_cursor_theme *cursor_theme;
79 struct wl_cursor *cursor;
Kristian Høgsberg546a8122012-02-01 07:45:51 -050080
Jason Ekstrand06ced802013-11-07 20:13:29 -060081 struct wl_list input_list;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010082};
83
84struct wayland_output {
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050085 struct weston_output base;
86
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010087 struct {
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050088 int draw_initial_frame;
89 struct wl_surface *surface;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -050090
91 struct wl_output *output;
92 uint32_t global_id;
93
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050094 struct wl_shell_surface *shell_surface;
Jason Ekstrand5ea04802013-11-07 20:13:33 -060095 int configure_width, configure_height;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010096 } parent;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050097
Jason Ekstrand7744f712013-10-27 22:24:55 -050098 int keyboard_count;
99
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600100 char *name;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500101 struct frame *frame;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500102
Jason Ekstrand7744f712013-10-27 22:24:55 -0500103 struct {
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500104 struct wl_egl_window *egl_window;
105 struct {
106 cairo_surface_t *top;
107 cairo_surface_t *left;
108 cairo_surface_t *right;
109 cairo_surface_t *bottom;
110 } border;
111 } gl;
112
113 struct {
114 struct wl_list buffers;
115 struct wl_list free_buffers;
116 } shm;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500117
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500118 struct weston_mode mode;
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500119 uint32_t scale;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100120};
121
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500122struct wayland_parent_output {
123 struct wayland_output *output;
124 struct wl_list link;
125
126 struct wl_output *global;
127 uint32_t id;
128
129 struct {
130 char *make;
131 char *model;
132 int32_t width, height;
133 uint32_t subpixel;
134 } physical;
135
136 int32_t x, y;
137 uint32_t transform;
138 uint32_t scale;
139
140 struct wl_list mode_list;
141 struct weston_mode *preferred_mode;
142 struct weston_mode *current_mode;
143};
144
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500145struct wayland_shm_buffer {
146 struct wayland_output *output;
147 struct wl_list link;
148 struct wl_list free_link;
149
150 struct wl_buffer *buffer;
151 void *data;
152 size_t size;
153 pixman_region32_t damage;
154 int frame_damaged;
155
156 pixman_image_t *pm_image;
157 cairo_surface_t *c_surface;
158};
159
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100160struct wayland_input {
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -0400161 struct weston_seat base;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300162 struct wayland_backend *backend;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100163 struct wl_list link;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500164
165 struct {
166 struct wl_seat *seat;
167 struct wl_pointer *pointer;
168 struct wl_keyboard *keyboard;
169 struct wl_touch *touch;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500170
171 struct {
172 struct wl_surface *surface;
173 int32_t hx, hy;
174 } cursor;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500175 } parent;
176
Jason Ekstrandb7d9f2e2014-04-02 19:53:57 -0500177 enum weston_key_state_update keyboard_state_update;
Daniel Stone50692802012-06-22 13:21:41 +0100178 uint32_t key_serial;
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400179 uint32_t enter_serial;
Derek Foreman4bcc54d2015-11-06 15:56:06 -0600180 bool has_focus;
Derek Foremancfce7d02015-11-06 15:56:08 -0600181 int seat_version;
Derek Foreman4bcc54d2015-11-06 15:56:06 -0600182
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400183 struct wayland_output *output;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500184 struct wayland_output *keyboard_focus;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100185};
186
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300187struct gl_renderer_interface *gl_renderer;
188
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500189static void
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500190wayland_shm_buffer_destroy(struct wayland_shm_buffer *buffer)
191{
192 cairo_surface_destroy(buffer->c_surface);
193 pixman_image_unref(buffer->pm_image);
194
195 wl_buffer_destroy(buffer->buffer);
196 munmap(buffer->data, buffer->size);
197
198 pixman_region32_fini(&buffer->damage);
199
200 wl_list_remove(&buffer->link);
201 wl_list_remove(&buffer->free_link);
202 free(buffer);
203}
204
205static void
206buffer_release(void *data, struct wl_buffer *buffer)
207{
208 struct wayland_shm_buffer *sb = data;
209
210 if (sb->output) {
211 wl_list_insert(&sb->output->shm.free_buffers, &sb->free_link);
212 } else {
213 wayland_shm_buffer_destroy(sb);
214 }
215}
216
217static const struct wl_buffer_listener buffer_listener = {
218 buffer_release
219};
220
221static struct wayland_shm_buffer *
222wayland_output_get_shm_buffer(struct wayland_output *output)
223{
Giulio Camuffo954f1832014-10-11 18:27:30 +0300224 struct wayland_backend *b =
225 (struct wayland_backend *) output->base.compositor->backend;
226 struct wl_shm *shm = b->parent.shm;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500227 struct wayland_shm_buffer *sb;
228
229 struct wl_shm_pool *pool;
230 int width, height, stride;
231 int32_t fx, fy;
232 int fd;
233 unsigned char *data;
234
235 if (!wl_list_empty(&output->shm.free_buffers)) {
236 sb = container_of(output->shm.free_buffers.next,
237 struct wayland_shm_buffer, free_link);
238 wl_list_remove(&sb->free_link);
239 wl_list_init(&sb->free_link);
240
241 return sb;
242 }
243
244 if (output->frame) {
245 width = frame_width(output->frame);
246 height = frame_height(output->frame);
247 } else {
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500248 width = output->base.current_mode->width;
249 height = output->base.current_mode->height;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500250 }
251
252 stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
253
254 fd = os_create_anonymous_file(height * stride);
255 if (fd < 0) {
Bryce W. Harringtona0935022014-03-21 05:54:02 +0000256 weston_log("could not create an anonymous file buffer: %m\n");
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500257 return NULL;
258 }
259
260 data = mmap(NULL, height * stride, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
261 if (data == MAP_FAILED) {
Bryce W. Harringtona0935022014-03-21 05:54:02 +0000262 weston_log("could not mmap %d memory for data: %m\n", height * stride);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500263 close(fd);
264 return NULL;
265 }
266
267 sb = zalloc(sizeof *sb);
Bryce W. Harringtonbfd74f42014-04-21 23:51:02 +0000268 if (sb == NULL) {
Thierry Reding6ac60c12014-05-27 09:08:29 +0200269 weston_log("could not zalloc %zu memory for sb: %m\n", sizeof *sb);
Bryce W. Harringtonbfd74f42014-04-21 23:51:02 +0000270 close(fd);
271 free(data);
272 return NULL;
273 }
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500274
275 sb->output = output;
276 wl_list_init(&sb->free_link);
277 wl_list_insert(&output->shm.buffers, &sb->link);
278
279 pixman_region32_init_rect(&sb->damage, 0, 0,
280 output->base.width, output->base.height);
281 sb->frame_damaged = 1;
282
283 sb->data = data;
284 sb->size = height * stride;
285
286 pool = wl_shm_create_pool(shm, fd, sb->size);
287
288 sb->buffer = wl_shm_pool_create_buffer(pool, 0,
289 width, height,
290 stride,
291 WL_SHM_FORMAT_ARGB8888);
292 wl_buffer_add_listener(sb->buffer, &buffer_listener, sb);
293 wl_shm_pool_destroy(pool);
294 close(fd);
295
296 memset(data, 0, sb->size);
297
298 sb->c_surface =
299 cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32,
300 width, height, stride);
301
302 fx = 0;
303 fy = 0;
304 if (output->frame)
305 frame_interior(output->frame, &fx, &fy, 0, 0);
306 sb->pm_image =
307 pixman_image_create_bits(PIXMAN_a8r8g8b8, width, height,
308 (uint32_t *)(data + fy * stride) + fx,
309 stride);
310
311 return sb;
312}
313
314static void
Kristian Høgsbergcdd61d02012-02-07 09:56:15 -0500315frame_done(void *data, struct wl_callback *callback, uint32_t time)
Kristian Høgsberg33418202011-08-16 23:01:28 -0400316{
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500317 struct weston_output *output = data;
Pekka Paalanenb5eedad2014-09-23 22:08:45 -0400318 struct timespec ts;
Kristian Høgsberg33418202011-08-16 23:01:28 -0400319
Kristian Høgsbergcdd61d02012-02-07 09:56:15 -0500320 wl_callback_destroy(callback);
Pekka Paalanenb5eedad2014-09-23 22:08:45 -0400321
322 /* XXX: use the presentation extension for proper timings */
Pekka Paalanen04f8a9b2015-04-02 16:26:06 +0300323
324 /*
325 * This is the fallback case, where Presentation extension is not
326 * available from the parent compositor. We do not know the base for
327 * 'time', so we cannot feed it to finish_frame(). Do the only thing
328 * we can, and pretend finish_frame time is when we process this
329 * event.
330 */
331 weston_compositor_read_presentation_clock(output->compositor, &ts);
Pekka Paalanen363aa7b2014-12-17 16:20:40 +0200332 weston_output_finish_frame(output, &ts, 0);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400333}
334
335static const struct wl_callback_listener frame_listener = {
336 frame_done
337};
338
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500339static void
Jonas Ådahle5a12252013-04-05 23:07:11 +0200340draw_initial_frame(struct wayland_output *output)
341{
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500342 struct wayland_shm_buffer *sb;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200343
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500344 sb = wayland_output_get_shm_buffer(output);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200345
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500346 /* If we are rendering with GL, then orphan it so that it gets
347 * destroyed immediately */
348 if (output->gl.egl_window)
349 sb->output = NULL;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500350
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500351 wl_surface_attach(output->parent.surface, sb->buffer, 0, 0);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500352 wl_surface_damage(output->parent.surface, 0, 0,
353 output->base.current_mode->width,
354 output->base.current_mode->height);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200355}
356
357static void
Jason Ekstrand7744f712013-10-27 22:24:55 -0500358wayland_output_update_gl_border(struct wayland_output *output)
359{
360 int32_t ix, iy, iwidth, iheight, fwidth, fheight;
361 cairo_t *cr;
362
363 if (!output->frame)
364 return;
365 if (!(frame_status(output->frame) & FRAME_STATUS_REPAINT))
366 return;
367
368 fwidth = frame_width(output->frame);
369 fheight = frame_height(output->frame);
370 frame_interior(output->frame, &ix, &iy, &iwidth, &iheight);
371
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500372 if (!output->gl.border.top)
373 output->gl.border.top =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500374 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
375 fwidth, iy);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500376 cr = cairo_create(output->gl.border.top);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500377 frame_repaint(output->frame, cr);
378 cairo_destroy(cr);
379 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_TOP,
380 fwidth, iy,
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500381 cairo_image_surface_get_stride(output->gl.border.top) / 4,
382 cairo_image_surface_get_data(output->gl.border.top));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500383
384
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500385 if (!output->gl.border.left)
386 output->gl.border.left =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500387 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
388 ix, 1);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500389 cr = cairo_create(output->gl.border.left);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500390 cairo_translate(cr, 0, -iy);
391 frame_repaint(output->frame, cr);
392 cairo_destroy(cr);
393 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_LEFT,
394 ix, 1,
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500395 cairo_image_surface_get_stride(output->gl.border.left) / 4,
396 cairo_image_surface_get_data(output->gl.border.left));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500397
398
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500399 if (!output->gl.border.right)
400 output->gl.border.right =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500401 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
402 fwidth - (ix + iwidth), 1);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500403 cr = cairo_create(output->gl.border.right);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500404 cairo_translate(cr, -(iwidth + ix), -iy);
405 frame_repaint(output->frame, cr);
406 cairo_destroy(cr);
407 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_RIGHT,
408 fwidth - (ix + iwidth), 1,
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500409 cairo_image_surface_get_stride(output->gl.border.right) / 4,
410 cairo_image_surface_get_data(output->gl.border.right));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500411
412
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500413 if (!output->gl.border.bottom)
414 output->gl.border.bottom =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500415 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
416 fwidth, fheight - (iy + iheight));
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500417 cr = cairo_create(output->gl.border.bottom);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500418 cairo_translate(cr, 0, -(iy + iheight));
419 frame_repaint(output->frame, cr);
420 cairo_destroy(cr);
421 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_BOTTOM,
422 fwidth, fheight - (iy + iheight),
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500423 cairo_image_surface_get_stride(output->gl.border.bottom) / 4,
424 cairo_image_surface_get_data(output->gl.border.bottom));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500425}
426
427static void
Jonas Ådahle5a12252013-04-05 23:07:11 +0200428wayland_output_start_repaint_loop(struct weston_output *output_base)
429{
430 struct wayland_output *output = (struct wayland_output *) output_base;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300431 struct wayland_backend *wb =
432 (struct wayland_backend *)output->base.compositor->backend;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200433 struct wl_callback *callback;
434
435 /* If this is the initial frame, we need to attach a buffer so that
436 * the compositor can map the surface and include it in its render
437 * loop. If the surface doesn't end up in the render loop, the frame
438 * callback won't be invoked. The buffer is transparent and of the
439 * same size as the future real output buffer. */
440 if (output->parent.draw_initial_frame) {
441 output->parent.draw_initial_frame = 0;
442
443 draw_initial_frame(output);
444 }
445
446 callback = wl_surface_frame(output->parent.surface);
447 wl_callback_add_listener(callback, &frame_listener, output);
448 wl_surface_commit(output->parent.surface);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300449 wl_display_flush(wb->parent.wl_display);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200450}
451
David Herrmann1edf44c2013-10-22 17:11:26 +0200452static int
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500453wayland_output_repaint_gl(struct weston_output *output_base,
454 pixman_region32_t *damage)
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400455{
456 struct wayland_output *output = (struct wayland_output *) output_base;
Kristian Høgsbergfa1be022012-09-05 22:49:55 -0400457 struct weston_compositor *ec = output->base.compositor;
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400458 struct wl_callback *callback;
Scott Moreau062be7e2012-04-20 13:37:33 -0600459
Kristian Høgsberg33418202011-08-16 23:01:28 -0400460 callback = wl_surface_frame(output->parent.surface);
461 wl_callback_add_listener(callback, &frame_listener, output);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100462
Jason Ekstrand7744f712013-10-27 22:24:55 -0500463 wayland_output_update_gl_border(output);
464
Pekka Paalanenbc106382012-10-10 12:49:31 +0300465 ec->renderer->repaint_output(&output->base, damage);
Ander Conselvan de Oliveira0a887722012-11-22 15:57:00 +0200466
467 pixman_region32_subtract(&ec->primary_plane.damage,
468 &ec->primary_plane.damage, damage);
David Herrmann1edf44c2013-10-22 17:11:26 +0200469 return 0;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100470}
471
Matt Roper361d2ad2011-08-29 13:52:23 -0700472static void
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500473wayland_output_update_shm_border(struct wayland_shm_buffer *buffer)
474{
475 int32_t ix, iy, iwidth, iheight, fwidth, fheight;
476 cairo_t *cr;
477
478 if (!buffer->output->frame || !buffer->frame_damaged)
479 return;
480
481 cr = cairo_create(buffer->c_surface);
482
483 frame_interior(buffer->output->frame, &ix, &iy, &iwidth, &iheight);
484 fwidth = frame_width(buffer->output->frame);
485 fheight = frame_height(buffer->output->frame);
486
487 /* Set the clip so we don't unnecisaraly damage the surface */
488 cairo_move_to(cr, ix, iy);
489 cairo_rel_line_to(cr, iwidth, 0);
490 cairo_rel_line_to(cr, 0, iheight);
491 cairo_rel_line_to(cr, -iwidth, 0);
492 cairo_line_to(cr, ix, iy);
493 cairo_line_to(cr, 0, iy);
494 cairo_line_to(cr, 0, fheight);
495 cairo_line_to(cr, fwidth, fheight);
496 cairo_line_to(cr, fwidth, 0);
497 cairo_line_to(cr, 0, 0);
498 cairo_line_to(cr, 0, iy);
499 cairo_close_path(cr);
500 cairo_clip(cr);
501
502 /* Draw using a pattern so that the final result gets clipped */
503 cairo_push_group(cr);
504 frame_repaint(buffer->output->frame, cr);
505 cairo_pop_group_to_source(cr);
506 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
507 cairo_paint(cr);
508
509 cairo_destroy(cr);
510}
511
512static void
513wayland_shm_buffer_attach(struct wayland_shm_buffer *sb)
514{
515 pixman_region32_t damage;
516 pixman_box32_t *rects;
517 int32_t ix, iy, iwidth, iheight, fwidth, fheight;
518 int i, n;
519
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500520 pixman_region32_init(&damage);
521 weston_transformed_region(sb->output->base.width,
522 sb->output->base.height,
523 sb->output->base.transform,
524 sb->output->base.current_scale,
525 &sb->damage, &damage);
526
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500527 if (sb->output->frame) {
528 frame_interior(sb->output->frame, &ix, &iy, &iwidth, &iheight);
529 fwidth = frame_width(sb->output->frame);
530 fheight = frame_height(sb->output->frame);
531
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500532 pixman_region32_translate(&damage, ix, iy);
533
534 if (sb->frame_damaged) {
535 pixman_region32_union_rect(&damage, &damage,
536 0, 0, fwidth, iy);
537 pixman_region32_union_rect(&damage, &damage,
538 0, iy, ix, iheight);
539 pixman_region32_union_rect(&damage, &damage,
540 ix + iwidth, iy,
541 fwidth - (ix + iwidth), iheight);
542 pixman_region32_union_rect(&damage, &damage,
543 0, iy + iheight,
544 fwidth, fheight - (iy + iheight));
545 }
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500546 }
547
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500548 rects = pixman_region32_rectangles(&damage, &n);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500549 wl_surface_attach(sb->output->parent.surface, sb->buffer, 0, 0);
550 for (i = 0; i < n; ++i)
551 wl_surface_damage(sb->output->parent.surface, rects[i].x1,
552 rects[i].y1, rects[i].x2 - rects[i].x1,
553 rects[i].y2 - rects[i].y1);
554
555 if (sb->output->frame)
556 pixman_region32_fini(&damage);
557}
558
559static int
560wayland_output_repaint_pixman(struct weston_output *output_base,
561 pixman_region32_t *damage)
562{
563 struct wayland_output *output = (struct wayland_output *) output_base;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300564 struct wayland_backend *b =
565 (struct wayland_backend *)output->base.compositor->backend;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500566 struct wl_callback *callback;
567 struct wayland_shm_buffer *sb;
568
569 if (output->frame) {
570 if (frame_status(output->frame) & FRAME_STATUS_REPAINT)
571 wl_list_for_each(sb, &output->shm.buffers, link)
572 sb->frame_damaged = 1;
573 }
574
575 wl_list_for_each(sb, &output->shm.buffers, link)
576 pixman_region32_union(&sb->damage, &sb->damage, damage);
577
578 sb = wayland_output_get_shm_buffer(output);
579
580 wayland_output_update_shm_border(sb);
581 pixman_renderer_output_set_buffer(output_base, sb->pm_image);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300582 b->compositor->renderer->repaint_output(output_base, &sb->damage);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500583
584 wayland_shm_buffer_attach(sb);
585
586 callback = wl_surface_frame(output->parent.surface);
587 wl_callback_add_listener(callback, &frame_listener, output);
588 wl_surface_commit(output->parent.surface);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300589 wl_display_flush(b->parent.wl_display);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500590
591 pixman_region32_fini(&sb->damage);
592 pixman_region32_init(&sb->damage);
593 sb->frame_damaged = 0;
594
Giulio Camuffo954f1832014-10-11 18:27:30 +0300595 pixman_region32_subtract(&b->compositor->primary_plane.damage,
596 &b->compositor->primary_plane.damage, damage);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500597 return 0;
598}
599
600static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -0500601wayland_output_destroy(struct weston_output *output_base)
Matt Roper361d2ad2011-08-29 13:52:23 -0700602{
603 struct wayland_output *output = (struct wayland_output *) output_base;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300604 struct wayland_backend *b =
605 (struct wayland_backend *) output->base.compositor->backend;
Matt Roper361d2ad2011-08-29 13:52:23 -0700606
Giulio Camuffo954f1832014-10-11 18:27:30 +0300607 if (b->use_pixman) {
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500608 pixman_renderer_output_destroy(output_base);
609 } else {
610 gl_renderer->output_destroy(output_base);
611 }
John Kåre Alsaker94659272012-11-13 19:10:18 +0100612
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500613 wl_egl_window_destroy(output->gl.egl_window);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500614 wl_surface_destroy(output->parent.surface);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500615 if (output->parent.shell_surface)
616 wl_shell_surface_destroy(output->parent.shell_surface);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500617
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600618 if (output->frame)
Jason Ekstrand7744f712013-10-27 22:24:55 -0500619 frame_destroy(output->frame);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600620
621 cairo_surface_destroy(output->gl.border.top);
622 cairo_surface_destroy(output->gl.border.left);
623 cairo_surface_destroy(output->gl.border.right);
624 cairo_surface_destroy(output->gl.border.bottom);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500625
626 weston_output_destroy(&output->base);
Matt Roper361d2ad2011-08-29 13:52:23 -0700627 free(output);
628
629 return;
630}
631
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300632static const struct wl_shell_surface_listener shell_surface_listener;
633
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200634static int
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500635wayland_output_init_gl_renderer(struct wayland_output *output)
636{
Jason Ekstrand00b84282013-10-27 22:24:59 -0500637 int32_t fwidth = 0, fheight = 0;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500638
639 if (output->frame) {
640 fwidth = frame_width(output->frame);
641 fheight = frame_height(output->frame);
642 } else {
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500643 fwidth = output->base.current_mode->width;
644 fheight = output->base.current_mode->height;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500645 }
646
647 output->gl.egl_window =
648 wl_egl_window_create(output->parent.surface,
649 fwidth, fheight);
650 if (!output->gl.egl_window) {
651 weston_log("failure to create wl_egl_window\n");
652 return -1;
653 }
654
655 if (gl_renderer->output_create(&output->base,
Neil Roberts77c1a5b2014-03-07 18:05:50 +0000656 output->gl.egl_window,
Jonny Lamb671148f2015-03-20 15:26:52 +0100657 output->gl.egl_window,
Neil Roberts77c1a5b2014-03-07 18:05:50 +0000658 gl_renderer->alpha_attribs,
Derek Foremane76f1852015-05-15 12:12:39 -0500659 NULL,
660 0) < 0)
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500661 goto cleanup_window;
662
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500663 return 0;
664
665cleanup_window:
666 wl_egl_window_destroy(output->gl.egl_window);
667 return -1;
668}
669
670static int
671wayland_output_init_pixman_renderer(struct wayland_output *output)
672{
673 return pixman_renderer_output_create(&output->base);
674}
675
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600676static void
677wayland_output_resize_surface(struct wayland_output *output)
678{
Giulio Camuffo954f1832014-10-11 18:27:30 +0300679 struct wayland_backend *b =
680 (struct wayland_backend *)output->base.compositor->backend;
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600681 struct wayland_shm_buffer *buffer, *next;
682 int32_t ix, iy, iwidth, iheight;
683 int32_t width, height;
684 struct wl_region *region;
685
686 width = output->base.current_mode->width;
687 height = output->base.current_mode->height;
688
689 if (output->frame) {
690 frame_resize_inside(output->frame, width, height);
691
692 frame_input_rect(output->frame, &ix, &iy, &iwidth, &iheight);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300693 region = wl_compositor_create_region(b->parent.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600694 wl_region_add(region, ix, iy, iwidth, iheight);
695 wl_surface_set_input_region(output->parent.surface, region);
696 wl_region_destroy(region);
697
698 frame_opaque_rect(output->frame, &ix, &iy, &iwidth, &iheight);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300699 region = wl_compositor_create_region(b->parent.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600700 wl_region_add(region, ix, iy, iwidth, iheight);
701 wl_surface_set_opaque_region(output->parent.surface, region);
702 wl_region_destroy(region);
703
704 width = frame_width(output->frame);
705 height = frame_height(output->frame);
706 } else {
Giulio Camuffo954f1832014-10-11 18:27:30 +0300707 region = wl_compositor_create_region(b->parent.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600708 wl_region_add(region, 0, 0, width, height);
709 wl_surface_set_input_region(output->parent.surface, region);
710 wl_region_destroy(region);
711
Giulio Camuffo954f1832014-10-11 18:27:30 +0300712 region = wl_compositor_create_region(b->parent.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600713 wl_region_add(region, 0, 0, width, height);
714 wl_surface_set_opaque_region(output->parent.surface, region);
715 wl_region_destroy(region);
716 }
717
718 if (output->gl.egl_window) {
719 wl_egl_window_resize(output->gl.egl_window,
720 width, height, 0, 0);
721
722 /* These will need to be re-created due to the resize */
723 gl_renderer->output_set_border(&output->base,
724 GL_RENDERER_BORDER_TOP,
725 0, 0, 0, NULL);
726 cairo_surface_destroy(output->gl.border.top);
727 output->gl.border.top = NULL;
728 gl_renderer->output_set_border(&output->base,
729 GL_RENDERER_BORDER_LEFT,
730 0, 0, 0, NULL);
731 cairo_surface_destroy(output->gl.border.left);
732 output->gl.border.left = NULL;
733 gl_renderer->output_set_border(&output->base,
734 GL_RENDERER_BORDER_RIGHT,
735 0, 0, 0, NULL);
736 cairo_surface_destroy(output->gl.border.right);
737 output->gl.border.right = NULL;
738 gl_renderer->output_set_border(&output->base,
739 GL_RENDERER_BORDER_BOTTOM,
740 0, 0, 0, NULL);
741 cairo_surface_destroy(output->gl.border.bottom);
742 output->gl.border.bottom = NULL;
743 }
744
745 /* Throw away any remaining SHM buffers */
Derek Foremanf53beb82015-05-29 16:32:52 -0500746 wl_list_for_each_safe(buffer, next, &output->shm.free_buffers, free_link)
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600747 wayland_shm_buffer_destroy(buffer);
748 /* These will get thrown away when they get released */
749 wl_list_for_each(buffer, &output->shm.buffers, link)
750 buffer->output = NULL;
751}
752
753static int
754wayland_output_set_windowed(struct wayland_output *output)
755{
Giulio Camuffo954f1832014-10-11 18:27:30 +0300756 struct wayland_backend *b =
757 (struct wayland_backend *)output->base.compositor->backend;
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600758 int tlen;
759 char *title;
760
761 if (output->frame)
762 return 0;
763
764 if (output->name) {
765 tlen = strlen(output->name) + strlen(WINDOW_TITLE " - ");
766 title = malloc(tlen + 1);
767 if (!title)
768 return -1;
769
770 snprintf(title, tlen + 1, WINDOW_TITLE " - %s", output->name);
771 } else {
772 title = strdup(WINDOW_TITLE);
773 }
774
Giulio Camuffo954f1832014-10-11 18:27:30 +0300775 if (!b->theme) {
776 b->theme = theme_create();
777 if (!b->theme) {
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600778 free(title);
779 return -1;
780 }
781 }
Giulio Camuffo954f1832014-10-11 18:27:30 +0300782 output->frame = frame_create(b->theme, 100, 100,
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600783 FRAME_BUTTON_CLOSE, title);
784 free(title);
785 if (!output->frame)
786 return -1;
787
788 if (output->keyboard_count)
789 frame_set_flag(output->frame, FRAME_FLAG_ACTIVE);
790
791 wayland_output_resize_surface(output);
792
793 wl_shell_surface_set_toplevel(output->parent.shell_surface);
794
795 return 0;
796}
797
798static void
799wayland_output_set_fullscreen(struct wayland_output *output,
800 enum wl_shell_surface_fullscreen_method method,
801 uint32_t framerate, struct wl_output *target)
802{
Giulio Camuffo954f1832014-10-11 18:27:30 +0300803 struct wayland_backend *b =
804 (struct wayland_backend *)output->base.compositor->backend;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500805
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600806 if (output->frame) {
807 frame_destroy(output->frame);
808 output->frame = NULL;
809 }
810
811 wayland_output_resize_surface(output);
812
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500813 if (output->parent.shell_surface) {
814 wl_shell_surface_set_fullscreen(output->parent.shell_surface,
815 method, framerate, target);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300816 } else if (b->parent.fshell) {
Jonas Ådahl496adb32015-11-17 16:00:27 +0800817 zwp_fullscreen_shell_v1_present_surface(b->parent.fshell,
818 output->parent.surface,
819 method, target);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500820 }
821}
822
823static struct weston_mode *
824wayland_output_choose_mode(struct wayland_output *output,
825 struct weston_mode *ref_mode)
826{
827 struct weston_mode *mode;
828
829 /* First look for an exact match */
830 wl_list_for_each(mode, &output->base.mode_list, link)
831 if (mode->width == ref_mode->width &&
832 mode->height == ref_mode->height &&
833 mode->refresh == ref_mode->refresh)
834 return mode;
835
836 /* If we can't find an exact match, ignore refresh and try again */
837 wl_list_for_each(mode, &output->base.mode_list, link)
838 if (mode->width == ref_mode->width &&
839 mode->height == ref_mode->height)
840 return mode;
841
842 /* Yeah, we failed */
843 return NULL;
844}
845
846enum mode_status {
847 MODE_STATUS_UNKNOWN,
848 MODE_STATUS_SUCCESS,
849 MODE_STATUS_FAIL,
850 MODE_STATUS_CANCEL,
851};
852
853static void
854mode_feedback_successful(void *data,
Jonas Ådahl496adb32015-11-17 16:00:27 +0800855 struct zwp_fullscreen_shell_mode_feedback_v1 *fb)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500856{
857 enum mode_status *value = data;
858
859 printf("Mode switch successful\n");
860
861 *value = MODE_STATUS_SUCCESS;
862}
863
864static void
Jonas Ådahl496adb32015-11-17 16:00:27 +0800865mode_feedback_failed(void *data, struct zwp_fullscreen_shell_mode_feedback_v1 *fb)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500866{
867 enum mode_status *value = data;
868
869 printf("Mode switch failed\n");
870
871 *value = MODE_STATUS_FAIL;
872}
873
874static void
Jonas Ådahl496adb32015-11-17 16:00:27 +0800875mode_feedback_cancelled(void *data, struct zwp_fullscreen_shell_mode_feedback_v1 *fb)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500876{
877 enum mode_status *value = data;
878
879 printf("Mode switch cancelled\n");
880
881 *value = MODE_STATUS_CANCEL;
882}
883
Jonas Ådahl496adb32015-11-17 16:00:27 +0800884struct zwp_fullscreen_shell_mode_feedback_v1_listener mode_feedback_listener = {
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500885 mode_feedback_successful,
886 mode_feedback_failed,
887 mode_feedback_cancelled,
888};
889
890static int
891wayland_output_switch_mode(struct weston_output *output_base,
892 struct weston_mode *mode)
893{
894 struct wayland_output *output = (struct wayland_output *) output_base;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300895 struct wayland_backend *b;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500896 struct wl_surface *old_surface;
897 struct weston_mode *old_mode;
Jonas Ådahl496adb32015-11-17 16:00:27 +0800898 struct zwp_fullscreen_shell_mode_feedback_v1 *mode_feedback;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500899 enum mode_status mode_status;
900 int ret = 0;
901
902 if (output_base == NULL) {
903 weston_log("output is NULL.\n");
904 return -1;
905 }
906
907 if (mode == NULL) {
908 weston_log("mode is NULL.\n");
909 return -1;
910 }
911
Giulio Camuffo954f1832014-10-11 18:27:30 +0300912 b = (struct wayland_backend *)output_base->compositor->backend;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500913
Giulio Camuffo954f1832014-10-11 18:27:30 +0300914 if (output->parent.shell_surface || !b->parent.fshell)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500915 return -1;
916
917 mode = wayland_output_choose_mode(output, mode);
918 if (mode == NULL)
919 return -1;
920
921 if (output->base.current_mode == mode)
922 return 0;
923
924 old_mode = output->base.current_mode;
925 old_surface = output->parent.surface;
926 output->base.current_mode = mode;
927 output->parent.surface =
Giulio Camuffo954f1832014-10-11 18:27:30 +0300928 wl_compositor_create_surface(b->parent.compositor);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500929 wl_surface_set_user_data(output->parent.surface, output);
930
931 /* Blow the old buffers because we changed size/surfaces */
932 wayland_output_resize_surface(output);
933
934 mode_feedback =
Jonas Ådahl496adb32015-11-17 16:00:27 +0800935 zwp_fullscreen_shell_v1_present_surface_for_mode(b->parent.fshell,
936 output->parent.surface,
937 output->parent.output,
938 mode->refresh);
939 zwp_fullscreen_shell_mode_feedback_v1_add_listener(mode_feedback,
940 &mode_feedback_listener,
941 &mode_status);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500942
943 /* This should kick-start things again */
944 output->parent.draw_initial_frame = 1;
945 wayland_output_start_repaint_loop(&output->base);
946
947 mode_status = MODE_STATUS_UNKNOWN;
948 while (mode_status == MODE_STATUS_UNKNOWN && ret >= 0)
Giulio Camuffo954f1832014-10-11 18:27:30 +0300949 ret = wl_display_dispatch(b->parent.wl_display);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500950
Jonas Ådahl496adb32015-11-17 16:00:27 +0800951 zwp_fullscreen_shell_mode_feedback_v1_destroy(mode_feedback);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500952
953 if (mode_status == MODE_STATUS_FAIL) {
954 output->base.current_mode = old_mode;
955 wl_surface_destroy(output->parent.surface);
956 output->parent.surface = old_surface;
957 wayland_output_resize_surface(output);
958
959 return -1;
960 }
961
962 old_mode->flags &= ~WL_OUTPUT_MODE_CURRENT;
963 output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
964
Giulio Camuffo954f1832014-10-11 18:27:30 +0300965 if (b->use_pixman) {
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500966 pixman_renderer_output_destroy(output_base);
967 if (wayland_output_init_pixman_renderer(output) < 0)
968 goto err_output;
969 } else {
970 gl_renderer->output_destroy(output_base);
971 wl_egl_window_destroy(output->gl.egl_window);
972 if (wayland_output_init_gl_renderer(output) < 0)
973 goto err_output;
974 }
975 wl_surface_destroy(old_surface);
976
977 weston_output_schedule_repaint(&output->base);
978
979 return 0;
980
981err_output:
982 /* XXX */
983 return -1;
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600984}
985
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500986static struct wayland_output *
Giulio Camuffo954f1832014-10-11 18:27:30 +0300987wayland_output_create(struct wayland_backend *b, int x, int y,
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600988 int width, int height, const char *name, int fullscreen,
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500989 uint32_t transform, int32_t scale)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100990{
991 struct wayland_output *output;
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500992 int output_width, output_height;
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600993
994 weston_log("Creating %dx%d wayland output at (%d, %d)\n",
995 width, height, x, y);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100996
Peter Huttererf3d62272013-08-08 11:57:05 +1000997 output = zalloc(sizeof *output);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100998 if (output == NULL)
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500999 return NULL;
1000
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001001 output->name = name ? strdup(name) : NULL;
1002 output->base.make = "waywayland";
1003 output->base.model = "none";
1004
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001005 output_width = width * scale;
1006 output_height = height * scale;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001007
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001008 output->parent.surface =
Giulio Camuffo954f1832014-10-11 18:27:30 +03001009 wl_compositor_create_surface(b->parent.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001010 if (!output->parent.surface)
1011 goto err_name;
1012 wl_surface_set_user_data(output->parent.surface, output);
1013
1014 output->parent.draw_initial_frame = 1;
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001015
Giulio Camuffo954f1832014-10-11 18:27:30 +03001016 if (b->parent.shell) {
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001017 output->parent.shell_surface =
Giulio Camuffo954f1832014-10-11 18:27:30 +03001018 wl_shell_get_shell_surface(b->parent.shell,
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001019 output->parent.surface);
1020 if (!output->parent.shell_surface)
1021 goto err_surface;
1022 wl_shell_surface_add_listener(output->parent.shell_surface,
1023 &shell_surface_listener, output);
1024 }
1025
Giulio Camuffo954f1832014-10-11 18:27:30 +03001026 if (fullscreen && b->parent.shell) {
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001027 wl_shell_surface_set_fullscreen(output->parent.shell_surface,
1028 0, 0, NULL);
Giulio Camuffo954f1832014-10-11 18:27:30 +03001029 wl_display_roundtrip(b->parent.wl_display);
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001030 if (!width)
1031 output_width = output->parent.configure_width;
1032 if (!height)
1033 output_height = output->parent.configure_height;
1034 }
1035
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -04001036 output->mode.flags =
1037 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001038 output->mode.width = output_width;
1039 output->mode.height = output_height;
1040 output->mode.refresh = 60000;
1041 output->scale = scale;
Kristian Høgsberg8f0ce052011-06-21 11:16:58 -04001042 wl_list_init(&output->base.mode_list);
1043 wl_list_insert(&output->base.mode_list, &output->mode.link);
Hardeningff39efa2013-09-18 23:56:35 +02001044 output->base.current_mode = &output->mode;
Kristian Høgsberg546a8122012-02-01 07:45:51 -05001045
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001046 wl_list_init(&output->shm.buffers);
1047 wl_list_init(&output->shm.free_buffers);
1048
Giulio Camuffo954f1832014-10-11 18:27:30 +03001049 weston_output_init(&output->base, b->compositor, x, y, width, height,
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001050 transform, scale);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001051
Giulio Camuffo954f1832014-10-11 18:27:30 +03001052 if (b->use_pixman) {
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001053 if (wayland_output_init_pixman_renderer(output) < 0)
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001054 goto err_output;
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001055 output->base.repaint = wayland_output_repaint_pixman;
1056 } else {
1057 if (wayland_output_init_gl_renderer(output) < 0)
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001058 goto err_output;
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001059 output->base.repaint = wayland_output_repaint_gl;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001060 }
1061
Jonas Ådahle5a12252013-04-05 23:07:11 +02001062 output->base.start_repaint_loop = wayland_output_start_repaint_loop;
Matt Roper361d2ad2011-08-29 13:52:23 -07001063 output->base.destroy = wayland_output_destroy;
Jesse Barnes5308a5e2012-02-09 13:12:57 -08001064 output->base.assign_planes = NULL;
Tiago Vignatti8e53c7f2012-02-29 19:53:50 +02001065 output->base.set_backlight = NULL;
1066 output->base.set_dpms = NULL;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001067 output->base.switch_mode = wayland_output_switch_mode;
Benjamin Franzkeeefc36c2011-03-11 16:39:20 +01001068
Giulio Camuffo954f1832014-10-11 18:27:30 +03001069 weston_compositor_add_output(b->compositor, &output->base);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001070
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001071 return output;
Benjamin Franzkebe014562011-02-18 17:04:24 +01001072
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001073err_output:
1074 weston_output_destroy(&output->base);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001075 if (output->parent.shell_surface)
1076 wl_shell_surface_destroy(output->parent.shell_surface);
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001077err_surface:
1078 wl_surface_destroy(output->parent.surface);
1079err_name:
1080 free(output->name);
1081
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001082 /* FIXME: cleanup weston_output */
Benjamin Franzkebe014562011-02-18 17:04:24 +01001083 free(output);
1084
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001085 return NULL;
1086}
1087
1088static struct wayland_output *
Giulio Camuffo954f1832014-10-11 18:27:30 +03001089wayland_output_create_for_config(struct wayland_backend *b,
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001090 struct weston_config_section *config_section,
Jason Ekstrand0cf39352013-11-07 20:13:31 -06001091 int option_width, int option_height,
Jason Ekstrand12c6dd92013-11-07 20:13:32 -06001092 int option_scale, int32_t x, int32_t y)
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001093{
1094 struct wayland_output *output;
1095 char *mode, *t, *name, *str;
1096 int width, height, scale;
1097 uint32_t transform;
Derek Foreman64a3df02014-10-23 12:24:18 -05001098 unsigned int slen;
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001099
1100 weston_config_section_get_string(config_section, "name", &name, NULL);
1101 if (name) {
1102 slen = strlen(name);
1103 slen += strlen(WINDOW_TITLE " - ");
1104 str = malloc(slen + 1);
1105 if (str)
1106 snprintf(str, slen + 1, WINDOW_TITLE " - %s", name);
1107 free(name);
1108 name = str;
1109 }
1110 if (!name)
U. Artie Eoff1a08d112014-01-17 12:22:50 -08001111 name = strdup(WINDOW_TITLE);
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001112
1113 weston_config_section_get_string(config_section,
1114 "mode", &mode, "1024x600");
1115 if (sscanf(mode, "%dx%d", &width, &height) != 2) {
1116 weston_log("Invalid mode \"%s\" for output %s\n",
1117 mode, name);
1118 width = 1024;
1119 height = 640;
1120 }
1121 free(mode);
1122
Jason Ekstrand0cf39352013-11-07 20:13:31 -06001123 if (option_width)
1124 width = option_width;
1125 if (option_height)
1126 height = option_height;
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001127
1128 weston_config_section_get_int(config_section, "scale", &scale, 1);
1129
Jason Ekstrand12c6dd92013-11-07 20:13:32 -06001130 if (option_scale)
1131 scale = option_scale;
1132
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001133 weston_config_section_get_string(config_section,
1134 "transform", &t, "normal");
Derek Foreman64a3df02014-10-23 12:24:18 -05001135 if (weston_parse_transform(t, &transform) < 0)
1136 weston_log("Invalid transform \"%s\" for output %s\n",
1137 t, name);
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001138 free(t);
1139
Giulio Camuffo954f1832014-10-11 18:27:30 +03001140 output = wayland_output_create(b, x, y, width, height, name, 0,
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001141 transform, scale);
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001142 free(name);
1143
1144 return output;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001145}
1146
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001147static struct wayland_output *
Giulio Camuffo954f1832014-10-11 18:27:30 +03001148wayland_output_create_for_parent_output(struct wayland_backend *b,
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001149 struct wayland_parent_output *poutput)
1150{
1151 struct wayland_output *output;
1152 struct weston_mode *mode;
1153 int32_t x;
1154
1155 if (poutput->current_mode) {
1156 mode = poutput->current_mode;
1157 } else if (poutput->preferred_mode) {
U. Artie Eoff67072d02014-05-06 14:50:02 -07001158 mode = poutput->preferred_mode;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001159 } else if (!wl_list_empty(&poutput->mode_list)) {
1160 mode = container_of(poutput->mode_list.next,
1161 struct weston_mode, link);
1162 } else {
Chris Michael90eea272015-09-29 17:03:20 +03001163 weston_log("No valid modes found. Skipping output\n");
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001164 return NULL;
1165 }
1166
Giulio Camuffo954f1832014-10-11 18:27:30 +03001167 if (!wl_list_empty(&b->compositor->output_list)) {
1168 output = container_of(b->compositor->output_list.prev,
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001169 struct wayland_output, base.link);
1170 x = output->base.x + output->base.current_mode->width;
1171 } else {
1172 x = 0;
1173 }
1174
Giulio Camuffo954f1832014-10-11 18:27:30 +03001175 output = wayland_output_create(b, x, 0, mode->width, mode->height,
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001176 NULL, 0,
1177 WL_OUTPUT_TRANSFORM_NORMAL, 1);
1178 if (!output)
1179 return NULL;
1180
1181 output->parent.output = poutput->global;
1182
1183 output->base.make = poutput->physical.make;
1184 output->base.model = poutput->physical.model;
1185 wl_list_init(&output->base.mode_list);
1186 wl_list_insert_list(&output->base.mode_list, &poutput->mode_list);
1187 wl_list_init(&poutput->mode_list);
1188
1189 wayland_output_set_fullscreen(output,
1190 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER,
1191 mode->refresh, poutput->global);
1192
1193 if (output->parent.shell_surface) {
1194 wl_shell_surface_set_fullscreen(output->parent.shell_surface,
1195 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER,
1196 mode->refresh, poutput->global);
Giulio Camuffo954f1832014-10-11 18:27:30 +03001197 } else if (b->parent.fshell) {
Jonas Ådahl496adb32015-11-17 16:00:27 +08001198 zwp_fullscreen_shell_v1_present_surface(b->parent.fshell,
1199 output->parent.surface,
1200 ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_CENTER,
1201 poutput->global);
1202 zwp_fullscreen_shell_mode_feedback_v1_destroy(
1203 zwp_fullscreen_shell_v1_present_surface_for_mode(b->parent.fshell,
1204 output->parent.surface,
1205 poutput->global,
1206 mode->refresh));
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001207 }
1208
1209 return output;
1210}
1211
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +03001212static void
1213shell_surface_ping(void *data, struct wl_shell_surface *shell_surface,
1214 uint32_t serial)
1215{
1216 wl_shell_surface_pong(shell_surface, serial);
1217}
1218
1219static void
1220shell_surface_configure(void *data, struct wl_shell_surface *shell_surface,
1221 uint32_t edges, int32_t width, int32_t height)
1222{
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001223 struct wayland_output *output = data;
1224
1225 output->parent.configure_width = width;
1226 output->parent.configure_height = height;
1227
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +03001228 /* FIXME: implement resizing */
1229}
1230
1231static void
1232shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface)
1233{
1234}
1235
1236static const struct wl_shell_surface_listener shell_surface_listener = {
1237 shell_surface_ping,
1238 shell_surface_configure,
1239 shell_surface_popup_done
1240};
1241
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001242/* Events received from the wayland-server this compositor is client of: */
1243
Jason Ekstrand7744f712013-10-27 22:24:55 -05001244/* parent input interface */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001245static void
Jason Ekstrand7744f712013-10-27 22:24:55 -05001246input_set_cursor(struct wayland_input *input)
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001247{
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001248
Jason Ekstrand7744f712013-10-27 22:24:55 -05001249 struct wl_buffer *buffer;
1250 struct wl_cursor_image *image;
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001251
Giulio Camuffo954f1832014-10-11 18:27:30 +03001252 if (!input->backend->cursor)
Jason Ekstrand7744f712013-10-27 22:24:55 -05001253 return; /* Couldn't load the cursor. Can't set it */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001254
Giulio Camuffo954f1832014-10-11 18:27:30 +03001255 image = input->backend->cursor->images[0];
Jason Ekstrand7744f712013-10-27 22:24:55 -05001256 buffer = wl_cursor_image_get_buffer(image);
Hardening842a36a2014-03-18 14:12:50 +01001257 if (!buffer)
1258 return;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001259
1260 wl_pointer_set_cursor(input->parent.pointer, input->enter_serial,
1261 input->parent.cursor.surface,
1262 image->hotspot_x, image->hotspot_y);
1263
1264 wl_surface_attach(input->parent.cursor.surface, buffer, 0, 0);
1265 wl_surface_damage(input->parent.cursor.surface, 0, 0,
1266 image->width, image->height);
1267 wl_surface_commit(input->parent.cursor.surface);
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001268}
1269
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001270static void
Daniel Stone37816df2012-05-16 18:45:18 +01001271input_handle_pointer_enter(void *data, struct wl_pointer *pointer,
1272 uint32_t serial, struct wl_surface *surface,
Kristian Høgsberge11bbe42012-05-09 12:19:04 -04001273 wl_fixed_t x, wl_fixed_t y)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001274{
1275 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001276 int32_t fx, fy;
1277 enum theme_location location;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001278
Daniel Stone50692802012-06-22 13:21:41 +01001279 /* XXX: If we get a modifier event immediately before the focus,
1280 * we should try to keep the same serial. */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001281 input->enter_serial = serial;
1282 input->output = wl_surface_get_user_data(surface);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001283
1284 if (input->output->frame) {
1285 location = frame_pointer_enter(input->output->frame, input,
1286 wl_fixed_to_int(x),
1287 wl_fixed_to_int(y));
1288 frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
1289 x -= wl_fixed_from_int(fx);
1290 y -= wl_fixed_from_int(fy);
1291
1292 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
1293 weston_output_schedule_repaint(&input->output->base);
1294 } else {
1295 location = THEME_LOCATION_CLIENT_AREA;
1296 }
1297
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001298 weston_output_transform_coordinate(&input->output->base, x, y, &x, &y);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001299
1300 if (location == THEME_LOCATION_CLIENT_AREA) {
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001301 input->has_focus = true;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001302 notify_pointer_focus(&input->base, &input->output->base, x, y);
1303 wl_pointer_set_cursor(input->parent.pointer,
1304 input->enter_serial, NULL, 0, 0);
1305 } else {
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001306 input->has_focus = false;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001307 notify_pointer_focus(&input->base, NULL, 0, 0);
1308 input_set_cursor(input);
1309 }
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001310}
1311
1312static void
Daniel Stone37816df2012-05-16 18:45:18 +01001313input_handle_pointer_leave(void *data, struct wl_pointer *pointer,
1314 uint32_t serial, struct wl_surface *surface)
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001315{
1316 struct wayland_input *input = data;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001317
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001318 if (!input->output)
1319 return;
1320
Jason Ekstrand7744f712013-10-27 22:24:55 -05001321 if (input->output->frame) {
1322 frame_pointer_leave(input->output->frame, input);
1323
1324 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
1325 weston_output_schedule_repaint(&input->output->base);
1326 }
1327
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001328 notify_pointer_focus(&input->base, NULL, 0, 0);
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001329 input->output = NULL;
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001330 input->has_focus = false;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001331}
1332
1333static void
Daniel Stone37816df2012-05-16 18:45:18 +01001334input_handle_motion(void *data, struct wl_pointer *pointer,
1335 uint32_t time, wl_fixed_t x, wl_fixed_t y)
1336{
1337 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001338 int32_t fx, fy;
1339 enum theme_location location;
Daniel Stone37816df2012-05-16 18:45:18 +01001340
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001341 if (!input->output)
1342 return;
1343
Jason Ekstrand7744f712013-10-27 22:24:55 -05001344 if (input->output->frame) {
1345 location = frame_pointer_motion(input->output->frame, input,
1346 wl_fixed_to_int(x),
1347 wl_fixed_to_int(y));
1348 frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
1349 x -= wl_fixed_from_int(fx);
1350 y -= wl_fixed_from_int(fy);
1351
1352 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
1353 weston_output_schedule_repaint(&input->output->base);
1354 } else {
1355 location = THEME_LOCATION_CLIENT_AREA;
1356 }
1357
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001358 weston_output_transform_coordinate(&input->output->base, x, y, &x, &y);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001359
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001360 if (input->has_focus && location != THEME_LOCATION_CLIENT_AREA) {
Jason Ekstrand7744f712013-10-27 22:24:55 -05001361 input_set_cursor(input);
1362 notify_pointer_focus(&input->base, NULL, 0, 0);
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001363 input->has_focus = false;
1364 } else if (!input->has_focus &&
1365 location == THEME_LOCATION_CLIENT_AREA) {
Jason Ekstrand7744f712013-10-27 22:24:55 -05001366 wl_pointer_set_cursor(input->parent.pointer,
1367 input->enter_serial, NULL, 0, 0);
1368 notify_pointer_focus(&input->base, &input->output->base, x, y);
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001369 input->has_focus = true;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001370 }
1371
1372 if (location == THEME_LOCATION_CLIENT_AREA)
1373 notify_motion_absolute(&input->base, time, x, y);
Daniel Stone37816df2012-05-16 18:45:18 +01001374}
1375
1376static void
1377input_handle_button(void *data, struct wl_pointer *pointer,
Daniel Stone4dbadb12012-05-30 16:31:51 +01001378 uint32_t serial, uint32_t time, uint32_t button,
1379 uint32_t state_w)
Daniel Stone37816df2012-05-16 18:45:18 +01001380{
1381 struct wayland_input *input = data;
Daniel Stone4dbadb12012-05-30 16:31:51 +01001382 enum wl_pointer_button_state state = state_w;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001383 enum frame_button_state fstate;
1384 enum theme_location location;
Daniel Stone37816df2012-05-16 18:45:18 +01001385
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001386 if (!input->output)
1387 return;
1388
Jason Ekstrand7744f712013-10-27 22:24:55 -05001389 if (input->output->frame) {
1390 fstate = state == WL_POINTER_BUTTON_STATE_PRESSED ?
1391 FRAME_BUTTON_PRESSED : FRAME_BUTTON_RELEASED;
1392
1393 location = frame_pointer_button(input->output->frame, input,
1394 button, fstate);
1395
1396 if (frame_status(input->output->frame) & FRAME_STATUS_MOVE) {
1397
1398 wl_shell_surface_move(input->output->parent.shell_surface,
1399 input->parent.seat, serial);
1400 frame_status_clear(input->output->frame,
1401 FRAME_STATUS_MOVE);
1402 return;
1403 }
1404
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001405 if (frame_status(input->output->frame) & FRAME_STATUS_CLOSE) {
1406 wayland_output_destroy(&input->output->base);
Dima Ryazanovb7e70af2015-05-20 01:03:53 -07001407 input->output = NULL;
1408 input->keyboard_focus = NULL;
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001409
Giulio Camuffo954f1832014-10-11 18:27:30 +03001410 if (wl_list_empty(&input->backend->compositor->output_list))
Giulio Camuffo459137b2014-10-11 23:56:24 +03001411 weston_compositor_exit(input->backend->compositor);
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001412
1413 return;
1414 }
Jason Ekstrand7744f712013-10-27 22:24:55 -05001415
1416 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
1417 weston_output_schedule_repaint(&input->output->base);
1418 } else {
1419 location = THEME_LOCATION_CLIENT_AREA;
1420 }
1421
1422 if (location == THEME_LOCATION_CLIENT_AREA)
1423 notify_button(&input->base, time, button, state);
Daniel Stone37816df2012-05-16 18:45:18 +01001424}
1425
1426static void
1427input_handle_axis(void *data, struct wl_pointer *pointer,
Daniel Stone2fce4022012-05-30 16:32:00 +01001428 uint32_t time, uint32_t axis, wl_fixed_t value)
Daniel Stone37816df2012-05-16 18:45:18 +01001429{
1430 struct wayland_input *input = data;
Daniel Stone37816df2012-05-16 18:45:18 +01001431
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001432 notify_axis(&input->base, time, axis, value);
Daniel Stone37816df2012-05-16 18:45:18 +01001433}
1434
1435static const struct wl_pointer_listener pointer_listener = {
1436 input_handle_pointer_enter,
1437 input_handle_pointer_leave,
1438 input_handle_motion,
1439 input_handle_button,
1440 input_handle_axis,
1441};
1442
1443static void
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001444input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
1445 int fd, uint32_t size)
1446{
1447 struct wayland_input *input = data;
1448 struct xkb_keymap *keymap;
1449 char *map_str;
1450
U. Artie Eoffd8d47012014-05-06 14:50:03 -07001451 if (!data) {
1452 close(fd);
1453 return;
1454 }
Jason Ekstrandb7d9f2e2014-04-02 19:53:57 -05001455
1456 if (format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
1457 map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
1458 if (map_str == MAP_FAILED) {
1459 weston_log("mmap failed: %m\n");
1460 goto error;
1461 }
1462
Giulio Camuffo954f1832014-10-11 18:27:30 +03001463 keymap = xkb_keymap_new_from_string(input->backend->compositor->xkb_context,
Ran Benita2e1968f2014-08-19 23:59:51 +03001464 map_str,
1465 XKB_KEYMAP_FORMAT_TEXT_V1,
1466 0);
Jason Ekstrandb7d9f2e2014-04-02 19:53:57 -05001467 munmap(map_str, size);
1468
1469 if (!keymap) {
1470 weston_log("failed to compile keymap\n");
1471 goto error;
1472 }
1473
1474 input->keyboard_state_update = STATE_UPDATE_NONE;
1475 } else if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP) {
1476 weston_log("No keymap provided; falling back to defalt\n");
1477 keymap = NULL;
1478 input->keyboard_state_update = STATE_UPDATE_AUTOMATIC;
1479 } else {
1480 weston_log("Invalid keymap\n");
1481 goto error;
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001482 }
1483
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001484 close(fd);
1485
Derek Foreman1281a362015-07-31 16:55:32 -05001486 if (weston_seat_get_keyboard(&input->base))
Rui Matos0c194ce2013-10-10 19:44:21 +02001487 weston_seat_update_keymap(&input->base, keymap);
1488 else
1489 weston_seat_init_keyboard(&input->base, keymap);
1490
Ran Benitac9c74152014-08-19 23:59:52 +03001491 xkb_keymap_unref(keymap);
Jason Ekstrandb7d9f2e2014-04-02 19:53:57 -05001492
1493 return;
1494
1495error:
1496 wl_keyboard_release(input->parent.keyboard);
1497 close(fd);
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001498}
1499
1500static void
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001501input_handle_keyboard_enter(void *data,
Daniel Stone37816df2012-05-16 18:45:18 +01001502 struct wl_keyboard *keyboard,
1503 uint32_t serial,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001504 struct wl_surface *surface,
1505 struct wl_array *keys)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001506{
Kristian Høgsbergaf82bea2011-01-27 20:18:17 -05001507 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001508 struct wayland_output *focus;
1509
1510 focus = input->keyboard_focus;
1511 if (focus) {
1512 /* This shouldn't happen */
1513 focus->keyboard_count--;
1514 if (!focus->keyboard_count && focus->frame)
1515 frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE);
1516 if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
1517 weston_output_schedule_repaint(&focus->base);
1518 }
1519
1520 input->keyboard_focus = wl_surface_get_user_data(surface);
1521 input->keyboard_focus->keyboard_count++;
1522
1523 focus = input->keyboard_focus;
1524 if (focus->frame) {
1525 frame_set_flag(focus->frame, FRAME_FLAG_ACTIVE);
1526 if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
1527 weston_output_schedule_repaint(&focus->base);
1528 }
1529
Kristian Høgsbergaf82bea2011-01-27 20:18:17 -05001530
Daniel Stone50692802012-06-22 13:21:41 +01001531 /* XXX: If we get a modifier event immediately before the focus,
1532 * we should try to keep the same serial. */
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001533 notify_keyboard_focus_in(&input->base, keys,
Daniel Stoned6da09e2012-06-22 13:21:29 +01001534 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001535}
1536
1537static void
1538input_handle_keyboard_leave(void *data,
Daniel Stone37816df2012-05-16 18:45:18 +01001539 struct wl_keyboard *keyboard,
1540 uint32_t serial,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001541 struct wl_surface *surface)
1542{
1543 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001544 struct wayland_output *focus;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001545
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001546 notify_keyboard_focus_out(&input->base);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001547
1548 focus = input->keyboard_focus;
1549 if (!focus)
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001550 return;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001551
1552 focus->keyboard_count--;
1553 if (!focus->keyboard_count && focus->frame) {
1554 frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE);
1555 if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
1556 weston_output_schedule_repaint(&focus->base);
1557 }
1558
1559 input->keyboard_focus = NULL;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001560}
1561
Daniel Stone37816df2012-05-16 18:45:18 +01001562static void
1563input_handle_key(void *data, struct wl_keyboard *keyboard,
1564 uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
1565{
1566 struct wayland_input *input = data;
Daniel Stone37816df2012-05-16 18:45:18 +01001567
Daniel Stone50692802012-06-22 13:21:41 +01001568 input->key_serial = serial;
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001569 notify_key(&input->base, time, key,
Daniel Stonec9785ea2012-05-30 16:31:52 +01001570 state ? WL_KEYBOARD_KEY_STATE_PRESSED :
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001571 WL_KEYBOARD_KEY_STATE_RELEASED,
Jason Ekstrandb7d9f2e2014-04-02 19:53:57 -05001572 input->keyboard_state_update);
Daniel Stone37816df2012-05-16 18:45:18 +01001573}
1574
Daniel Stone351eb612012-05-31 15:27:47 -04001575static void
Derek Foreman1281a362015-07-31 16:55:32 -05001576input_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard,
Daniel Stone50692802012-06-22 13:21:41 +01001577 uint32_t serial_in, uint32_t mods_depressed,
Daniel Stone351eb612012-05-31 15:27:47 -04001578 uint32_t mods_latched, uint32_t mods_locked,
1579 uint32_t group)
1580{
Derek Foreman1281a362015-07-31 16:55:32 -05001581 struct weston_keyboard *keyboard;
Daniel Stone50692802012-06-22 13:21:41 +01001582 struct wayland_input *input = data;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001583 struct wayland_backend *b = input->backend;
Daniel Stone50692802012-06-22 13:21:41 +01001584 uint32_t serial_out;
1585
1586 /* If we get a key event followed by a modifier event with the
1587 * same serial number, then we try to preserve those semantics by
1588 * reusing the same serial number on the way out too. */
1589 if (serial_in == input->key_serial)
Giulio Camuffo954f1832014-10-11 18:27:30 +03001590 serial_out = wl_display_get_serial(b->compositor->wl_display);
Daniel Stone50692802012-06-22 13:21:41 +01001591 else
Giulio Camuffo954f1832014-10-11 18:27:30 +03001592 serial_out = wl_display_next_serial(b->compositor->wl_display);
Daniel Stone50692802012-06-22 13:21:41 +01001593
Derek Foreman1281a362015-07-31 16:55:32 -05001594 keyboard = weston_seat_get_keyboard(&input->base);
1595 xkb_state_update_mask(keyboard->xkb_state.state,
Daniel Stone50692802012-06-22 13:21:41 +01001596 mods_depressed, mods_latched,
1597 mods_locked, 0, 0, group);
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001598 notify_modifiers(&input->base, serial_out);
Daniel Stone351eb612012-05-31 15:27:47 -04001599}
1600
Jonny Lamb497994a2014-08-12 14:58:26 +02001601static void
1602input_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
1603 int32_t rate, int32_t delay)
1604{
1605 struct wayland_input *input = data;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001606 struct wayland_backend *b = input->backend;
Jonny Lamb497994a2014-08-12 14:58:26 +02001607
Giulio Camuffo954f1832014-10-11 18:27:30 +03001608 b->compositor->kb_repeat_rate = rate;
1609 b->compositor->kb_repeat_delay = delay;
Jonny Lamb497994a2014-08-12 14:58:26 +02001610}
1611
Daniel Stone37816df2012-05-16 18:45:18 +01001612static const struct wl_keyboard_listener keyboard_listener = {
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001613 input_handle_keymap,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001614 input_handle_keyboard_enter,
1615 input_handle_keyboard_leave,
Daniel Stone37816df2012-05-16 18:45:18 +01001616 input_handle_key,
Daniel Stone351eb612012-05-31 15:27:47 -04001617 input_handle_modifiers,
Jonny Lamb497994a2014-08-12 14:58:26 +02001618 input_handle_repeat_info,
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001619};
1620
1621static void
Daniel Stone37816df2012-05-16 18:45:18 +01001622input_handle_capabilities(void *data, struct wl_seat *seat,
1623 enum wl_seat_capability caps)
1624{
1625 struct wayland_input *input = data;
1626
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001627 if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->parent.pointer) {
1628 input->parent.pointer = wl_seat_get_pointer(seat);
1629 wl_pointer_set_user_data(input->parent.pointer, input);
1630 wl_pointer_add_listener(input->parent.pointer,
1631 &pointer_listener, input);
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -04001632 weston_seat_init_pointer(&input->base);
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001633 } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->parent.pointer) {
Derek Foremancfce7d02015-11-06 15:56:08 -06001634 if (input->seat_version >= WL_POINTER_RELEASE_SINCE_VERSION)
1635 wl_pointer_release(input->parent.pointer);
1636 else
1637 wl_pointer_destroy(input->parent.pointer);
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001638 input->parent.pointer = NULL;
Derek Foremancfce7d02015-11-06 15:56:08 -06001639 weston_seat_release_pointer(&input->base);
Daniel Stone37816df2012-05-16 18:45:18 +01001640 }
1641
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001642 if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->parent.keyboard) {
1643 input->parent.keyboard = wl_seat_get_keyboard(seat);
1644 wl_keyboard_set_user_data(input->parent.keyboard, input);
1645 wl_keyboard_add_listener(input->parent.keyboard,
1646 &keyboard_listener, input);
1647 } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->parent.keyboard) {
Derek Foremancfce7d02015-11-06 15:56:08 -06001648 if (input->seat_version >= WL_KEYBOARD_RELEASE_SINCE_VERSION)
1649 wl_keyboard_release(input->parent.keyboard);
1650 else
1651 wl_keyboard_destroy(input->parent.keyboard);
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001652 input->parent.keyboard = NULL;
Derek Foremancfce7d02015-11-06 15:56:08 -06001653 weston_seat_release_keyboard(&input->base);
Daniel Stone37816df2012-05-16 18:45:18 +01001654 }
1655}
1656
Jonny Lamb497994a2014-08-12 14:58:26 +02001657static void
1658input_handle_name(void *data, struct wl_seat *seat,
1659 const char *name)
1660{
1661}
1662
Daniel Stone37816df2012-05-16 18:45:18 +01001663static const struct wl_seat_listener seat_listener = {
1664 input_handle_capabilities,
Jonny Lamb497994a2014-08-12 14:58:26 +02001665 input_handle_name,
Daniel Stone37816df2012-05-16 18:45:18 +01001666};
1667
1668static void
Derek Foremancfce7d02015-11-06 15:56:08 -06001669display_add_seat(struct wayland_backend *b, uint32_t id, uint32_t available_version)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001670{
1671 struct wayland_input *input;
Derek Foremancfce7d02015-11-06 15:56:08 -06001672 uint32_t version = MIN(available_version, 4);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001673
Peter Huttererf3d62272013-08-08 11:57:05 +10001674 input = zalloc(sizeof *input);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001675 if (input == NULL)
1676 return;
1677
Giulio Camuffo954f1832014-10-11 18:27:30 +03001678 weston_seat_init(&input->base, b->compositor, "default");
1679 input->backend = b;
1680 input->parent.seat = wl_registry_bind(b->parent.registry, id,
Derek Foremancfce7d02015-11-06 15:56:08 -06001681 &wl_seat_interface, version);
1682 input->seat_version = version;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001683 wl_list_insert(b->input_list.prev, &input->link);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001684
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05001685 wl_seat_add_listener(input->parent.seat, &seat_listener, input);
1686 wl_seat_set_user_data(input->parent.seat, input);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001687
1688 input->parent.cursor.surface =
Giulio Camuffo954f1832014-10-11 18:27:30 +03001689 wl_compositor_create_surface(b->parent.compositor);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001690}
1691
1692static void
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001693wayland_parent_output_geometry(void *data, struct wl_output *output_proxy,
1694 int32_t x, int32_t y,
1695 int32_t physical_width, int32_t physical_height,
1696 int32_t subpixel, const char *make,
1697 const char *model, int32_t transform)
1698{
1699 struct wayland_parent_output *output = data;
1700
1701 output->x = x;
1702 output->y = y;
1703 output->physical.width = physical_width;
1704 output->physical.height = physical_height;
1705 output->physical.subpixel = subpixel;
1706
1707 free(output->physical.make);
1708 output->physical.make = strdup(make);
1709 free(output->physical.model);
1710 output->physical.model = strdup(model);
1711
1712 output->transform = transform;
1713}
1714
1715static struct weston_mode *
1716find_mode(struct wl_list *list, int32_t width, int32_t height, uint32_t refresh)
1717{
1718 struct weston_mode *mode;
1719
1720 wl_list_for_each(mode, list, link) {
1721 if (mode->width == width && mode->height == height &&
1722 mode->refresh == refresh)
1723 return mode;
1724 }
1725
1726 mode = zalloc(sizeof *mode);
1727 if (!mode)
1728 return NULL;
1729
1730 mode->width = width;
1731 mode->height = height;
1732 mode->refresh = refresh;
1733 wl_list_insert(list, &mode->link);
1734
1735 return mode;
1736}
1737
1738static void
1739wayland_parent_output_mode(void *data, struct wl_output *wl_output_proxy,
1740 uint32_t flags, int32_t width, int32_t height,
1741 int32_t refresh)
1742{
1743 struct wayland_parent_output *output = data;
1744 struct weston_mode *mode;
1745
1746 if (output->output) {
1747 mode = find_mode(&output->output->base.mode_list,
1748 width, height, refresh);
1749 if (!mode)
1750 return;
1751 mode->flags = flags;
1752 /* Do a mode-switch on current mode change? */
1753 } else {
1754 mode = find_mode(&output->mode_list, width, height, refresh);
1755 if (!mode)
1756 return;
1757 mode->flags = flags;
1758 if (flags & WL_OUTPUT_MODE_CURRENT)
1759 output->current_mode = mode;
1760 if (flags & WL_OUTPUT_MODE_PREFERRED)
1761 output->preferred_mode = mode;
1762 }
1763}
1764
1765static const struct wl_output_listener output_listener = {
1766 wayland_parent_output_geometry,
1767 wayland_parent_output_mode
1768};
1769
1770static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03001771wayland_backend_register_output(struct wayland_backend *b, uint32_t id)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001772{
1773 struct wayland_parent_output *output;
1774
1775 output = zalloc(sizeof *output);
1776 if (!output)
1777 return;
1778
1779 output->id = id;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001780 output->global = wl_registry_bind(b->parent.registry, id,
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001781 &wl_output_interface, 1);
U. Artie Eoff8cbd8f32014-05-06 14:50:01 -07001782 if (!output->global) {
1783 free(output);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001784 return;
U. Artie Eoff8cbd8f32014-05-06 14:50:01 -07001785 }
1786
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001787 wl_output_add_listener(output->global, &output_listener, output);
1788
1789 output->scale = 0;
1790 output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
1791 output->physical.subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
1792 wl_list_init(&output->mode_list);
Giulio Camuffo954f1832014-10-11 18:27:30 +03001793 wl_list_insert(&b->parent.output_list, &output->link);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001794
Giulio Camuffo954f1832014-10-11 18:27:30 +03001795 if (b->sprawl_across_outputs) {
1796 wl_display_roundtrip(b->parent.wl_display);
1797 wayland_output_create_for_parent_output(b, output);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001798 }
1799}
1800
1801static void
1802wayland_parent_output_destroy(struct wayland_parent_output *output)
1803{
1804 struct weston_mode *mode, *next;
1805
1806 if (output->output)
1807 wayland_output_destroy(&output->output->base);
1808
1809 wl_output_destroy(output->global);
1810 free(output->physical.make);
1811 free(output->physical.model);
1812
1813 wl_list_for_each_safe(mode, next, &output->mode_list, link) {
1814 wl_list_remove(&mode->link);
1815 free(mode);
1816 }
1817}
1818
1819static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001820registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
1821 const char *interface, uint32_t version)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001822{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001823 struct wayland_backend *b = data;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001824
Benjamin Franzke080ab6c2011-04-30 10:41:27 +02001825 if (strcmp(interface, "wl_compositor") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001826 b->parent.compositor =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001827 wl_registry_bind(registry, name,
1828 &wl_compositor_interface, 1);
Benjamin Franzke080ab6c2011-04-30 10:41:27 +02001829 } else if (strcmp(interface, "wl_shell") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001830 b->parent.shell =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001831 wl_registry_bind(registry, name,
1832 &wl_shell_interface, 1);
Jonas Ådahl496adb32015-11-17 16:00:27 +08001833 } else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001834 b->parent.fshell =
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001835 wl_registry_bind(registry, name,
Jonas Ådahl496adb32015-11-17 16:00:27 +08001836 &zwp_fullscreen_shell_v1_interface, 1);
Daniel Stone725c2c32012-06-22 14:04:36 +01001837 } else if (strcmp(interface, "wl_seat") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001838 display_add_seat(b, name, version);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001839 } else if (strcmp(interface, "wl_output") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001840 wayland_backend_register_output(b, name);
Jonas Ådahle5a12252013-04-05 23:07:11 +02001841 } else if (strcmp(interface, "wl_shm") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001842 b->parent.shm =
Jonas Ådahle5a12252013-04-05 23:07:11 +02001843 wl_registry_bind(registry, name, &wl_shm_interface, 1);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001844 }
1845}
1846
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001847static void
1848registry_handle_global_remove(void *data, struct wl_registry *registry,
1849 uint32_t name)
1850{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001851 struct wayland_backend *b = data;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001852 struct wayland_parent_output *output;
1853
Giulio Camuffo954f1832014-10-11 18:27:30 +03001854 wl_list_for_each(output, &b->parent.output_list, link)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001855 if (output->id == name)
1856 wayland_parent_output_destroy(output);
1857}
1858
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001859static const struct wl_registry_listener registry_listener = {
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001860 registry_handle_global,
1861 registry_handle_global_remove
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04001862};
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001863
Kristian Høgsberg95d843d2011-04-22 13:01:26 -04001864static int
Giulio Camuffo954f1832014-10-11 18:27:30 +03001865wayland_backend_handle_event(int fd, uint32_t mask, void *data)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001866{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001867 struct wayland_backend *b = data;
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -04001868 int count = 0;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001869
Kristian Høgsberg453de7a2013-10-30 23:15:44 -07001870 if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
Giulio Camuffo459137b2014-10-11 23:56:24 +03001871 weston_compositor_exit(b->compositor);
Kristian Høgsberg453de7a2013-10-30 23:15:44 -07001872 return 0;
1873 }
1874
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001875 if (mask & WL_EVENT_READABLE)
Giulio Camuffo954f1832014-10-11 18:27:30 +03001876 count = wl_display_dispatch(b->parent.wl_display);
Kristian Høgsbergf258a312011-12-28 22:51:20 -05001877 if (mask & WL_EVENT_WRITABLE)
Giulio Camuffo954f1832014-10-11 18:27:30 +03001878 wl_display_flush(b->parent.wl_display);
Kristian Høgsberg95d843d2011-04-22 13:01:26 -04001879
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -04001880 if (mask == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03001881 count = wl_display_dispatch_pending(b->parent.wl_display);
1882 wl_display_flush(b->parent.wl_display);
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -04001883 }
1884
1885 return count;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001886}
1887
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001888static void
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -04001889wayland_restore(struct weston_compositor *ec)
1890{
1891}
1892
1893static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001894wayland_destroy(struct weston_compositor *ec)
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001895{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001896 struct wayland_backend *b = (struct wayland_backend *) ec->backend;
Jonas Ådahle5a12252013-04-05 23:07:11 +02001897
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05001898 weston_compositor_shutdown(ec);
Matt Roper361d2ad2011-08-29 13:52:23 -07001899
Giulio Camuffo954f1832014-10-11 18:27:30 +03001900 if (b->parent.shm)
1901 wl_shm_destroy(b->parent.shm);
Jonas Ådahle5a12252013-04-05 23:07:11 +02001902
Giulio Camuffo954f1832014-10-11 18:27:30 +03001903 free(b);
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05001904}
1905
Jason Ekstrand7744f712013-10-27 22:24:55 -05001906static const char *left_ptrs[] = {
1907 "left_ptr",
1908 "default",
1909 "top_left_arrow",
1910 "left-arrow"
1911};
1912
1913static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03001914create_cursor(struct wayland_backend *b, struct weston_config *config)
Jason Ekstrand7744f712013-10-27 22:24:55 -05001915{
1916 struct weston_config_section *s;
1917 int size;
1918 char *theme = NULL;
1919 unsigned int i;
1920
1921 s = weston_config_get_section(config, "shell", NULL, NULL);
1922 weston_config_section_get_string(s, "cursor-theme", &theme, NULL);
1923 weston_config_section_get_int(s, "cursor-size", &size, 32);
1924
Giulio Camuffo954f1832014-10-11 18:27:30 +03001925 b->cursor_theme = wl_cursor_theme_load(theme, size, b->parent.shm);
1926 if (!b->cursor_theme) {
Hardening842a36a2014-03-18 14:12:50 +01001927 fprintf(stderr, "could not load cursor theme\n");
1928 return;
1929 }
Jason Ekstrand7744f712013-10-27 22:24:55 -05001930
U. Artie Eoffff755002014-01-17 12:36:58 -08001931 free(theme);
1932
Giulio Camuffo954f1832014-10-11 18:27:30 +03001933 b->cursor = NULL;
1934 for (i = 0; !b->cursor && i < ARRAY_LENGTH(left_ptrs); ++i)
1935 b->cursor = wl_cursor_theme_get_cursor(b->cursor_theme,
Jason Ekstrand7744f712013-10-27 22:24:55 -05001936 left_ptrs[i]);
Giulio Camuffo954f1832014-10-11 18:27:30 +03001937 if (!b->cursor) {
Jason Ekstrand7744f712013-10-27 22:24:55 -05001938 fprintf(stderr, "could not load left cursor\n");
1939 return;
1940 }
1941}
1942
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001943static void
Derek Foreman8ae2db52015-07-15 13:00:36 -05001944fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time,
1945 uint32_t key, void *data)
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001946{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001947 struct wayland_backend *b = data;
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001948 struct wayland_input *input = NULL;
1949
Giulio Camuffo954f1832014-10-11 18:27:30 +03001950 wl_list_for_each(input, &b->input_list, link)
Derek Foreman8ae2db52015-07-15 13:00:36 -05001951 if (&input->base == keyboard->seat)
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001952 break;
1953
1954 if (!input || !input->output)
1955 return;
1956
1957 if (input->output->frame)
1958 wayland_output_set_fullscreen(input->output, 0, 0, NULL);
1959 else
1960 wayland_output_set_windowed(input->output);
1961
1962 weston_output_schedule_repaint(&input->output->base);
1963}
1964
Giulio Camuffo954f1832014-10-11 18:27:30 +03001965static struct wayland_backend *
1966wayland_backend_create(struct weston_compositor *compositor, int use_pixman,
1967 const char *display_name, int *argc, char *argv[],
1968 struct weston_config *config)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001969{
Giulio Camuffo954f1832014-10-11 18:27:30 +03001970 struct wayland_backend *b;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001971 struct wl_event_loop *loop;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06001972 int fd;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001973
Giulio Camuffo954f1832014-10-11 18:27:30 +03001974 b = zalloc(sizeof *b);
1975 if (b == NULL)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001976 return NULL;
1977
Giulio Camuffo954f1832014-10-11 18:27:30 +03001978 b->compositor = compositor;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001979 if (weston_compositor_set_presentation_clock_software(compositor) < 0)
Pekka Paalanenb5eedad2014-09-23 22:08:45 -04001980 goto err_compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001981
Giulio Camuffo954f1832014-10-11 18:27:30 +03001982 b->parent.wl_display = wl_display_connect(display_name);
1983 if (b->parent.wl_display == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +02001984 weston_log("failed to create display: %m\n");
Martin Olssonc5db50f2012-07-08 03:03:43 +02001985 goto err_compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001986 }
1987
Giulio Camuffo954f1832014-10-11 18:27:30 +03001988 wl_list_init(&b->parent.output_list);
1989 wl_list_init(&b->input_list);
1990 b->parent.registry = wl_display_get_registry(b->parent.wl_display);
1991 wl_registry_add_listener(b->parent.registry, &registry_listener, b);
1992 wl_display_roundtrip(b->parent.wl_display);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001993
Giulio Camuffo954f1832014-10-11 18:27:30 +03001994 create_cursor(b, config);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001995
Giulio Camuffo954f1832014-10-11 18:27:30 +03001996 b->use_pixman = use_pixman;
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +03001997
Giulio Camuffo954f1832014-10-11 18:27:30 +03001998 if (!b->use_pixman) {
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001999 gl_renderer = weston_load_module("gl-renderer.so",
2000 "gl_renderer_interface");
2001 if (!gl_renderer)
Giulio Camuffo954f1832014-10-11 18:27:30 +03002002 b->use_pixman = 1;
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002003 }
2004
Giulio Camuffo954f1832014-10-11 18:27:30 +03002005 if (!b->use_pixman) {
2006 if (gl_renderer->create(compositor,
Derek Foremane76f1852015-05-15 12:12:39 -05002007 EGL_PLATFORM_WAYLAND_KHR,
Giulio Camuffo954f1832014-10-11 18:27:30 +03002008 b->parent.wl_display,
Derek Foremane76f1852015-05-15 12:12:39 -05002009 gl_renderer->alpha_attribs,
2010 NULL,
2011 0) < 0) {
Jason Ekstrandff2fd462013-10-27 22:24:58 -05002012 weston_log("Failed to initialize the GL renderer; "
2013 "falling back to pixman.\n");
Giulio Camuffo954f1832014-10-11 18:27:30 +03002014 b->use_pixman = 1;
Jason Ekstrandff2fd462013-10-27 22:24:58 -05002015 }
2016 }
2017
Giulio Camuffo954f1832014-10-11 18:27:30 +03002018 if (b->use_pixman) {
2019 if (pixman_renderer_init(compositor) < 0) {
Jason Ekstrandff2fd462013-10-27 22:24:58 -05002020 weston_log("Failed to initialize pixman renderer\n");
2021 goto err_display;
2022 }
2023 }
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002024
Giulio Camuffo954f1832014-10-11 18:27:30 +03002025 b->base.destroy = wayland_destroy;
2026 b->base.restore = wayland_restore;
Benjamin Franzkeecfb2b92011-01-15 12:34:48 +01002027
Giulio Camuffo954f1832014-10-11 18:27:30 +03002028 loop = wl_display_get_event_loop(compositor->wl_display);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002029
Giulio Camuffo954f1832014-10-11 18:27:30 +03002030 fd = wl_display_get_fd(b->parent.wl_display);
2031 b->parent.wl_source =
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002032 wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
Giulio Camuffo954f1832014-10-11 18:27:30 +03002033 wayland_backend_handle_event, b);
2034 if (b->parent.wl_source == NULL)
Dawid Gajownik82d49252015-07-31 00:02:28 -03002035 goto err_display;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002036
Giulio Camuffo954f1832014-10-11 18:27:30 +03002037 wl_event_source_check(b->parent.wl_source);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002038
Emmanuel Gil Peyrotc59f18e2015-09-25 11:58:40 +02002039 if (compositor->renderer->import_dmabuf) {
2040 if (linux_dmabuf_setup(compositor) < 0)
2041 weston_log("Error: initializing dmabuf "
2042 "support failed.\n");
2043 }
2044
Giulio Camuffo954f1832014-10-11 18:27:30 +03002045 compositor->backend = &b->base;
2046 return b;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002047err_display:
Giulio Camuffo954f1832014-10-11 18:27:30 +03002048 wl_display_disconnect(b->parent.wl_display);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002049err_compositor:
Giulio Camuffo954f1832014-10-11 18:27:30 +03002050 weston_compositor_shutdown(compositor);
Giulio Camuffo954f1832014-10-11 18:27:30 +03002051 free(b);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002052 return NULL;
2053}
2054
2055static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03002056wayland_backend_destroy(struct wayland_backend *b)
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002057{
Giulio Camuffo954f1832014-10-11 18:27:30 +03002058 wl_display_disconnect(b->parent.wl_display);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002059
Giulio Camuffo954f1832014-10-11 18:27:30 +03002060 if (b->theme)
2061 theme_destroy(b->theme);
2062 if (b->frame_device)
2063 cairo_device_destroy(b->frame_device);
2064 wl_cursor_theme_destroy(b->cursor_theme);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002065
Giulio Camuffo954f1832014-10-11 18:27:30 +03002066 weston_compositor_shutdown(b->compositor);
2067 free(b);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002068}
2069
Giulio Camuffo954f1832014-10-11 18:27:30 +03002070WL_EXPORT int
2071backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
Giulio Camuffo93daabb2015-10-17 19:24:14 +03002072 struct weston_config *config,
2073 struct weston_backend_config *config_base)
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002074{
Giulio Camuffo954f1832014-10-11 18:27:30 +03002075 struct wayland_backend *b;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002076 struct wayland_output *output;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002077 struct wayland_parent_output *poutput;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002078 struct weston_config_section *section;
Jason Ekstrande4ca8b02014-04-02 19:53:55 -05002079 int x, count, width, height, scale, use_pixman, fullscreen, sprawl;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002080 const char *section_name, *display_name;
2081 char *name;
2082
2083 const struct weston_option wayland_options[] = {
2084 { WESTON_OPTION_INTEGER, "width", 0, &width },
2085 { WESTON_OPTION_INTEGER, "height", 0, &height },
Jason Ekstrand12c6dd92013-11-07 20:13:32 -06002086 { WESTON_OPTION_INTEGER, "scale", 0, &scale },
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002087 { WESTON_OPTION_STRING, "display", 0, &display_name },
2088 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
2089 { WESTON_OPTION_INTEGER, "output-count", 0, &count },
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002090 { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fullscreen },
Jason Ekstrande4ca8b02014-04-02 19:53:55 -05002091 { WESTON_OPTION_BOOLEAN, "sprawl", 0, &sprawl },
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002092 };
2093
2094 width = 0;
2095 height = 0;
Jason Ekstrand12c6dd92013-11-07 20:13:32 -06002096 scale = 0;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002097 display_name = NULL;
2098 use_pixman = 0;
2099 count = 1;
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002100 fullscreen = 0;
Jason Ekstrande4ca8b02014-04-02 19:53:55 -05002101 sprawl = 0;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002102 parse_options(wayland_options,
2103 ARRAY_LENGTH(wayland_options), argc, argv);
2104
Giulio Camuffo954f1832014-10-11 18:27:30 +03002105 b = wayland_backend_create(compositor, use_pixman, display_name,
2106 argc, argv, config);
2107 if (!b)
2108 return -1;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002109
Giulio Camuffo954f1832014-10-11 18:27:30 +03002110 if (sprawl || b->parent.fshell) {
2111 b->sprawl_across_outputs = 1;
2112 wl_display_roundtrip(b->parent.wl_display);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002113
Giulio Camuffo954f1832014-10-11 18:27:30 +03002114 wl_list_for_each(poutput, &b->parent.output_list, link)
2115 wayland_output_create_for_parent_output(b, poutput);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002116
Giulio Camuffo954f1832014-10-11 18:27:30 +03002117 return 0;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002118 }
2119
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002120 if (fullscreen) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03002121 output = wayland_output_create(b, 0, 0, width, height,
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002122 NULL, 1, 0, 1);
2123 if (!output)
2124 goto err_outputs;
2125
Axel Davydd8b88d2013-11-17 21:34:16 +01002126 wayland_output_set_fullscreen(output, 0, 0, NULL);
Giulio Camuffo954f1832014-10-11 18:27:30 +03002127 return 0;
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002128 }
2129
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002130 section = NULL;
2131 x = 0;
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002132 while (weston_config_next_section(config, &section, &section_name)) {
2133 if (!section_name || strcmp(section_name, "output") != 0)
2134 continue;
2135 weston_config_section_get_string(section, "name", &name, NULL);
2136 if (name == NULL)
2137 continue;
2138
2139 if (name[0] != 'W' || name[1] != 'L') {
2140 free(name);
2141 continue;
2142 }
2143 free(name);
2144
Giulio Camuffo954f1832014-10-11 18:27:30 +03002145 output = wayland_output_create_for_config(b, section, width,
Jason Ekstrand12c6dd92013-11-07 20:13:32 -06002146 height, scale, x, 0);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002147 if (!output)
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002148 goto err_outputs;
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002149 if (wayland_output_set_windowed(output))
2150 goto err_outputs;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002151
2152 x += output->base.width;
2153 --count;
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002154 }
2155
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002156 if (!width)
2157 width = 1024;
2158 if (!height)
2159 height = 640;
Jason Ekstrand12c6dd92013-11-07 20:13:32 -06002160 if (!scale)
2161 scale = 1;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002162 while (count > 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03002163 output = wayland_output_create(b, x, 0, width, height,
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002164 NULL, 0, 0, scale);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002165 if (!output)
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002166 goto err_outputs;
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002167 if (wayland_output_set_windowed(output))
2168 goto err_outputs;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002169
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002170 x += width;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002171 --count;
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002172 }
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002173
Giulio Camuffo954f1832014-10-11 18:27:30 +03002174 weston_compositor_add_key_binding(compositor, KEY_F,
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002175 MODIFIER_CTRL | MODIFIER_ALT,
Giulio Camuffo954f1832014-10-11 18:27:30 +03002176 fullscreen_binding, b);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002177
Giulio Camuffo954f1832014-10-11 18:27:30 +03002178 return 0;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002179
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002180err_outputs:
Giulio Camuffo954f1832014-10-11 18:27:30 +03002181 wayland_backend_destroy(b);
2182 return -1;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002183}