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