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