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