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