blob: 1900ab083cd84488809289000d63447356840fd8 [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
Armin Krezović174448a2016-09-30 14:11:09 +020029#include <assert.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010030#include <stddef.h>
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030031#include <stdint.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010032#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <fcntl.h>
36#include <unistd.h>
Daniel Stoneb7452fe2012-06-01 12:14:06 +010037#include <sys/mman.h>
Jason Ekstrand5ea04802013-11-07 20:13:33 -060038#include <linux/input.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010039
Benjamin Franzkebe014562011-02-18 17:04:24 +010040#include <wayland-client.h>
Jason Ekstrand7744f712013-10-27 22:24:55 -050041#include <wayland-cursor.h>
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010042
Armin Krezovićb08e1a52016-12-09 22:58:27 +010043#ifdef ENABLE_EGL
44#include <wayland-egl.h>
45#endif
46
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010047#include "compositor.h"
Benoit Gschwind639322a2016-04-28 20:33:15 +020048#include "compositor-wayland.h"
John Kåre Alsaker30d2b1f2012-11-13 19:10:28 +010049#include "gl-renderer.h"
Vincent Abriouc9506672016-10-05 16:14:07 +020050#include "weston-egl-ext.h"
Jason Ekstrandff2fd462013-10-27 22:24:58 -050051#include "pixman-renderer.h"
Jon Cruz35b2eaa2015-06-15 15:37:08 -070052#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070053#include "shared/image-loader.h"
54#include "shared/os-compatibility.h"
55#include "shared/cairo-util.h"
Jonas Ådahl496adb32015-11-17 16:00:27 +080056#include "fullscreen-shell-unstable-v1-client-protocol.h"
Armin Krezović34476192016-11-21 18:42:42 +010057#include "xdg-shell-unstable-v6-client-protocol.h"
Pekka Paalanenb00c79b2016-02-18 16:53:27 +020058#include "presentation-time-server-protocol.h"
Emmanuel Gil Peyrotc59f18e2015-09-25 11:58:40 +020059#include "linux-dmabuf.h"
Armin Krezović174448a2016-09-30 14:11:09 +020060#include "windowed-output-api.h"
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010061
Jason Ekstrand48ce4212013-10-27 22:25:02 -050062#define WINDOW_TITLE "Weston Compositor"
63
Giulio Camuffo954f1832014-10-11 18:27:30 +030064struct wayland_backend {
65 struct weston_backend base;
66 struct weston_compositor *compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010067
68 struct {
Kristian Høgsberg362b6722012-06-18 15:13:51 -040069 struct wl_display *wl_display;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -040070 struct wl_registry *registry;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010071 struct wl_compositor *compositor;
72 struct wl_shell *shell;
Armin Krezović34476192016-11-21 18:42:42 +010073 struct zxdg_shell_v6 *xdg_shell;
Jonas Ådahl496adb32015-11-17 16:00:27 +080074 struct zwp_fullscreen_shell_v1 *fshell;
Jonas Ådahle5a12252013-04-05 23:07:11 +020075 struct wl_shm *shm;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010076
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -050077 struct wl_list output_list;
78
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010079 struct wl_event_source *wl_source;
80 uint32_t event_mask;
81 } parent;
82
Armin Krezović7e71b872016-10-09 17:30:22 +020083 bool use_pixman;
Armin Krezović7f1c0b82016-10-09 17:30:23 +020084 bool sprawl_across_outputs;
Armin Krezović20450162016-10-13 12:01:43 +020085 bool fullscreen;
Jason Ekstrandff2fd462013-10-27 22:24:58 -050086
Jason Ekstrand7744f712013-10-27 22:24:55 -050087 struct theme *theme;
88 cairo_device_t *frame_device;
89 struct wl_cursor_theme *cursor_theme;
90 struct wl_cursor *cursor;
Kristian Høgsberg546a8122012-02-01 07:45:51 -050091
Jason Ekstrand06ced802013-11-07 20:13:29 -060092 struct wl_list input_list;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010093};
94
95struct wayland_output {
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -050096 struct weston_output base;
97
Benjamin Franzkeec2e6422010-11-27 19:04:12 +010098 struct {
Armin Krezović2d321e32016-10-09 17:30:25 +020099 bool draw_initial_frame;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500100 struct wl_surface *surface;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500101
102 struct wl_output *output;
103 uint32_t global_id;
104
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500105 struct wl_shell_surface *shell_surface;
Armin Krezović34476192016-11-21 18:42:42 +0100106 struct zxdg_surface_v6 *xdg_surface;
107 struct zxdg_toplevel_v6 *xdg_toplevel;
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600108 int configure_width, configure_height;
Armin Krezović34476192016-11-21 18:42:42 +0100109 bool wait_for_configure;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100110 } parent;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500111
Jason Ekstrand7744f712013-10-27 22:24:55 -0500112 int keyboard_count;
113
Sergi Granell2dcbb8d2017-03-24 20:48:01 +0100114 char *title;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500115 struct frame *frame;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500116
Jason Ekstrand7744f712013-10-27 22:24:55 -0500117 struct {
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500118 struct wl_egl_window *egl_window;
119 struct {
120 cairo_surface_t *top;
121 cairo_surface_t *left;
122 cairo_surface_t *right;
123 cairo_surface_t *bottom;
124 } border;
125 } gl;
126
127 struct {
128 struct wl_list buffers;
129 struct wl_list free_buffers;
130 } shm;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500131
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500132 struct weston_mode mode;
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500133 uint32_t scale;
Dima Ryazanov89c2f632016-11-24 05:13:12 -0800134
135 struct wl_callback *frame_cb;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100136};
137
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500138struct wayland_parent_output {
139 struct wayland_output *output;
140 struct wl_list link;
141
142 struct wl_output *global;
143 uint32_t id;
144
145 struct {
146 char *make;
147 char *model;
148 int32_t width, height;
149 uint32_t subpixel;
150 } physical;
151
152 int32_t x, y;
153 uint32_t transform;
154 uint32_t scale;
155
156 struct wl_list mode_list;
157 struct weston_mode *preferred_mode;
158 struct weston_mode *current_mode;
159};
160
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500161struct wayland_shm_buffer {
162 struct wayland_output *output;
163 struct wl_list link;
164 struct wl_list free_link;
165
166 struct wl_buffer *buffer;
167 void *data;
168 size_t size;
169 pixman_region32_t damage;
170 int frame_damaged;
171
172 pixman_image_t *pm_image;
173 cairo_surface_t *c_surface;
174};
175
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100176struct wayland_input {
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -0400177 struct weston_seat base;
Giulio Camuffo954f1832014-10-11 18:27:30 +0300178 struct wayland_backend *backend;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100179 struct wl_list link;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500180
181 struct {
182 struct wl_seat *seat;
183 struct wl_pointer *pointer;
184 struct wl_keyboard *keyboard;
185 struct wl_touch *touch;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500186
187 struct {
188 struct wl_surface *surface;
189 int32_t hx, hy;
190 } cursor;
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -0500191 } parent;
192
Jason Ekstrandb7d9f2e2014-04-02 19:53:57 -0500193 enum weston_key_state_update keyboard_state_update;
Daniel Stone50692802012-06-22 13:21:41 +0100194 uint32_t key_serial;
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400195 uint32_t enter_serial;
Derek Foreman748c6952015-11-06 15:56:10 -0600196 uint32_t touch_points;
197 bool touch_active;
Derek Foreman4bcc54d2015-11-06 15:56:06 -0600198 bool has_focus;
Derek Foremancfce7d02015-11-06 15:56:08 -0600199 int seat_version;
Derek Foreman4bcc54d2015-11-06 15:56:06 -0600200
Kristian Høgsberg539d85f2012-08-13 23:29:53 -0400201 struct wayland_output *output;
Derek Foreman748c6952015-11-06 15:56:10 -0600202 struct wayland_output *touch_focus;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500203 struct wayland_output *keyboard_focus;
Peter Hutterer87743e92016-01-18 16:38:22 +1000204
205 struct weston_pointer_axis_event vert, horiz;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100206};
207
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +0300208struct gl_renderer_interface *gl_renderer;
209
Armin Krezović938dc522016-08-01 19:17:57 +0200210static inline struct wayland_output *
211to_wayland_output(struct weston_output *base)
212{
213 return container_of(base, struct wayland_output, base);
214}
215
216static inline struct wayland_backend *
217to_wayland_backend(struct weston_compositor *base)
218{
219 return container_of(base->backend, struct wayland_backend, base);
220}
221
Kristian Høgsberg546a8122012-02-01 07:45:51 -0500222static void
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500223wayland_shm_buffer_destroy(struct wayland_shm_buffer *buffer)
224{
225 cairo_surface_destroy(buffer->c_surface);
226 pixman_image_unref(buffer->pm_image);
227
228 wl_buffer_destroy(buffer->buffer);
229 munmap(buffer->data, buffer->size);
230
231 pixman_region32_fini(&buffer->damage);
232
233 wl_list_remove(&buffer->link);
234 wl_list_remove(&buffer->free_link);
235 free(buffer);
236}
237
238static void
239buffer_release(void *data, struct wl_buffer *buffer)
240{
241 struct wayland_shm_buffer *sb = data;
242
243 if (sb->output) {
244 wl_list_insert(&sb->output->shm.free_buffers, &sb->free_link);
245 } else {
246 wayland_shm_buffer_destroy(sb);
247 }
248}
249
250static const struct wl_buffer_listener buffer_listener = {
251 buffer_release
252};
253
254static struct wayland_shm_buffer *
255wayland_output_get_shm_buffer(struct wayland_output *output)
256{
Giulio Camuffo954f1832014-10-11 18:27:30 +0300257 struct wayland_backend *b =
Armin Krezović938dc522016-08-01 19:17:57 +0200258 to_wayland_backend(output->base.compositor);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300259 struct wl_shm *shm = b->parent.shm;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500260 struct wayland_shm_buffer *sb;
261
262 struct wl_shm_pool *pool;
263 int width, height, stride;
264 int32_t fx, fy;
265 int fd;
266 unsigned char *data;
267
268 if (!wl_list_empty(&output->shm.free_buffers)) {
269 sb = container_of(output->shm.free_buffers.next,
270 struct wayland_shm_buffer, free_link);
271 wl_list_remove(&sb->free_link);
272 wl_list_init(&sb->free_link);
273
274 return sb;
275 }
276
277 if (output->frame) {
278 width = frame_width(output->frame);
279 height = frame_height(output->frame);
280 } else {
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500281 width = output->base.current_mode->width;
282 height = output->base.current_mode->height;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500283 }
284
285 stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
286
287 fd = os_create_anonymous_file(height * stride);
288 if (fd < 0) {
Bryce W. Harringtona0935022014-03-21 05:54:02 +0000289 weston_log("could not create an anonymous file buffer: %m\n");
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500290 return NULL;
291 }
292
293 data = mmap(NULL, height * stride, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
294 if (data == MAP_FAILED) {
Bryce W. Harringtona0935022014-03-21 05:54:02 +0000295 weston_log("could not mmap %d memory for data: %m\n", height * stride);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500296 close(fd);
297 return NULL;
298 }
299
300 sb = zalloc(sizeof *sb);
Bryce W. Harringtonbfd74f42014-04-21 23:51:02 +0000301 if (sb == NULL) {
Thierry Reding6ac60c12014-05-27 09:08:29 +0200302 weston_log("could not zalloc %zu memory for sb: %m\n", sizeof *sb);
Bryce W. Harringtonbfd74f42014-04-21 23:51:02 +0000303 close(fd);
304 free(data);
305 return NULL;
306 }
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500307
308 sb->output = output;
309 wl_list_init(&sb->free_link);
310 wl_list_insert(&output->shm.buffers, &sb->link);
311
312 pixman_region32_init_rect(&sb->damage, 0, 0,
313 output->base.width, output->base.height);
314 sb->frame_damaged = 1;
315
316 sb->data = data;
317 sb->size = height * stride;
318
319 pool = wl_shm_create_pool(shm, fd, sb->size);
320
321 sb->buffer = wl_shm_pool_create_buffer(pool, 0,
322 width, height,
323 stride,
324 WL_SHM_FORMAT_ARGB8888);
325 wl_buffer_add_listener(sb->buffer, &buffer_listener, sb);
326 wl_shm_pool_destroy(pool);
327 close(fd);
328
329 memset(data, 0, sb->size);
330
331 sb->c_surface =
332 cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32,
333 width, height, stride);
334
335 fx = 0;
336 fy = 0;
337 if (output->frame)
338 frame_interior(output->frame, &fx, &fy, 0, 0);
339 sb->pm_image =
340 pixman_image_create_bits(PIXMAN_a8r8g8b8, width, height,
341 (uint32_t *)(data + fy * stride) + fx,
342 stride);
343
344 return sb;
345}
346
347static void
Kristian Høgsbergcdd61d02012-02-07 09:56:15 -0500348frame_done(void *data, struct wl_callback *callback, uint32_t time)
Kristian Høgsberg33418202011-08-16 23:01:28 -0400349{
Dima Ryazanov89c2f632016-11-24 05:13:12 -0800350 struct wayland_output *output = data;
Pekka Paalanenb5eedad2014-09-23 22:08:45 -0400351 struct timespec ts;
Kristian Høgsberg33418202011-08-16 23:01:28 -0400352
Dima Ryazanov89c2f632016-11-24 05:13:12 -0800353 assert(callback == output->frame_cb);
Kristian Høgsbergcdd61d02012-02-07 09:56:15 -0500354 wl_callback_destroy(callback);
Dima Ryazanov89c2f632016-11-24 05:13:12 -0800355 output->frame_cb = NULL;
Pekka Paalanenb5eedad2014-09-23 22:08:45 -0400356
357 /* XXX: use the presentation extension for proper timings */
Pekka Paalanen04f8a9b2015-04-02 16:26:06 +0300358
359 /*
360 * This is the fallback case, where Presentation extension is not
361 * available from the parent compositor. We do not know the base for
362 * 'time', so we cannot feed it to finish_frame(). Do the only thing
363 * we can, and pretend finish_frame time is when we process this
364 * event.
365 */
Dima Ryazanov89c2f632016-11-24 05:13:12 -0800366 weston_compositor_read_presentation_clock(output->base.compositor, &ts);
367 weston_output_finish_frame(&output->base, &ts, 0);
Kristian Høgsberg33418202011-08-16 23:01:28 -0400368}
369
370static const struct wl_callback_listener frame_listener = {
371 frame_done
372};
373
Kristian Høgsberg06cf6b02012-01-25 23:47:45 -0500374static void
Jonas Ådahle5a12252013-04-05 23:07:11 +0200375draw_initial_frame(struct wayland_output *output)
376{
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500377 struct wayland_shm_buffer *sb;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200378
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500379 sb = wayland_output_get_shm_buffer(output);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200380
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500381 /* If we are rendering with GL, then orphan it so that it gets
382 * destroyed immediately */
383 if (output->gl.egl_window)
384 sb->output = NULL;
Jason Ekstrand7744f712013-10-27 22:24:55 -0500385
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500386 wl_surface_attach(output->parent.surface, sb->buffer, 0, 0);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500387 wl_surface_damage(output->parent.surface, 0, 0,
388 output->base.current_mode->width,
389 output->base.current_mode->height);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200390}
391
Armin Krezovićb08e1a52016-12-09 22:58:27 +0100392#ifdef ENABLE_EGL
Jonas Ådahle5a12252013-04-05 23:07:11 +0200393static void
Jason Ekstrand7744f712013-10-27 22:24:55 -0500394wayland_output_update_gl_border(struct wayland_output *output)
395{
396 int32_t ix, iy, iwidth, iheight, fwidth, fheight;
397 cairo_t *cr;
398
399 if (!output->frame)
400 return;
401 if (!(frame_status(output->frame) & FRAME_STATUS_REPAINT))
402 return;
403
404 fwidth = frame_width(output->frame);
405 fheight = frame_height(output->frame);
406 frame_interior(output->frame, &ix, &iy, &iwidth, &iheight);
407
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500408 if (!output->gl.border.top)
409 output->gl.border.top =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500410 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
411 fwidth, iy);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500412 cr = cairo_create(output->gl.border.top);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500413 frame_repaint(output->frame, cr);
414 cairo_destroy(cr);
415 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_TOP,
416 fwidth, iy,
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500417 cairo_image_surface_get_stride(output->gl.border.top) / 4,
418 cairo_image_surface_get_data(output->gl.border.top));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500419
420
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500421 if (!output->gl.border.left)
422 output->gl.border.left =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500423 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
424 ix, 1);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500425 cr = cairo_create(output->gl.border.left);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500426 cairo_translate(cr, 0, -iy);
427 frame_repaint(output->frame, cr);
428 cairo_destroy(cr);
429 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_LEFT,
430 ix, 1,
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500431 cairo_image_surface_get_stride(output->gl.border.left) / 4,
432 cairo_image_surface_get_data(output->gl.border.left));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500433
434
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500435 if (!output->gl.border.right)
436 output->gl.border.right =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500437 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
438 fwidth - (ix + iwidth), 1);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500439 cr = cairo_create(output->gl.border.right);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500440 cairo_translate(cr, -(iwidth + ix), -iy);
441 frame_repaint(output->frame, cr);
442 cairo_destroy(cr);
443 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_RIGHT,
444 fwidth - (ix + iwidth), 1,
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500445 cairo_image_surface_get_stride(output->gl.border.right) / 4,
446 cairo_image_surface_get_data(output->gl.border.right));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500447
448
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500449 if (!output->gl.border.bottom)
450 output->gl.border.bottom =
Jason Ekstrand7744f712013-10-27 22:24:55 -0500451 cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
452 fwidth, fheight - (iy + iheight));
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500453 cr = cairo_create(output->gl.border.bottom);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500454 cairo_translate(cr, 0, -(iy + iheight));
455 frame_repaint(output->frame, cr);
456 cairo_destroy(cr);
457 gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_BOTTOM,
458 fwidth, fheight - (iy + iheight),
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500459 cairo_image_surface_get_stride(output->gl.border.bottom) / 4,
460 cairo_image_surface_get_data(output->gl.border.bottom));
Jason Ekstrand7744f712013-10-27 22:24:55 -0500461}
Armin Krezovićb08e1a52016-12-09 22:58:27 +0100462#endif
Jason Ekstrand7744f712013-10-27 22:24:55 -0500463
464static void
Jonas Ådahle5a12252013-04-05 23:07:11 +0200465wayland_output_start_repaint_loop(struct weston_output *output_base)
466{
Armin Krezović938dc522016-08-01 19:17:57 +0200467 struct wayland_output *output = to_wayland_output(output_base);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300468 struct wayland_backend *wb =
Armin Krezović938dc522016-08-01 19:17:57 +0200469 to_wayland_backend(output->base.compositor);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200470
471 /* If this is the initial frame, we need to attach a buffer so that
472 * the compositor can map the surface and include it in its render
473 * loop. If the surface doesn't end up in the render loop, the frame
474 * callback won't be invoked. The buffer is transparent and of the
475 * same size as the future real output buffer. */
476 if (output->parent.draw_initial_frame) {
Armin Krezović2d321e32016-10-09 17:30:25 +0200477 output->parent.draw_initial_frame = false;
Jonas Ådahle5a12252013-04-05 23:07:11 +0200478
479 draw_initial_frame(output);
480 }
481
Dima Ryazanov89c2f632016-11-24 05:13:12 -0800482 output->frame_cb = wl_surface_frame(output->parent.surface);
483 wl_callback_add_listener(output->frame_cb, &frame_listener, output);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200484 wl_surface_commit(output->parent.surface);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300485 wl_display_flush(wb->parent.wl_display);
Jonas Ådahle5a12252013-04-05 23:07:11 +0200486}
487
Armin Krezovićb08e1a52016-12-09 22:58:27 +0100488#ifdef ENABLE_EGL
David Herrmann1edf44c2013-10-22 17:11:26 +0200489static int
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500490wayland_output_repaint_gl(struct weston_output *output_base,
Daniel Stoneb1f166d2017-03-01 11:34:10 +0000491 pixman_region32_t *damage,
492 void *repaint_data)
Kristian Høgsbergd7c17262012-09-05 21:54:15 -0400493{
Armin Krezović938dc522016-08-01 19:17:57 +0200494 struct wayland_output *output = to_wayland_output(output_base);
Kristian Høgsbergfa1be022012-09-05 22:49:55 -0400495 struct weston_compositor *ec = output->base.compositor;
Scott Moreau062be7e2012-04-20 13:37:33 -0600496
Dima Ryazanov89c2f632016-11-24 05:13:12 -0800497 output->frame_cb = wl_surface_frame(output->parent.surface);
498 wl_callback_add_listener(output->frame_cb, &frame_listener, output);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100499
Jason Ekstrand7744f712013-10-27 22:24:55 -0500500 wayland_output_update_gl_border(output);
501
Pekka Paalanenbc106382012-10-10 12:49:31 +0300502 ec->renderer->repaint_output(&output->base, damage);
Ander Conselvan de Oliveira0a887722012-11-22 15:57:00 +0200503
504 pixman_region32_subtract(&ec->primary_plane.damage,
505 &ec->primary_plane.damage, damage);
David Herrmann1edf44c2013-10-22 17:11:26 +0200506 return 0;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100507}
Armin Krezovićb08e1a52016-12-09 22:58:27 +0100508#endif
Benjamin Franzkeec2e6422010-11-27 19:04:12 +0100509
Matt Roper361d2ad2011-08-29 13:52:23 -0700510static void
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500511wayland_output_update_shm_border(struct wayland_shm_buffer *buffer)
512{
513 int32_t ix, iy, iwidth, iheight, fwidth, fheight;
514 cairo_t *cr;
515
516 if (!buffer->output->frame || !buffer->frame_damaged)
517 return;
518
519 cr = cairo_create(buffer->c_surface);
520
521 frame_interior(buffer->output->frame, &ix, &iy, &iwidth, &iheight);
522 fwidth = frame_width(buffer->output->frame);
523 fheight = frame_height(buffer->output->frame);
524
525 /* Set the clip so we don't unnecisaraly damage the surface */
526 cairo_move_to(cr, ix, iy);
527 cairo_rel_line_to(cr, iwidth, 0);
528 cairo_rel_line_to(cr, 0, iheight);
529 cairo_rel_line_to(cr, -iwidth, 0);
530 cairo_line_to(cr, ix, iy);
531 cairo_line_to(cr, 0, iy);
532 cairo_line_to(cr, 0, fheight);
533 cairo_line_to(cr, fwidth, fheight);
534 cairo_line_to(cr, fwidth, 0);
535 cairo_line_to(cr, 0, 0);
536 cairo_line_to(cr, 0, iy);
537 cairo_close_path(cr);
538 cairo_clip(cr);
539
540 /* Draw using a pattern so that the final result gets clipped */
541 cairo_push_group(cr);
542 frame_repaint(buffer->output->frame, cr);
543 cairo_pop_group_to_source(cr);
544 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
545 cairo_paint(cr);
546
547 cairo_destroy(cr);
548}
549
550static void
551wayland_shm_buffer_attach(struct wayland_shm_buffer *sb)
552{
553 pixman_region32_t damage;
554 pixman_box32_t *rects;
555 int32_t ix, iy, iwidth, iheight, fwidth, fheight;
556 int i, n;
557
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500558 pixman_region32_init(&damage);
559 weston_transformed_region(sb->output->base.width,
560 sb->output->base.height,
561 sb->output->base.transform,
562 sb->output->base.current_scale,
563 &sb->damage, &damage);
564
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500565 if (sb->output->frame) {
566 frame_interior(sb->output->frame, &ix, &iy, &iwidth, &iheight);
567 fwidth = frame_width(sb->output->frame);
568 fheight = frame_height(sb->output->frame);
569
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500570 pixman_region32_translate(&damage, ix, iy);
571
572 if (sb->frame_damaged) {
573 pixman_region32_union_rect(&damage, &damage,
574 0, 0, fwidth, iy);
575 pixman_region32_union_rect(&damage, &damage,
576 0, iy, ix, iheight);
577 pixman_region32_union_rect(&damage, &damage,
578 ix + iwidth, iy,
579 fwidth - (ix + iwidth), iheight);
580 pixman_region32_union_rect(&damage, &damage,
581 0, iy + iheight,
582 fwidth, fheight - (iy + iheight));
583 }
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500584 }
585
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500586 rects = pixman_region32_rectangles(&damage, &n);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500587 wl_surface_attach(sb->output->parent.surface, sb->buffer, 0, 0);
588 for (i = 0; i < n; ++i)
589 wl_surface_damage(sb->output->parent.surface, rects[i].x1,
590 rects[i].y1, rects[i].x2 - rects[i].x1,
591 rects[i].y2 - rects[i].y1);
592
593 if (sb->output->frame)
594 pixman_region32_fini(&damage);
595}
596
597static int
598wayland_output_repaint_pixman(struct weston_output *output_base,
Daniel Stoneb1f166d2017-03-01 11:34:10 +0000599 pixman_region32_t *damage,
600 void *repaint_data)
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500601{
Armin Krezović938dc522016-08-01 19:17:57 +0200602 struct wayland_output *output = to_wayland_output(output_base);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300603 struct wayland_backend *b =
Armin Krezović938dc522016-08-01 19:17:57 +0200604 to_wayland_backend(output->base.compositor);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500605 struct wayland_shm_buffer *sb;
606
607 if (output->frame) {
608 if (frame_status(output->frame) & FRAME_STATUS_REPAINT)
609 wl_list_for_each(sb, &output->shm.buffers, link)
610 sb->frame_damaged = 1;
611 }
612
613 wl_list_for_each(sb, &output->shm.buffers, link)
614 pixman_region32_union(&sb->damage, &sb->damage, damage);
615
616 sb = wayland_output_get_shm_buffer(output);
617
618 wayland_output_update_shm_border(sb);
619 pixman_renderer_output_set_buffer(output_base, sb->pm_image);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300620 b->compositor->renderer->repaint_output(output_base, &sb->damage);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500621
622 wayland_shm_buffer_attach(sb);
623
Daniel Stone21fac602016-11-28 16:05:35 +0000624 output->frame_cb = wl_surface_frame(output->parent.surface);
625 wl_callback_add_listener(output->frame_cb, &frame_listener, output);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500626 wl_surface_commit(output->parent.surface);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300627 wl_display_flush(b->parent.wl_display);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500628
629 pixman_region32_fini(&sb->damage);
630 pixman_region32_init(&sb->damage);
631 sb->frame_damaged = 0;
632
Giulio Camuffo954f1832014-10-11 18:27:30 +0300633 pixman_region32_subtract(&b->compositor->primary_plane.damage,
634 &b->compositor->primary_plane.damage, damage);
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500635 return 0;
636}
637
638static void
Armin Krezović174448a2016-09-30 14:11:09 +0200639wayland_backend_destroy_output_surface(struct wayland_output *output)
Matt Roper361d2ad2011-08-29 13:52:23 -0700640{
Armin Krezović34476192016-11-21 18:42:42 +0100641 if (output->parent.xdg_toplevel)
642 zxdg_toplevel_v6_destroy(output->parent.xdg_toplevel);
643
644 if (output->parent.xdg_surface)
645 zxdg_surface_v6_destroy(output->parent.xdg_surface);
646
Armin Krezović174448a2016-09-30 14:11:09 +0200647 if (output->parent.shell_surface)
648 wl_shell_surface_destroy(output->parent.shell_surface);
649
650 wl_surface_destroy(output->parent.surface);
651}
652
Armin Krezović2e662522016-10-09 17:30:29 +0200653static void
654wayland_output_destroy_shm_buffers(struct wayland_output *output)
655{
656 struct wayland_shm_buffer *buffer, *next;
657
658 /* Throw away any remaining SHM buffers */
659 wl_list_for_each_safe(buffer, next, &output->shm.free_buffers, free_link)
660 wayland_shm_buffer_destroy(buffer);
661 /* These will get thrown away when they get released */
662 wl_list_for_each(buffer, &output->shm.buffers, link)
663 buffer->output = NULL;
664}
665
Armin Krezović174448a2016-09-30 14:11:09 +0200666static int
667wayland_output_disable(struct weston_output *base)
668{
669 struct wayland_output *output = to_wayland_output(base);
670 struct wayland_backend *b = to_wayland_backend(base->compositor);
671
672 if (!output->base.enabled)
673 return 0;
Matt Roper361d2ad2011-08-29 13:52:23 -0700674
Giulio Camuffo954f1832014-10-11 18:27:30 +0300675 if (b->use_pixman) {
Armin Krezović174448a2016-09-30 14:11:09 +0200676 pixman_renderer_output_destroy(&output->base);
Armin Krezovićb08e1a52016-12-09 22:58:27 +0100677#ifdef ENABLE_EGL
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500678 } else {
Armin Krezović174448a2016-09-30 14:11:09 +0200679 gl_renderer->output_destroy(&output->base);
Emmanuel Gil Peyrot85571a32016-09-01 15:19:46 +0100680 wl_egl_window_destroy(output->gl.egl_window);
Armin Krezovićb08e1a52016-12-09 22:58:27 +0100681#endif
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500682 }
John Kåre Alsaker94659272012-11-13 19:10:18 +0100683
Armin Krezović2e662522016-10-09 17:30:29 +0200684 wayland_output_destroy_shm_buffers(output);
685
Armin Krezovićf054d352016-10-09 17:30:27 +0200686 wayland_backend_destroy_output_surface(output);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500687
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600688 if (output->frame)
Jason Ekstrand7744f712013-10-27 22:24:55 -0500689 frame_destroy(output->frame);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600690
691 cairo_surface_destroy(output->gl.border.top);
692 cairo_surface_destroy(output->gl.border.left);
693 cairo_surface_destroy(output->gl.border.right);
694 cairo_surface_destroy(output->gl.border.bottom);
Jason Ekstrand7744f712013-10-27 22:24:55 -0500695
Armin Krezović174448a2016-09-30 14:11:09 +0200696 return 0;
697}
Matt Roper361d2ad2011-08-29 13:52:23 -0700698
Armin Krezović174448a2016-09-30 14:11:09 +0200699static void
700wayland_output_destroy(struct weston_output *base)
701{
702 struct wayland_output *output = to_wayland_output(base);
Armin Krezović174448a2016-09-30 14:11:09 +0200703
704 wayland_output_disable(&output->base);
705
Armin Krezović174448a2016-09-30 14:11:09 +0200706 weston_output_destroy(&output->base);
707
Dima Ryazanov89c2f632016-11-24 05:13:12 -0800708 if (output->frame_cb)
709 wl_callback_destroy(output->frame_cb);
710
Sergi Granell2dcbb8d2017-03-24 20:48:01 +0100711 free(output->title);
Armin Krezović174448a2016-09-30 14:11:09 +0200712 free(output);
Matt Roper361d2ad2011-08-29 13:52:23 -0700713}
714
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +0300715static const struct wl_shell_surface_listener shell_surface_listener;
716
Armin Krezovićb08e1a52016-12-09 22:58:27 +0100717#ifdef ENABLE_EGL
Benjamin Franzke431da9a2011-04-20 11:02:58 +0200718static int
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500719wayland_output_init_gl_renderer(struct wayland_output *output)
720{
Jason Ekstrand00b84282013-10-27 22:24:59 -0500721 int32_t fwidth = 0, fheight = 0;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500722
723 if (output->frame) {
724 fwidth = frame_width(output->frame);
725 fheight = frame_height(output->frame);
726 } else {
Jason Ekstrand48ce4212013-10-27 22:25:02 -0500727 fwidth = output->base.current_mode->width;
728 fheight = output->base.current_mode->height;
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500729 }
730
731 output->gl.egl_window =
732 wl_egl_window_create(output->parent.surface,
733 fwidth, fheight);
734 if (!output->gl.egl_window) {
735 weston_log("failure to create wl_egl_window\n");
736 return -1;
737 }
738
Miguel A. Vicoc095cde2016-05-18 17:43:00 +0200739 if (gl_renderer->output_window_create(&output->base,
740 output->gl.egl_window,
741 output->gl.egl_window,
742 gl_renderer->alpha_attribs,
743 NULL,
744 0) < 0)
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500745 goto cleanup_window;
746
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500747 return 0;
748
749cleanup_window:
750 wl_egl_window_destroy(output->gl.egl_window);
751 return -1;
752}
Armin Krezovićb08e1a52016-12-09 22:58:27 +0100753#endif
Jason Ekstrandff2fd462013-10-27 22:24:58 -0500754
755static int
756wayland_output_init_pixman_renderer(struct wayland_output *output)
757{
758 return pixman_renderer_output_create(&output->base);
759}
760
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600761static void
762wayland_output_resize_surface(struct wayland_output *output)
763{
Giulio Camuffo954f1832014-10-11 18:27:30 +0300764 struct wayland_backend *b =
Armin Krezović938dc522016-08-01 19:17:57 +0200765 to_wayland_backend(output->base.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600766 int32_t ix, iy, iwidth, iheight;
767 int32_t width, height;
768 struct wl_region *region;
769
770 width = output->base.current_mode->width;
771 height = output->base.current_mode->height;
772
773 if (output->frame) {
774 frame_resize_inside(output->frame, width, height);
775
776 frame_input_rect(output->frame, &ix, &iy, &iwidth, &iheight);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300777 region = wl_compositor_create_region(b->parent.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600778 wl_region_add(region, ix, iy, iwidth, iheight);
779 wl_surface_set_input_region(output->parent.surface, region);
780 wl_region_destroy(region);
781
782 frame_opaque_rect(output->frame, &ix, &iy, &iwidth, &iheight);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300783 region = wl_compositor_create_region(b->parent.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600784 wl_region_add(region, ix, iy, iwidth, iheight);
785 wl_surface_set_opaque_region(output->parent.surface, region);
786 wl_region_destroy(region);
787
Sergi Granelled016bf2017-03-24 23:45:13 +0100788 if (output->parent.xdg_surface) {
789 zxdg_surface_v6_set_window_geometry(output->parent.xdg_surface,
790 ix,
791 iy,
792 iwidth,
793 iheight);
794 }
795
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600796 width = frame_width(output->frame);
797 height = frame_height(output->frame);
798 } else {
Giulio Camuffo954f1832014-10-11 18:27:30 +0300799 region = wl_compositor_create_region(b->parent.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600800 wl_region_add(region, 0, 0, width, height);
801 wl_surface_set_input_region(output->parent.surface, region);
802 wl_region_destroy(region);
803
Giulio Camuffo954f1832014-10-11 18:27:30 +0300804 region = wl_compositor_create_region(b->parent.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600805 wl_region_add(region, 0, 0, width, height);
806 wl_surface_set_opaque_region(output->parent.surface, region);
807 wl_region_destroy(region);
Sergi Granelled016bf2017-03-24 23:45:13 +0100808
809 if (output->parent.xdg_surface) {
810 zxdg_surface_v6_set_window_geometry(output->parent.xdg_surface,
811 0,
812 0,
813 width,
814 height);
815 }
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600816 }
817
Armin Krezovićb08e1a52016-12-09 22:58:27 +0100818#ifdef ENABLE_EGL
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600819 if (output->gl.egl_window) {
820 wl_egl_window_resize(output->gl.egl_window,
821 width, height, 0, 0);
822
823 /* These will need to be re-created due to the resize */
824 gl_renderer->output_set_border(&output->base,
825 GL_RENDERER_BORDER_TOP,
826 0, 0, 0, NULL);
827 cairo_surface_destroy(output->gl.border.top);
828 output->gl.border.top = NULL;
829 gl_renderer->output_set_border(&output->base,
830 GL_RENDERER_BORDER_LEFT,
831 0, 0, 0, NULL);
832 cairo_surface_destroy(output->gl.border.left);
833 output->gl.border.left = NULL;
834 gl_renderer->output_set_border(&output->base,
835 GL_RENDERER_BORDER_RIGHT,
836 0, 0, 0, NULL);
837 cairo_surface_destroy(output->gl.border.right);
838 output->gl.border.right = NULL;
839 gl_renderer->output_set_border(&output->base,
840 GL_RENDERER_BORDER_BOTTOM,
841 0, 0, 0, NULL);
842 cairo_surface_destroy(output->gl.border.bottom);
843 output->gl.border.bottom = NULL;
844 }
Armin Krezovićb08e1a52016-12-09 22:58:27 +0100845#endif
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600846
Armin Krezović2e662522016-10-09 17:30:29 +0200847 wayland_output_destroy_shm_buffers(output);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600848}
849
850static int
851wayland_output_set_windowed(struct wayland_output *output)
852{
Giulio Camuffo954f1832014-10-11 18:27:30 +0300853 struct wayland_backend *b =
Armin Krezović938dc522016-08-01 19:17:57 +0200854 to_wayland_backend(output->base.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600855
856 if (output->frame)
857 return 0;
858
Giulio Camuffo954f1832014-10-11 18:27:30 +0300859 if (!b->theme) {
860 b->theme = theme_create();
Sergi Granell2dcbb8d2017-03-24 20:48:01 +0100861 if (!b->theme)
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600862 return -1;
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600863 }
Giulio Camuffo954f1832014-10-11 18:27:30 +0300864 output->frame = frame_create(b->theme, 100, 100,
Sergi Granell2dcbb8d2017-03-24 20:48:01 +0100865 FRAME_BUTTON_CLOSE, output->title);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600866 if (!output->frame)
867 return -1;
868
869 if (output->keyboard_count)
870 frame_set_flag(output->frame, FRAME_FLAG_ACTIVE);
871
872 wayland_output_resize_surface(output);
873
Armin Krezović34476192016-11-21 18:42:42 +0100874 if (output->parent.shell_surface)
875 wl_shell_surface_set_toplevel(output->parent.shell_surface);
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600876
877 return 0;
878}
879
880static void
881wayland_output_set_fullscreen(struct wayland_output *output,
882 enum wl_shell_surface_fullscreen_method method,
883 uint32_t framerate, struct wl_output *target)
884{
Giulio Camuffo954f1832014-10-11 18:27:30 +0300885 struct wayland_backend *b =
Armin Krezović938dc522016-08-01 19:17:57 +0200886 to_wayland_backend(output->base.compositor);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500887
Jason Ekstrand5ea04802013-11-07 20:13:33 -0600888 if (output->frame) {
889 frame_destroy(output->frame);
890 output->frame = NULL;
891 }
892
893 wayland_output_resize_surface(output);
894
Armin Krezović34476192016-11-21 18:42:42 +0100895 if (output->parent.xdg_toplevel) {
896 zxdg_toplevel_v6_set_fullscreen(output->parent.xdg_toplevel, target);
897 } else if (output->parent.shell_surface) {
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500898 wl_shell_surface_set_fullscreen(output->parent.shell_surface,
899 method, framerate, target);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300900 } else if (b->parent.fshell) {
Jonas Ådahl496adb32015-11-17 16:00:27 +0800901 zwp_fullscreen_shell_v1_present_surface(b->parent.fshell,
902 output->parent.surface,
903 method, target);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500904 }
905}
906
907static struct weston_mode *
908wayland_output_choose_mode(struct wayland_output *output,
909 struct weston_mode *ref_mode)
910{
911 struct weston_mode *mode;
912
913 /* First look for an exact match */
914 wl_list_for_each(mode, &output->base.mode_list, link)
915 if (mode->width == ref_mode->width &&
916 mode->height == ref_mode->height &&
917 mode->refresh == ref_mode->refresh)
918 return mode;
919
920 /* If we can't find an exact match, ignore refresh and try again */
921 wl_list_for_each(mode, &output->base.mode_list, link)
922 if (mode->width == ref_mode->width &&
923 mode->height == ref_mode->height)
924 return mode;
925
926 /* Yeah, we failed */
927 return NULL;
928}
929
930enum mode_status {
931 MODE_STATUS_UNKNOWN,
932 MODE_STATUS_SUCCESS,
933 MODE_STATUS_FAIL,
934 MODE_STATUS_CANCEL,
935};
936
937static void
938mode_feedback_successful(void *data,
Jonas Ådahl496adb32015-11-17 16:00:27 +0800939 struct zwp_fullscreen_shell_mode_feedback_v1 *fb)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500940{
941 enum mode_status *value = data;
942
943 printf("Mode switch successful\n");
944
945 *value = MODE_STATUS_SUCCESS;
946}
947
948static void
Jonas Ådahl496adb32015-11-17 16:00:27 +0800949mode_feedback_failed(void *data, struct zwp_fullscreen_shell_mode_feedback_v1 *fb)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500950{
951 enum mode_status *value = data;
952
953 printf("Mode switch failed\n");
954
955 *value = MODE_STATUS_FAIL;
956}
957
958static void
Jonas Ådahl496adb32015-11-17 16:00:27 +0800959mode_feedback_cancelled(void *data, struct zwp_fullscreen_shell_mode_feedback_v1 *fb)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500960{
961 enum mode_status *value = data;
962
963 printf("Mode switch cancelled\n");
964
965 *value = MODE_STATUS_CANCEL;
966}
967
Jonas Ådahl496adb32015-11-17 16:00:27 +0800968struct zwp_fullscreen_shell_mode_feedback_v1_listener mode_feedback_listener = {
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500969 mode_feedback_successful,
970 mode_feedback_failed,
971 mode_feedback_cancelled,
972};
973
974static int
975wayland_output_switch_mode(struct weston_output *output_base,
976 struct weston_mode *mode)
977{
Armin Krezović938dc522016-08-01 19:17:57 +0200978 struct wayland_output *output = to_wayland_output(output_base);
Giulio Camuffo954f1832014-10-11 18:27:30 +0300979 struct wayland_backend *b;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500980 struct wl_surface *old_surface;
981 struct weston_mode *old_mode;
Jonas Ådahl496adb32015-11-17 16:00:27 +0800982 struct zwp_fullscreen_shell_mode_feedback_v1 *mode_feedback;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500983 enum mode_status mode_status;
984 int ret = 0;
985
986 if (output_base == NULL) {
987 weston_log("output is NULL.\n");
988 return -1;
989 }
990
991 if (mode == NULL) {
992 weston_log("mode is NULL.\n");
993 return -1;
994 }
995
Armin Krezović938dc522016-08-01 19:17:57 +0200996 b = to_wayland_backend(output_base->compositor);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500997
Armin Krezović34476192016-11-21 18:42:42 +0100998 if (output->parent.xdg_surface || output->parent.shell_surface || !b->parent.fshell)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -0500999 return -1;
1000
1001 mode = wayland_output_choose_mode(output, mode);
1002 if (mode == NULL)
1003 return -1;
1004
1005 if (output->base.current_mode == mode)
1006 return 0;
1007
1008 old_mode = output->base.current_mode;
1009 old_surface = output->parent.surface;
1010 output->base.current_mode = mode;
1011 output->parent.surface =
Giulio Camuffo954f1832014-10-11 18:27:30 +03001012 wl_compositor_create_surface(b->parent.compositor);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001013 wl_surface_set_user_data(output->parent.surface, output);
1014
1015 /* Blow the old buffers because we changed size/surfaces */
1016 wayland_output_resize_surface(output);
1017
1018 mode_feedback =
Jonas Ådahl496adb32015-11-17 16:00:27 +08001019 zwp_fullscreen_shell_v1_present_surface_for_mode(b->parent.fshell,
1020 output->parent.surface,
1021 output->parent.output,
1022 mode->refresh);
1023 zwp_fullscreen_shell_mode_feedback_v1_add_listener(mode_feedback,
1024 &mode_feedback_listener,
1025 &mode_status);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001026
1027 /* This should kick-start things again */
Armin Krezović2d321e32016-10-09 17:30:25 +02001028 output->parent.draw_initial_frame = true;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001029 wayland_output_start_repaint_loop(&output->base);
1030
1031 mode_status = MODE_STATUS_UNKNOWN;
1032 while (mode_status == MODE_STATUS_UNKNOWN && ret >= 0)
Giulio Camuffo954f1832014-10-11 18:27:30 +03001033 ret = wl_display_dispatch(b->parent.wl_display);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001034
Jonas Ådahl496adb32015-11-17 16:00:27 +08001035 zwp_fullscreen_shell_mode_feedback_v1_destroy(mode_feedback);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001036
1037 if (mode_status == MODE_STATUS_FAIL) {
1038 output->base.current_mode = old_mode;
1039 wl_surface_destroy(output->parent.surface);
1040 output->parent.surface = old_surface;
1041 wayland_output_resize_surface(output);
1042
1043 return -1;
1044 }
1045
1046 old_mode->flags &= ~WL_OUTPUT_MODE_CURRENT;
1047 output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
1048
Giulio Camuffo954f1832014-10-11 18:27:30 +03001049 if (b->use_pixman) {
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001050 pixman_renderer_output_destroy(output_base);
1051 if (wayland_output_init_pixman_renderer(output) < 0)
1052 goto err_output;
Armin Krezovićb08e1a52016-12-09 22:58:27 +01001053#ifdef ENABLE_EGL
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001054 } else {
1055 gl_renderer->output_destroy(output_base);
1056 wl_egl_window_destroy(output->gl.egl_window);
1057 if (wayland_output_init_gl_renderer(output) < 0)
1058 goto err_output;
Armin Krezovićb08e1a52016-12-09 22:58:27 +01001059#endif
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001060 }
1061 wl_surface_destroy(old_surface);
1062
1063 weston_output_schedule_repaint(&output->base);
1064
1065 return 0;
1066
1067err_output:
1068 /* XXX */
1069 return -1;
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001070}
1071
Armin Krezović34476192016-11-21 18:42:42 +01001072static void
1073handle_xdg_surface_configure(void *data, struct zxdg_surface_v6 *surface,
1074 uint32_t serial)
1075{
1076 zxdg_surface_v6_ack_configure(surface, serial);
1077}
1078
1079static const struct zxdg_surface_v6_listener xdg_surface_listener = {
1080 handle_xdg_surface_configure
1081};
1082
1083static void
1084handle_xdg_toplevel_configure(void *data, struct zxdg_toplevel_v6 *toplevel,
1085 int32_t width, int32_t height,
1086 struct wl_array *states)
1087{
1088 struct wayland_output *output = data;
1089
1090 output->parent.configure_width = width;
1091 output->parent.configure_height = height;
1092
1093 output->parent.wait_for_configure = false;
1094 /* FIXME: implement resizing */
1095}
1096
1097static void
1098handle_xdg_toplevel_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel)
1099{
1100}
1101
1102static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
1103 handle_xdg_toplevel_configure,
1104 handle_xdg_toplevel_close,
1105};
1106
Armin Krezović174448a2016-09-30 14:11:09 +02001107static int
1108wayland_backend_create_output_surface(struct wayland_output *output)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001109{
Armin Krezović174448a2016-09-30 14:11:09 +02001110 struct wayland_backend *b = to_wayland_backend(output->base.compositor);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001111
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001112 output->parent.surface =
Giulio Camuffo954f1832014-10-11 18:27:30 +03001113 wl_compositor_create_surface(b->parent.compositor);
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001114 if (!output->parent.surface)
Armin Krezović174448a2016-09-30 14:11:09 +02001115 return -1;
1116
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001117 wl_surface_set_user_data(output->parent.surface, output);
1118
Armin Krezović2d321e32016-10-09 17:30:25 +02001119 output->parent.draw_initial_frame = true;
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001120
Armin Krezović34476192016-11-21 18:42:42 +01001121 if (b->parent.xdg_shell) {
1122 output->parent.xdg_surface =
1123 zxdg_shell_v6_get_xdg_surface(b->parent.xdg_shell,
1124 output->parent.surface);
1125 zxdg_surface_v6_add_listener(output->parent.xdg_surface,
1126 &xdg_surface_listener, output);
1127
1128 output->parent.xdg_toplevel =
1129 zxdg_surface_v6_get_toplevel(output->parent.xdg_surface);
1130 zxdg_toplevel_v6_add_listener(output->parent.xdg_toplevel,
1131 &xdg_toplevel_listener, output);
1132
Sergi Granell2dcbb8d2017-03-24 20:48:01 +01001133 zxdg_toplevel_v6_set_title(output->parent.xdg_toplevel, output->title);
1134
Armin Krezović34476192016-11-21 18:42:42 +01001135 wl_surface_commit(output->parent.surface);
1136
1137 output->parent.wait_for_configure = true;
1138
1139 while (output->parent.wait_for_configure)
1140 wl_display_dispatch(b->parent.wl_display);
1141
1142 weston_log("wayland-backend: Using xdg_shell_v6\n");
1143 }
1144 else if (b->parent.shell) {
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001145 output->parent.shell_surface =
Giulio Camuffo954f1832014-10-11 18:27:30 +03001146 wl_shell_get_shell_surface(b->parent.shell,
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001147 output->parent.surface);
Armin Krezović174448a2016-09-30 14:11:09 +02001148 if (!output->parent.shell_surface) {
1149 wl_surface_destroy(output->parent.surface);
1150 return -1;
1151 }
1152
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001153 wl_shell_surface_add_listener(output->parent.shell_surface,
1154 &shell_surface_listener, output);
Armin Krezović34476192016-11-21 18:42:42 +01001155
1156 weston_log("wayland-backend: Using wl_shell\n");
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001157 }
1158
Armin Krezović174448a2016-09-30 14:11:09 +02001159 return 0;
1160}
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001161
Armin Krezović174448a2016-09-30 14:11:09 +02001162static int
1163wayland_output_enable(struct weston_output *base)
1164{
1165 struct wayland_output *output = to_wayland_output(base);
1166 struct wayland_backend *b = to_wayland_backend(base->compositor);
1167 int ret = 0;
1168
Armin Krezović174448a2016-09-30 14:11:09 +02001169 weston_log("Creating %dx%d wayland output at (%d, %d)\n",
1170 output->base.current_mode->width,
1171 output->base.current_mode->height,
1172 output->base.x, output->base.y);
1173
Armin Krezovićf054d352016-10-09 17:30:27 +02001174 if (!output->parent.surface)
Armin Krezović174448a2016-09-30 14:11:09 +02001175 ret = wayland_backend_create_output_surface(output);
1176
1177 if (ret < 0)
1178 return -1;
Kristian Høgsberg546a8122012-02-01 07:45:51 -05001179
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001180 wl_list_init(&output->shm.buffers);
1181 wl_list_init(&output->shm.free_buffers);
1182
Giulio Camuffo954f1832014-10-11 18:27:30 +03001183 if (b->use_pixman) {
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001184 if (wayland_output_init_pixman_renderer(output) < 0)
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001185 goto err_output;
Armin Krezovićf16de172016-10-09 17:30:26 +02001186
1187 output->base.repaint = wayland_output_repaint_pixman;
Armin Krezovićb08e1a52016-12-09 22:58:27 +01001188#ifdef ENABLE_EGL
Jason Ekstrandff2fd462013-10-27 22:24:58 -05001189 } else {
1190 if (wayland_output_init_gl_renderer(output) < 0)
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001191 goto err_output;
Armin Krezovićf16de172016-10-09 17:30:26 +02001192
1193 output->base.repaint = wayland_output_repaint_gl;
Armin Krezovićb08e1a52016-12-09 22:58:27 +01001194#endif
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001195 }
1196
Armin Krezovićf16de172016-10-09 17:30:26 +02001197 output->base.start_repaint_loop = wayland_output_start_repaint_loop;
1198 output->base.assign_planes = NULL;
1199 output->base.set_backlight = NULL;
1200 output->base.set_dpms = NULL;
1201 output->base.switch_mode = wayland_output_switch_mode;
1202
Armin Krezović174448a2016-09-30 14:11:09 +02001203 if (b->sprawl_across_outputs) {
1204 wayland_output_set_fullscreen(output,
1205 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER,
1206 output->mode.refresh, output->parent.output);
1207
Armin Krezović34476192016-11-21 18:42:42 +01001208 if (output->parent.xdg_toplevel) {
1209 zxdg_toplevel_v6_set_fullscreen(output->parent.xdg_toplevel,
1210 output->parent.output);
1211 }
1212 else if (output->parent.shell_surface) {
Armin Krezović174448a2016-09-30 14:11:09 +02001213 wl_shell_surface_set_fullscreen(output->parent.shell_surface,
1214 WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER,
1215 output->mode.refresh, output->parent.output);
1216 } else if (b->parent.fshell) {
1217 zwp_fullscreen_shell_v1_present_surface(b->parent.fshell,
1218 output->parent.surface,
1219 ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_CENTER,
1220 output->parent.output);
1221 zwp_fullscreen_shell_mode_feedback_v1_destroy(
1222 zwp_fullscreen_shell_v1_present_surface_for_mode(b->parent.fshell,
1223 output->parent.surface,
1224 output->parent.output,
1225 output->mode.refresh));
1226 }
1227 } else if (b->fullscreen) {
1228 wayland_output_set_fullscreen(output, 0, 0, NULL);
1229 } else {
1230 wayland_output_set_windowed(output);
1231 }
1232
1233 return 0;
1234
1235err_output:
Armin Krezovićf054d352016-10-09 17:30:27 +02001236 wayland_backend_destroy_output_surface(output);
Armin Krezović174448a2016-09-30 14:11:09 +02001237
1238 return -1;
1239}
1240
1241static struct wayland_output *
Sergi Granell2dcbb8d2017-03-24 20:48:01 +01001242wayland_output_create_common(const char *name)
Armin Krezović174448a2016-09-30 14:11:09 +02001243{
1244 struct wayland_output *output;
Sergi Granell2dcbb8d2017-03-24 20:48:01 +01001245 size_t len;
1246
1247 /* name can't be NULL. */
1248 assert(name);
Armin Krezović174448a2016-09-30 14:11:09 +02001249
1250 output = zalloc(sizeof *output);
1251 if (output == NULL) {
1252 perror("zalloc");
1253 return NULL;
1254 }
1255
Matt Roper361d2ad2011-08-29 13:52:23 -07001256 output->base.destroy = wayland_output_destroy;
Armin Krezović174448a2016-09-30 14:11:09 +02001257 output->base.disable = wayland_output_disable;
1258 output->base.enable = wayland_output_enable;
Sergi Granell2dcbb8d2017-03-24 20:48:01 +01001259 output->base.name = strdup(name);
1260
1261 /* setup output name/title. */
1262 len = strlen(WINDOW_TITLE " - ") + strlen(name) + 1;
1263 output->title = zalloc(len);
1264 if (!output->title) {
1265 free(output->base.name);
1266 free(output);
1267 return NULL;
1268 }
1269
1270 snprintf(output->title, len, WINDOW_TITLE " - %s", name);
Armin Krezović174448a2016-09-30 14:11:09 +02001271
1272 return output;
1273}
1274
1275static int
1276wayland_output_create(struct weston_compositor *compositor, const char *name)
1277{
Sergi Granell2dcbb8d2017-03-24 20:48:01 +01001278 struct wayland_output *output = wayland_output_create_common(name);
Armin Krezović174448a2016-09-30 14:11:09 +02001279
Sergi Granell7fecb432017-03-24 20:48:02 +01001280 if (!output)
1281 return -1;
1282
Armin Krezović40087402016-09-30 14:11:12 +02001283 weston_output_init(&output->base, compositor);
Armin Krezović174448a2016-09-30 14:11:09 +02001284 weston_compositor_add_pending_output(&output->base, compositor);
1285
1286 return 0;
1287}
1288
1289static int
1290wayland_output_set_size(struct weston_output *base, int width, int height)
1291{
1292 struct wayland_output *output = to_wayland_output(base);
Armin Krezović174448a2016-09-30 14:11:09 +02001293 int output_width, output_height;
1294
1295 /* We can only be called once. */
1296 assert(!output->base.current_mode);
1297
1298 /* Make sure we have scale set. */
1299 assert(output->base.scale);
1300
1301 if (width < 1) {
1302 weston_log("Invalid width \"%d\" for output %s\n",
1303 width, output->base.name);
1304 return -1;
1305 }
1306
1307 if (height < 1) {
1308 weston_log("Invalid height \"%d\" for output %s\n",
1309 height, output->base.name);
1310 return -1;
1311 }
1312
1313 output_width = width * output->base.scale;
1314 output_height = height * output->base.scale;
1315
1316 output->mode.flags =
1317 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
1318
1319 output->mode.width = output_width;
1320 output->mode.height = output_height;
1321 output->mode.refresh = 60000;
1322 output->scale = output->base.scale;
1323 wl_list_init(&output->base.mode_list);
1324 wl_list_insert(&output->base.mode_list, &output->mode.link);
1325
1326 output->base.current_mode = &output->mode;
1327 output->base.make = "wayland";
1328 output->base.model = "none";
1329
1330 /* XXX: Calculate proper size. */
1331 output->base.mm_width = width;
1332 output->base.mm_height = height;
1333
Armin Krezović174448a2016-09-30 14:11:09 +02001334 return 0;
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001335}
1336
Armin Krezović174448a2016-09-30 14:11:09 +02001337static int
Giulio Camuffo954f1832014-10-11 18:27:30 +03001338wayland_output_create_for_parent_output(struct wayland_backend *b,
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001339 struct wayland_parent_output *poutput)
1340{
Sergi Granell7fecb432017-03-24 20:48:02 +01001341 struct wayland_output *output;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001342 struct weston_mode *mode;
Armin Krezović174448a2016-09-30 14:11:09 +02001343
Sergi Granell7fecb432017-03-24 20:48:02 +01001344 output = wayland_output_create_common("wlparent");
1345 if (!output)
1346 return -1;
1347
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001348 if (poutput->current_mode) {
1349 mode = poutput->current_mode;
1350 } else if (poutput->preferred_mode) {
U. Artie Eoff67072d02014-05-06 14:50:02 -07001351 mode = poutput->preferred_mode;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001352 } else if (!wl_list_empty(&poutput->mode_list)) {
1353 mode = container_of(poutput->mode_list.next,
1354 struct weston_mode, link);
1355 } else {
Armin Krezović174448a2016-09-30 14:11:09 +02001356 weston_log("No valid modes found. Skipping output.\n");
1357 goto out;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001358 }
1359
Armin Krezović40087402016-09-30 14:11:12 +02001360 weston_output_init(&output->base, b->compositor);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001361
Armin Krezović174448a2016-09-30 14:11:09 +02001362 output->base.scale = 1;
1363 output->base.transform = WL_OUTPUT_TRANSFORM_NORMAL;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001364
Armin Krezović174448a2016-09-30 14:11:09 +02001365 if (wayland_output_set_size(&output->base, mode->width, mode->height) < 0)
1366 goto out;
1367
1368 output->mode = *mode;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001369 output->parent.output = poutput->global;
1370
1371 output->base.make = poutput->physical.make;
1372 output->base.model = poutput->physical.model;
Armin Krezović174448a2016-09-30 14:11:09 +02001373
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001374 wl_list_init(&output->base.mode_list);
1375 wl_list_insert_list(&output->base.mode_list, &poutput->mode_list);
1376 wl_list_init(&poutput->mode_list);
1377
Armin Krezović174448a2016-09-30 14:11:09 +02001378 weston_compositor_add_pending_output(&output->base, b->compositor);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001379
Armin Krezović174448a2016-09-30 14:11:09 +02001380 return 0;
1381
1382out:
Sergi Granell2dcbb8d2017-03-24 20:48:01 +01001383 free(output->base.name);
1384 free(output->title);
Armin Krezović174448a2016-09-30 14:11:09 +02001385 free(output);
1386
1387 return -1;
1388}
1389
1390static int
1391wayland_output_create_fullscreen(struct wayland_backend *b)
1392{
Sergi Granell7fecb432017-03-24 20:48:02 +01001393 struct wayland_output *output;
Armin Krezović174448a2016-09-30 14:11:09 +02001394 int width = 0, height = 0;
1395
Sergi Granell7fecb432017-03-24 20:48:02 +01001396 output = wayland_output_create_common("wayland-fullscreen");
1397 if (!output)
1398 return -1;
1399
Armin Krezović40087402016-09-30 14:11:12 +02001400 weston_output_init(&output->base, b->compositor);
Armin Krezović174448a2016-09-30 14:11:09 +02001401
1402 output->base.scale = 1;
1403 output->base.transform = WL_OUTPUT_TRANSFORM_NORMAL;
1404
1405 if (wayland_backend_create_output_surface(output) < 0)
1406 goto err_surface;
1407
1408 /* What should size be set if conditional is false? */
Armin Krezović34476192016-11-21 18:42:42 +01001409 if (b->parent.xdg_shell || b->parent.shell) {
1410 if (output->parent.xdg_toplevel)
1411 zxdg_toplevel_v6_set_fullscreen(output->parent.xdg_toplevel,
1412 output->parent.output);
1413 else if (output->parent.shell_surface)
1414 wl_shell_surface_set_fullscreen(output->parent.shell_surface,
1415 0, 0, NULL);
1416
Armin Krezović174448a2016-09-30 14:11:09 +02001417 wl_display_roundtrip(b->parent.wl_display);
1418
1419 width = output->parent.configure_width;
1420 height = output->parent.configure_height;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001421 }
1422
Armin Krezović174448a2016-09-30 14:11:09 +02001423 if (wayland_output_set_size(&output->base, width, height) < 0)
1424 goto err_set_size;
1425
1426 weston_compositor_add_pending_output(&output->base, b->compositor);
1427
1428 return 0;
1429
1430err_set_size:
1431 wayland_backend_destroy_output_surface(output);
1432err_surface:
Sergi Granell2dcbb8d2017-03-24 20:48:01 +01001433 free(output->base.name);
1434 free(output->title);
Armin Krezović174448a2016-09-30 14:11:09 +02001435 free(output);
1436
1437 return -1;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05001438}
1439
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +03001440static void
1441shell_surface_ping(void *data, struct wl_shell_surface *shell_surface,
1442 uint32_t serial)
1443{
1444 wl_shell_surface_pong(shell_surface, serial);
1445}
1446
1447static void
1448shell_surface_configure(void *data, struct wl_shell_surface *shell_surface,
1449 uint32_t edges, int32_t width, int32_t height)
1450{
Jason Ekstrand5ea04802013-11-07 20:13:33 -06001451 struct wayland_output *output = data;
1452
1453 output->parent.configure_width = width;
1454 output->parent.configure_height = height;
1455
Ander Conselvan de Oliveira563c5b82012-06-18 17:36:21 +03001456 /* FIXME: implement resizing */
1457}
1458
1459static void
1460shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface)
1461{
1462}
1463
1464static const struct wl_shell_surface_listener shell_surface_listener = {
1465 shell_surface_ping,
1466 shell_surface_configure,
1467 shell_surface_popup_done
1468};
1469
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001470/* Events received from the wayland-server this compositor is client of: */
1471
Jason Ekstrand7744f712013-10-27 22:24:55 -05001472/* parent input interface */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001473static void
Jason Ekstrand7744f712013-10-27 22:24:55 -05001474input_set_cursor(struct wayland_input *input)
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001475{
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001476
Jason Ekstrand7744f712013-10-27 22:24:55 -05001477 struct wl_buffer *buffer;
1478 struct wl_cursor_image *image;
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001479
Giulio Camuffo954f1832014-10-11 18:27:30 +03001480 if (!input->backend->cursor)
Jason Ekstrand7744f712013-10-27 22:24:55 -05001481 return; /* Couldn't load the cursor. Can't set it */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001482
Giulio Camuffo954f1832014-10-11 18:27:30 +03001483 image = input->backend->cursor->images[0];
Jason Ekstrand7744f712013-10-27 22:24:55 -05001484 buffer = wl_cursor_image_get_buffer(image);
Hardening842a36a2014-03-18 14:12:50 +01001485 if (!buffer)
1486 return;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001487
1488 wl_pointer_set_cursor(input->parent.pointer, input->enter_serial,
1489 input->parent.cursor.surface,
1490 image->hotspot_x, image->hotspot_y);
1491
1492 wl_surface_attach(input->parent.cursor.surface, buffer, 0, 0);
1493 wl_surface_damage(input->parent.cursor.surface, 0, 0,
1494 image->width, image->height);
1495 wl_surface_commit(input->parent.cursor.surface);
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001496}
1497
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001498static void
Daniel Stone37816df2012-05-16 18:45:18 +01001499input_handle_pointer_enter(void *data, struct wl_pointer *pointer,
1500 uint32_t serial, struct wl_surface *surface,
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001501 wl_fixed_t fixed_x, wl_fixed_t fixed_y)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001502{
1503 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001504 int32_t fx, fy;
1505 enum theme_location location;
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001506 double x, y;
1507
1508 x = wl_fixed_to_double(fixed_x);
1509 y = wl_fixed_to_double(fixed_y);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001510
Daniel Stone50692802012-06-22 13:21:41 +01001511 /* XXX: If we get a modifier event immediately before the focus,
1512 * we should try to keep the same serial. */
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001513 input->enter_serial = serial;
1514 input->output = wl_surface_get_user_data(surface);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001515
1516 if (input->output->frame) {
1517 location = frame_pointer_enter(input->output->frame, input,
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001518 x, y);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001519 frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001520 x -= fx;
1521 y -= fy;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001522
1523 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
1524 weston_output_schedule_repaint(&input->output->base);
1525 } else {
1526 location = THEME_LOCATION_CLIENT_AREA;
1527 }
1528
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001529 weston_output_transform_coordinate(&input->output->base, x, y, &x, &y);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001530
1531 if (location == THEME_LOCATION_CLIENT_AREA) {
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001532 input->has_focus = true;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001533 notify_pointer_focus(&input->base, &input->output->base, x, y);
1534 wl_pointer_set_cursor(input->parent.pointer,
1535 input->enter_serial, NULL, 0, 0);
1536 } else {
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001537 input->has_focus = false;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001538 notify_pointer_focus(&input->base, NULL, 0, 0);
1539 input_set_cursor(input);
1540 }
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001541}
1542
1543static void
Daniel Stone37816df2012-05-16 18:45:18 +01001544input_handle_pointer_leave(void *data, struct wl_pointer *pointer,
1545 uint32_t serial, struct wl_surface *surface)
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001546{
1547 struct wayland_input *input = data;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001548
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001549 if (!input->output)
1550 return;
1551
Jason Ekstrand7744f712013-10-27 22:24:55 -05001552 if (input->output->frame) {
1553 frame_pointer_leave(input->output->frame, input);
1554
1555 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
1556 weston_output_schedule_repaint(&input->output->base);
1557 }
1558
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001559 notify_pointer_focus(&input->base, NULL, 0, 0);
Kristian Høgsberg539d85f2012-08-13 23:29:53 -04001560 input->output = NULL;
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001561 input->has_focus = false;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001562}
1563
1564static void
Daniel Stone37816df2012-05-16 18:45:18 +01001565input_handle_motion(void *data, struct wl_pointer *pointer,
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001566 uint32_t time, wl_fixed_t fixed_x, wl_fixed_t fixed_y)
Daniel Stone37816df2012-05-16 18:45:18 +01001567{
1568 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001569 int32_t fx, fy;
1570 enum theme_location location;
Peter Hutterer87743e92016-01-18 16:38:22 +10001571 bool want_frame = false;
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001572 double x, y;
Daniel Stone37816df2012-05-16 18:45:18 +01001573
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001574 if (!input->output)
1575 return;
1576
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001577 x = wl_fixed_to_double(fixed_x);
1578 y = wl_fixed_to_double(fixed_y);
1579
Jason Ekstrand7744f712013-10-27 22:24:55 -05001580 if (input->output->frame) {
1581 location = frame_pointer_motion(input->output->frame, input,
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001582 x, y);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001583 frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001584 x -= fx;
1585 y -= fy;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001586
1587 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
1588 weston_output_schedule_repaint(&input->output->base);
1589 } else {
1590 location = THEME_LOCATION_CLIENT_AREA;
1591 }
1592
Jason Ekstrand48ce4212013-10-27 22:25:02 -05001593 weston_output_transform_coordinate(&input->output->base, x, y, &x, &y);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001594
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001595 if (input->has_focus && location != THEME_LOCATION_CLIENT_AREA) {
Jason Ekstrand7744f712013-10-27 22:24:55 -05001596 input_set_cursor(input);
1597 notify_pointer_focus(&input->base, NULL, 0, 0);
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001598 input->has_focus = false;
Peter Hutterer87743e92016-01-18 16:38:22 +10001599 want_frame = true;
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001600 } else if (!input->has_focus &&
1601 location == THEME_LOCATION_CLIENT_AREA) {
Jason Ekstrand7744f712013-10-27 22:24:55 -05001602 wl_pointer_set_cursor(input->parent.pointer,
1603 input->enter_serial, NULL, 0, 0);
1604 notify_pointer_focus(&input->base, &input->output->base, x, y);
Derek Foreman4bcc54d2015-11-06 15:56:06 -06001605 input->has_focus = true;
Peter Hutterer87743e92016-01-18 16:38:22 +10001606 want_frame = true;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001607 }
1608
Peter Hutterer87743e92016-01-18 16:38:22 +10001609 if (location == THEME_LOCATION_CLIENT_AREA) {
Jason Ekstrand7744f712013-10-27 22:24:55 -05001610 notify_motion_absolute(&input->base, time, x, y);
Peter Hutterer87743e92016-01-18 16:38:22 +10001611 want_frame = true;
1612 }
1613
1614 if (want_frame && input->seat_version < WL_POINTER_FRAME_SINCE_VERSION)
1615 notify_pointer_frame(&input->base);
Daniel Stone37816df2012-05-16 18:45:18 +01001616}
1617
1618static void
1619input_handle_button(void *data, struct wl_pointer *pointer,
Daniel Stone4dbadb12012-05-30 16:31:51 +01001620 uint32_t serial, uint32_t time, uint32_t button,
Quentin Glidicd8b17bc2016-07-10 11:00:55 +02001621 enum wl_pointer_button_state state)
Daniel Stone37816df2012-05-16 18:45:18 +01001622{
1623 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001624 enum theme_location location;
Daniel Stone37816df2012-05-16 18:45:18 +01001625
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001626 if (!input->output)
1627 return;
1628
Jason Ekstrand7744f712013-10-27 22:24:55 -05001629 if (input->output->frame) {
Jason Ekstrand7744f712013-10-27 22:24:55 -05001630 location = frame_pointer_button(input->output->frame, input,
Quentin Glidicd8b17bc2016-07-10 11:00:55 +02001631 button, state);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001632
1633 if (frame_status(input->output->frame) & FRAME_STATUS_MOVE) {
Armin Krezović34476192016-11-21 18:42:42 +01001634 if (input->output->parent.xdg_toplevel)
1635 zxdg_toplevel_v6_move(input->output->parent.xdg_toplevel,
Jason Ekstrand7744f712013-10-27 22:24:55 -05001636 input->parent.seat, serial);
Armin Krezović34476192016-11-21 18:42:42 +01001637 else if (input->output->parent.shell_surface)
1638 wl_shell_surface_move(input->output->parent.shell_surface,
1639 input->parent.seat, serial);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001640 frame_status_clear(input->output->frame,
1641 FRAME_STATUS_MOVE);
1642 return;
1643 }
1644
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001645 if (frame_status(input->output->frame) & FRAME_STATUS_CLOSE) {
1646 wayland_output_destroy(&input->output->base);
Dima Ryazanovb7e70af2015-05-20 01:03:53 -07001647 input->output = NULL;
1648 input->keyboard_focus = NULL;
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001649
Giulio Camuffo954f1832014-10-11 18:27:30 +03001650 if (wl_list_empty(&input->backend->compositor->output_list))
Giulio Camuffo459137b2014-10-11 23:56:24 +03001651 weston_compositor_exit(input->backend->compositor);
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001652
1653 return;
1654 }
Jason Ekstrand7744f712013-10-27 22:24:55 -05001655
1656 if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
1657 weston_output_schedule_repaint(&input->output->base);
1658 } else {
1659 location = THEME_LOCATION_CLIENT_AREA;
1660 }
1661
Peter Hutterer87743e92016-01-18 16:38:22 +10001662 if (location == THEME_LOCATION_CLIENT_AREA) {
Jason Ekstrand7744f712013-10-27 22:24:55 -05001663 notify_button(&input->base, time, button, state);
Peter Hutterer87743e92016-01-18 16:38:22 +10001664 if (input->seat_version < WL_POINTER_FRAME_SINCE_VERSION)
1665 notify_pointer_frame(&input->base);
1666 }
Daniel Stone37816df2012-05-16 18:45:18 +01001667}
1668
1669static void
1670input_handle_axis(void *data, struct wl_pointer *pointer,
Daniel Stone2fce4022012-05-30 16:32:00 +01001671 uint32_t time, uint32_t axis, wl_fixed_t value)
Daniel Stone37816df2012-05-16 18:45:18 +01001672{
1673 struct wayland_input *input = data;
Peter Hutterer89b6a492016-01-18 15:58:17 +10001674 struct weston_pointer_axis_event weston_event;
Daniel Stone37816df2012-05-16 18:45:18 +01001675
Peter Hutterer89b6a492016-01-18 15:58:17 +10001676 weston_event.axis = axis;
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001677 weston_event.value = wl_fixed_to_double(value);
Peter Hutterer89b6a492016-01-18 15:58:17 +10001678
Peter Hutterer87743e92016-01-18 16:38:22 +10001679 if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL &&
1680 input->vert.has_discrete) {
1681 weston_event.has_discrete = true;
1682 weston_event.discrete = input->vert.discrete;
1683 input->vert.has_discrete = false;
1684 } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL &&
1685 input->horiz.has_discrete) {
1686 weston_event.has_discrete = true;
1687 weston_event.discrete = input->horiz.discrete;
1688 input->horiz.has_discrete = false;
1689 }
1690
Peter Hutterer89b6a492016-01-18 15:58:17 +10001691 notify_axis(&input->base, time, &weston_event);
Peter Hutterer87743e92016-01-18 16:38:22 +10001692
1693 if (input->seat_version < WL_POINTER_FRAME_SINCE_VERSION)
1694 notify_pointer_frame(&input->base);
1695}
1696
1697static void
1698input_handle_frame(void *data, struct wl_pointer *pointer)
1699{
1700 struct wayland_input *input = data;
1701
1702 notify_pointer_frame(&input->base);
1703}
1704
1705static void
1706input_handle_axis_source(void *data, struct wl_pointer *pointer,
1707 uint32_t source)
1708{
1709 struct wayland_input *input = data;
1710
1711 notify_axis_source(&input->base, source);
1712}
1713
1714static void
1715input_handle_axis_stop(void *data, struct wl_pointer *pointer,
1716 uint32_t time, uint32_t axis)
1717{
1718 struct wayland_input *input = data;
1719 struct weston_pointer_axis_event weston_event;
1720
1721 weston_event.axis = axis;
1722 weston_event.value = 0;
1723
1724 notify_axis(&input->base, time, &weston_event);
1725}
1726
1727static void
1728input_handle_axis_discrete(void *data, struct wl_pointer *pointer,
1729 uint32_t axis, int32_t discrete)
1730{
1731 struct wayland_input *input = data;
1732
1733 if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
1734 input->vert.has_discrete = true;
1735 input->vert.discrete = discrete;
1736 } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
1737 input->horiz.has_discrete = true;
1738 input->horiz.discrete = discrete;
1739 }
Daniel Stone37816df2012-05-16 18:45:18 +01001740}
1741
1742static const struct wl_pointer_listener pointer_listener = {
1743 input_handle_pointer_enter,
1744 input_handle_pointer_leave,
1745 input_handle_motion,
1746 input_handle_button,
1747 input_handle_axis,
Peter Hutterer87743e92016-01-18 16:38:22 +10001748 input_handle_frame,
1749 input_handle_axis_source,
1750 input_handle_axis_stop,
1751 input_handle_axis_discrete,
Daniel Stone37816df2012-05-16 18:45:18 +01001752};
1753
1754static void
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001755input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
1756 int fd, uint32_t size)
1757{
1758 struct wayland_input *input = data;
1759 struct xkb_keymap *keymap;
1760 char *map_str;
1761
U. Artie Eoffd8d47012014-05-06 14:50:03 -07001762 if (!data) {
1763 close(fd);
1764 return;
1765 }
Jason Ekstrandb7d9f2e2014-04-02 19:53:57 -05001766
1767 if (format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
1768 map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
1769 if (map_str == MAP_FAILED) {
1770 weston_log("mmap failed: %m\n");
1771 goto error;
1772 }
1773
Giulio Camuffo954f1832014-10-11 18:27:30 +03001774 keymap = xkb_keymap_new_from_string(input->backend->compositor->xkb_context,
Ran Benita2e1968f2014-08-19 23:59:51 +03001775 map_str,
1776 XKB_KEYMAP_FORMAT_TEXT_V1,
1777 0);
Jason Ekstrandb7d9f2e2014-04-02 19:53:57 -05001778 munmap(map_str, size);
1779
1780 if (!keymap) {
1781 weston_log("failed to compile keymap\n");
1782 goto error;
1783 }
1784
1785 input->keyboard_state_update = STATE_UPDATE_NONE;
1786 } else if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP) {
1787 weston_log("No keymap provided; falling back to defalt\n");
1788 keymap = NULL;
1789 input->keyboard_state_update = STATE_UPDATE_AUTOMATIC;
1790 } else {
1791 weston_log("Invalid keymap\n");
1792 goto error;
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001793 }
1794
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001795 close(fd);
1796
Derek Foreman1281a362015-07-31 16:55:32 -05001797 if (weston_seat_get_keyboard(&input->base))
Rui Matos0c194ce2013-10-10 19:44:21 +02001798 weston_seat_update_keymap(&input->base, keymap);
1799 else
1800 weston_seat_init_keyboard(&input->base, keymap);
1801
Ran Benitac9c74152014-08-19 23:59:52 +03001802 xkb_keymap_unref(keymap);
Jason Ekstrandb7d9f2e2014-04-02 19:53:57 -05001803
1804 return;
1805
1806error:
1807 wl_keyboard_release(input->parent.keyboard);
1808 close(fd);
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001809}
1810
1811static void
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001812input_handle_keyboard_enter(void *data,
Daniel Stone37816df2012-05-16 18:45:18 +01001813 struct wl_keyboard *keyboard,
1814 uint32_t serial,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001815 struct wl_surface *surface,
1816 struct wl_array *keys)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001817{
Kristian Høgsbergaf82bea2011-01-27 20:18:17 -05001818 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001819 struct wayland_output *focus;
1820
1821 focus = input->keyboard_focus;
1822 if (focus) {
1823 /* This shouldn't happen */
1824 focus->keyboard_count--;
1825 if (!focus->keyboard_count && focus->frame)
1826 frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE);
1827 if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
1828 weston_output_schedule_repaint(&focus->base);
1829 }
1830
1831 input->keyboard_focus = wl_surface_get_user_data(surface);
1832 input->keyboard_focus->keyboard_count++;
1833
1834 focus = input->keyboard_focus;
1835 if (focus->frame) {
1836 frame_set_flag(focus->frame, FRAME_FLAG_ACTIVE);
1837 if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
1838 weston_output_schedule_repaint(&focus->base);
1839 }
1840
Kristian Høgsbergaf82bea2011-01-27 20:18:17 -05001841
Daniel Stone50692802012-06-22 13:21:41 +01001842 /* XXX: If we get a modifier event immediately before the focus,
1843 * we should try to keep the same serial. */
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001844 notify_keyboard_focus_in(&input->base, keys,
Daniel Stoned6da09e2012-06-22 13:21:29 +01001845 STATE_UPDATE_AUTOMATIC);
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001846}
1847
1848static void
1849input_handle_keyboard_leave(void *data,
Daniel Stone37816df2012-05-16 18:45:18 +01001850 struct wl_keyboard *keyboard,
1851 uint32_t serial,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001852 struct wl_surface *surface)
1853{
1854 struct wayland_input *input = data;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001855 struct wayland_output *focus;
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001856
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001857 notify_keyboard_focus_out(&input->base);
Jason Ekstrand7744f712013-10-27 22:24:55 -05001858
1859 focus = input->keyboard_focus;
1860 if (!focus)
Dima Ryazanov01d5c022015-05-18 23:14:16 -07001861 return;
Jason Ekstrand7744f712013-10-27 22:24:55 -05001862
1863 focus->keyboard_count--;
1864 if (!focus->keyboard_count && focus->frame) {
1865 frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE);
1866 if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
1867 weston_output_schedule_repaint(&focus->base);
1868 }
1869
1870 input->keyboard_focus = NULL;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001871}
1872
Daniel Stone37816df2012-05-16 18:45:18 +01001873static void
1874input_handle_key(void *data, struct wl_keyboard *keyboard,
1875 uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
1876{
1877 struct wayland_input *input = data;
Daniel Stone37816df2012-05-16 18:45:18 +01001878
Daniel Stone50692802012-06-22 13:21:41 +01001879 input->key_serial = serial;
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001880 notify_key(&input->base, time, key,
Daniel Stonec9785ea2012-05-30 16:31:52 +01001881 state ? WL_KEYBOARD_KEY_STATE_PRESSED :
Daniel Stone1b4e11f2012-06-22 13:21:37 +01001882 WL_KEYBOARD_KEY_STATE_RELEASED,
Jason Ekstrandb7d9f2e2014-04-02 19:53:57 -05001883 input->keyboard_state_update);
Daniel Stone37816df2012-05-16 18:45:18 +01001884}
1885
Daniel Stone351eb612012-05-31 15:27:47 -04001886static void
Derek Foreman1281a362015-07-31 16:55:32 -05001887input_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard,
Daniel Stone50692802012-06-22 13:21:41 +01001888 uint32_t serial_in, uint32_t mods_depressed,
Daniel Stone351eb612012-05-31 15:27:47 -04001889 uint32_t mods_latched, uint32_t mods_locked,
1890 uint32_t group)
1891{
Derek Foreman1281a362015-07-31 16:55:32 -05001892 struct weston_keyboard *keyboard;
Daniel Stone50692802012-06-22 13:21:41 +01001893 struct wayland_input *input = data;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001894 struct wayland_backend *b = input->backend;
Daniel Stone50692802012-06-22 13:21:41 +01001895 uint32_t serial_out;
1896
1897 /* If we get a key event followed by a modifier event with the
1898 * same serial number, then we try to preserve those semantics by
1899 * reusing the same serial number on the way out too. */
1900 if (serial_in == input->key_serial)
Giulio Camuffo954f1832014-10-11 18:27:30 +03001901 serial_out = wl_display_get_serial(b->compositor->wl_display);
Daniel Stone50692802012-06-22 13:21:41 +01001902 else
Giulio Camuffo954f1832014-10-11 18:27:30 +03001903 serial_out = wl_display_next_serial(b->compositor->wl_display);
Daniel Stone50692802012-06-22 13:21:41 +01001904
Derek Foreman1281a362015-07-31 16:55:32 -05001905 keyboard = weston_seat_get_keyboard(&input->base);
1906 xkb_state_update_mask(keyboard->xkb_state.state,
Daniel Stone50692802012-06-22 13:21:41 +01001907 mods_depressed, mods_latched,
1908 mods_locked, 0, 0, group);
Kristian Høgsbergcb3eaae2012-08-10 09:50:11 -04001909 notify_modifiers(&input->base, serial_out);
Daniel Stone351eb612012-05-31 15:27:47 -04001910}
1911
Jonny Lamb497994a2014-08-12 14:58:26 +02001912static void
1913input_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
1914 int32_t rate, int32_t delay)
1915{
1916 struct wayland_input *input = data;
Giulio Camuffo954f1832014-10-11 18:27:30 +03001917 struct wayland_backend *b = input->backend;
Jonny Lamb497994a2014-08-12 14:58:26 +02001918
Giulio Camuffo954f1832014-10-11 18:27:30 +03001919 b->compositor->kb_repeat_rate = rate;
1920 b->compositor->kb_repeat_delay = delay;
Jonny Lamb497994a2014-08-12 14:58:26 +02001921}
1922
Daniel Stone37816df2012-05-16 18:45:18 +01001923static const struct wl_keyboard_listener keyboard_listener = {
Daniel Stoneb7452fe2012-06-01 12:14:06 +01001924 input_handle_keymap,
Kristian Høgsberg06d58b72012-02-23 09:59:05 -05001925 input_handle_keyboard_enter,
1926 input_handle_keyboard_leave,
Daniel Stone37816df2012-05-16 18:45:18 +01001927 input_handle_key,
Daniel Stone351eb612012-05-31 15:27:47 -04001928 input_handle_modifiers,
Jonny Lamb497994a2014-08-12 14:58:26 +02001929 input_handle_repeat_info,
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01001930};
1931
1932static void
Derek Foreman748c6952015-11-06 15:56:10 -06001933input_handle_touch_down(void *data, struct wl_touch *wl_touch,
1934 uint32_t serial, uint32_t time,
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001935 struct wl_surface *surface, int32_t id,
1936 wl_fixed_t fixed_x, wl_fixed_t fixed_y)
Derek Foreman748c6952015-11-06 15:56:10 -06001937{
1938 struct wayland_input *input = data;
1939 struct wayland_output *output;
1940 enum theme_location location;
1941 bool first_touch;
1942 int32_t fx, fy;
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001943 double x, y;
1944
1945 x = wl_fixed_to_double(fixed_x);
1946 y = wl_fixed_to_double(fixed_y);
Derek Foreman748c6952015-11-06 15:56:10 -06001947
1948 first_touch = (input->touch_points == 0);
1949 input->touch_points++;
1950
1951 input->touch_focus = wl_surface_get_user_data(surface);
1952 output = input->touch_focus;
1953 if (!first_touch && !input->touch_active)
1954 return;
1955
1956 if (output->frame) {
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001957 location = frame_touch_down(output->frame, input, id, x, y);
Derek Foreman748c6952015-11-06 15:56:10 -06001958
1959 frame_interior(output->frame, &fx, &fy, NULL, NULL);
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02001960 x -= fx;
1961 y -= fy;
Derek Foreman748c6952015-11-06 15:56:10 -06001962
1963 if (frame_status(output->frame) & FRAME_STATUS_REPAINT)
1964 weston_output_schedule_repaint(&output->base);
1965
1966 if (first_touch && (frame_status(output->frame) & FRAME_STATUS_MOVE)) {
1967 input->touch_points--;
Armin Krezović34476192016-11-21 18:42:42 +01001968 if (output->parent.xdg_toplevel)
1969 zxdg_toplevel_v6_move(output->parent.xdg_toplevel,
1970 input->parent.seat, serial);
1971 else if (output->parent.shell_surface)
1972 wl_shell_surface_move(output->parent.shell_surface,
1973 input->parent.seat, serial);
Derek Foreman748c6952015-11-06 15:56:10 -06001974 frame_status_clear(output->frame,
1975 FRAME_STATUS_MOVE);
1976 return;
1977 }
1978
1979 if (first_touch && location != THEME_LOCATION_CLIENT_AREA)
1980 return;
1981 }
1982
1983 weston_output_transform_coordinate(&output->base, x, y, &x, &y);
1984
1985 notify_touch(&input->base, time, id, x, y, WL_TOUCH_DOWN);
1986 input->touch_active = true;
1987}
1988
1989static void
1990input_handle_touch_up(void *data, struct wl_touch *wl_touch,
1991 uint32_t serial, uint32_t time, int32_t id)
1992{
1993 struct wayland_input *input = data;
1994 struct wayland_output *output = input->touch_focus;
1995 bool active = input->touch_active;
1996
1997 input->touch_points--;
1998 if (input->touch_points == 0) {
1999 input->touch_focus = NULL;
2000 input->touch_active = false;
2001 }
2002
2003 if (!output)
2004 return;
2005
2006 if (output->frame) {
2007 frame_touch_up(output->frame, input, id);
2008
2009 if (frame_status(output->frame) & FRAME_STATUS_CLOSE) {
2010 wayland_output_destroy(&output->base);
2011 input->touch_focus = NULL;
2012 input->keyboard_focus = NULL;
2013 if (wl_list_empty(&input->backend->compositor->output_list))
2014 weston_compositor_exit(input->backend->compositor);
2015
2016 return;
2017 }
2018 if (frame_status(output->frame) & FRAME_STATUS_REPAINT)
2019 weston_output_schedule_repaint(&output->base);
2020 }
2021
2022 if (active)
2023 notify_touch(&input->base, time, id, 0, 0, WL_TOUCH_UP);
2024}
2025
2026static void
2027input_handle_touch_motion(void *data, struct wl_touch *wl_touch,
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02002028 uint32_t time, int32_t id,
2029 wl_fixed_t fixed_x, wl_fixed_t fixed_y)
Derek Foreman748c6952015-11-06 15:56:10 -06002030{
2031 struct wayland_input *input = data;
2032 struct wayland_output *output = input->touch_focus;
2033 int32_t fx, fy;
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02002034 double x, y;
2035
2036 x = wl_fixed_to_double(fixed_x);
2037 y = wl_fixed_to_double(fixed_y);
Derek Foreman748c6952015-11-06 15:56:10 -06002038
2039 if (!output || !input->touch_active)
2040 return;
2041
2042 if (output->frame) {
2043 frame_interior(output->frame, &fx, &fy, NULL, NULL);
Giulio Camuffo90a6fc62016-03-22 17:44:54 +02002044 x -= fx;
2045 y -= fy;
Derek Foreman748c6952015-11-06 15:56:10 -06002046 }
2047
2048 weston_output_transform_coordinate(&output->base, x, y, &x, &y);
2049
2050 notify_touch(&input->base, time, id, x, y, WL_TOUCH_MOTION);
2051}
2052
2053static void
2054input_handle_touch_frame(void *data, struct wl_touch *wl_touch)
2055{
2056 struct wayland_input *input = data;
2057
2058 if (!input->touch_focus || !input->touch_active)
2059 return;
2060
2061 notify_touch_frame(&input->base);
2062}
2063
2064static void
2065input_handle_touch_cancel(void *data, struct wl_touch *wl_touch)
2066{
2067 struct wayland_input *input = data;
2068
2069 if (!input->touch_focus || !input->touch_active)
2070 return;
2071
2072 notify_touch_cancel(&input->base);
2073}
2074
2075static const struct wl_touch_listener touch_listener = {
2076 input_handle_touch_down,
2077 input_handle_touch_up,
2078 input_handle_touch_motion,
2079 input_handle_touch_frame,
2080 input_handle_touch_cancel,
2081};
2082
2083
2084static void
Daniel Stone37816df2012-05-16 18:45:18 +01002085input_handle_capabilities(void *data, struct wl_seat *seat,
2086 enum wl_seat_capability caps)
2087{
2088 struct wayland_input *input = data;
2089
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05002090 if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->parent.pointer) {
2091 input->parent.pointer = wl_seat_get_pointer(seat);
2092 wl_pointer_set_user_data(input->parent.pointer, input);
2093 wl_pointer_add_listener(input->parent.pointer,
2094 &pointer_listener, input);
Kristian Høgsberg7af7ced2012-08-10 10:01:33 -04002095 weston_seat_init_pointer(&input->base);
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05002096 } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->parent.pointer) {
Derek Foremancfce7d02015-11-06 15:56:08 -06002097 if (input->seat_version >= WL_POINTER_RELEASE_SINCE_VERSION)
2098 wl_pointer_release(input->parent.pointer);
2099 else
2100 wl_pointer_destroy(input->parent.pointer);
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05002101 input->parent.pointer = NULL;
Derek Foremancfce7d02015-11-06 15:56:08 -06002102 weston_seat_release_pointer(&input->base);
Daniel Stone37816df2012-05-16 18:45:18 +01002103 }
2104
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05002105 if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->parent.keyboard) {
2106 input->parent.keyboard = wl_seat_get_keyboard(seat);
2107 wl_keyboard_set_user_data(input->parent.keyboard, input);
2108 wl_keyboard_add_listener(input->parent.keyboard,
2109 &keyboard_listener, input);
2110 } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->parent.keyboard) {
Derek Foremancfce7d02015-11-06 15:56:08 -06002111 if (input->seat_version >= WL_KEYBOARD_RELEASE_SINCE_VERSION)
2112 wl_keyboard_release(input->parent.keyboard);
2113 else
2114 wl_keyboard_destroy(input->parent.keyboard);
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05002115 input->parent.keyboard = NULL;
Derek Foremancfce7d02015-11-06 15:56:08 -06002116 weston_seat_release_keyboard(&input->base);
Daniel Stone37816df2012-05-16 18:45:18 +01002117 }
Derek Foreman748c6952015-11-06 15:56:10 -06002118
2119 if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->parent.touch) {
2120 input->parent.touch = wl_seat_get_touch(seat);
2121 wl_touch_set_user_data(input->parent.touch, input);
2122 wl_touch_add_listener(input->parent.touch,
2123 &touch_listener, input);
2124 weston_seat_init_touch(&input->base);
2125 } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->parent.touch) {
2126 if (input->seat_version >= WL_TOUCH_RELEASE_SINCE_VERSION)
2127 wl_touch_release(input->parent.touch);
2128 else
2129 wl_touch_destroy(input->parent.touch);
2130 input->parent.touch = NULL;
2131 weston_seat_release_touch(&input->base);
2132 }
Daniel Stone37816df2012-05-16 18:45:18 +01002133}
2134
Jonny Lamb497994a2014-08-12 14:58:26 +02002135static void
2136input_handle_name(void *data, struct wl_seat *seat,
2137 const char *name)
2138{
2139}
2140
Daniel Stone37816df2012-05-16 18:45:18 +01002141static const struct wl_seat_listener seat_listener = {
2142 input_handle_capabilities,
Jonny Lamb497994a2014-08-12 14:58:26 +02002143 input_handle_name,
Daniel Stone37816df2012-05-16 18:45:18 +01002144};
2145
2146static void
Derek Foremancfce7d02015-11-06 15:56:08 -06002147display_add_seat(struct wayland_backend *b, uint32_t id, uint32_t available_version)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002148{
2149 struct wayland_input *input;
Derek Foremancfce7d02015-11-06 15:56:08 -06002150 uint32_t version = MIN(available_version, 4);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002151
Peter Huttererf3d62272013-08-08 11:57:05 +10002152 input = zalloc(sizeof *input);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002153 if (input == NULL)
2154 return;
2155
Giulio Camuffo954f1832014-10-11 18:27:30 +03002156 weston_seat_init(&input->base, b->compositor, "default");
2157 input->backend = b;
2158 input->parent.seat = wl_registry_bind(b->parent.registry, id,
Derek Foremancfce7d02015-11-06 15:56:08 -06002159 &wl_seat_interface, version);
2160 input->seat_version = version;
Giulio Camuffo954f1832014-10-11 18:27:30 +03002161 wl_list_insert(b->input_list.prev, &input->link);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002162
Jason Ekstrand8f89fcb2013-10-27 22:24:53 -05002163 wl_seat_add_listener(input->parent.seat, &seat_listener, input);
2164 wl_seat_set_user_data(input->parent.seat, input);
Jason Ekstrand7744f712013-10-27 22:24:55 -05002165
2166 input->parent.cursor.surface =
Giulio Camuffo954f1832014-10-11 18:27:30 +03002167 wl_compositor_create_surface(b->parent.compositor);
Peter Hutterer87743e92016-01-18 16:38:22 +10002168
2169 input->vert.axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
2170 input->horiz.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002171}
2172
2173static void
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002174wayland_parent_output_geometry(void *data, struct wl_output *output_proxy,
2175 int32_t x, int32_t y,
2176 int32_t physical_width, int32_t physical_height,
2177 int32_t subpixel, const char *make,
2178 const char *model, int32_t transform)
2179{
2180 struct wayland_parent_output *output = data;
2181
2182 output->x = x;
2183 output->y = y;
2184 output->physical.width = physical_width;
2185 output->physical.height = physical_height;
2186 output->physical.subpixel = subpixel;
2187
2188 free(output->physical.make);
2189 output->physical.make = strdup(make);
2190 free(output->physical.model);
2191 output->physical.model = strdup(model);
2192
2193 output->transform = transform;
2194}
2195
2196static struct weston_mode *
2197find_mode(struct wl_list *list, int32_t width, int32_t height, uint32_t refresh)
2198{
2199 struct weston_mode *mode;
2200
2201 wl_list_for_each(mode, list, link) {
2202 if (mode->width == width && mode->height == height &&
2203 mode->refresh == refresh)
2204 return mode;
2205 }
2206
2207 mode = zalloc(sizeof *mode);
2208 if (!mode)
2209 return NULL;
2210
2211 mode->width = width;
2212 mode->height = height;
2213 mode->refresh = refresh;
2214 wl_list_insert(list, &mode->link);
2215
2216 return mode;
2217}
2218
2219static void
2220wayland_parent_output_mode(void *data, struct wl_output *wl_output_proxy,
2221 uint32_t flags, int32_t width, int32_t height,
2222 int32_t refresh)
2223{
2224 struct wayland_parent_output *output = data;
2225 struct weston_mode *mode;
2226
2227 if (output->output) {
2228 mode = find_mode(&output->output->base.mode_list,
2229 width, height, refresh);
2230 if (!mode)
2231 return;
2232 mode->flags = flags;
2233 /* Do a mode-switch on current mode change? */
2234 } else {
2235 mode = find_mode(&output->mode_list, width, height, refresh);
2236 if (!mode)
2237 return;
2238 mode->flags = flags;
2239 if (flags & WL_OUTPUT_MODE_CURRENT)
2240 output->current_mode = mode;
2241 if (flags & WL_OUTPUT_MODE_PREFERRED)
2242 output->preferred_mode = mode;
2243 }
2244}
2245
2246static const struct wl_output_listener output_listener = {
2247 wayland_parent_output_geometry,
2248 wayland_parent_output_mode
2249};
2250
2251static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03002252wayland_backend_register_output(struct wayland_backend *b, uint32_t id)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002253{
2254 struct wayland_parent_output *output;
2255
2256 output = zalloc(sizeof *output);
2257 if (!output)
2258 return;
2259
2260 output->id = id;
Giulio Camuffo954f1832014-10-11 18:27:30 +03002261 output->global = wl_registry_bind(b->parent.registry, id,
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002262 &wl_output_interface, 1);
U. Artie Eoff8cbd8f32014-05-06 14:50:01 -07002263 if (!output->global) {
2264 free(output);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002265 return;
U. Artie Eoff8cbd8f32014-05-06 14:50:01 -07002266 }
2267
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002268 wl_output_add_listener(output->global, &output_listener, output);
2269
2270 output->scale = 0;
2271 output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
2272 output->physical.subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
2273 wl_list_init(&output->mode_list);
Giulio Camuffo954f1832014-10-11 18:27:30 +03002274 wl_list_insert(&b->parent.output_list, &output->link);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002275
Giulio Camuffo954f1832014-10-11 18:27:30 +03002276 if (b->sprawl_across_outputs) {
2277 wl_display_roundtrip(b->parent.wl_display);
2278 wayland_output_create_for_parent_output(b, output);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002279 }
2280}
2281
2282static void
2283wayland_parent_output_destroy(struct wayland_parent_output *output)
2284{
2285 struct weston_mode *mode, *next;
2286
2287 if (output->output)
2288 wayland_output_destroy(&output->output->base);
2289
2290 wl_output_destroy(output->global);
2291 free(output->physical.make);
2292 free(output->physical.model);
2293
2294 wl_list_for_each_safe(mode, next, &output->mode_list, link) {
2295 wl_list_remove(&mode->link);
2296 free(mode);
2297 }
2298}
2299
2300static void
Armin Krezović34476192016-11-21 18:42:42 +01002301xdg_shell_ping(void *data, struct zxdg_shell_v6 *shell, uint32_t serial)
2302{
2303 zxdg_shell_v6_pong(shell, serial);
2304}
2305
2306static const struct zxdg_shell_v6_listener xdg_shell_listener = {
2307 xdg_shell_ping,
2308};
2309
2310static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04002311registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
2312 const char *interface, uint32_t version)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002313{
Giulio Camuffo954f1832014-10-11 18:27:30 +03002314 struct wayland_backend *b = data;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002315
Benjamin Franzke080ab6c2011-04-30 10:41:27 +02002316 if (strcmp(interface, "wl_compositor") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03002317 b->parent.compositor =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04002318 wl_registry_bind(registry, name,
2319 &wl_compositor_interface, 1);
Armin Krezović34476192016-11-21 18:42:42 +01002320 } else if (strcmp(interface, "zxdg_shell_v6") == 0) {
2321 b->parent.xdg_shell =
2322 wl_registry_bind(registry, name,
2323 &zxdg_shell_v6_interface, 1);
2324 zxdg_shell_v6_add_listener(b->parent.xdg_shell,
2325 &xdg_shell_listener, b);
Benjamin Franzke080ab6c2011-04-30 10:41:27 +02002326 } else if (strcmp(interface, "wl_shell") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03002327 b->parent.shell =
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04002328 wl_registry_bind(registry, name,
2329 &wl_shell_interface, 1);
Jonas Ådahl496adb32015-11-17 16:00:27 +08002330 } else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03002331 b->parent.fshell =
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002332 wl_registry_bind(registry, name,
Jonas Ådahl496adb32015-11-17 16:00:27 +08002333 &zwp_fullscreen_shell_v1_interface, 1);
Daniel Stone725c2c32012-06-22 14:04:36 +01002334 } else if (strcmp(interface, "wl_seat") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03002335 display_add_seat(b, name, version);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002336 } else if (strcmp(interface, "wl_output") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03002337 wayland_backend_register_output(b, name);
Jonas Ådahle5a12252013-04-05 23:07:11 +02002338 } else if (strcmp(interface, "wl_shm") == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03002339 b->parent.shm =
Jonas Ådahle5a12252013-04-05 23:07:11 +02002340 wl_registry_bind(registry, name, &wl_shm_interface, 1);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002341 }
2342}
2343
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002344static void
2345registry_handle_global_remove(void *data, struct wl_registry *registry,
2346 uint32_t name)
2347{
Giulio Camuffo954f1832014-10-11 18:27:30 +03002348 struct wayland_backend *b = data;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002349 struct wayland_parent_output *output;
2350
Giulio Camuffo954f1832014-10-11 18:27:30 +03002351 wl_list_for_each(output, &b->parent.output_list, link)
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002352 if (output->id == name)
2353 wayland_parent_output_destroy(output);
2354}
2355
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04002356static const struct wl_registry_listener registry_listener = {
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002357 registry_handle_global,
2358 registry_handle_global_remove
Kristian Høgsbergfa80e112012-10-10 21:34:26 -04002359};
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002360
Kristian Høgsberg95d843d2011-04-22 13:01:26 -04002361static int
Giulio Camuffo954f1832014-10-11 18:27:30 +03002362wayland_backend_handle_event(int fd, uint32_t mask, void *data)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002363{
Giulio Camuffo954f1832014-10-11 18:27:30 +03002364 struct wayland_backend *b = data;
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -04002365 int count = 0;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002366
Kristian Høgsberg453de7a2013-10-30 23:15:44 -07002367 if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
Giulio Camuffo459137b2014-10-11 23:56:24 +03002368 weston_compositor_exit(b->compositor);
Kristian Høgsberg453de7a2013-10-30 23:15:44 -07002369 return 0;
2370 }
2371
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002372 if (mask & WL_EVENT_READABLE)
Giulio Camuffo954f1832014-10-11 18:27:30 +03002373 count = wl_display_dispatch(b->parent.wl_display);
Kristian Høgsbergf258a312011-12-28 22:51:20 -05002374 if (mask & WL_EVENT_WRITABLE)
Giulio Camuffo954f1832014-10-11 18:27:30 +03002375 wl_display_flush(b->parent.wl_display);
Kristian Høgsberg95d843d2011-04-22 13:01:26 -04002376
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -04002377 if (mask == 0) {
Giulio Camuffo954f1832014-10-11 18:27:30 +03002378 count = wl_display_dispatch_pending(b->parent.wl_display);
2379 wl_display_flush(b->parent.wl_display);
Kristian Høgsbergfeb3c1d2012-10-15 12:56:11 -04002380 }
2381
2382 return count;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002383}
2384
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05002385static void
Kristian Høgsberg7b884bc2012-07-31 14:32:01 -04002386wayland_restore(struct weston_compositor *ec)
2387{
2388}
2389
2390static void
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002391wayland_destroy(struct weston_compositor *ec)
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05002392{
Armin Krezović938dc522016-08-01 19:17:57 +02002393 struct wayland_backend *b = to_wayland_backend(ec);
Jonas Ådahle5a12252013-04-05 23:07:11 +02002394
Armin Krezović78895c52016-10-09 17:30:28 +02002395 wl_event_source_remove(b->parent.wl_source);
2396
Kristian Høgsberg8334bc12012-01-03 10:29:47 -05002397 weston_compositor_shutdown(ec);
Matt Roper361d2ad2011-08-29 13:52:23 -07002398
Giulio Camuffo954f1832014-10-11 18:27:30 +03002399 if (b->parent.shm)
2400 wl_shm_destroy(b->parent.shm);
Jonas Ådahle5a12252013-04-05 23:07:11 +02002401
Armin Krezović34476192016-11-21 18:42:42 +01002402 if (b->parent.xdg_shell)
2403 zxdg_shell_v6_destroy(b->parent.xdg_shell);
2404
2405 if (b->parent.shell)
2406 wl_shell_destroy(b->parent.shell);
2407
Armin Krezović78895c52016-10-09 17:30:28 +02002408 if (b->parent.fshell)
2409 zwp_fullscreen_shell_v1_release(b->parent.fshell);
2410
2411 if (b->parent.compositor)
2412 wl_compositor_destroy(b->parent.compositor);
2413
Armin Krezović78895c52016-10-09 17:30:28 +02002414 if (b->theme)
2415 theme_destroy(b->theme);
2416
2417 if (b->frame_device)
2418 cairo_device_destroy(b->frame_device);
2419
2420 wl_cursor_theme_destroy(b->cursor_theme);
2421
Daniel Stone698f9bf2016-11-24 15:31:33 +00002422 wl_registry_destroy(b->parent.registry);
2423 wl_display_flush(b->parent.wl_display);
2424 wl_display_disconnect(b->parent.wl_display);
2425
Giulio Camuffo954f1832014-10-11 18:27:30 +03002426 free(b);
Kristian Høgsbergcaa64422010-12-01 16:52:15 -05002427}
2428
Jason Ekstrand7744f712013-10-27 22:24:55 -05002429static const char *left_ptrs[] = {
2430 "left_ptr",
2431 "default",
2432 "top_left_arrow",
2433 "left-arrow"
2434};
2435
2436static void
Benoit Gschwind244ff792016-04-28 20:33:11 +02002437create_cursor(struct wayland_backend *b,
2438 struct weston_wayland_backend_config *config)
Jason Ekstrand7744f712013-10-27 22:24:55 -05002439{
Jason Ekstrand7744f712013-10-27 22:24:55 -05002440 unsigned int i;
2441
Benoit Gschwind244ff792016-04-28 20:33:11 +02002442 b->cursor_theme = wl_cursor_theme_load(config->cursor_theme,
2443 config->cursor_size,
2444 b->parent.shm);
Giulio Camuffo954f1832014-10-11 18:27:30 +03002445 if (!b->cursor_theme) {
Hardening842a36a2014-03-18 14:12:50 +01002446 fprintf(stderr, "could not load cursor theme\n");
2447 return;
2448 }
Jason Ekstrand7744f712013-10-27 22:24:55 -05002449
Giulio Camuffo954f1832014-10-11 18:27:30 +03002450 b->cursor = NULL;
2451 for (i = 0; !b->cursor && i < ARRAY_LENGTH(left_ptrs); ++i)
2452 b->cursor = wl_cursor_theme_get_cursor(b->cursor_theme,
Jason Ekstrand7744f712013-10-27 22:24:55 -05002453 left_ptrs[i]);
Giulio Camuffo954f1832014-10-11 18:27:30 +03002454 if (!b->cursor) {
Jason Ekstrand7744f712013-10-27 22:24:55 -05002455 fprintf(stderr, "could not load left cursor\n");
2456 return;
2457 }
2458}
2459
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002460static void
Derek Foreman8ae2db52015-07-15 13:00:36 -05002461fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time,
2462 uint32_t key, void *data)
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002463{
Giulio Camuffo954f1832014-10-11 18:27:30 +03002464 struct wayland_backend *b = data;
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002465 struct wayland_input *input = NULL;
2466
Giulio Camuffo954f1832014-10-11 18:27:30 +03002467 wl_list_for_each(input, &b->input_list, link)
Derek Foreman8ae2db52015-07-15 13:00:36 -05002468 if (&input->base == keyboard->seat)
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002469 break;
2470
2471 if (!input || !input->output)
2472 return;
2473
2474 if (input->output->frame)
2475 wayland_output_set_fullscreen(input->output, 0, 0, NULL);
2476 else
2477 wayland_output_set_windowed(input->output);
2478
2479 weston_output_schedule_repaint(&input->output->base);
2480}
2481
Giulio Camuffo954f1832014-10-11 18:27:30 +03002482static struct wayland_backend *
Benoit Gschwind3a49b512016-04-28 20:33:10 +02002483wayland_backend_create(struct weston_compositor *compositor,
Pekka Paalanena256c5e2016-06-03 14:56:18 +03002484 struct weston_wayland_backend_config *new_config)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002485{
Giulio Camuffo954f1832014-10-11 18:27:30 +03002486 struct wayland_backend *b;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002487 struct wl_event_loop *loop;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002488 int fd;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002489
Giulio Camuffo954f1832014-10-11 18:27:30 +03002490 b = zalloc(sizeof *b);
2491 if (b == NULL)
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002492 return NULL;
2493
Giulio Camuffo954f1832014-10-11 18:27:30 +03002494 b->compositor = compositor;
Giulio Camuffo954f1832014-10-11 18:27:30 +03002495 if (weston_compositor_set_presentation_clock_software(compositor) < 0)
Pekka Paalanenb5eedad2014-09-23 22:08:45 -04002496 goto err_compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002497
Benoit Gschwind3a49b512016-04-28 20:33:10 +02002498 b->parent.wl_display = wl_display_connect(new_config->display_name);
Giulio Camuffo954f1832014-10-11 18:27:30 +03002499 if (b->parent.wl_display == NULL) {
Martin Minarik6d118362012-06-07 18:01:59 +02002500 weston_log("failed to create display: %m\n");
Martin Olssonc5db50f2012-07-08 03:03:43 +02002501 goto err_compositor;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002502 }
2503
Giulio Camuffo954f1832014-10-11 18:27:30 +03002504 wl_list_init(&b->parent.output_list);
2505 wl_list_init(&b->input_list);
2506 b->parent.registry = wl_display_get_registry(b->parent.wl_display);
2507 wl_registry_add_listener(b->parent.registry, &registry_listener, b);
2508 wl_display_roundtrip(b->parent.wl_display);
Jason Ekstrand7744f712013-10-27 22:24:55 -05002509
Benoit Gschwind244ff792016-04-28 20:33:11 +02002510 create_cursor(b, new_config);
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002511
Armin Krezovićb08e1a52016-12-09 22:58:27 +01002512#ifdef ENABLE_EGL
Benoit Gschwind3a49b512016-04-28 20:33:10 +02002513 b->use_pixman = new_config->use_pixman;
Armin Krezovićb08e1a52016-12-09 22:58:27 +01002514#else
2515 b->use_pixman = true;
2516#endif
Armin Krezović174448a2016-09-30 14:11:09 +02002517 b->fullscreen = new_config->fullscreen;
Ander Conselvan de Oliveira97f29522013-10-14 15:57:11 +03002518
Giulio Camuffo954f1832014-10-11 18:27:30 +03002519 if (!b->use_pixman) {
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002520 gl_renderer = weston_load_module("gl-renderer.so",
2521 "gl_renderer_interface");
2522 if (!gl_renderer)
Armin Krezović7e71b872016-10-09 17:30:22 +02002523 b->use_pixman = true;
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002524 }
2525
Giulio Camuffo954f1832014-10-11 18:27:30 +03002526 if (!b->use_pixman) {
Miguel A. Vicodddc6702016-05-18 17:41:07 +02002527 if (gl_renderer->display_create(compositor,
2528 EGL_PLATFORM_WAYLAND_KHR,
2529 b->parent.wl_display,
Miguel A. Vico41700e32016-05-18 17:47:59 +02002530 NULL,
Miguel A. Vicodddc6702016-05-18 17:41:07 +02002531 gl_renderer->alpha_attribs,
2532 NULL,
2533 0) < 0) {
Jason Ekstrandff2fd462013-10-27 22:24:58 -05002534 weston_log("Failed to initialize the GL renderer; "
2535 "falling back to pixman.\n");
Armin Krezović7e71b872016-10-09 17:30:22 +02002536 b->use_pixman = true;
Jason Ekstrandff2fd462013-10-27 22:24:58 -05002537 }
2538 }
2539
Giulio Camuffo954f1832014-10-11 18:27:30 +03002540 if (b->use_pixman) {
2541 if (pixman_renderer_init(compositor) < 0) {
Jason Ekstrandff2fd462013-10-27 22:24:58 -05002542 weston_log("Failed to initialize pixman renderer\n");
2543 goto err_display;
2544 }
2545 }
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002546
Giulio Camuffo954f1832014-10-11 18:27:30 +03002547 b->base.destroy = wayland_destroy;
2548 b->base.restore = wayland_restore;
Benjamin Franzkeecfb2b92011-01-15 12:34:48 +01002549
Giulio Camuffo954f1832014-10-11 18:27:30 +03002550 loop = wl_display_get_event_loop(compositor->wl_display);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002551
Giulio Camuffo954f1832014-10-11 18:27:30 +03002552 fd = wl_display_get_fd(b->parent.wl_display);
2553 b->parent.wl_source =
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002554 wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
Giulio Camuffo954f1832014-10-11 18:27:30 +03002555 wayland_backend_handle_event, b);
2556 if (b->parent.wl_source == NULL)
Dawid Gajownik82d49252015-07-31 00:02:28 -03002557 goto err_display;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002558
Giulio Camuffo954f1832014-10-11 18:27:30 +03002559 wl_event_source_check(b->parent.wl_source);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002560
Emmanuel Gil Peyrotc59f18e2015-09-25 11:58:40 +02002561 if (compositor->renderer->import_dmabuf) {
2562 if (linux_dmabuf_setup(compositor) < 0)
2563 weston_log("Error: initializing dmabuf "
2564 "support failed.\n");
2565 }
2566
Giulio Camuffo954f1832014-10-11 18:27:30 +03002567 compositor->backend = &b->base;
2568 return b;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002569err_display:
Giulio Camuffo954f1832014-10-11 18:27:30 +03002570 wl_display_disconnect(b->parent.wl_display);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002571err_compositor:
Giulio Camuffo954f1832014-10-11 18:27:30 +03002572 weston_compositor_shutdown(compositor);
Giulio Camuffo954f1832014-10-11 18:27:30 +03002573 free(b);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002574 return NULL;
2575}
2576
2577static void
Giulio Camuffo954f1832014-10-11 18:27:30 +03002578wayland_backend_destroy(struct wayland_backend *b)
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002579{
Giulio Camuffo954f1832014-10-11 18:27:30 +03002580 wl_display_disconnect(b->parent.wl_display);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002581
Giulio Camuffo954f1832014-10-11 18:27:30 +03002582 if (b->theme)
2583 theme_destroy(b->theme);
2584 if (b->frame_device)
2585 cairo_device_destroy(b->frame_device);
2586 wl_cursor_theme_destroy(b->cursor_theme);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002587
Giulio Camuffo954f1832014-10-11 18:27:30 +03002588 weston_compositor_shutdown(b->compositor);
2589 free(b);
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002590}
2591
Armin Krezović174448a2016-09-30 14:11:09 +02002592static const struct weston_windowed_output_api windowed_api = {
2593 wayland_output_set_size,
2594 wayland_output_create,
2595};
2596
Benoit Gschwindcd63b3e2016-04-28 20:33:14 +02002597static void
Benoit Gschwinde091b452016-05-10 22:47:48 +02002598config_init_to_defaults(struct weston_wayland_backend_config *config)
2599{
2600}
2601
Benoit Gschwindcd63b3e2016-04-28 20:33:14 +02002602WL_EXPORT int
Quentin Glidic23e1d6f2016-12-02 14:08:44 +01002603weston_backend_init(struct weston_compositor *compositor,
2604 struct weston_backend_config *config_base)
Benoit Gschwindcd63b3e2016-04-28 20:33:14 +02002605{
2606 struct wayland_backend *b;
Benoit Gschwindcd63b3e2016-04-28 20:33:14 +02002607 struct wayland_parent_output *poutput;
2608 struct weston_wayland_backend_config new_config;
Armin Krezović174448a2016-09-30 14:11:09 +02002609 int ret;
Benoit Gschwindcd63b3e2016-04-28 20:33:14 +02002610
Benoit Gschwinde091b452016-05-10 22:47:48 +02002611 if (config_base == NULL ||
2612 config_base->struct_version != WESTON_WAYLAND_BACKEND_CONFIG_VERSION ||
2613 config_base->struct_size > sizeof(struct weston_wayland_backend_config)) {
2614 weston_log("wayland backend config structure is invalid\n");
Benoit Gschwinde091b452016-05-10 22:47:48 +02002615 return -1;
2616 }
2617
2618 config_init_to_defaults(&new_config);
2619 memcpy(&new_config, config_base, config_base->struct_size);
2620
Pekka Paalanena256c5e2016-06-03 14:56:18 +03002621 b = wayland_backend_create(compositor, &new_config);
Benoit Gschwind37a68072016-04-28 20:33:08 +02002622
Giulio Camuffo954f1832014-10-11 18:27:30 +03002623 if (!b)
2624 return -1;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002625
Benoit Gschwind37a68072016-04-28 20:33:08 +02002626 if (new_config.sprawl || b->parent.fshell) {
Armin Krezović7f1c0b82016-10-09 17:30:23 +02002627 b->sprawl_across_outputs = true;
Giulio Camuffo954f1832014-10-11 18:27:30 +03002628 wl_display_roundtrip(b->parent.wl_display);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002629
Giulio Camuffo954f1832014-10-11 18:27:30 +03002630 wl_list_for_each(poutput, &b->parent.output_list, link)
2631 wayland_output_create_for_parent_output(b, poutput);
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002632
Giulio Camuffo954f1832014-10-11 18:27:30 +03002633 return 0;
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002634 }
2635
Benoit Gschwind37a68072016-04-28 20:33:08 +02002636 if (new_config.fullscreen) {
Armin Krezović174448a2016-09-30 14:11:09 +02002637 if (wayland_output_create_fullscreen(b) < 0) {
2638 weston_log("Unable to create a fullscreen output.\n");
Benoit Gschwindcd63b3e2016-04-28 20:33:14 +02002639 goto err_outputs;
Armin Krezović174448a2016-09-30 14:11:09 +02002640 }
Benoit Gschwind830b7882016-04-28 20:33:12 +02002641
Giulio Camuffo954f1832014-10-11 18:27:30 +03002642 return 0;
Jason Ekstrand5ea04802013-11-07 20:13:33 -06002643 }
2644
Armin Krezović174448a2016-09-30 14:11:09 +02002645 ret = weston_plugin_api_register(compositor, WESTON_WINDOWED_OUTPUT_API_NAME,
2646 &windowed_api, sizeof(windowed_api));
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002647
Armin Krezović174448a2016-09-30 14:11:09 +02002648 if (ret < 0) {
2649 weston_log("Failed to register output API.\n");
2650 wayland_backend_destroy(b);
2651 return -1;
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002652 }
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002653
Giulio Camuffo954f1832014-10-11 18:27:30 +03002654 weston_compositor_add_key_binding(compositor, KEY_F,
Jason Ekstrand53ee0dc2014-04-02 19:53:54 -05002655 MODIFIER_CTRL | MODIFIER_ALT,
Giulio Camuffo954f1832014-10-11 18:27:30 +03002656 fullscreen_binding, b);
Giulio Camuffo954f1832014-10-11 18:27:30 +03002657 return 0;
Jason Ekstrand0cf39352013-11-07 20:13:31 -06002658
Jason Ekstrand48ce4212013-10-27 22:25:02 -05002659err_outputs:
Giulio Camuffo954f1832014-10-11 18:27:30 +03002660 wayland_backend_destroy(b);
2661 return -1;
Benjamin Franzkeec2e6422010-11-27 19:04:12 +01002662}