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