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