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