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