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