Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 2 | * Copyright © 2010-2011 Benjamin Franzke |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 3 | * Copyright © 2013 Jason Ekstrand |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 4 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 5 | * 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 Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 12 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 13 | * 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 Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 25 | */ |
| 26 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 27 | #include "config.h" |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 28 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 29 | #include <assert.h> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 30 | #include <stddef.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 31 | #include <stdint.h> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 32 | #include <stdio.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <string.h> |
| 35 | #include <fcntl.h> |
| 36 | #include <unistd.h> |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 37 | #include <sys/mman.h> |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 38 | #include <linux/input.h> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 39 | |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 40 | #include <wayland-client.h> |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 41 | #include <wayland-cursor.h> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 42 | |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 43 | #ifdef ENABLE_EGL |
| 44 | #include <wayland-egl.h> |
| 45 | #endif |
| 46 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 47 | #include "compositor.h" |
Benoit Gschwind | 639322a | 2016-04-28 20:33:15 +0200 | [diff] [blame] | 48 | #include "compositor-wayland.h" |
John Kåre Alsaker | 30d2b1f | 2012-11-13 19:10:28 +0100 | [diff] [blame] | 49 | #include "gl-renderer.h" |
Vincent Abriou | c950667 | 2016-10-05 16:14:07 +0200 | [diff] [blame] | 50 | #include "weston-egl-ext.h" |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 51 | #include "pixman-renderer.h" |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 52 | #include "shared/helpers.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 53 | #include "shared/image-loader.h" |
| 54 | #include "shared/os-compatibility.h" |
| 55 | #include "shared/cairo-util.h" |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 56 | #include "fullscreen-shell-unstable-v1-client-protocol.h" |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 57 | #include "xdg-shell-unstable-v6-client-protocol.h" |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 58 | #include "presentation-time-server-protocol.h" |
Emmanuel Gil Peyrot | c59f18e | 2015-09-25 11:58:40 +0200 | [diff] [blame] | 59 | #include "linux-dmabuf.h" |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 60 | #include "windowed-output-api.h" |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 61 | |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 62 | #define WINDOW_TITLE "Weston Compositor" |
| 63 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 64 | struct wayland_backend { |
| 65 | struct weston_backend base; |
| 66 | struct weston_compositor *compositor; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 67 | |
| 68 | struct { |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 69 | struct wl_display *wl_display; |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 70 | struct wl_registry *registry; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 71 | struct wl_compositor *compositor; |
| 72 | struct wl_shell *shell; |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 73 | struct zxdg_shell_v6 *xdg_shell; |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 74 | struct zwp_fullscreen_shell_v1 *fshell; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 75 | struct wl_shm *shm; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 76 | |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 77 | struct wl_list output_list; |
| 78 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 79 | struct wl_event_source *wl_source; |
| 80 | uint32_t event_mask; |
| 81 | } parent; |
| 82 | |
Armin Krezović | 7e71b87 | 2016-10-09 17:30:22 +0200 | [diff] [blame] | 83 | bool use_pixman; |
Armin Krezović | 7f1c0b8 | 2016-10-09 17:30:23 +0200 | [diff] [blame] | 84 | bool sprawl_across_outputs; |
Armin Krezović | 2045016 | 2016-10-13 12:01:43 +0200 | [diff] [blame] | 85 | bool fullscreen; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 86 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 87 | struct theme *theme; |
| 88 | cairo_device_t *frame_device; |
| 89 | struct wl_cursor_theme *cursor_theme; |
| 90 | struct wl_cursor *cursor; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 91 | |
Jason Ekstrand | 06ced80 | 2013-11-07 20:13:29 -0600 | [diff] [blame] | 92 | struct wl_list input_list; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | struct wayland_output { |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 96 | struct weston_output base; |
| 97 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 98 | struct { |
Armin Krezović | 2d321e3 | 2016-10-09 17:30:25 +0200 | [diff] [blame] | 99 | bool draw_initial_frame; |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 100 | struct wl_surface *surface; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 101 | |
| 102 | struct wl_output *output; |
| 103 | uint32_t global_id; |
| 104 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 105 | struct wl_shell_surface *shell_surface; |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 106 | struct zxdg_surface_v6 *xdg_surface; |
| 107 | struct zxdg_toplevel_v6 *xdg_toplevel; |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 108 | int configure_width, configure_height; |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 109 | bool wait_for_configure; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 110 | } parent; |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 111 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 112 | int keyboard_count; |
| 113 | |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 114 | char *title; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 115 | struct frame *frame; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 116 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 117 | struct { |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 118 | 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 Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 131 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 132 | struct weston_mode mode; |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 133 | uint32_t scale; |
Dima Ryazanov | 89c2f63 | 2016-11-24 05:13:12 -0800 | [diff] [blame] | 134 | |
| 135 | struct wl_callback *frame_cb; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 136 | }; |
| 137 | |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 138 | struct 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 Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 161 | struct 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 Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 176 | struct wayland_input { |
Kristian Høgsberg | 7af7ced | 2012-08-10 10:01:33 -0400 | [diff] [blame] | 177 | struct weston_seat base; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 178 | struct wayland_backend *backend; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 179 | struct wl_list link; |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 180 | |
| 181 | struct { |
| 182 | struct wl_seat *seat; |
| 183 | struct wl_pointer *pointer; |
| 184 | struct wl_keyboard *keyboard; |
| 185 | struct wl_touch *touch; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 186 | |
| 187 | struct { |
| 188 | struct wl_surface *surface; |
| 189 | int32_t hx, hy; |
| 190 | } cursor; |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 191 | } parent; |
| 192 | |
Jason Ekstrand | b7d9f2e | 2014-04-02 19:53:57 -0500 | [diff] [blame] | 193 | enum weston_key_state_update keyboard_state_update; |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 194 | uint32_t key_serial; |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 195 | uint32_t enter_serial; |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 196 | uint32_t touch_points; |
| 197 | bool touch_active; |
Derek Foreman | 4bcc54d | 2015-11-06 15:56:06 -0600 | [diff] [blame] | 198 | bool has_focus; |
Derek Foreman | cfce7d0 | 2015-11-06 15:56:08 -0600 | [diff] [blame] | 199 | int seat_version; |
Derek Foreman | 4bcc54d | 2015-11-06 15:56:06 -0600 | [diff] [blame] | 200 | |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 201 | struct wayland_output *output; |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 202 | struct wayland_output *touch_focus; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 203 | struct wayland_output *keyboard_focus; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 204 | |
| 205 | struct weston_pointer_axis_event vert, horiz; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 206 | }; |
| 207 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 208 | struct gl_renderer_interface *gl_renderer; |
| 209 | |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 210 | static inline struct wayland_output * |
| 211 | to_wayland_output(struct weston_output *base) |
| 212 | { |
| 213 | return container_of(base, struct wayland_output, base); |
| 214 | } |
| 215 | |
| 216 | static inline struct wayland_backend * |
| 217 | to_wayland_backend(struct weston_compositor *base) |
| 218 | { |
| 219 | return container_of(base->backend, struct wayland_backend, base); |
| 220 | } |
| 221 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 222 | static void |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 223 | wayland_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 | |
| 238 | static void |
| 239 | buffer_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 | |
| 250 | static const struct wl_buffer_listener buffer_listener = { |
| 251 | buffer_release |
| 252 | }; |
| 253 | |
| 254 | static struct wayland_shm_buffer * |
| 255 | wayland_output_get_shm_buffer(struct wayland_output *output) |
| 256 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 257 | struct wayland_backend *b = |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 258 | to_wayland_backend(output->base.compositor); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 259 | struct wl_shm *shm = b->parent.shm; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 260 | 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 Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 281 | width = output->base.current_mode->width; |
| 282 | height = output->base.current_mode->height; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 283 | } |
| 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. Harrington | a093502 | 2014-03-21 05:54:02 +0000 | [diff] [blame] | 289 | weston_log("could not create an anonymous file buffer: %m\n"); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 290 | 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. Harrington | a093502 | 2014-03-21 05:54:02 +0000 | [diff] [blame] | 295 | weston_log("could not mmap %d memory for data: %m\n", height * stride); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 296 | close(fd); |
| 297 | return NULL; |
| 298 | } |
| 299 | |
| 300 | sb = zalloc(sizeof *sb); |
Bryce W. Harrington | bfd74f4 | 2014-04-21 23:51:02 +0000 | [diff] [blame] | 301 | if (sb == NULL) { |
Thierry Reding | 6ac60c1 | 2014-05-27 09:08:29 +0200 | [diff] [blame] | 302 | weston_log("could not zalloc %zu memory for sb: %m\n", sizeof *sb); |
Bryce W. Harrington | bfd74f4 | 2014-04-21 23:51:02 +0000 | [diff] [blame] | 303 | close(fd); |
Raúl Peñacoba | fec723e | 2017-03-29 22:23:07 +0200 | [diff] [blame] | 304 | munmap(data, height * stride); |
Bryce W. Harrington | bfd74f4 | 2014-04-21 23:51:02 +0000 | [diff] [blame] | 305 | return NULL; |
| 306 | } |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 307 | |
| 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 | |
| 347 | static void |
Kristian Høgsberg | cdd61d0 | 2012-02-07 09:56:15 -0500 | [diff] [blame] | 348 | frame_done(void *data, struct wl_callback *callback, uint32_t time) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 349 | { |
Dima Ryazanov | 89c2f63 | 2016-11-24 05:13:12 -0800 | [diff] [blame] | 350 | struct wayland_output *output = data; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 351 | struct timespec ts; |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 352 | |
Dima Ryazanov | 89c2f63 | 2016-11-24 05:13:12 -0800 | [diff] [blame] | 353 | assert(callback == output->frame_cb); |
Kristian Høgsberg | cdd61d0 | 2012-02-07 09:56:15 -0500 | [diff] [blame] | 354 | wl_callback_destroy(callback); |
Dima Ryazanov | 89c2f63 | 2016-11-24 05:13:12 -0800 | [diff] [blame] | 355 | output->frame_cb = NULL; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 356 | |
| 357 | /* XXX: use the presentation extension for proper timings */ |
Pekka Paalanen | 04f8a9b | 2015-04-02 16:26:06 +0300 | [diff] [blame] | 358 | |
| 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 Ryazanov | 89c2f63 | 2016-11-24 05:13:12 -0800 | [diff] [blame] | 366 | weston_compositor_read_presentation_clock(output->base.compositor, &ts); |
| 367 | weston_output_finish_frame(&output->base, &ts, 0); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | static const struct wl_callback_listener frame_listener = { |
| 371 | frame_done |
| 372 | }; |
| 373 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 374 | static void |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 375 | draw_initial_frame(struct wayland_output *output) |
| 376 | { |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 377 | struct wayland_shm_buffer *sb; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 378 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 379 | sb = wayland_output_get_shm_buffer(output); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 380 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 381 | /* 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 Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 385 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 386 | wl_surface_attach(output->parent.surface, sb->buffer, 0, 0); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 387 | wl_surface_damage(output->parent.surface, 0, 0, |
| 388 | output->base.current_mode->width, |
| 389 | output->base.current_mode->height); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 390 | } |
| 391 | |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 392 | #ifdef ENABLE_EGL |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 393 | static void |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 394 | wayland_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 Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 408 | if (!output->gl.border.top) |
| 409 | output->gl.border.top = |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 410 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 411 | fwidth, iy); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 412 | cr = cairo_create(output->gl.border.top); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 413 | 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 Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 417 | cairo_image_surface_get_stride(output->gl.border.top) / 4, |
| 418 | cairo_image_surface_get_data(output->gl.border.top)); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 419 | |
| 420 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 421 | if (!output->gl.border.left) |
| 422 | output->gl.border.left = |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 423 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 424 | ix, 1); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 425 | cr = cairo_create(output->gl.border.left); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 426 | 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 Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 431 | cairo_image_surface_get_stride(output->gl.border.left) / 4, |
| 432 | cairo_image_surface_get_data(output->gl.border.left)); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 433 | |
| 434 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 435 | if (!output->gl.border.right) |
| 436 | output->gl.border.right = |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 437 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 438 | fwidth - (ix + iwidth), 1); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 439 | cr = cairo_create(output->gl.border.right); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 440 | 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 Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 445 | cairo_image_surface_get_stride(output->gl.border.right) / 4, |
| 446 | cairo_image_surface_get_data(output->gl.border.right)); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 447 | |
| 448 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 449 | if (!output->gl.border.bottom) |
| 450 | output->gl.border.bottom = |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 451 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 452 | fwidth, fheight - (iy + iheight)); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 453 | cr = cairo_create(output->gl.border.bottom); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 454 | 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 Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 459 | cairo_image_surface_get_stride(output->gl.border.bottom) / 4, |
| 460 | cairo_image_surface_get_data(output->gl.border.bottom)); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 461 | } |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 462 | #endif |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 463 | |
| 464 | static void |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 465 | wayland_output_start_repaint_loop(struct weston_output *output_base) |
| 466 | { |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 467 | struct wayland_output *output = to_wayland_output(output_base); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 468 | struct wayland_backend *wb = |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 469 | to_wayland_backend(output->base.compositor); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 470 | |
| 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ć | 2d321e3 | 2016-10-09 17:30:25 +0200 | [diff] [blame] | 477 | output->parent.draw_initial_frame = false; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 478 | |
| 479 | draw_initial_frame(output); |
| 480 | } |
| 481 | |
Dima Ryazanov | 89c2f63 | 2016-11-24 05:13:12 -0800 | [diff] [blame] | 482 | output->frame_cb = wl_surface_frame(output->parent.surface); |
| 483 | wl_callback_add_listener(output->frame_cb, &frame_listener, output); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 484 | wl_surface_commit(output->parent.surface); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 485 | wl_display_flush(wb->parent.wl_display); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 486 | } |
| 487 | |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 488 | #ifdef ENABLE_EGL |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 489 | static int |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 490 | wayland_output_repaint_gl(struct weston_output *output_base, |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 491 | pixman_region32_t *damage, |
| 492 | void *repaint_data) |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 493 | { |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 494 | struct wayland_output *output = to_wayland_output(output_base); |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 495 | struct weston_compositor *ec = output->base.compositor; |
Scott Moreau | 062be7e | 2012-04-20 13:37:33 -0600 | [diff] [blame] | 496 | |
Dima Ryazanov | 89c2f63 | 2016-11-24 05:13:12 -0800 | [diff] [blame] | 497 | output->frame_cb = wl_surface_frame(output->parent.surface); |
| 498 | wl_callback_add_listener(output->frame_cb, &frame_listener, output); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 499 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 500 | wayland_output_update_gl_border(output); |
| 501 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 502 | ec->renderer->repaint_output(&output->base, damage); |
Ander Conselvan de Oliveira | 0a88772 | 2012-11-22 15:57:00 +0200 | [diff] [blame] | 503 | |
| 504 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 505 | &ec->primary_plane.damage, damage); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 506 | return 0; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 507 | } |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 508 | #endif |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 509 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 510 | static void |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 511 | wayland_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 | |
| 550 | static void |
| 551 | wayland_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 Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 558 | 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 Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 565 | 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 Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 570 | 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 Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 584 | } |
| 585 | |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 586 | rects = pixman_region32_rectangles(&damage, &n); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 587 | 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 | |
| 597 | static int |
| 598 | wayland_output_repaint_pixman(struct weston_output *output_base, |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 599 | pixman_region32_t *damage, |
| 600 | void *repaint_data) |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 601 | { |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 602 | struct wayland_output *output = to_wayland_output(output_base); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 603 | struct wayland_backend *b = |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 604 | to_wayland_backend(output->base.compositor); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 605 | 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 Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 620 | b->compositor->renderer->repaint_output(output_base, &sb->damage); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 621 | |
| 622 | wayland_shm_buffer_attach(sb); |
| 623 | |
Daniel Stone | 21fac60 | 2016-11-28 16:05:35 +0000 | [diff] [blame] | 624 | output->frame_cb = wl_surface_frame(output->parent.surface); |
| 625 | wl_callback_add_listener(output->frame_cb, &frame_listener, output); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 626 | wl_surface_commit(output->parent.surface); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 627 | wl_display_flush(b->parent.wl_display); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 628 | |
| 629 | pixman_region32_fini(&sb->damage); |
| 630 | pixman_region32_init(&sb->damage); |
| 631 | sb->frame_damaged = 0; |
| 632 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 633 | pixman_region32_subtract(&b->compositor->primary_plane.damage, |
| 634 | &b->compositor->primary_plane.damage, damage); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | static void |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 639 | wayland_backend_destroy_output_surface(struct wayland_output *output) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 640 | { |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 641 | 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ć | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 647 | 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ć | 2e66252 | 2016-10-09 17:30:29 +0200 | [diff] [blame] | 653 | static void |
| 654 | wayland_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ć | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 666 | static int |
| 667 | wayland_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 Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 674 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 675 | if (b->use_pixman) { |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 676 | pixman_renderer_output_destroy(&output->base); |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 677 | #ifdef ENABLE_EGL |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 678 | } else { |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 679 | gl_renderer->output_destroy(&output->base); |
Emmanuel Gil Peyrot | 85571a3 | 2016-09-01 15:19:46 +0100 | [diff] [blame] | 680 | wl_egl_window_destroy(output->gl.egl_window); |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 681 | #endif |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 682 | } |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 683 | |
Armin Krezović | 2e66252 | 2016-10-09 17:30:29 +0200 | [diff] [blame] | 684 | wayland_output_destroy_shm_buffers(output); |
| 685 | |
Armin Krezović | f054d35 | 2016-10-09 17:30:27 +0200 | [diff] [blame] | 686 | wayland_backend_destroy_output_surface(output); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 687 | |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 688 | if (output->frame) |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 689 | frame_destroy(output->frame); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 690 | |
| 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 Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 695 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 696 | return 0; |
| 697 | } |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 698 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 699 | static void |
| 700 | wayland_output_destroy(struct weston_output *base) |
| 701 | { |
| 702 | struct wayland_output *output = to_wayland_output(base); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 703 | |
| 704 | wayland_output_disable(&output->base); |
| 705 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 706 | weston_output_destroy(&output->base); |
| 707 | |
Dima Ryazanov | 89c2f63 | 2016-11-24 05:13:12 -0800 | [diff] [blame] | 708 | if (output->frame_cb) |
| 709 | wl_callback_destroy(output->frame_cb); |
| 710 | |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 711 | free(output->title); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 712 | free(output); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Ander Conselvan de Oliveira | 563c5b8 | 2012-06-18 17:36:21 +0300 | [diff] [blame] | 715 | static const struct wl_shell_surface_listener shell_surface_listener; |
| 716 | |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 717 | #ifdef ENABLE_EGL |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 718 | static int |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 719 | wayland_output_init_gl_renderer(struct wayland_output *output) |
| 720 | { |
Jason Ekstrand | 00b8428 | 2013-10-27 22:24:59 -0500 | [diff] [blame] | 721 | int32_t fwidth = 0, fheight = 0; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 722 | |
| 723 | if (output->frame) { |
| 724 | fwidth = frame_width(output->frame); |
| 725 | fheight = frame_height(output->frame); |
| 726 | } else { |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 727 | fwidth = output->base.current_mode->width; |
| 728 | fheight = output->base.current_mode->height; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 729 | } |
| 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. Vico | c095cde | 2016-05-18 17:43:00 +0200 | [diff] [blame] | 739 | 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 Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 745 | goto cleanup_window; |
| 746 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 747 | return 0; |
| 748 | |
| 749 | cleanup_window: |
| 750 | wl_egl_window_destroy(output->gl.egl_window); |
| 751 | return -1; |
| 752 | } |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 753 | #endif |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 754 | |
| 755 | static int |
| 756 | wayland_output_init_pixman_renderer(struct wayland_output *output) |
| 757 | { |
| 758 | return pixman_renderer_output_create(&output->base); |
| 759 | } |
| 760 | |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 761 | static void |
| 762 | wayland_output_resize_surface(struct wayland_output *output) |
| 763 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 764 | struct wayland_backend *b = |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 765 | to_wayland_backend(output->base.compositor); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 766 | 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 Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 777 | region = wl_compositor_create_region(b->parent.compositor); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 778 | 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 Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 783 | region = wl_compositor_create_region(b->parent.compositor); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 784 | 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 Granell | ed016bf | 2017-03-24 23:45:13 +0100 | [diff] [blame] | 788 | 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 Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 796 | width = frame_width(output->frame); |
| 797 | height = frame_height(output->frame); |
| 798 | } else { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 799 | region = wl_compositor_create_region(b->parent.compositor); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 800 | 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 Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 804 | region = wl_compositor_create_region(b->parent.compositor); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 805 | wl_region_add(region, 0, 0, width, height); |
| 806 | wl_surface_set_opaque_region(output->parent.surface, region); |
| 807 | wl_region_destroy(region); |
Sergi Granell | ed016bf | 2017-03-24 23:45:13 +0100 | [diff] [blame] | 808 | |
| 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 Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 816 | } |
| 817 | |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 818 | #ifdef ENABLE_EGL |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 819 | 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ć | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 845 | #endif |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 846 | |
Armin Krezović | 2e66252 | 2016-10-09 17:30:29 +0200 | [diff] [blame] | 847 | wayland_output_destroy_shm_buffers(output); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | static int |
| 851 | wayland_output_set_windowed(struct wayland_output *output) |
| 852 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 853 | struct wayland_backend *b = |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 854 | to_wayland_backend(output->base.compositor); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 855 | |
| 856 | if (output->frame) |
| 857 | return 0; |
| 858 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 859 | if (!b->theme) { |
| 860 | b->theme = theme_create(); |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 861 | if (!b->theme) |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 862 | return -1; |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 863 | } |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 864 | output->frame = frame_create(b->theme, 100, 100, |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 865 | FRAME_BUTTON_CLOSE, output->title); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 866 | 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ć | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 874 | if (output->parent.shell_surface) |
| 875 | wl_shell_surface_set_toplevel(output->parent.shell_surface); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | static void |
| 881 | wayland_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 Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 885 | struct wayland_backend *b = |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 886 | to_wayland_backend(output->base.compositor); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 887 | |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 888 | if (output->frame) { |
| 889 | frame_destroy(output->frame); |
| 890 | output->frame = NULL; |
| 891 | } |
| 892 | |
| 893 | wayland_output_resize_surface(output); |
| 894 | |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 895 | if (output->parent.xdg_toplevel) { |
| 896 | zxdg_toplevel_v6_set_fullscreen(output->parent.xdg_toplevel, target); |
| 897 | } else if (output->parent.shell_surface) { |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 898 | wl_shell_surface_set_fullscreen(output->parent.shell_surface, |
| 899 | method, framerate, target); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 900 | } else if (b->parent.fshell) { |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 901 | zwp_fullscreen_shell_v1_present_surface(b->parent.fshell, |
| 902 | output->parent.surface, |
| 903 | method, target); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | |
| 907 | static struct weston_mode * |
| 908 | wayland_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 | |
| 930 | enum mode_status { |
| 931 | MODE_STATUS_UNKNOWN, |
| 932 | MODE_STATUS_SUCCESS, |
| 933 | MODE_STATUS_FAIL, |
| 934 | MODE_STATUS_CANCEL, |
| 935 | }; |
| 936 | |
| 937 | static void |
| 938 | mode_feedback_successful(void *data, |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 939 | struct zwp_fullscreen_shell_mode_feedback_v1 *fb) |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 940 | { |
| 941 | enum mode_status *value = data; |
| 942 | |
| 943 | printf("Mode switch successful\n"); |
| 944 | |
| 945 | *value = MODE_STATUS_SUCCESS; |
| 946 | } |
| 947 | |
| 948 | static void |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 949 | mode_feedback_failed(void *data, struct zwp_fullscreen_shell_mode_feedback_v1 *fb) |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 950 | { |
| 951 | enum mode_status *value = data; |
| 952 | |
| 953 | printf("Mode switch failed\n"); |
| 954 | |
| 955 | *value = MODE_STATUS_FAIL; |
| 956 | } |
| 957 | |
| 958 | static void |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 959 | mode_feedback_cancelled(void *data, struct zwp_fullscreen_shell_mode_feedback_v1 *fb) |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 960 | { |
| 961 | enum mode_status *value = data; |
| 962 | |
| 963 | printf("Mode switch cancelled\n"); |
| 964 | |
| 965 | *value = MODE_STATUS_CANCEL; |
| 966 | } |
| 967 | |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 968 | struct zwp_fullscreen_shell_mode_feedback_v1_listener mode_feedback_listener = { |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 969 | mode_feedback_successful, |
| 970 | mode_feedback_failed, |
| 971 | mode_feedback_cancelled, |
| 972 | }; |
| 973 | |
| 974 | static int |
| 975 | wayland_output_switch_mode(struct weston_output *output_base, |
| 976 | struct weston_mode *mode) |
| 977 | { |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 978 | struct wayland_output *output = to_wayland_output(output_base); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 979 | struct wayland_backend *b; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 980 | struct wl_surface *old_surface; |
| 981 | struct weston_mode *old_mode; |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 982 | struct zwp_fullscreen_shell_mode_feedback_v1 *mode_feedback; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 983 | 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ć | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 996 | b = to_wayland_backend(output_base->compositor); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 997 | |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 998 | if (output->parent.xdg_surface || output->parent.shell_surface || !b->parent.fshell) |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 999 | 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 Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1012 | wl_compositor_create_surface(b->parent.compositor); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1013 | 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 Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 1019 | 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 Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1026 | |
| 1027 | /* This should kick-start things again */ |
Armin Krezović | 2d321e3 | 2016-10-09 17:30:25 +0200 | [diff] [blame] | 1028 | output->parent.draw_initial_frame = true; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1029 | wayland_output_start_repaint_loop(&output->base); |
| 1030 | |
| 1031 | mode_status = MODE_STATUS_UNKNOWN; |
| 1032 | while (mode_status == MODE_STATUS_UNKNOWN && ret >= 0) |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1033 | ret = wl_display_dispatch(b->parent.wl_display); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1034 | |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 1035 | zwp_fullscreen_shell_mode_feedback_v1_destroy(mode_feedback); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1036 | |
| 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 Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1049 | if (b->use_pixman) { |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1050 | pixman_renderer_output_destroy(output_base); |
| 1051 | if (wayland_output_init_pixman_renderer(output) < 0) |
| 1052 | goto err_output; |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 1053 | #ifdef ENABLE_EGL |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1054 | } 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ć | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 1059 | #endif |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1060 | } |
| 1061 | wl_surface_destroy(old_surface); |
| 1062 | |
| 1063 | weston_output_schedule_repaint(&output->base); |
| 1064 | |
| 1065 | return 0; |
| 1066 | |
| 1067 | err_output: |
| 1068 | /* XXX */ |
| 1069 | return -1; |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 1070 | } |
| 1071 | |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 1072 | static void |
| 1073 | handle_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 | |
| 1079 | static const struct zxdg_surface_v6_listener xdg_surface_listener = { |
| 1080 | handle_xdg_surface_configure |
| 1081 | }; |
| 1082 | |
| 1083 | static void |
| 1084 | handle_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 | |
| 1097 | static void |
| 1098 | handle_xdg_toplevel_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel) |
| 1099 | { |
Sergi Granell | eaa7358 | 2017-03-25 17:19:36 +0100 | [diff] [blame] | 1100 | struct wayland_output *output = data; |
| 1101 | |
| 1102 | weston_compositor_exit(output->base.compositor); |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = { |
| 1106 | handle_xdg_toplevel_configure, |
| 1107 | handle_xdg_toplevel_close, |
| 1108 | }; |
| 1109 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1110 | static int |
| 1111 | wayland_backend_create_output_surface(struct wayland_output *output) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1112 | { |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1113 | struct wayland_backend *b = to_wayland_backend(output->base.compositor); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1114 | |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 1115 | output->parent.surface = |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1116 | wl_compositor_create_surface(b->parent.compositor); |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 1117 | if (!output->parent.surface) |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1118 | return -1; |
| 1119 | |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 1120 | wl_surface_set_user_data(output->parent.surface, output); |
| 1121 | |
Armin Krezović | 2d321e3 | 2016-10-09 17:30:25 +0200 | [diff] [blame] | 1122 | output->parent.draw_initial_frame = true; |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 1123 | |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 1124 | if (b->parent.xdg_shell) { |
| 1125 | output->parent.xdg_surface = |
| 1126 | zxdg_shell_v6_get_xdg_surface(b->parent.xdg_shell, |
| 1127 | output->parent.surface); |
| 1128 | zxdg_surface_v6_add_listener(output->parent.xdg_surface, |
| 1129 | &xdg_surface_listener, output); |
| 1130 | |
| 1131 | output->parent.xdg_toplevel = |
| 1132 | zxdg_surface_v6_get_toplevel(output->parent.xdg_surface); |
| 1133 | zxdg_toplevel_v6_add_listener(output->parent.xdg_toplevel, |
| 1134 | &xdg_toplevel_listener, output); |
| 1135 | |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 1136 | zxdg_toplevel_v6_set_title(output->parent.xdg_toplevel, output->title); |
| 1137 | |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 1138 | wl_surface_commit(output->parent.surface); |
| 1139 | |
| 1140 | output->parent.wait_for_configure = true; |
| 1141 | |
| 1142 | while (output->parent.wait_for_configure) |
| 1143 | wl_display_dispatch(b->parent.wl_display); |
| 1144 | |
| 1145 | weston_log("wayland-backend: Using xdg_shell_v6\n"); |
| 1146 | } |
| 1147 | else if (b->parent.shell) { |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1148 | output->parent.shell_surface = |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1149 | wl_shell_get_shell_surface(b->parent.shell, |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1150 | output->parent.surface); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1151 | if (!output->parent.shell_surface) { |
| 1152 | wl_surface_destroy(output->parent.surface); |
| 1153 | return -1; |
| 1154 | } |
| 1155 | |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1156 | wl_shell_surface_add_listener(output->parent.shell_surface, |
| 1157 | &shell_surface_listener, output); |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 1158 | |
| 1159 | weston_log("wayland-backend: Using wl_shell\n"); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1160 | } |
| 1161 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1162 | return 0; |
| 1163 | } |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 1164 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1165 | static int |
| 1166 | wayland_output_enable(struct weston_output *base) |
| 1167 | { |
| 1168 | struct wayland_output *output = to_wayland_output(base); |
| 1169 | struct wayland_backend *b = to_wayland_backend(base->compositor); |
| 1170 | int ret = 0; |
| 1171 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1172 | weston_log("Creating %dx%d wayland output at (%d, %d)\n", |
| 1173 | output->base.current_mode->width, |
| 1174 | output->base.current_mode->height, |
| 1175 | output->base.x, output->base.y); |
| 1176 | |
Armin Krezović | f054d35 | 2016-10-09 17:30:27 +0200 | [diff] [blame] | 1177 | if (!output->parent.surface) |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1178 | ret = wayland_backend_create_output_surface(output); |
| 1179 | |
| 1180 | if (ret < 0) |
| 1181 | return -1; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 1182 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 1183 | wl_list_init(&output->shm.buffers); |
| 1184 | wl_list_init(&output->shm.free_buffers); |
| 1185 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1186 | if (b->use_pixman) { |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 1187 | if (wayland_output_init_pixman_renderer(output) < 0) |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 1188 | goto err_output; |
Armin Krezović | f16de17 | 2016-10-09 17:30:26 +0200 | [diff] [blame] | 1189 | |
| 1190 | output->base.repaint = wayland_output_repaint_pixman; |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 1191 | #ifdef ENABLE_EGL |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 1192 | } else { |
| 1193 | if (wayland_output_init_gl_renderer(output) < 0) |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 1194 | goto err_output; |
Armin Krezović | f16de17 | 2016-10-09 17:30:26 +0200 | [diff] [blame] | 1195 | |
| 1196 | output->base.repaint = wayland_output_repaint_gl; |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 1197 | #endif |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1198 | } |
| 1199 | |
Armin Krezović | f16de17 | 2016-10-09 17:30:26 +0200 | [diff] [blame] | 1200 | output->base.start_repaint_loop = wayland_output_start_repaint_loop; |
| 1201 | output->base.assign_planes = NULL; |
| 1202 | output->base.set_backlight = NULL; |
| 1203 | output->base.set_dpms = NULL; |
| 1204 | output->base.switch_mode = wayland_output_switch_mode; |
| 1205 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1206 | if (b->sprawl_across_outputs) { |
| 1207 | wayland_output_set_fullscreen(output, |
| 1208 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER, |
| 1209 | output->mode.refresh, output->parent.output); |
| 1210 | |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 1211 | if (output->parent.xdg_toplevel) { |
| 1212 | zxdg_toplevel_v6_set_fullscreen(output->parent.xdg_toplevel, |
| 1213 | output->parent.output); |
| 1214 | } |
| 1215 | else if (output->parent.shell_surface) { |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1216 | wl_shell_surface_set_fullscreen(output->parent.shell_surface, |
| 1217 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER, |
| 1218 | output->mode.refresh, output->parent.output); |
| 1219 | } else if (b->parent.fshell) { |
| 1220 | zwp_fullscreen_shell_v1_present_surface(b->parent.fshell, |
| 1221 | output->parent.surface, |
| 1222 | ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_CENTER, |
| 1223 | output->parent.output); |
| 1224 | zwp_fullscreen_shell_mode_feedback_v1_destroy( |
| 1225 | zwp_fullscreen_shell_v1_present_surface_for_mode(b->parent.fshell, |
| 1226 | output->parent.surface, |
| 1227 | output->parent.output, |
| 1228 | output->mode.refresh)); |
| 1229 | } |
| 1230 | } else if (b->fullscreen) { |
| 1231 | wayland_output_set_fullscreen(output, 0, 0, NULL); |
| 1232 | } else { |
| 1233 | wayland_output_set_windowed(output); |
| 1234 | } |
| 1235 | |
| 1236 | return 0; |
| 1237 | |
| 1238 | err_output: |
Armin Krezović | f054d35 | 2016-10-09 17:30:27 +0200 | [diff] [blame] | 1239 | wayland_backend_destroy_output_surface(output); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1240 | |
| 1241 | return -1; |
| 1242 | } |
| 1243 | |
| 1244 | static struct wayland_output * |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 1245 | wayland_output_create_common(const char *name) |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1246 | { |
| 1247 | struct wayland_output *output; |
Pekka Paalanen | ffa42ff | 2017-08-11 15:55:32 +0300 | [diff] [blame^] | 1248 | char *title; |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 1249 | |
| 1250 | /* name can't be NULL. */ |
| 1251 | assert(name); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1252 | |
| 1253 | output = zalloc(sizeof *output); |
| 1254 | if (output == NULL) { |
| 1255 | perror("zalloc"); |
| 1256 | return NULL; |
| 1257 | } |
| 1258 | |
Pekka Paalanen | ffa42ff | 2017-08-11 15:55:32 +0300 | [diff] [blame^] | 1259 | if (asprintf(&title, "%s - %s", WINDOW_TITLE, name) < 0) { |
| 1260 | free(output); |
| 1261 | return NULL; |
| 1262 | } |
| 1263 | output->title = title; |
| 1264 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1265 | output->base.destroy = wayland_output_destroy; |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1266 | output->base.disable = wayland_output_disable; |
| 1267 | output->base.enable = wayland_output_enable; |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 1268 | output->base.name = strdup(name); |
| 1269 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1270 | return output; |
| 1271 | } |
| 1272 | |
| 1273 | static int |
| 1274 | wayland_output_create(struct weston_compositor *compositor, const char *name) |
| 1275 | { |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 1276 | struct wayland_output *output = wayland_output_create_common(name); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1277 | |
Sergi Granell | 7fecb43 | 2017-03-24 20:48:02 +0100 | [diff] [blame] | 1278 | if (!output) |
| 1279 | return -1; |
| 1280 | |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 1281 | weston_output_init(&output->base, compositor); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1282 | weston_compositor_add_pending_output(&output->base, compositor); |
| 1283 | |
| 1284 | return 0; |
| 1285 | } |
| 1286 | |
| 1287 | static int |
| 1288 | wayland_output_set_size(struct weston_output *base, int width, int height) |
| 1289 | { |
| 1290 | struct wayland_output *output = to_wayland_output(base); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1291 | int output_width, output_height; |
| 1292 | |
| 1293 | /* We can only be called once. */ |
| 1294 | assert(!output->base.current_mode); |
| 1295 | |
| 1296 | /* Make sure we have scale set. */ |
| 1297 | assert(output->base.scale); |
| 1298 | |
| 1299 | if (width < 1) { |
| 1300 | weston_log("Invalid width \"%d\" for output %s\n", |
| 1301 | width, output->base.name); |
| 1302 | return -1; |
| 1303 | } |
| 1304 | |
| 1305 | if (height < 1) { |
| 1306 | weston_log("Invalid height \"%d\" for output %s\n", |
| 1307 | height, output->base.name); |
| 1308 | return -1; |
| 1309 | } |
| 1310 | |
| 1311 | output_width = width * output->base.scale; |
| 1312 | output_height = height * output->base.scale; |
| 1313 | |
| 1314 | output->mode.flags = |
| 1315 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 1316 | |
| 1317 | output->mode.width = output_width; |
| 1318 | output->mode.height = output_height; |
| 1319 | output->mode.refresh = 60000; |
| 1320 | output->scale = output->base.scale; |
| 1321 | wl_list_init(&output->base.mode_list); |
| 1322 | wl_list_insert(&output->base.mode_list, &output->mode.link); |
| 1323 | |
| 1324 | output->base.current_mode = &output->mode; |
| 1325 | output->base.make = "wayland"; |
| 1326 | output->base.model = "none"; |
| 1327 | |
| 1328 | /* XXX: Calculate proper size. */ |
| 1329 | output->base.mm_width = width; |
| 1330 | output->base.mm_height = height; |
| 1331 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1332 | return 0; |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 1333 | } |
| 1334 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1335 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1336 | wayland_output_create_for_parent_output(struct wayland_backend *b, |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1337 | struct wayland_parent_output *poutput) |
| 1338 | { |
Sergi Granell | 7fecb43 | 2017-03-24 20:48:02 +0100 | [diff] [blame] | 1339 | struct wayland_output *output; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1340 | struct weston_mode *mode; |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1341 | |
Sergi Granell | 7fecb43 | 2017-03-24 20:48:02 +0100 | [diff] [blame] | 1342 | output = wayland_output_create_common("wlparent"); |
| 1343 | if (!output) |
| 1344 | return -1; |
| 1345 | |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1346 | if (poutput->current_mode) { |
| 1347 | mode = poutput->current_mode; |
| 1348 | } else if (poutput->preferred_mode) { |
U. Artie Eoff | 67072d0 | 2014-05-06 14:50:02 -0700 | [diff] [blame] | 1349 | mode = poutput->preferred_mode; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1350 | } else if (!wl_list_empty(&poutput->mode_list)) { |
| 1351 | mode = container_of(poutput->mode_list.next, |
| 1352 | struct weston_mode, link); |
| 1353 | } else { |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1354 | weston_log("No valid modes found. Skipping output.\n"); |
| 1355 | goto out; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1356 | } |
| 1357 | |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 1358 | weston_output_init(&output->base, b->compositor); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1359 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1360 | output->base.scale = 1; |
| 1361 | output->base.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1362 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1363 | if (wayland_output_set_size(&output->base, mode->width, mode->height) < 0) |
| 1364 | goto out; |
| 1365 | |
| 1366 | output->mode = *mode; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1367 | output->parent.output = poutput->global; |
| 1368 | |
| 1369 | output->base.make = poutput->physical.make; |
| 1370 | output->base.model = poutput->physical.model; |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1371 | |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1372 | wl_list_init(&output->base.mode_list); |
| 1373 | wl_list_insert_list(&output->base.mode_list, &poutput->mode_list); |
| 1374 | wl_list_init(&poutput->mode_list); |
| 1375 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1376 | weston_compositor_add_pending_output(&output->base, b->compositor); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1377 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1378 | return 0; |
| 1379 | |
| 1380 | out: |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 1381 | free(output->base.name); |
| 1382 | free(output->title); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1383 | free(output); |
| 1384 | |
| 1385 | return -1; |
| 1386 | } |
| 1387 | |
| 1388 | static int |
| 1389 | wayland_output_create_fullscreen(struct wayland_backend *b) |
| 1390 | { |
Sergi Granell | 7fecb43 | 2017-03-24 20:48:02 +0100 | [diff] [blame] | 1391 | struct wayland_output *output; |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1392 | int width = 0, height = 0; |
| 1393 | |
Sergi Granell | 7fecb43 | 2017-03-24 20:48:02 +0100 | [diff] [blame] | 1394 | output = wayland_output_create_common("wayland-fullscreen"); |
| 1395 | if (!output) |
| 1396 | return -1; |
| 1397 | |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 1398 | weston_output_init(&output->base, b->compositor); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1399 | |
| 1400 | output->base.scale = 1; |
| 1401 | output->base.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 1402 | |
| 1403 | if (wayland_backend_create_output_surface(output) < 0) |
| 1404 | goto err_surface; |
| 1405 | |
| 1406 | /* What should size be set if conditional is false? */ |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 1407 | if (b->parent.xdg_shell || b->parent.shell) { |
| 1408 | if (output->parent.xdg_toplevel) |
| 1409 | zxdg_toplevel_v6_set_fullscreen(output->parent.xdg_toplevel, |
| 1410 | output->parent.output); |
| 1411 | else if (output->parent.shell_surface) |
| 1412 | wl_shell_surface_set_fullscreen(output->parent.shell_surface, |
| 1413 | 0, 0, NULL); |
| 1414 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1415 | wl_display_roundtrip(b->parent.wl_display); |
| 1416 | |
| 1417 | width = output->parent.configure_width; |
| 1418 | height = output->parent.configure_height; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1419 | } |
| 1420 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1421 | if (wayland_output_set_size(&output->base, width, height) < 0) |
| 1422 | goto err_set_size; |
| 1423 | |
| 1424 | weston_compositor_add_pending_output(&output->base, b->compositor); |
| 1425 | |
| 1426 | return 0; |
| 1427 | |
| 1428 | err_set_size: |
| 1429 | wayland_backend_destroy_output_surface(output); |
| 1430 | err_surface: |
Sergi Granell | 2dcbb8d | 2017-03-24 20:48:01 +0100 | [diff] [blame] | 1431 | free(output->base.name); |
| 1432 | free(output->title); |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 1433 | free(output); |
| 1434 | |
| 1435 | return -1; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 1436 | } |
| 1437 | |
Ander Conselvan de Oliveira | 563c5b8 | 2012-06-18 17:36:21 +0300 | [diff] [blame] | 1438 | static void |
| 1439 | shell_surface_ping(void *data, struct wl_shell_surface *shell_surface, |
| 1440 | uint32_t serial) |
| 1441 | { |
| 1442 | wl_shell_surface_pong(shell_surface, serial); |
| 1443 | } |
| 1444 | |
| 1445 | static void |
| 1446 | shell_surface_configure(void *data, struct wl_shell_surface *shell_surface, |
| 1447 | uint32_t edges, int32_t width, int32_t height) |
| 1448 | { |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 1449 | struct wayland_output *output = data; |
| 1450 | |
| 1451 | output->parent.configure_width = width; |
| 1452 | output->parent.configure_height = height; |
| 1453 | |
Ander Conselvan de Oliveira | 563c5b8 | 2012-06-18 17:36:21 +0300 | [diff] [blame] | 1454 | /* FIXME: implement resizing */ |
| 1455 | } |
| 1456 | |
| 1457 | static void |
| 1458 | shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface) |
| 1459 | { |
| 1460 | } |
| 1461 | |
| 1462 | static const struct wl_shell_surface_listener shell_surface_listener = { |
| 1463 | shell_surface_ping, |
| 1464 | shell_surface_configure, |
| 1465 | shell_surface_popup_done |
| 1466 | }; |
| 1467 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1468 | /* Events received from the wayland-server this compositor is client of: */ |
| 1469 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1470 | /* parent input interface */ |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 1471 | static void |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1472 | input_set_cursor(struct wayland_input *input) |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 1473 | { |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 1474 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1475 | struct wl_buffer *buffer; |
| 1476 | struct wl_cursor_image *image; |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 1477 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1478 | if (!input->backend->cursor) |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1479 | return; /* Couldn't load the cursor. Can't set it */ |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 1480 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1481 | image = input->backend->cursor->images[0]; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1482 | buffer = wl_cursor_image_get_buffer(image); |
Hardening | 842a36a | 2014-03-18 14:12:50 +0100 | [diff] [blame] | 1483 | if (!buffer) |
| 1484 | return; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1485 | |
| 1486 | wl_pointer_set_cursor(input->parent.pointer, input->enter_serial, |
| 1487 | input->parent.cursor.surface, |
| 1488 | image->hotspot_x, image->hotspot_y); |
| 1489 | |
| 1490 | wl_surface_attach(input->parent.cursor.surface, buffer, 0, 0); |
| 1491 | wl_surface_damage(input->parent.cursor.surface, 0, 0, |
| 1492 | image->width, image->height); |
| 1493 | wl_surface_commit(input->parent.cursor.surface); |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 1494 | } |
| 1495 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1496 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1497 | input_handle_pointer_enter(void *data, struct wl_pointer *pointer, |
| 1498 | uint32_t serial, struct wl_surface *surface, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1499 | wl_fixed_t fixed_x, wl_fixed_t fixed_y) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1500 | { |
| 1501 | struct wayland_input *input = data; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1502 | int32_t fx, fy; |
| 1503 | enum theme_location location; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1504 | double x, y; |
| 1505 | |
| 1506 | x = wl_fixed_to_double(fixed_x); |
| 1507 | y = wl_fixed_to_double(fixed_y); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1508 | |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1509 | /* XXX: If we get a modifier event immediately before the focus, |
| 1510 | * we should try to keep the same serial. */ |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 1511 | input->enter_serial = serial; |
| 1512 | input->output = wl_surface_get_user_data(surface); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1513 | |
| 1514 | if (input->output->frame) { |
| 1515 | location = frame_pointer_enter(input->output->frame, input, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1516 | x, y); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1517 | frame_interior(input->output->frame, &fx, &fy, NULL, NULL); |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1518 | x -= fx; |
| 1519 | y -= fy; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1520 | |
| 1521 | if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT) |
| 1522 | weston_output_schedule_repaint(&input->output->base); |
| 1523 | } else { |
| 1524 | location = THEME_LOCATION_CLIENT_AREA; |
| 1525 | } |
| 1526 | |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 1527 | weston_output_transform_coordinate(&input->output->base, x, y, &x, &y); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1528 | |
| 1529 | if (location == THEME_LOCATION_CLIENT_AREA) { |
Derek Foreman | 4bcc54d | 2015-11-06 15:56:06 -0600 | [diff] [blame] | 1530 | input->has_focus = true; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1531 | notify_pointer_focus(&input->base, &input->output->base, x, y); |
| 1532 | wl_pointer_set_cursor(input->parent.pointer, |
| 1533 | input->enter_serial, NULL, 0, 0); |
| 1534 | } else { |
Derek Foreman | 4bcc54d | 2015-11-06 15:56:06 -0600 | [diff] [blame] | 1535 | input->has_focus = false; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1536 | notify_pointer_focus(&input->base, NULL, 0, 0); |
| 1537 | input_set_cursor(input); |
| 1538 | } |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1542 | input_handle_pointer_leave(void *data, struct wl_pointer *pointer, |
| 1543 | uint32_t serial, struct wl_surface *surface) |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1544 | { |
| 1545 | struct wayland_input *input = data; |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1546 | |
Dima Ryazanov | 01d5c02 | 2015-05-18 23:14:16 -0700 | [diff] [blame] | 1547 | if (!input->output) |
| 1548 | return; |
| 1549 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1550 | if (input->output->frame) { |
| 1551 | frame_pointer_leave(input->output->frame, input); |
| 1552 | |
| 1553 | if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT) |
| 1554 | weston_output_schedule_repaint(&input->output->base); |
| 1555 | } |
| 1556 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1557 | notify_pointer_focus(&input->base, NULL, 0, 0); |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 1558 | input->output = NULL; |
Derek Foreman | 4bcc54d | 2015-11-06 15:56:06 -0600 | [diff] [blame] | 1559 | input->has_focus = false; |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1563 | input_handle_motion(void *data, struct wl_pointer *pointer, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1564 | uint32_t time, wl_fixed_t fixed_x, wl_fixed_t fixed_y) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1565 | { |
| 1566 | struct wayland_input *input = data; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1567 | int32_t fx, fy; |
| 1568 | enum theme_location location; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1569 | bool want_frame = false; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1570 | double x, y; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1571 | |
Dima Ryazanov | 01d5c02 | 2015-05-18 23:14:16 -0700 | [diff] [blame] | 1572 | if (!input->output) |
| 1573 | return; |
| 1574 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1575 | x = wl_fixed_to_double(fixed_x); |
| 1576 | y = wl_fixed_to_double(fixed_y); |
| 1577 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1578 | if (input->output->frame) { |
| 1579 | location = frame_pointer_motion(input->output->frame, input, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1580 | x, y); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1581 | frame_interior(input->output->frame, &fx, &fy, NULL, NULL); |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1582 | x -= fx; |
| 1583 | y -= fy; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1584 | |
| 1585 | if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT) |
| 1586 | weston_output_schedule_repaint(&input->output->base); |
| 1587 | } else { |
| 1588 | location = THEME_LOCATION_CLIENT_AREA; |
| 1589 | } |
| 1590 | |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 1591 | weston_output_transform_coordinate(&input->output->base, x, y, &x, &y); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1592 | |
Derek Foreman | 4bcc54d | 2015-11-06 15:56:06 -0600 | [diff] [blame] | 1593 | if (input->has_focus && location != THEME_LOCATION_CLIENT_AREA) { |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1594 | input_set_cursor(input); |
| 1595 | notify_pointer_focus(&input->base, NULL, 0, 0); |
Derek Foreman | 4bcc54d | 2015-11-06 15:56:06 -0600 | [diff] [blame] | 1596 | input->has_focus = false; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1597 | want_frame = true; |
Derek Foreman | 4bcc54d | 2015-11-06 15:56:06 -0600 | [diff] [blame] | 1598 | } else if (!input->has_focus && |
| 1599 | location == THEME_LOCATION_CLIENT_AREA) { |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1600 | wl_pointer_set_cursor(input->parent.pointer, |
| 1601 | input->enter_serial, NULL, 0, 0); |
| 1602 | notify_pointer_focus(&input->base, &input->output->base, x, y); |
Derek Foreman | 4bcc54d | 2015-11-06 15:56:06 -0600 | [diff] [blame] | 1603 | input->has_focus = true; |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1604 | want_frame = true; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1605 | } |
| 1606 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1607 | if (location == THEME_LOCATION_CLIENT_AREA) { |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1608 | notify_motion_absolute(&input->base, time, x, y); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1609 | want_frame = true; |
| 1610 | } |
| 1611 | |
| 1612 | if (want_frame && input->seat_version < WL_POINTER_FRAME_SINCE_VERSION) |
| 1613 | notify_pointer_frame(&input->base); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | static void |
| 1617 | input_handle_button(void *data, struct wl_pointer *pointer, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1618 | uint32_t serial, uint32_t time, uint32_t button, |
Quentin Glidic | d8b17bc | 2016-07-10 11:00:55 +0200 | [diff] [blame] | 1619 | enum wl_pointer_button_state state) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1620 | { |
| 1621 | struct wayland_input *input = data; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1622 | enum theme_location location; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1623 | |
Dima Ryazanov | 01d5c02 | 2015-05-18 23:14:16 -0700 | [diff] [blame] | 1624 | if (!input->output) |
| 1625 | return; |
| 1626 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1627 | if (input->output->frame) { |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1628 | location = frame_pointer_button(input->output->frame, input, |
Quentin Glidic | d8b17bc | 2016-07-10 11:00:55 +0200 | [diff] [blame] | 1629 | button, state); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1630 | |
| 1631 | if (frame_status(input->output->frame) & FRAME_STATUS_MOVE) { |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 1632 | if (input->output->parent.xdg_toplevel) |
| 1633 | zxdg_toplevel_v6_move(input->output->parent.xdg_toplevel, |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1634 | input->parent.seat, serial); |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 1635 | else if (input->output->parent.shell_surface) |
| 1636 | wl_shell_surface_move(input->output->parent.shell_surface, |
| 1637 | input->parent.seat, serial); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1638 | frame_status_clear(input->output->frame, |
| 1639 | FRAME_STATUS_MOVE); |
| 1640 | return; |
| 1641 | } |
| 1642 | |
Dima Ryazanov | 01d5c02 | 2015-05-18 23:14:16 -0700 | [diff] [blame] | 1643 | if (frame_status(input->output->frame) & FRAME_STATUS_CLOSE) { |
| 1644 | wayland_output_destroy(&input->output->base); |
Dima Ryazanov | b7e70af | 2015-05-20 01:03:53 -0700 | [diff] [blame] | 1645 | input->output = NULL; |
| 1646 | input->keyboard_focus = NULL; |
Dima Ryazanov | 01d5c02 | 2015-05-18 23:14:16 -0700 | [diff] [blame] | 1647 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1648 | if (wl_list_empty(&input->backend->compositor->output_list)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 1649 | weston_compositor_exit(input->backend->compositor); |
Dima Ryazanov | 01d5c02 | 2015-05-18 23:14:16 -0700 | [diff] [blame] | 1650 | |
| 1651 | return; |
| 1652 | } |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1653 | |
| 1654 | if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT) |
| 1655 | weston_output_schedule_repaint(&input->output->base); |
| 1656 | } else { |
| 1657 | location = THEME_LOCATION_CLIENT_AREA; |
| 1658 | } |
| 1659 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1660 | if (location == THEME_LOCATION_CLIENT_AREA) { |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1661 | notify_button(&input->base, time, button, state); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1662 | if (input->seat_version < WL_POINTER_FRAME_SINCE_VERSION) |
| 1663 | notify_pointer_frame(&input->base); |
| 1664 | } |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | static void |
| 1668 | input_handle_axis(void *data, struct wl_pointer *pointer, |
Daniel Stone | 2fce402 | 2012-05-30 16:32:00 +0100 | [diff] [blame] | 1669 | uint32_t time, uint32_t axis, wl_fixed_t value) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1670 | { |
| 1671 | struct wayland_input *input = data; |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1672 | struct weston_pointer_axis_event weston_event; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1673 | |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1674 | weston_event.axis = axis; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1675 | weston_event.value = wl_fixed_to_double(value); |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1676 | |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1677 | if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL && |
| 1678 | input->vert.has_discrete) { |
| 1679 | weston_event.has_discrete = true; |
| 1680 | weston_event.discrete = input->vert.discrete; |
| 1681 | input->vert.has_discrete = false; |
| 1682 | } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL && |
| 1683 | input->horiz.has_discrete) { |
| 1684 | weston_event.has_discrete = true; |
| 1685 | weston_event.discrete = input->horiz.discrete; |
| 1686 | input->horiz.has_discrete = false; |
| 1687 | } |
| 1688 | |
Peter Hutterer | 89b6a49 | 2016-01-18 15:58:17 +1000 | [diff] [blame] | 1689 | notify_axis(&input->base, time, &weston_event); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1690 | |
| 1691 | if (input->seat_version < WL_POINTER_FRAME_SINCE_VERSION) |
| 1692 | notify_pointer_frame(&input->base); |
| 1693 | } |
| 1694 | |
| 1695 | static void |
| 1696 | input_handle_frame(void *data, struct wl_pointer *pointer) |
| 1697 | { |
| 1698 | struct wayland_input *input = data; |
| 1699 | |
| 1700 | notify_pointer_frame(&input->base); |
| 1701 | } |
| 1702 | |
| 1703 | static void |
| 1704 | input_handle_axis_source(void *data, struct wl_pointer *pointer, |
| 1705 | uint32_t source) |
| 1706 | { |
| 1707 | struct wayland_input *input = data; |
| 1708 | |
| 1709 | notify_axis_source(&input->base, source); |
| 1710 | } |
| 1711 | |
| 1712 | static void |
| 1713 | input_handle_axis_stop(void *data, struct wl_pointer *pointer, |
| 1714 | uint32_t time, uint32_t axis) |
| 1715 | { |
| 1716 | struct wayland_input *input = data; |
| 1717 | struct weston_pointer_axis_event weston_event; |
| 1718 | |
| 1719 | weston_event.axis = axis; |
| 1720 | weston_event.value = 0; |
| 1721 | |
| 1722 | notify_axis(&input->base, time, &weston_event); |
| 1723 | } |
| 1724 | |
| 1725 | static void |
| 1726 | input_handle_axis_discrete(void *data, struct wl_pointer *pointer, |
| 1727 | uint32_t axis, int32_t discrete) |
| 1728 | { |
| 1729 | struct wayland_input *input = data; |
| 1730 | |
| 1731 | if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { |
| 1732 | input->vert.has_discrete = true; |
| 1733 | input->vert.discrete = discrete; |
| 1734 | } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { |
| 1735 | input->horiz.has_discrete = true; |
| 1736 | input->horiz.discrete = discrete; |
| 1737 | } |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | static const struct wl_pointer_listener pointer_listener = { |
| 1741 | input_handle_pointer_enter, |
| 1742 | input_handle_pointer_leave, |
| 1743 | input_handle_motion, |
| 1744 | input_handle_button, |
| 1745 | input_handle_axis, |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 1746 | input_handle_frame, |
| 1747 | input_handle_axis_source, |
| 1748 | input_handle_axis_stop, |
| 1749 | input_handle_axis_discrete, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1750 | }; |
| 1751 | |
| 1752 | static void |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 1753 | input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format, |
| 1754 | int fd, uint32_t size) |
| 1755 | { |
| 1756 | struct wayland_input *input = data; |
| 1757 | struct xkb_keymap *keymap; |
| 1758 | char *map_str; |
| 1759 | |
U. Artie Eoff | d8d4701 | 2014-05-06 14:50:03 -0700 | [diff] [blame] | 1760 | if (!data) { |
| 1761 | close(fd); |
| 1762 | return; |
| 1763 | } |
Jason Ekstrand | b7d9f2e | 2014-04-02 19:53:57 -0500 | [diff] [blame] | 1764 | |
| 1765 | if (format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { |
| 1766 | map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); |
| 1767 | if (map_str == MAP_FAILED) { |
| 1768 | weston_log("mmap failed: %m\n"); |
| 1769 | goto error; |
| 1770 | } |
| 1771 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1772 | keymap = xkb_keymap_new_from_string(input->backend->compositor->xkb_context, |
Ran Benita | 2e1968f | 2014-08-19 23:59:51 +0300 | [diff] [blame] | 1773 | map_str, |
| 1774 | XKB_KEYMAP_FORMAT_TEXT_V1, |
| 1775 | 0); |
Jason Ekstrand | b7d9f2e | 2014-04-02 19:53:57 -0500 | [diff] [blame] | 1776 | munmap(map_str, size); |
| 1777 | |
| 1778 | if (!keymap) { |
| 1779 | weston_log("failed to compile keymap\n"); |
| 1780 | goto error; |
| 1781 | } |
| 1782 | |
| 1783 | input->keyboard_state_update = STATE_UPDATE_NONE; |
| 1784 | } else if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP) { |
| 1785 | weston_log("No keymap provided; falling back to defalt\n"); |
| 1786 | keymap = NULL; |
| 1787 | input->keyboard_state_update = STATE_UPDATE_AUTOMATIC; |
| 1788 | } else { |
| 1789 | weston_log("Invalid keymap\n"); |
| 1790 | goto error; |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 1791 | } |
| 1792 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 1793 | close(fd); |
| 1794 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1795 | if (weston_seat_get_keyboard(&input->base)) |
Rui Matos | 0c194ce | 2013-10-10 19:44:21 +0200 | [diff] [blame] | 1796 | weston_seat_update_keymap(&input->base, keymap); |
| 1797 | else |
| 1798 | weston_seat_init_keyboard(&input->base, keymap); |
| 1799 | |
Ran Benita | c9c7415 | 2014-08-19 23:59:52 +0300 | [diff] [blame] | 1800 | xkb_keymap_unref(keymap); |
Jason Ekstrand | b7d9f2e | 2014-04-02 19:53:57 -0500 | [diff] [blame] | 1801 | |
| 1802 | return; |
| 1803 | |
| 1804 | error: |
| 1805 | wl_keyboard_release(input->parent.keyboard); |
| 1806 | close(fd); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | static void |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1810 | input_handle_keyboard_enter(void *data, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1811 | struct wl_keyboard *keyboard, |
| 1812 | uint32_t serial, |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1813 | struct wl_surface *surface, |
| 1814 | struct wl_array *keys) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1815 | { |
Kristian Høgsberg | af82bea | 2011-01-27 20:18:17 -0500 | [diff] [blame] | 1816 | struct wayland_input *input = data; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1817 | struct wayland_output *focus; |
| 1818 | |
| 1819 | focus = input->keyboard_focus; |
| 1820 | if (focus) { |
| 1821 | /* This shouldn't happen */ |
| 1822 | focus->keyboard_count--; |
| 1823 | if (!focus->keyboard_count && focus->frame) |
| 1824 | frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE); |
| 1825 | if (frame_status(focus->frame) & FRAME_STATUS_REPAINT) |
| 1826 | weston_output_schedule_repaint(&focus->base); |
| 1827 | } |
| 1828 | |
| 1829 | input->keyboard_focus = wl_surface_get_user_data(surface); |
| 1830 | input->keyboard_focus->keyboard_count++; |
| 1831 | |
| 1832 | focus = input->keyboard_focus; |
| 1833 | if (focus->frame) { |
| 1834 | frame_set_flag(focus->frame, FRAME_FLAG_ACTIVE); |
| 1835 | if (frame_status(focus->frame) & FRAME_STATUS_REPAINT) |
| 1836 | weston_output_schedule_repaint(&focus->base); |
| 1837 | } |
| 1838 | |
Kristian Høgsberg | af82bea | 2011-01-27 20:18:17 -0500 | [diff] [blame] | 1839 | |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1840 | /* XXX: If we get a modifier event immediately before the focus, |
| 1841 | * we should try to keep the same serial. */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1842 | notify_keyboard_focus_in(&input->base, keys, |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 1843 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | static void |
| 1847 | input_handle_keyboard_leave(void *data, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1848 | struct wl_keyboard *keyboard, |
| 1849 | uint32_t serial, |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1850 | struct wl_surface *surface) |
| 1851 | { |
| 1852 | struct wayland_input *input = data; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1853 | struct wayland_output *focus; |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1854 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1855 | notify_keyboard_focus_out(&input->base); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1856 | |
| 1857 | focus = input->keyboard_focus; |
| 1858 | if (!focus) |
Dima Ryazanov | 01d5c02 | 2015-05-18 23:14:16 -0700 | [diff] [blame] | 1859 | return; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1860 | |
| 1861 | focus->keyboard_count--; |
| 1862 | if (!focus->keyboard_count && focus->frame) { |
| 1863 | frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE); |
| 1864 | if (frame_status(focus->frame) & FRAME_STATUS_REPAINT) |
| 1865 | weston_output_schedule_repaint(&focus->base); |
| 1866 | } |
| 1867 | |
| 1868 | input->keyboard_focus = NULL; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1869 | } |
| 1870 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1871 | static void |
| 1872 | input_handle_key(void *data, struct wl_keyboard *keyboard, |
| 1873 | uint32_t serial, uint32_t time, uint32_t key, uint32_t state) |
| 1874 | { |
| 1875 | struct wayland_input *input = data; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1876 | |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1877 | input->key_serial = serial; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1878 | notify_key(&input->base, time, key, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 1879 | state ? WL_KEYBOARD_KEY_STATE_PRESSED : |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 1880 | WL_KEYBOARD_KEY_STATE_RELEASED, |
Jason Ekstrand | b7d9f2e | 2014-04-02 19:53:57 -0500 | [diff] [blame] | 1881 | input->keyboard_state_update); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1882 | } |
| 1883 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 1884 | static void |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1885 | input_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard, |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1886 | uint32_t serial_in, uint32_t mods_depressed, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 1887 | uint32_t mods_latched, uint32_t mods_locked, |
| 1888 | uint32_t group) |
| 1889 | { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1890 | struct weston_keyboard *keyboard; |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1891 | struct wayland_input *input = data; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1892 | struct wayland_backend *b = input->backend; |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1893 | uint32_t serial_out; |
| 1894 | |
| 1895 | /* If we get a key event followed by a modifier event with the |
| 1896 | * same serial number, then we try to preserve those semantics by |
| 1897 | * reusing the same serial number on the way out too. */ |
| 1898 | if (serial_in == input->key_serial) |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1899 | serial_out = wl_display_get_serial(b->compositor->wl_display); |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1900 | else |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1901 | serial_out = wl_display_next_serial(b->compositor->wl_display); |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1902 | |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1903 | keyboard = weston_seat_get_keyboard(&input->base); |
| 1904 | xkb_state_update_mask(keyboard->xkb_state.state, |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1905 | mods_depressed, mods_latched, |
| 1906 | mods_locked, 0, 0, group); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1907 | notify_modifiers(&input->base, serial_out); |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 1908 | } |
| 1909 | |
Jonny Lamb | 497994a | 2014-08-12 14:58:26 +0200 | [diff] [blame] | 1910 | static void |
| 1911 | input_handle_repeat_info(void *data, struct wl_keyboard *keyboard, |
| 1912 | int32_t rate, int32_t delay) |
| 1913 | { |
| 1914 | struct wayland_input *input = data; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1915 | struct wayland_backend *b = input->backend; |
Jonny Lamb | 497994a | 2014-08-12 14:58:26 +0200 | [diff] [blame] | 1916 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 1917 | b->compositor->kb_repeat_rate = rate; |
| 1918 | b->compositor->kb_repeat_delay = delay; |
Jonny Lamb | 497994a | 2014-08-12 14:58:26 +0200 | [diff] [blame] | 1919 | } |
| 1920 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1921 | static const struct wl_keyboard_listener keyboard_listener = { |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 1922 | input_handle_keymap, |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1923 | input_handle_keyboard_enter, |
| 1924 | input_handle_keyboard_leave, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1925 | input_handle_key, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 1926 | input_handle_modifiers, |
Jonny Lamb | 497994a | 2014-08-12 14:58:26 +0200 | [diff] [blame] | 1927 | input_handle_repeat_info, |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1928 | }; |
| 1929 | |
| 1930 | static void |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 1931 | input_handle_touch_down(void *data, struct wl_touch *wl_touch, |
| 1932 | uint32_t serial, uint32_t time, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1933 | struct wl_surface *surface, int32_t id, |
| 1934 | wl_fixed_t fixed_x, wl_fixed_t fixed_y) |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 1935 | { |
| 1936 | struct wayland_input *input = data; |
| 1937 | struct wayland_output *output; |
| 1938 | enum theme_location location; |
| 1939 | bool first_touch; |
| 1940 | int32_t fx, fy; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1941 | double x, y; |
| 1942 | |
| 1943 | x = wl_fixed_to_double(fixed_x); |
| 1944 | y = wl_fixed_to_double(fixed_y); |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 1945 | |
| 1946 | first_touch = (input->touch_points == 0); |
| 1947 | input->touch_points++; |
| 1948 | |
| 1949 | input->touch_focus = wl_surface_get_user_data(surface); |
| 1950 | output = input->touch_focus; |
| 1951 | if (!first_touch && !input->touch_active) |
| 1952 | return; |
| 1953 | |
| 1954 | if (output->frame) { |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1955 | location = frame_touch_down(output->frame, input, id, x, y); |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 1956 | |
| 1957 | frame_interior(output->frame, &fx, &fy, NULL, NULL); |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 1958 | x -= fx; |
| 1959 | y -= fy; |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 1960 | |
| 1961 | if (frame_status(output->frame) & FRAME_STATUS_REPAINT) |
| 1962 | weston_output_schedule_repaint(&output->base); |
| 1963 | |
| 1964 | if (first_touch && (frame_status(output->frame) & FRAME_STATUS_MOVE)) { |
| 1965 | input->touch_points--; |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 1966 | if (output->parent.xdg_toplevel) |
| 1967 | zxdg_toplevel_v6_move(output->parent.xdg_toplevel, |
| 1968 | input->parent.seat, serial); |
| 1969 | else if (output->parent.shell_surface) |
| 1970 | wl_shell_surface_move(output->parent.shell_surface, |
| 1971 | input->parent.seat, serial); |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 1972 | frame_status_clear(output->frame, |
| 1973 | FRAME_STATUS_MOVE); |
| 1974 | return; |
| 1975 | } |
| 1976 | |
| 1977 | if (first_touch && location != THEME_LOCATION_CLIENT_AREA) |
| 1978 | return; |
| 1979 | } |
| 1980 | |
| 1981 | weston_output_transform_coordinate(&output->base, x, y, &x, &y); |
| 1982 | |
| 1983 | notify_touch(&input->base, time, id, x, y, WL_TOUCH_DOWN); |
| 1984 | input->touch_active = true; |
| 1985 | } |
| 1986 | |
| 1987 | static void |
| 1988 | input_handle_touch_up(void *data, struct wl_touch *wl_touch, |
| 1989 | uint32_t serial, uint32_t time, int32_t id) |
| 1990 | { |
| 1991 | struct wayland_input *input = data; |
| 1992 | struct wayland_output *output = input->touch_focus; |
| 1993 | bool active = input->touch_active; |
| 1994 | |
| 1995 | input->touch_points--; |
| 1996 | if (input->touch_points == 0) { |
| 1997 | input->touch_focus = NULL; |
| 1998 | input->touch_active = false; |
| 1999 | } |
| 2000 | |
| 2001 | if (!output) |
| 2002 | return; |
| 2003 | |
| 2004 | if (output->frame) { |
| 2005 | frame_touch_up(output->frame, input, id); |
| 2006 | |
| 2007 | if (frame_status(output->frame) & FRAME_STATUS_CLOSE) { |
| 2008 | wayland_output_destroy(&output->base); |
| 2009 | input->touch_focus = NULL; |
| 2010 | input->keyboard_focus = NULL; |
| 2011 | if (wl_list_empty(&input->backend->compositor->output_list)) |
| 2012 | weston_compositor_exit(input->backend->compositor); |
| 2013 | |
| 2014 | return; |
| 2015 | } |
| 2016 | if (frame_status(output->frame) & FRAME_STATUS_REPAINT) |
| 2017 | weston_output_schedule_repaint(&output->base); |
| 2018 | } |
| 2019 | |
| 2020 | if (active) |
| 2021 | notify_touch(&input->base, time, id, 0, 0, WL_TOUCH_UP); |
| 2022 | } |
| 2023 | |
| 2024 | static void |
| 2025 | input_handle_touch_motion(void *data, struct wl_touch *wl_touch, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 2026 | uint32_t time, int32_t id, |
| 2027 | wl_fixed_t fixed_x, wl_fixed_t fixed_y) |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 2028 | { |
| 2029 | struct wayland_input *input = data; |
| 2030 | struct wayland_output *output = input->touch_focus; |
| 2031 | int32_t fx, fy; |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 2032 | double x, y; |
| 2033 | |
| 2034 | x = wl_fixed_to_double(fixed_x); |
| 2035 | y = wl_fixed_to_double(fixed_y); |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 2036 | |
| 2037 | if (!output || !input->touch_active) |
| 2038 | return; |
| 2039 | |
| 2040 | if (output->frame) { |
| 2041 | frame_interior(output->frame, &fx, &fy, NULL, NULL); |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 2042 | x -= fx; |
| 2043 | y -= fy; |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | weston_output_transform_coordinate(&output->base, x, y, &x, &y); |
| 2047 | |
| 2048 | notify_touch(&input->base, time, id, x, y, WL_TOUCH_MOTION); |
| 2049 | } |
| 2050 | |
| 2051 | static void |
| 2052 | input_handle_touch_frame(void *data, struct wl_touch *wl_touch) |
| 2053 | { |
| 2054 | struct wayland_input *input = data; |
| 2055 | |
| 2056 | if (!input->touch_focus || !input->touch_active) |
| 2057 | return; |
| 2058 | |
| 2059 | notify_touch_frame(&input->base); |
| 2060 | } |
| 2061 | |
| 2062 | static void |
| 2063 | input_handle_touch_cancel(void *data, struct wl_touch *wl_touch) |
| 2064 | { |
| 2065 | struct wayland_input *input = data; |
| 2066 | |
| 2067 | if (!input->touch_focus || !input->touch_active) |
| 2068 | return; |
| 2069 | |
| 2070 | notify_touch_cancel(&input->base); |
| 2071 | } |
| 2072 | |
| 2073 | static const struct wl_touch_listener touch_listener = { |
| 2074 | input_handle_touch_down, |
| 2075 | input_handle_touch_up, |
| 2076 | input_handle_touch_motion, |
| 2077 | input_handle_touch_frame, |
| 2078 | input_handle_touch_cancel, |
| 2079 | }; |
| 2080 | |
| 2081 | |
| 2082 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2083 | input_handle_capabilities(void *data, struct wl_seat *seat, |
| 2084 | enum wl_seat_capability caps) |
| 2085 | { |
| 2086 | struct wayland_input *input = data; |
| 2087 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 2088 | if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->parent.pointer) { |
| 2089 | input->parent.pointer = wl_seat_get_pointer(seat); |
| 2090 | wl_pointer_set_user_data(input->parent.pointer, input); |
| 2091 | wl_pointer_add_listener(input->parent.pointer, |
| 2092 | &pointer_listener, input); |
Kristian Høgsberg | 7af7ced | 2012-08-10 10:01:33 -0400 | [diff] [blame] | 2093 | weston_seat_init_pointer(&input->base); |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 2094 | } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->parent.pointer) { |
Derek Foreman | cfce7d0 | 2015-11-06 15:56:08 -0600 | [diff] [blame] | 2095 | if (input->seat_version >= WL_POINTER_RELEASE_SINCE_VERSION) |
| 2096 | wl_pointer_release(input->parent.pointer); |
| 2097 | else |
| 2098 | wl_pointer_destroy(input->parent.pointer); |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 2099 | input->parent.pointer = NULL; |
Derek Foreman | cfce7d0 | 2015-11-06 15:56:08 -0600 | [diff] [blame] | 2100 | weston_seat_release_pointer(&input->base); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2101 | } |
| 2102 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 2103 | if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->parent.keyboard) { |
| 2104 | input->parent.keyboard = wl_seat_get_keyboard(seat); |
| 2105 | wl_keyboard_set_user_data(input->parent.keyboard, input); |
| 2106 | wl_keyboard_add_listener(input->parent.keyboard, |
| 2107 | &keyboard_listener, input); |
| 2108 | } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->parent.keyboard) { |
Derek Foreman | cfce7d0 | 2015-11-06 15:56:08 -0600 | [diff] [blame] | 2109 | if (input->seat_version >= WL_KEYBOARD_RELEASE_SINCE_VERSION) |
| 2110 | wl_keyboard_release(input->parent.keyboard); |
| 2111 | else |
| 2112 | wl_keyboard_destroy(input->parent.keyboard); |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 2113 | input->parent.keyboard = NULL; |
Derek Foreman | cfce7d0 | 2015-11-06 15:56:08 -0600 | [diff] [blame] | 2114 | weston_seat_release_keyboard(&input->base); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2115 | } |
Derek Foreman | 748c695 | 2015-11-06 15:56:10 -0600 | [diff] [blame] | 2116 | |
| 2117 | if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->parent.touch) { |
| 2118 | input->parent.touch = wl_seat_get_touch(seat); |
| 2119 | wl_touch_set_user_data(input->parent.touch, input); |
| 2120 | wl_touch_add_listener(input->parent.touch, |
| 2121 | &touch_listener, input); |
| 2122 | weston_seat_init_touch(&input->base); |
| 2123 | } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->parent.touch) { |
| 2124 | if (input->seat_version >= WL_TOUCH_RELEASE_SINCE_VERSION) |
| 2125 | wl_touch_release(input->parent.touch); |
| 2126 | else |
| 2127 | wl_touch_destroy(input->parent.touch); |
| 2128 | input->parent.touch = NULL; |
| 2129 | weston_seat_release_touch(&input->base); |
| 2130 | } |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
Jonny Lamb | 497994a | 2014-08-12 14:58:26 +0200 | [diff] [blame] | 2133 | static void |
| 2134 | input_handle_name(void *data, struct wl_seat *seat, |
| 2135 | const char *name) |
| 2136 | { |
| 2137 | } |
| 2138 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2139 | static const struct wl_seat_listener seat_listener = { |
| 2140 | input_handle_capabilities, |
Jonny Lamb | 497994a | 2014-08-12 14:58:26 +0200 | [diff] [blame] | 2141 | input_handle_name, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2142 | }; |
| 2143 | |
| 2144 | static void |
Derek Foreman | cfce7d0 | 2015-11-06 15:56:08 -0600 | [diff] [blame] | 2145 | display_add_seat(struct wayland_backend *b, uint32_t id, uint32_t available_version) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2146 | { |
| 2147 | struct wayland_input *input; |
Derek Foreman | cfce7d0 | 2015-11-06 15:56:08 -0600 | [diff] [blame] | 2148 | uint32_t version = MIN(available_version, 4); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2149 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 2150 | input = zalloc(sizeof *input); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2151 | if (input == NULL) |
| 2152 | return; |
| 2153 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2154 | weston_seat_init(&input->base, b->compositor, "default"); |
| 2155 | input->backend = b; |
| 2156 | input->parent.seat = wl_registry_bind(b->parent.registry, id, |
Derek Foreman | cfce7d0 | 2015-11-06 15:56:08 -0600 | [diff] [blame] | 2157 | &wl_seat_interface, version); |
| 2158 | input->seat_version = version; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2159 | wl_list_insert(b->input_list.prev, &input->link); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2160 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 2161 | wl_seat_add_listener(input->parent.seat, &seat_listener, input); |
| 2162 | wl_seat_set_user_data(input->parent.seat, input); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 2163 | |
| 2164 | input->parent.cursor.surface = |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2165 | wl_compositor_create_surface(b->parent.compositor); |
Peter Hutterer | 87743e9 | 2016-01-18 16:38:22 +1000 | [diff] [blame] | 2166 | |
| 2167 | input->vert.axis = WL_POINTER_AXIS_VERTICAL_SCROLL; |
| 2168 | input->horiz.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | static void |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2172 | wayland_parent_output_geometry(void *data, struct wl_output *output_proxy, |
| 2173 | int32_t x, int32_t y, |
| 2174 | int32_t physical_width, int32_t physical_height, |
| 2175 | int32_t subpixel, const char *make, |
| 2176 | const char *model, int32_t transform) |
| 2177 | { |
| 2178 | struct wayland_parent_output *output = data; |
| 2179 | |
| 2180 | output->x = x; |
| 2181 | output->y = y; |
| 2182 | output->physical.width = physical_width; |
| 2183 | output->physical.height = physical_height; |
| 2184 | output->physical.subpixel = subpixel; |
| 2185 | |
| 2186 | free(output->physical.make); |
| 2187 | output->physical.make = strdup(make); |
| 2188 | free(output->physical.model); |
| 2189 | output->physical.model = strdup(model); |
| 2190 | |
| 2191 | output->transform = transform; |
| 2192 | } |
| 2193 | |
| 2194 | static struct weston_mode * |
| 2195 | find_mode(struct wl_list *list, int32_t width, int32_t height, uint32_t refresh) |
| 2196 | { |
| 2197 | struct weston_mode *mode; |
| 2198 | |
| 2199 | wl_list_for_each(mode, list, link) { |
| 2200 | if (mode->width == width && mode->height == height && |
| 2201 | mode->refresh == refresh) |
| 2202 | return mode; |
| 2203 | } |
| 2204 | |
| 2205 | mode = zalloc(sizeof *mode); |
| 2206 | if (!mode) |
| 2207 | return NULL; |
| 2208 | |
| 2209 | mode->width = width; |
| 2210 | mode->height = height; |
| 2211 | mode->refresh = refresh; |
| 2212 | wl_list_insert(list, &mode->link); |
| 2213 | |
| 2214 | return mode; |
| 2215 | } |
| 2216 | |
| 2217 | static void |
| 2218 | wayland_parent_output_mode(void *data, struct wl_output *wl_output_proxy, |
| 2219 | uint32_t flags, int32_t width, int32_t height, |
| 2220 | int32_t refresh) |
| 2221 | { |
| 2222 | struct wayland_parent_output *output = data; |
| 2223 | struct weston_mode *mode; |
| 2224 | |
| 2225 | if (output->output) { |
| 2226 | mode = find_mode(&output->output->base.mode_list, |
| 2227 | width, height, refresh); |
| 2228 | if (!mode) |
| 2229 | return; |
| 2230 | mode->flags = flags; |
| 2231 | /* Do a mode-switch on current mode change? */ |
| 2232 | } else { |
| 2233 | mode = find_mode(&output->mode_list, width, height, refresh); |
| 2234 | if (!mode) |
| 2235 | return; |
| 2236 | mode->flags = flags; |
| 2237 | if (flags & WL_OUTPUT_MODE_CURRENT) |
| 2238 | output->current_mode = mode; |
| 2239 | if (flags & WL_OUTPUT_MODE_PREFERRED) |
| 2240 | output->preferred_mode = mode; |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | static const struct wl_output_listener output_listener = { |
| 2245 | wayland_parent_output_geometry, |
| 2246 | wayland_parent_output_mode |
| 2247 | }; |
| 2248 | |
| 2249 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2250 | wayland_backend_register_output(struct wayland_backend *b, uint32_t id) |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2251 | { |
| 2252 | struct wayland_parent_output *output; |
| 2253 | |
| 2254 | output = zalloc(sizeof *output); |
| 2255 | if (!output) |
| 2256 | return; |
| 2257 | |
| 2258 | output->id = id; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2259 | output->global = wl_registry_bind(b->parent.registry, id, |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2260 | &wl_output_interface, 1); |
U. Artie Eoff | 8cbd8f3 | 2014-05-06 14:50:01 -0700 | [diff] [blame] | 2261 | if (!output->global) { |
| 2262 | free(output); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2263 | return; |
U. Artie Eoff | 8cbd8f3 | 2014-05-06 14:50:01 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2266 | wl_output_add_listener(output->global, &output_listener, output); |
| 2267 | |
| 2268 | output->scale = 0; |
| 2269 | output->transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 2270 | output->physical.subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN; |
| 2271 | wl_list_init(&output->mode_list); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2272 | wl_list_insert(&b->parent.output_list, &output->link); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2273 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2274 | if (b->sprawl_across_outputs) { |
| 2275 | wl_display_roundtrip(b->parent.wl_display); |
| 2276 | wayland_output_create_for_parent_output(b, output); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2277 | } |
| 2278 | } |
| 2279 | |
| 2280 | static void |
| 2281 | wayland_parent_output_destroy(struct wayland_parent_output *output) |
| 2282 | { |
| 2283 | struct weston_mode *mode, *next; |
| 2284 | |
| 2285 | if (output->output) |
| 2286 | wayland_output_destroy(&output->output->base); |
| 2287 | |
| 2288 | wl_output_destroy(output->global); |
| 2289 | free(output->physical.make); |
| 2290 | free(output->physical.model); |
| 2291 | |
| 2292 | wl_list_for_each_safe(mode, next, &output->mode_list, link) { |
| 2293 | wl_list_remove(&mode->link); |
| 2294 | free(mode); |
| 2295 | } |
| 2296 | } |
| 2297 | |
| 2298 | static void |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 2299 | xdg_shell_ping(void *data, struct zxdg_shell_v6 *shell, uint32_t serial) |
| 2300 | { |
| 2301 | zxdg_shell_v6_pong(shell, serial); |
| 2302 | } |
| 2303 | |
| 2304 | static const struct zxdg_shell_v6_listener xdg_shell_listener = { |
| 2305 | xdg_shell_ping, |
| 2306 | }; |
| 2307 | |
| 2308 | static void |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 2309 | registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, |
| 2310 | const char *interface, uint32_t version) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2311 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2312 | struct wayland_backend *b = data; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2313 | |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 2314 | if (strcmp(interface, "wl_compositor") == 0) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2315 | b->parent.compositor = |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 2316 | wl_registry_bind(registry, name, |
Derek Foreman | dbfd248 | 2017-05-19 10:42:07 -0500 | [diff] [blame] | 2317 | &wl_compositor_interface, |
| 2318 | MIN(version, 4)); |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 2319 | } else if (strcmp(interface, "zxdg_shell_v6") == 0) { |
| 2320 | b->parent.xdg_shell = |
| 2321 | wl_registry_bind(registry, name, |
| 2322 | &zxdg_shell_v6_interface, 1); |
| 2323 | zxdg_shell_v6_add_listener(b->parent.xdg_shell, |
| 2324 | &xdg_shell_listener, b); |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 2325 | } else if (strcmp(interface, "wl_shell") == 0) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2326 | b->parent.shell = |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 2327 | wl_registry_bind(registry, name, |
| 2328 | &wl_shell_interface, 1); |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 2329 | } else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2330 | b->parent.fshell = |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2331 | wl_registry_bind(registry, name, |
Jonas Ådahl | 496adb3 | 2015-11-17 16:00:27 +0800 | [diff] [blame] | 2332 | &zwp_fullscreen_shell_v1_interface, 1); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2333 | } else if (strcmp(interface, "wl_seat") == 0) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2334 | display_add_seat(b, name, version); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2335 | } else if (strcmp(interface, "wl_output") == 0) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2336 | wayland_backend_register_output(b, name); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2337 | } else if (strcmp(interface, "wl_shm") == 0) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2338 | b->parent.shm = |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2339 | wl_registry_bind(registry, name, &wl_shm_interface, 1); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2340 | } |
| 2341 | } |
| 2342 | |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2343 | static void |
| 2344 | registry_handle_global_remove(void *data, struct wl_registry *registry, |
| 2345 | uint32_t name) |
| 2346 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2347 | struct wayland_backend *b = data; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2348 | struct wayland_parent_output *output; |
| 2349 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2350 | wl_list_for_each(output, &b->parent.output_list, link) |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2351 | if (output->id == name) |
| 2352 | wayland_parent_output_destroy(output); |
| 2353 | } |
| 2354 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 2355 | static const struct wl_registry_listener registry_listener = { |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2356 | registry_handle_global, |
| 2357 | registry_handle_global_remove |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 2358 | }; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2359 | |
Kristian Høgsberg | 95d843d | 2011-04-22 13:01:26 -0400 | [diff] [blame] | 2360 | static int |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2361 | wayland_backend_handle_event(int fd, uint32_t mask, void *data) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2362 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2363 | struct wayland_backend *b = data; |
Kristian Høgsberg | feb3c1d | 2012-10-15 12:56:11 -0400 | [diff] [blame] | 2364 | int count = 0; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2365 | |
Kristian Høgsberg | 453de7a | 2013-10-30 23:15:44 -0700 | [diff] [blame] | 2366 | if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) { |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 2367 | weston_compositor_exit(b->compositor); |
Kristian Høgsberg | 453de7a | 2013-10-30 23:15:44 -0700 | [diff] [blame] | 2368 | return 0; |
| 2369 | } |
| 2370 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2371 | if (mask & WL_EVENT_READABLE) |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2372 | count = wl_display_dispatch(b->parent.wl_display); |
Kristian Høgsberg | f258a31 | 2011-12-28 22:51:20 -0500 | [diff] [blame] | 2373 | if (mask & WL_EVENT_WRITABLE) |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2374 | wl_display_flush(b->parent.wl_display); |
Kristian Høgsberg | 95d843d | 2011-04-22 13:01:26 -0400 | [diff] [blame] | 2375 | |
Kristian Høgsberg | feb3c1d | 2012-10-15 12:56:11 -0400 | [diff] [blame] | 2376 | if (mask == 0) { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2377 | count = wl_display_dispatch_pending(b->parent.wl_display); |
| 2378 | wl_display_flush(b->parent.wl_display); |
Kristian Høgsberg | feb3c1d | 2012-10-15 12:56:11 -0400 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | return count; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2382 | } |
| 2383 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2384 | static void |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 2385 | wayland_restore(struct weston_compositor *ec) |
| 2386 | { |
| 2387 | } |
| 2388 | |
| 2389 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2390 | wayland_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2391 | { |
Armin Krezović | 938dc52 | 2016-08-01 19:17:57 +0200 | [diff] [blame] | 2392 | struct wayland_backend *b = to_wayland_backend(ec); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2393 | |
Armin Krezović | 78895c5 | 2016-10-09 17:30:28 +0200 | [diff] [blame] | 2394 | wl_event_source_remove(b->parent.wl_source); |
| 2395 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2396 | weston_compositor_shutdown(ec); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2397 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2398 | if (b->parent.shm) |
| 2399 | wl_shm_destroy(b->parent.shm); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2400 | |
Armin Krezović | 3447619 | 2016-11-21 18:42:42 +0100 | [diff] [blame] | 2401 | if (b->parent.xdg_shell) |
| 2402 | zxdg_shell_v6_destroy(b->parent.xdg_shell); |
| 2403 | |
| 2404 | if (b->parent.shell) |
| 2405 | wl_shell_destroy(b->parent.shell); |
| 2406 | |
Armin Krezović | 78895c5 | 2016-10-09 17:30:28 +0200 | [diff] [blame] | 2407 | if (b->parent.fshell) |
| 2408 | zwp_fullscreen_shell_v1_release(b->parent.fshell); |
| 2409 | |
| 2410 | if (b->parent.compositor) |
| 2411 | wl_compositor_destroy(b->parent.compositor); |
| 2412 | |
Armin Krezović | 78895c5 | 2016-10-09 17:30:28 +0200 | [diff] [blame] | 2413 | if (b->theme) |
| 2414 | theme_destroy(b->theme); |
| 2415 | |
| 2416 | if (b->frame_device) |
| 2417 | cairo_device_destroy(b->frame_device); |
| 2418 | |
| 2419 | wl_cursor_theme_destroy(b->cursor_theme); |
| 2420 | |
Daniel Stone | 698f9bf | 2016-11-24 15:31:33 +0000 | [diff] [blame] | 2421 | wl_registry_destroy(b->parent.registry); |
| 2422 | wl_display_flush(b->parent.wl_display); |
| 2423 | wl_display_disconnect(b->parent.wl_display); |
| 2424 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2425 | free(b); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 2426 | } |
| 2427 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 2428 | static const char *left_ptrs[] = { |
| 2429 | "left_ptr", |
| 2430 | "default", |
| 2431 | "top_left_arrow", |
| 2432 | "left-arrow" |
| 2433 | }; |
| 2434 | |
| 2435 | static void |
Benoit Gschwind | 244ff79 | 2016-04-28 20:33:11 +0200 | [diff] [blame] | 2436 | create_cursor(struct wayland_backend *b, |
| 2437 | struct weston_wayland_backend_config *config) |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 2438 | { |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 2439 | unsigned int i; |
| 2440 | |
Benoit Gschwind | 244ff79 | 2016-04-28 20:33:11 +0200 | [diff] [blame] | 2441 | b->cursor_theme = wl_cursor_theme_load(config->cursor_theme, |
| 2442 | config->cursor_size, |
| 2443 | b->parent.shm); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2444 | if (!b->cursor_theme) { |
Hardening | 842a36a | 2014-03-18 14:12:50 +0100 | [diff] [blame] | 2445 | fprintf(stderr, "could not load cursor theme\n"); |
| 2446 | return; |
| 2447 | } |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 2448 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2449 | b->cursor = NULL; |
| 2450 | for (i = 0; !b->cursor && i < ARRAY_LENGTH(left_ptrs); ++i) |
| 2451 | b->cursor = wl_cursor_theme_get_cursor(b->cursor_theme, |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 2452 | left_ptrs[i]); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2453 | if (!b->cursor) { |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 2454 | fprintf(stderr, "could not load left cursor\n"); |
| 2455 | return; |
| 2456 | } |
| 2457 | } |
| 2458 | |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 2459 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 2460 | fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time, |
| 2461 | uint32_t key, void *data) |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 2462 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2463 | struct wayland_backend *b = data; |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 2464 | struct wayland_input *input = NULL; |
| 2465 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2466 | wl_list_for_each(input, &b->input_list, link) |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 2467 | if (&input->base == keyboard->seat) |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 2468 | break; |
| 2469 | |
| 2470 | if (!input || !input->output) |
| 2471 | return; |
| 2472 | |
| 2473 | if (input->output->frame) |
| 2474 | wayland_output_set_fullscreen(input->output, 0, 0, NULL); |
| 2475 | else |
| 2476 | wayland_output_set_windowed(input->output); |
| 2477 | |
| 2478 | weston_output_schedule_repaint(&input->output->base); |
| 2479 | } |
| 2480 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2481 | static struct wayland_backend * |
Benoit Gschwind | 3a49b51 | 2016-04-28 20:33:10 +0200 | [diff] [blame] | 2482 | wayland_backend_create(struct weston_compositor *compositor, |
Pekka Paalanen | a256c5e | 2016-06-03 14:56:18 +0300 | [diff] [blame] | 2483 | struct weston_wayland_backend_config *new_config) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2484 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2485 | struct wayland_backend *b; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2486 | struct wl_event_loop *loop; |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2487 | int fd; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2488 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2489 | b = zalloc(sizeof *b); |
| 2490 | if (b == NULL) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2491 | return NULL; |
| 2492 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2493 | b->compositor = compositor; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2494 | if (weston_compositor_set_presentation_clock_software(compositor) < 0) |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2495 | goto err_compositor; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2496 | |
Benoit Gschwind | 3a49b51 | 2016-04-28 20:33:10 +0200 | [diff] [blame] | 2497 | b->parent.wl_display = wl_display_connect(new_config->display_name); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2498 | if (b->parent.wl_display == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2499 | weston_log("failed to create display: %m\n"); |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 2500 | goto err_compositor; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2501 | } |
| 2502 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2503 | wl_list_init(&b->parent.output_list); |
| 2504 | wl_list_init(&b->input_list); |
| 2505 | b->parent.registry = wl_display_get_registry(b->parent.wl_display); |
| 2506 | wl_registry_add_listener(b->parent.registry, ®istry_listener, b); |
| 2507 | wl_display_roundtrip(b->parent.wl_display); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 2508 | |
Benoit Gschwind | 244ff79 | 2016-04-28 20:33:11 +0200 | [diff] [blame] | 2509 | create_cursor(b, new_config); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2510 | |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 2511 | #ifdef ENABLE_EGL |
Benoit Gschwind | 3a49b51 | 2016-04-28 20:33:10 +0200 | [diff] [blame] | 2512 | b->use_pixman = new_config->use_pixman; |
Armin Krezović | b08e1a5 | 2016-12-09 22:58:27 +0100 | [diff] [blame] | 2513 | #else |
| 2514 | b->use_pixman = true; |
| 2515 | #endif |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 2516 | b->fullscreen = new_config->fullscreen; |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 2517 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2518 | if (!b->use_pixman) { |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 2519 | gl_renderer = weston_load_module("gl-renderer.so", |
| 2520 | "gl_renderer_interface"); |
| 2521 | if (!gl_renderer) |
Armin Krezović | 7e71b87 | 2016-10-09 17:30:22 +0200 | [diff] [blame] | 2522 | b->use_pixman = true; |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 2523 | } |
| 2524 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2525 | if (!b->use_pixman) { |
Miguel A. Vico | dddc670 | 2016-05-18 17:41:07 +0200 | [diff] [blame] | 2526 | if (gl_renderer->display_create(compositor, |
| 2527 | EGL_PLATFORM_WAYLAND_KHR, |
| 2528 | b->parent.wl_display, |
Miguel A. Vico | 41700e3 | 2016-05-18 17:47:59 +0200 | [diff] [blame] | 2529 | NULL, |
Miguel A. Vico | dddc670 | 2016-05-18 17:41:07 +0200 | [diff] [blame] | 2530 | gl_renderer->alpha_attribs, |
| 2531 | NULL, |
| 2532 | 0) < 0) { |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 2533 | weston_log("Failed to initialize the GL renderer; " |
| 2534 | "falling back to pixman.\n"); |
Armin Krezović | 7e71b87 | 2016-10-09 17:30:22 +0200 | [diff] [blame] | 2535 | b->use_pixman = true; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 2536 | } |
| 2537 | } |
| 2538 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2539 | if (b->use_pixman) { |
| 2540 | if (pixman_renderer_init(compositor) < 0) { |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 2541 | weston_log("Failed to initialize pixman renderer\n"); |
| 2542 | goto err_display; |
| 2543 | } |
| 2544 | } |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2545 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2546 | b->base.destroy = wayland_destroy; |
| 2547 | b->base.restore = wayland_restore; |
Benjamin Franzke | ecfb2b9 | 2011-01-15 12:34:48 +0100 | [diff] [blame] | 2548 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2549 | loop = wl_display_get_event_loop(compositor->wl_display); |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2550 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2551 | fd = wl_display_get_fd(b->parent.wl_display); |
| 2552 | b->parent.wl_source = |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2553 | wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2554 | wayland_backend_handle_event, b); |
| 2555 | if (b->parent.wl_source == NULL) |
Dawid Gajownik | 82d4925 | 2015-07-31 00:02:28 -0300 | [diff] [blame] | 2556 | goto err_display; |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2557 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2558 | wl_event_source_check(b->parent.wl_source); |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2559 | |
Emmanuel Gil Peyrot | c59f18e | 2015-09-25 11:58:40 +0200 | [diff] [blame] | 2560 | if (compositor->renderer->import_dmabuf) { |
| 2561 | if (linux_dmabuf_setup(compositor) < 0) |
| 2562 | weston_log("Error: initializing dmabuf " |
| 2563 | "support failed.\n"); |
| 2564 | } |
| 2565 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2566 | compositor->backend = &b->base; |
| 2567 | return b; |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2568 | err_display: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2569 | wl_display_disconnect(b->parent.wl_display); |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2570 | err_compositor: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2571 | weston_compositor_shutdown(compositor); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2572 | free(b); |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2573 | return NULL; |
| 2574 | } |
| 2575 | |
| 2576 | static void |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2577 | wayland_backend_destroy(struct wayland_backend *b) |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2578 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2579 | wl_display_disconnect(b->parent.wl_display); |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2580 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2581 | if (b->theme) |
| 2582 | theme_destroy(b->theme); |
| 2583 | if (b->frame_device) |
| 2584 | cairo_device_destroy(b->frame_device); |
| 2585 | wl_cursor_theme_destroy(b->cursor_theme); |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2586 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2587 | weston_compositor_shutdown(b->compositor); |
| 2588 | free(b); |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2589 | } |
| 2590 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 2591 | static const struct weston_windowed_output_api windowed_api = { |
| 2592 | wayland_output_set_size, |
| 2593 | wayland_output_create, |
| 2594 | }; |
| 2595 | |
Benoit Gschwind | cd63b3e | 2016-04-28 20:33:14 +0200 | [diff] [blame] | 2596 | static void |
Benoit Gschwind | e091b45 | 2016-05-10 22:47:48 +0200 | [diff] [blame] | 2597 | config_init_to_defaults(struct weston_wayland_backend_config *config) |
| 2598 | { |
| 2599 | } |
| 2600 | |
Benoit Gschwind | cd63b3e | 2016-04-28 20:33:14 +0200 | [diff] [blame] | 2601 | WL_EXPORT int |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame] | 2602 | weston_backend_init(struct weston_compositor *compositor, |
| 2603 | struct weston_backend_config *config_base) |
Benoit Gschwind | cd63b3e | 2016-04-28 20:33:14 +0200 | [diff] [blame] | 2604 | { |
| 2605 | struct wayland_backend *b; |
Benoit Gschwind | cd63b3e | 2016-04-28 20:33:14 +0200 | [diff] [blame] | 2606 | struct wayland_parent_output *poutput; |
| 2607 | struct weston_wayland_backend_config new_config; |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 2608 | int ret; |
Benoit Gschwind | cd63b3e | 2016-04-28 20:33:14 +0200 | [diff] [blame] | 2609 | |
Benoit Gschwind | e091b45 | 2016-05-10 22:47:48 +0200 | [diff] [blame] | 2610 | if (config_base == NULL || |
| 2611 | config_base->struct_version != WESTON_WAYLAND_BACKEND_CONFIG_VERSION || |
| 2612 | config_base->struct_size > sizeof(struct weston_wayland_backend_config)) { |
| 2613 | weston_log("wayland backend config structure is invalid\n"); |
Benoit Gschwind | e091b45 | 2016-05-10 22:47:48 +0200 | [diff] [blame] | 2614 | return -1; |
| 2615 | } |
| 2616 | |
| 2617 | config_init_to_defaults(&new_config); |
| 2618 | memcpy(&new_config, config_base, config_base->struct_size); |
| 2619 | |
Pekka Paalanen | a256c5e | 2016-06-03 14:56:18 +0300 | [diff] [blame] | 2620 | b = wayland_backend_create(compositor, &new_config); |
Benoit Gschwind | 37a6807 | 2016-04-28 20:33:08 +0200 | [diff] [blame] | 2621 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2622 | if (!b) |
| 2623 | return -1; |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2624 | |
Benoit Gschwind | 37a6807 | 2016-04-28 20:33:08 +0200 | [diff] [blame] | 2625 | if (new_config.sprawl || b->parent.fshell) { |
Armin Krezović | 7f1c0b8 | 2016-10-09 17:30:23 +0200 | [diff] [blame] | 2626 | b->sprawl_across_outputs = true; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2627 | wl_display_roundtrip(b->parent.wl_display); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2628 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2629 | wl_list_for_each(poutput, &b->parent.output_list, link) |
| 2630 | wayland_output_create_for_parent_output(b, poutput); |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2631 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2632 | return 0; |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2633 | } |
| 2634 | |
Benoit Gschwind | 37a6807 | 2016-04-28 20:33:08 +0200 | [diff] [blame] | 2635 | if (new_config.fullscreen) { |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 2636 | if (wayland_output_create_fullscreen(b) < 0) { |
| 2637 | weston_log("Unable to create a fullscreen output.\n"); |
Benoit Gschwind | cd63b3e | 2016-04-28 20:33:14 +0200 | [diff] [blame] | 2638 | goto err_outputs; |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 2639 | } |
Benoit Gschwind | 830b788 | 2016-04-28 20:33:12 +0200 | [diff] [blame] | 2640 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2641 | return 0; |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 2642 | } |
| 2643 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 2644 | ret = weston_plugin_api_register(compositor, WESTON_WINDOWED_OUTPUT_API_NAME, |
| 2645 | &windowed_api, sizeof(windowed_api)); |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2646 | |
Armin Krezović | 174448a | 2016-09-30 14:11:09 +0200 | [diff] [blame] | 2647 | if (ret < 0) { |
| 2648 | weston_log("Failed to register output API.\n"); |
| 2649 | wayland_backend_destroy(b); |
| 2650 | return -1; |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 2651 | } |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2652 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2653 | weston_compositor_add_key_binding(compositor, KEY_F, |
Jason Ekstrand | 53ee0dc | 2014-04-02 19:53:54 -0500 | [diff] [blame] | 2654 | MODIFIER_CTRL | MODIFIER_ALT, |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2655 | fullscreen_binding, b); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2656 | return 0; |
Jason Ekstrand | 0cf3935 | 2013-11-07 20:13:31 -0600 | [diff] [blame] | 2657 | |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 2658 | err_outputs: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 2659 | wayland_backend_destroy(b); |
| 2660 | return -1; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 2661 | } |