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