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