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