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