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