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