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