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