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