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