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