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