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> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 33 | |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 34 | #include <wayland-client.h> |
| 35 | #include <wayland-egl.h> |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 36 | #include <wayland-cursor.h> |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 37 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 38 | #include "compositor.h" |
John Kåre Alsaker | 30d2b1f | 2012-11-13 19:10:28 +0100 | [diff] [blame] | 39 | #include "gl-renderer.h" |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 40 | #include "pixman-renderer.h" |
Kristian Høgsberg | 3c2360f | 2013-01-28 16:01:22 -0500 | [diff] [blame] | 41 | #include "../shared/image-loader.h" |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 42 | #include "../shared/os-compatibility.h" |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 43 | #include "../shared/cairo-util.h" |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 44 | |
| 45 | struct wayland_compositor { |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 46 | struct weston_compositor base; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 47 | |
| 48 | struct { |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 49 | struct wl_display *wl_display; |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 50 | struct wl_registry *registry; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 51 | struct wl_compositor *compositor; |
| 52 | struct wl_shell *shell; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 53 | struct wl_output *output; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 54 | struct wl_shm *shm; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 55 | |
| 56 | struct { |
| 57 | int32_t x, y, width, height; |
| 58 | } screen_allocation; |
| 59 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 60 | struct wl_event_source *wl_source; |
| 61 | uint32_t event_mask; |
| 62 | } parent; |
| 63 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 64 | int use_pixman; |
| 65 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 66 | struct theme *theme; |
| 67 | cairo_device_t *frame_device; |
| 68 | struct wl_cursor_theme *cursor_theme; |
| 69 | struct wl_cursor *cursor; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 70 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 71 | struct wl_list inputs; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | struct wayland_output { |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 75 | struct weston_output base; |
| 76 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 77 | struct { |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 78 | int draw_initial_frame; |
| 79 | struct wl_surface *surface; |
| 80 | struct wl_shell_surface *shell_surface; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 81 | } parent; |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 82 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 83 | int keyboard_count; |
| 84 | |
| 85 | struct frame *frame; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 86 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 87 | struct { |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 88 | struct wl_egl_window *egl_window; |
| 89 | struct { |
| 90 | cairo_surface_t *top; |
| 91 | cairo_surface_t *left; |
| 92 | cairo_surface_t *right; |
| 93 | cairo_surface_t *bottom; |
| 94 | } border; |
| 95 | } gl; |
| 96 | |
| 97 | struct { |
| 98 | struct wl_list buffers; |
| 99 | struct wl_list free_buffers; |
| 100 | } shm; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 101 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 102 | struct weston_mode mode; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 103 | }; |
| 104 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 105 | struct wayland_shm_buffer { |
| 106 | struct wayland_output *output; |
| 107 | struct wl_list link; |
| 108 | struct wl_list free_link; |
| 109 | |
| 110 | struct wl_buffer *buffer; |
| 111 | void *data; |
| 112 | size_t size; |
| 113 | pixman_region32_t damage; |
| 114 | int frame_damaged; |
| 115 | |
| 116 | pixman_image_t *pm_image; |
| 117 | cairo_surface_t *c_surface; |
| 118 | }; |
| 119 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 120 | struct wayland_input { |
Kristian Høgsberg | 7af7ced | 2012-08-10 10:01:33 -0400 | [diff] [blame] | 121 | struct weston_seat base; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 122 | struct wayland_compositor *compositor; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 123 | struct wl_list link; |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 124 | |
| 125 | struct { |
| 126 | struct wl_seat *seat; |
| 127 | struct wl_pointer *pointer; |
| 128 | struct wl_keyboard *keyboard; |
| 129 | struct wl_touch *touch; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 130 | |
| 131 | struct { |
| 132 | struct wl_surface *surface; |
| 133 | int32_t hx, hy; |
| 134 | } cursor; |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 135 | } parent; |
| 136 | |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 137 | uint32_t key_serial; |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 138 | uint32_t enter_serial; |
| 139 | int focus; |
| 140 | struct wayland_output *output; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 141 | struct wayland_output *keyboard_focus; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 142 | }; |
| 143 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 144 | struct gl_renderer_interface *gl_renderer; |
| 145 | |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 146 | static void |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 147 | wayland_shm_buffer_destroy(struct wayland_shm_buffer *buffer) |
| 148 | { |
| 149 | cairo_surface_destroy(buffer->c_surface); |
| 150 | pixman_image_unref(buffer->pm_image); |
| 151 | |
| 152 | wl_buffer_destroy(buffer->buffer); |
| 153 | munmap(buffer->data, buffer->size); |
| 154 | |
| 155 | pixman_region32_fini(&buffer->damage); |
| 156 | |
| 157 | wl_list_remove(&buffer->link); |
| 158 | wl_list_remove(&buffer->free_link); |
| 159 | free(buffer); |
| 160 | } |
| 161 | |
| 162 | static void |
| 163 | buffer_release(void *data, struct wl_buffer *buffer) |
| 164 | { |
| 165 | struct wayland_shm_buffer *sb = data; |
| 166 | |
| 167 | if (sb->output) { |
| 168 | wl_list_insert(&sb->output->shm.free_buffers, &sb->free_link); |
| 169 | } else { |
| 170 | wayland_shm_buffer_destroy(sb); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | static const struct wl_buffer_listener buffer_listener = { |
| 175 | buffer_release |
| 176 | }; |
| 177 | |
| 178 | static struct wayland_shm_buffer * |
| 179 | wayland_output_get_shm_buffer(struct wayland_output *output) |
| 180 | { |
| 181 | struct wayland_compositor *c = |
| 182 | (struct wayland_compositor *) output->base.compositor; |
| 183 | struct wl_shm *shm = c->parent.shm; |
| 184 | struct wayland_shm_buffer *sb; |
| 185 | |
| 186 | struct wl_shm_pool *pool; |
| 187 | int width, height, stride; |
| 188 | int32_t fx, fy; |
| 189 | int fd; |
| 190 | unsigned char *data; |
| 191 | |
| 192 | if (!wl_list_empty(&output->shm.free_buffers)) { |
| 193 | sb = container_of(output->shm.free_buffers.next, |
| 194 | struct wayland_shm_buffer, free_link); |
| 195 | wl_list_remove(&sb->free_link); |
| 196 | wl_list_init(&sb->free_link); |
| 197 | |
| 198 | return sb; |
| 199 | } |
| 200 | |
| 201 | if (output->frame) { |
| 202 | width = frame_width(output->frame); |
| 203 | height = frame_height(output->frame); |
| 204 | } else { |
| 205 | width = output->mode.width; |
| 206 | height = output->mode.height; |
| 207 | } |
| 208 | |
| 209 | stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); |
| 210 | |
| 211 | fd = os_create_anonymous_file(height * stride); |
| 212 | if (fd < 0) { |
| 213 | perror("os_create_anonymous_file"); |
| 214 | return NULL; |
| 215 | } |
| 216 | |
| 217 | data = mmap(NULL, height * stride, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
| 218 | if (data == MAP_FAILED) { |
| 219 | perror("mmap"); |
| 220 | close(fd); |
| 221 | return NULL; |
| 222 | } |
| 223 | |
| 224 | sb = zalloc(sizeof *sb); |
| 225 | |
| 226 | sb->output = output; |
| 227 | wl_list_init(&sb->free_link); |
| 228 | wl_list_insert(&output->shm.buffers, &sb->link); |
| 229 | |
| 230 | pixman_region32_init_rect(&sb->damage, 0, 0, |
| 231 | output->base.width, output->base.height); |
| 232 | sb->frame_damaged = 1; |
| 233 | |
| 234 | sb->data = data; |
| 235 | sb->size = height * stride; |
| 236 | |
| 237 | pool = wl_shm_create_pool(shm, fd, sb->size); |
| 238 | |
| 239 | sb->buffer = wl_shm_pool_create_buffer(pool, 0, |
| 240 | width, height, |
| 241 | stride, |
| 242 | WL_SHM_FORMAT_ARGB8888); |
| 243 | wl_buffer_add_listener(sb->buffer, &buffer_listener, sb); |
| 244 | wl_shm_pool_destroy(pool); |
| 245 | close(fd); |
| 246 | |
| 247 | memset(data, 0, sb->size); |
| 248 | |
| 249 | sb->c_surface = |
| 250 | cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, |
| 251 | width, height, stride); |
| 252 | |
| 253 | fx = 0; |
| 254 | fy = 0; |
| 255 | if (output->frame) |
| 256 | frame_interior(output->frame, &fx, &fy, 0, 0); |
| 257 | sb->pm_image = |
| 258 | pixman_image_create_bits(PIXMAN_a8r8g8b8, width, height, |
| 259 | (uint32_t *)(data + fy * stride) + fx, |
| 260 | stride); |
| 261 | |
| 262 | return sb; |
| 263 | } |
| 264 | |
| 265 | static void |
Kristian Høgsberg | cdd61d0 | 2012-02-07 09:56:15 -0500 | [diff] [blame] | 266 | frame_done(void *data, struct wl_callback *callback, uint32_t time) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 267 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 268 | struct weston_output *output = data; |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 269 | |
Kristian Høgsberg | cdd61d0 | 2012-02-07 09:56:15 -0500 | [diff] [blame] | 270 | wl_callback_destroy(callback); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 271 | weston_output_finish_frame(output, time); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static const struct wl_callback_listener frame_listener = { |
| 275 | frame_done |
| 276 | }; |
| 277 | |
Kristian Høgsberg | 06cf6b0 | 2012-01-25 23:47:45 -0500 | [diff] [blame] | 278 | static void |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 279 | draw_initial_frame(struct wayland_output *output) |
| 280 | { |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 281 | struct wayland_shm_buffer *sb; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 282 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 283 | sb = wayland_output_get_shm_buffer(output); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 284 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 285 | /* If we are rendering with GL, then orphan it so that it gets |
| 286 | * destroyed immediately */ |
| 287 | if (output->gl.egl_window) |
| 288 | sb->output = NULL; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 289 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 290 | wl_surface_attach(output->parent.surface, sb->buffer, 0, 0); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 291 | |
| 292 | /* We only need to damage some part, as its only transparant |
| 293 | * pixels anyway. */ |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 294 | wl_surface_damage(output->parent.surface, 0, 0, 1, 1); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static void |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 298 | wayland_output_update_gl_border(struct wayland_output *output) |
| 299 | { |
| 300 | int32_t ix, iy, iwidth, iheight, fwidth, fheight; |
| 301 | cairo_t *cr; |
| 302 | |
| 303 | if (!output->frame) |
| 304 | return; |
| 305 | if (!(frame_status(output->frame) & FRAME_STATUS_REPAINT)) |
| 306 | return; |
| 307 | |
| 308 | fwidth = frame_width(output->frame); |
| 309 | fheight = frame_height(output->frame); |
| 310 | frame_interior(output->frame, &ix, &iy, &iwidth, &iheight); |
| 311 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 312 | if (!output->gl.border.top) |
| 313 | output->gl.border.top = |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 314 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 315 | fwidth, iy); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 316 | cr = cairo_create(output->gl.border.top); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 317 | frame_repaint(output->frame, cr); |
| 318 | cairo_destroy(cr); |
| 319 | gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_TOP, |
| 320 | fwidth, iy, |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 321 | cairo_image_surface_get_stride(output->gl.border.top) / 4, |
| 322 | cairo_image_surface_get_data(output->gl.border.top)); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 323 | |
| 324 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 325 | if (!output->gl.border.left) |
| 326 | output->gl.border.left = |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 327 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 328 | ix, 1); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 329 | cr = cairo_create(output->gl.border.left); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 330 | cairo_translate(cr, 0, -iy); |
| 331 | frame_repaint(output->frame, cr); |
| 332 | cairo_destroy(cr); |
| 333 | gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_LEFT, |
| 334 | ix, 1, |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 335 | cairo_image_surface_get_stride(output->gl.border.left) / 4, |
| 336 | cairo_image_surface_get_data(output->gl.border.left)); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 337 | |
| 338 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 339 | if (!output->gl.border.right) |
| 340 | output->gl.border.right = |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 341 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 342 | fwidth - (ix + iwidth), 1); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 343 | cr = cairo_create(output->gl.border.right); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 344 | cairo_translate(cr, -(iwidth + ix), -iy); |
| 345 | frame_repaint(output->frame, cr); |
| 346 | cairo_destroy(cr); |
| 347 | gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_RIGHT, |
| 348 | fwidth - (ix + iwidth), 1, |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 349 | cairo_image_surface_get_stride(output->gl.border.right) / 4, |
| 350 | cairo_image_surface_get_data(output->gl.border.right)); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 351 | |
| 352 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 353 | if (!output->gl.border.bottom) |
| 354 | output->gl.border.bottom = |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 355 | cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
| 356 | fwidth, fheight - (iy + iheight)); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 357 | cr = cairo_create(output->gl.border.bottom); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 358 | cairo_translate(cr, 0, -(iy + iheight)); |
| 359 | frame_repaint(output->frame, cr); |
| 360 | cairo_destroy(cr); |
| 361 | gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_BOTTOM, |
| 362 | fwidth, fheight - (iy + iheight), |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 363 | cairo_image_surface_get_stride(output->gl.border.bottom) / 4, |
| 364 | cairo_image_surface_get_data(output->gl.border.bottom)); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | static void |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 368 | wayland_output_start_repaint_loop(struct weston_output *output_base) |
| 369 | { |
| 370 | struct wayland_output *output = (struct wayland_output *) output_base; |
Jason Ekstrand | 286ff68 | 2013-10-27 22:24:57 -0500 | [diff] [blame] | 371 | struct wayland_compositor *wc = |
| 372 | (struct wayland_compositor *)output->base.compositor; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 373 | struct wl_callback *callback; |
| 374 | |
| 375 | /* If this is the initial frame, we need to attach a buffer so that |
| 376 | * the compositor can map the surface and include it in its render |
| 377 | * loop. If the surface doesn't end up in the render loop, the frame |
| 378 | * callback won't be invoked. The buffer is transparent and of the |
| 379 | * same size as the future real output buffer. */ |
| 380 | if (output->parent.draw_initial_frame) { |
| 381 | output->parent.draw_initial_frame = 0; |
| 382 | |
| 383 | draw_initial_frame(output); |
| 384 | } |
| 385 | |
| 386 | callback = wl_surface_frame(output->parent.surface); |
| 387 | wl_callback_add_listener(callback, &frame_listener, output); |
| 388 | wl_surface_commit(output->parent.surface); |
Jason Ekstrand | 286ff68 | 2013-10-27 22:24:57 -0500 | [diff] [blame] | 389 | wl_display_flush(wc->parent.wl_display); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 390 | } |
| 391 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 392 | static int |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 393 | wayland_output_repaint_gl(struct weston_output *output_base, |
| 394 | pixman_region32_t *damage) |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 395 | { |
| 396 | struct wayland_output *output = (struct wayland_output *) output_base; |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 397 | struct weston_compositor *ec = output->base.compositor; |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 398 | struct wl_callback *callback; |
Scott Moreau | 062be7e | 2012-04-20 13:37:33 -0600 | [diff] [blame] | 399 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 400 | callback = wl_surface_frame(output->parent.surface); |
| 401 | wl_callback_add_listener(callback, &frame_listener, output); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 402 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 403 | wayland_output_update_gl_border(output); |
| 404 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 405 | ec->renderer->repaint_output(&output->base, damage); |
Ander Conselvan de Oliveira | 0a88772 | 2012-11-22 15:57:00 +0200 | [diff] [blame] | 406 | |
| 407 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 408 | &ec->primary_plane.damage, damage); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 409 | return 0; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 410 | } |
| 411 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 412 | static void |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 413 | wayland_output_update_shm_border(struct wayland_shm_buffer *buffer) |
| 414 | { |
| 415 | int32_t ix, iy, iwidth, iheight, fwidth, fheight; |
| 416 | cairo_t *cr; |
| 417 | |
| 418 | if (!buffer->output->frame || !buffer->frame_damaged) |
| 419 | return; |
| 420 | |
| 421 | cr = cairo_create(buffer->c_surface); |
| 422 | |
| 423 | frame_interior(buffer->output->frame, &ix, &iy, &iwidth, &iheight); |
| 424 | fwidth = frame_width(buffer->output->frame); |
| 425 | fheight = frame_height(buffer->output->frame); |
| 426 | |
| 427 | /* Set the clip so we don't unnecisaraly damage the surface */ |
| 428 | cairo_move_to(cr, ix, iy); |
| 429 | cairo_rel_line_to(cr, iwidth, 0); |
| 430 | cairo_rel_line_to(cr, 0, iheight); |
| 431 | cairo_rel_line_to(cr, -iwidth, 0); |
| 432 | cairo_line_to(cr, ix, iy); |
| 433 | cairo_line_to(cr, 0, iy); |
| 434 | cairo_line_to(cr, 0, fheight); |
| 435 | cairo_line_to(cr, fwidth, fheight); |
| 436 | cairo_line_to(cr, fwidth, 0); |
| 437 | cairo_line_to(cr, 0, 0); |
| 438 | cairo_line_to(cr, 0, iy); |
| 439 | cairo_close_path(cr); |
| 440 | cairo_clip(cr); |
| 441 | |
| 442 | /* Draw using a pattern so that the final result gets clipped */ |
| 443 | cairo_push_group(cr); |
| 444 | frame_repaint(buffer->output->frame, cr); |
| 445 | cairo_pop_group_to_source(cr); |
| 446 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
| 447 | cairo_paint(cr); |
| 448 | |
| 449 | cairo_destroy(cr); |
| 450 | } |
| 451 | |
| 452 | static void |
| 453 | wayland_shm_buffer_attach(struct wayland_shm_buffer *sb) |
| 454 | { |
| 455 | pixman_region32_t damage; |
| 456 | pixman_box32_t *rects; |
| 457 | int32_t ix, iy, iwidth, iheight, fwidth, fheight; |
| 458 | int i, n; |
| 459 | |
| 460 | if (sb->output->frame) { |
| 461 | frame_interior(sb->output->frame, &ix, &iy, &iwidth, &iheight); |
| 462 | fwidth = frame_width(sb->output->frame); |
| 463 | fheight = frame_height(sb->output->frame); |
| 464 | |
| 465 | pixman_region32_init(&damage); |
| 466 | pixman_region32_copy(&damage, &sb->damage); |
| 467 | pixman_region32_translate(&damage, ix, iy); |
| 468 | |
| 469 | if (sb->frame_damaged) { |
| 470 | pixman_region32_union_rect(&damage, &damage, |
| 471 | 0, 0, fwidth, iy); |
| 472 | pixman_region32_union_rect(&damage, &damage, |
| 473 | 0, iy, ix, iheight); |
| 474 | pixman_region32_union_rect(&damage, &damage, |
| 475 | ix + iwidth, iy, |
| 476 | fwidth - (ix + iwidth), iheight); |
| 477 | pixman_region32_union_rect(&damage, &damage, |
| 478 | 0, iy + iheight, |
| 479 | fwidth, fheight - (iy + iheight)); |
| 480 | } |
| 481 | rects = pixman_region32_rectangles(&damage, &n); |
| 482 | } else { |
| 483 | rects = pixman_region32_rectangles(&sb->damage, &n); |
| 484 | } |
| 485 | |
| 486 | wl_surface_attach(sb->output->parent.surface, sb->buffer, 0, 0); |
| 487 | for (i = 0; i < n; ++i) |
| 488 | wl_surface_damage(sb->output->parent.surface, rects[i].x1, |
| 489 | rects[i].y1, rects[i].x2 - rects[i].x1, |
| 490 | rects[i].y2 - rects[i].y1); |
| 491 | |
| 492 | if (sb->output->frame) |
| 493 | pixman_region32_fini(&damage); |
| 494 | } |
| 495 | |
| 496 | static int |
| 497 | wayland_output_repaint_pixman(struct weston_output *output_base, |
| 498 | pixman_region32_t *damage) |
| 499 | { |
| 500 | struct wayland_output *output = (struct wayland_output *) output_base; |
| 501 | struct wayland_compositor *c = |
| 502 | (struct wayland_compositor *)output->base.compositor; |
| 503 | struct wl_callback *callback; |
| 504 | struct wayland_shm_buffer *sb; |
| 505 | |
| 506 | if (output->frame) { |
| 507 | if (frame_status(output->frame) & FRAME_STATUS_REPAINT) |
| 508 | wl_list_for_each(sb, &output->shm.buffers, link) |
| 509 | sb->frame_damaged = 1; |
| 510 | } |
| 511 | |
| 512 | wl_list_for_each(sb, &output->shm.buffers, link) |
| 513 | pixman_region32_union(&sb->damage, &sb->damage, damage); |
| 514 | |
| 515 | sb = wayland_output_get_shm_buffer(output); |
| 516 | |
| 517 | wayland_output_update_shm_border(sb); |
| 518 | pixman_renderer_output_set_buffer(output_base, sb->pm_image); |
| 519 | c->base.renderer->repaint_output(output_base, &sb->damage); |
| 520 | |
| 521 | wayland_shm_buffer_attach(sb); |
| 522 | |
| 523 | callback = wl_surface_frame(output->parent.surface); |
| 524 | wl_callback_add_listener(callback, &frame_listener, output); |
| 525 | wl_surface_commit(output->parent.surface); |
| 526 | wl_display_flush(c->parent.wl_display); |
| 527 | |
| 528 | pixman_region32_fini(&sb->damage); |
| 529 | pixman_region32_init(&sb->damage); |
| 530 | sb->frame_damaged = 0; |
| 531 | |
| 532 | pixman_region32_subtract(&c->base.primary_plane.damage, |
| 533 | &c->base.primary_plane.damage, damage); |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 538 | wayland_output_destroy(struct weston_output *output_base) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 539 | { |
| 540 | struct wayland_output *output = (struct wayland_output *) output_base; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 541 | struct wayland_compositor *c = |
| 542 | (struct wayland_compositor *) output->base.compositor; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 543 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 544 | if (c->use_pixman) { |
| 545 | pixman_renderer_output_destroy(output_base); |
| 546 | } else { |
| 547 | gl_renderer->output_destroy(output_base); |
| 548 | } |
John Kåre Alsaker | 9465927 | 2012-11-13 19:10:18 +0100 | [diff] [blame] | 549 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 550 | wl_egl_window_destroy(output->gl.egl_window); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 551 | wl_surface_destroy(output->parent.surface); |
| 552 | wl_shell_surface_destroy(output->parent.shell_surface); |
| 553 | |
| 554 | if (output->frame) { |
| 555 | frame_destroy(output->frame); |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 556 | cairo_surface_destroy(output->gl.border.top); |
| 557 | cairo_surface_destroy(output->gl.border.left); |
| 558 | cairo_surface_destroy(output->gl.border.right); |
| 559 | cairo_surface_destroy(output->gl.border.bottom); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | weston_output_destroy(&output->base); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 563 | free(output); |
| 564 | |
| 565 | return; |
| 566 | } |
| 567 | |
Ander Conselvan de Oliveira | 563c5b8 | 2012-06-18 17:36:21 +0300 | [diff] [blame] | 568 | static const struct wl_shell_surface_listener shell_surface_listener; |
| 569 | |
Benjamin Franzke | 431da9a | 2011-04-20 11:02:58 +0200 | [diff] [blame] | 570 | static int |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 571 | wayland_output_init_gl_renderer(struct wayland_output *output) |
| 572 | { |
Jason Ekstrand | 00b8428 | 2013-10-27 22:24:59 -0500 | [diff] [blame^] | 573 | int32_t fwidth = 0, fheight = 0; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 574 | |
| 575 | if (output->frame) { |
| 576 | fwidth = frame_width(output->frame); |
| 577 | fheight = frame_height(output->frame); |
| 578 | } else { |
| 579 | fwidth = output->base.width; |
| 580 | fheight = output->base.height; |
| 581 | } |
| 582 | |
| 583 | output->gl.egl_window = |
| 584 | wl_egl_window_create(output->parent.surface, |
| 585 | fwidth, fheight); |
| 586 | if (!output->gl.egl_window) { |
| 587 | weston_log("failure to create wl_egl_window\n"); |
| 588 | return -1; |
| 589 | } |
| 590 | |
| 591 | if (gl_renderer->output_create(&output->base, |
| 592 | output->gl.egl_window) < 0) |
| 593 | goto cleanup_window; |
| 594 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 595 | return 0; |
| 596 | |
| 597 | cleanup_window: |
| 598 | wl_egl_window_destroy(output->gl.egl_window); |
| 599 | return -1; |
| 600 | } |
| 601 | |
| 602 | static int |
| 603 | wayland_output_init_pixman_renderer(struct wayland_output *output) |
| 604 | { |
| 605 | return pixman_renderer_output_create(&output->base); |
| 606 | } |
| 607 | |
| 608 | static int |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 609 | wayland_compositor_create_output(struct wayland_compositor *c, |
| 610 | int width, int height) |
| 611 | { |
| 612 | struct wayland_output *output; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 613 | int32_t fx, fy, fwidth, fheight; |
| 614 | struct wl_region *region; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 615 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 616 | output = zalloc(sizeof *output); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 617 | if (output == NULL) |
| 618 | return -1; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 619 | |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 620 | output->mode.flags = |
| 621 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 622 | output->mode.width = width; |
| 623 | output->mode.height = height; |
| 624 | output->mode.refresh = 60; |
| 625 | wl_list_init(&output->base.mode_list); |
| 626 | wl_list_insert(&output->base.mode_list, &output->mode.link); |
| 627 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 628 | output->base.current_mode = &output->mode; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 629 | weston_output_init(&output->base, &c->base, 0, 0, width, height, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 630 | WL_OUTPUT_TRANSFORM_NORMAL, 1); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 631 | |
Kristian Høgsberg | 90bc88c | 2012-08-13 23:34:04 -0400 | [diff] [blame] | 632 | output->base.make = "waywayland"; |
| 633 | output->base.model = "none"; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 634 | |
| 635 | weston_output_move(&output->base, 0, 0); |
| 636 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 637 | wl_list_init(&output->shm.buffers); |
| 638 | wl_list_init(&output->shm.free_buffers); |
| 639 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 640 | if (!c->theme) |
| 641 | c->theme = theme_create(); |
| 642 | output->frame = frame_create(c->theme, width, height, |
| 643 | FRAME_BUTTON_CLOSE, "Weston"); |
| 644 | frame_resize_inside(output->frame, width, height); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 645 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 646 | weston_log("Creating %dx%d wayland output\n", width, height); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 647 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 648 | output->parent.surface = |
| 649 | wl_compositor_create_surface(c->parent.compositor); |
| 650 | wl_surface_set_user_data(output->parent.surface, output); |
| 651 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 652 | if (c->use_pixman) { |
| 653 | if (wayland_output_init_pixman_renderer(output) < 0) |
| 654 | goto cleanup_output; |
| 655 | output->base.repaint = wayland_output_repaint_pixman; |
| 656 | } else { |
| 657 | if (wayland_output_init_gl_renderer(output) < 0) |
| 658 | goto cleanup_output; |
| 659 | output->base.repaint = wayland_output_repaint_gl; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 660 | } |
| 661 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 662 | frame_input_rect(output->frame, &fx, &fy, &fwidth, &fheight); |
| 663 | region = wl_compositor_create_region(c->parent.compositor); |
| 664 | wl_region_add(region, fx, fy, fwidth, fheight); |
| 665 | wl_surface_set_input_region(output->parent.surface, region); |
| 666 | wl_region_destroy(region); |
| 667 | |
| 668 | frame_opaque_rect(output->frame, &fx, &fy, &fwidth, &fheight); |
| 669 | region = wl_compositor_create_region(c->parent.compositor); |
| 670 | wl_region_add(region, fx, fy, fwidth, fheight); |
| 671 | wl_surface_set_opaque_region(output->parent.surface, region); |
| 672 | wl_region_destroy(region); |
| 673 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 674 | output->parent.draw_initial_frame = 1; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 675 | output->parent.shell_surface = |
| 676 | wl_shell_get_shell_surface(c->parent.shell, |
| 677 | output->parent.surface); |
Ander Conselvan de Oliveira | 563c5b8 | 2012-06-18 17:36:21 +0300 | [diff] [blame] | 678 | wl_shell_surface_add_listener(output->parent.shell_surface, |
| 679 | &shell_surface_listener, output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 680 | wl_shell_surface_set_toplevel(output->parent.shell_surface); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 681 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 682 | output->base.start_repaint_loop = wayland_output_start_repaint_loop; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 683 | output->base.destroy = wayland_output_destroy; |
Jesse Barnes | 5308a5e | 2012-02-09 13:12:57 -0800 | [diff] [blame] | 684 | output->base.assign_planes = NULL; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 685 | output->base.set_backlight = NULL; |
| 686 | output->base.set_dpms = NULL; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 687 | output->base.switch_mode = NULL; |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 688 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 689 | wl_list_insert(c->base.output_list.prev, &output->base.link); |
| 690 | |
| 691 | return 0; |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 692 | |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 693 | cleanup_output: |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 694 | /* FIXME: cleanup weston_output */ |
Benjamin Franzke | be01456 | 2011-02-18 17:04:24 +0100 | [diff] [blame] | 695 | free(output); |
| 696 | |
| 697 | return -1; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 698 | } |
| 699 | |
Ander Conselvan de Oliveira | 563c5b8 | 2012-06-18 17:36:21 +0300 | [diff] [blame] | 700 | static void |
| 701 | shell_surface_ping(void *data, struct wl_shell_surface *shell_surface, |
| 702 | uint32_t serial) |
| 703 | { |
| 704 | wl_shell_surface_pong(shell_surface, serial); |
| 705 | } |
| 706 | |
| 707 | static void |
| 708 | shell_surface_configure(void *data, struct wl_shell_surface *shell_surface, |
| 709 | uint32_t edges, int32_t width, int32_t height) |
| 710 | { |
| 711 | /* FIXME: implement resizing */ |
| 712 | } |
| 713 | |
| 714 | static void |
| 715 | shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface) |
| 716 | { |
| 717 | } |
| 718 | |
| 719 | static const struct wl_shell_surface_listener shell_surface_listener = { |
| 720 | shell_surface_ping, |
| 721 | shell_surface_configure, |
| 722 | shell_surface_popup_done |
| 723 | }; |
| 724 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 725 | /* Events received from the wayland-server this compositor is client of: */ |
| 726 | |
| 727 | /* parent output interface */ |
| 728 | static void |
| 729 | display_handle_geometry(void *data, |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 730 | struct wl_output *wl_output, |
| 731 | int x, |
| 732 | int y, |
| 733 | int physical_width, |
| 734 | int physical_height, |
| 735 | int subpixel, |
| 736 | const char *make, |
Kristian Høgsberg | 0e69647 | 2012-07-22 15:49:57 -0400 | [diff] [blame] | 737 | const char *model, |
| 738 | int transform) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 739 | { |
| 740 | struct wayland_compositor *c = data; |
| 741 | |
Kristian Høgsberg | f8fc08f | 2010-12-01 20:10:10 -0500 | [diff] [blame] | 742 | c->parent.screen_allocation.x = x; |
| 743 | c->parent.screen_allocation.y = y; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static void |
| 747 | display_handle_mode(void *data, |
| 748 | struct wl_output *wl_output, |
| 749 | uint32_t flags, |
| 750 | int width, |
| 751 | int height, |
| 752 | int refresh) |
| 753 | { |
| 754 | struct wayland_compositor *c = data; |
| 755 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 756 | c->parent.screen_allocation.width = width; |
| 757 | c->parent.screen_allocation.height = height; |
| 758 | } |
| 759 | |
| 760 | static const struct wl_output_listener output_listener = { |
| 761 | display_handle_geometry, |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 762 | display_handle_mode |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 763 | }; |
| 764 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 765 | /* parent input interface */ |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 766 | static void |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 767 | input_set_cursor(struct wayland_input *input) |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 768 | { |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 769 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 770 | struct wl_buffer *buffer; |
| 771 | struct wl_cursor_image *image; |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 772 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 773 | if (!input->compositor->cursor) |
| 774 | return; /* Couldn't load the cursor. Can't set it */ |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 775 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 776 | image = input->compositor->cursor->images[0]; |
| 777 | buffer = wl_cursor_image_get_buffer(image); |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 778 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 779 | |
| 780 | wl_pointer_set_cursor(input->parent.pointer, input->enter_serial, |
| 781 | input->parent.cursor.surface, |
| 782 | image->hotspot_x, image->hotspot_y); |
| 783 | |
| 784 | wl_surface_attach(input->parent.cursor.surface, buffer, 0, 0); |
| 785 | wl_surface_damage(input->parent.cursor.surface, 0, 0, |
| 786 | image->width, image->height); |
| 787 | wl_surface_commit(input->parent.cursor.surface); |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 788 | } |
| 789 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 790 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 791 | input_handle_pointer_enter(void *data, struct wl_pointer *pointer, |
| 792 | uint32_t serial, struct wl_surface *surface, |
Kristian Høgsberg | e11bbe4 | 2012-05-09 12:19:04 -0400 | [diff] [blame] | 793 | wl_fixed_t x, wl_fixed_t y) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 794 | { |
| 795 | struct wayland_input *input = data; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 796 | int32_t fx, fy; |
| 797 | enum theme_location location; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 798 | |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 799 | /* XXX: If we get a modifier event immediately before the focus, |
| 800 | * we should try to keep the same serial. */ |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 801 | input->enter_serial = serial; |
| 802 | input->output = wl_surface_get_user_data(surface); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 803 | |
| 804 | if (input->output->frame) { |
| 805 | location = frame_pointer_enter(input->output->frame, input, |
| 806 | wl_fixed_to_int(x), |
| 807 | wl_fixed_to_int(y)); |
| 808 | frame_interior(input->output->frame, &fx, &fy, NULL, NULL); |
| 809 | x -= wl_fixed_from_int(fx); |
| 810 | y -= wl_fixed_from_int(fy); |
| 811 | |
| 812 | if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT) |
| 813 | weston_output_schedule_repaint(&input->output->base); |
| 814 | } else { |
| 815 | location = THEME_LOCATION_CLIENT_AREA; |
| 816 | } |
| 817 | |
| 818 | x += wl_fixed_from_int(input->output->base.x); |
| 819 | y += wl_fixed_from_int(input->output->base.y); |
| 820 | |
| 821 | if (location == THEME_LOCATION_CLIENT_AREA) { |
| 822 | input->focus = 1; |
| 823 | notify_pointer_focus(&input->base, &input->output->base, x, y); |
| 824 | wl_pointer_set_cursor(input->parent.pointer, |
| 825 | input->enter_serial, NULL, 0, 0); |
| 826 | } else { |
| 827 | input->focus = 0; |
| 828 | notify_pointer_focus(&input->base, NULL, 0, 0); |
| 829 | input_set_cursor(input); |
| 830 | } |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 834 | input_handle_pointer_leave(void *data, struct wl_pointer *pointer, |
| 835 | uint32_t serial, struct wl_surface *surface) |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 836 | { |
| 837 | struct wayland_input *input = data; |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 838 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 839 | if (input->output->frame) { |
| 840 | frame_pointer_leave(input->output->frame, input); |
| 841 | |
| 842 | if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT) |
| 843 | weston_output_schedule_repaint(&input->output->base); |
| 844 | } |
| 845 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 846 | notify_pointer_focus(&input->base, NULL, 0, 0); |
Kristian Høgsberg | 539d85f | 2012-08-13 23:29:53 -0400 | [diff] [blame] | 847 | input->output = NULL; |
| 848 | input->focus = 0; |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 852 | input_handle_motion(void *data, struct wl_pointer *pointer, |
| 853 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
| 854 | { |
| 855 | struct wayland_input *input = data; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 856 | int32_t fx, fy; |
| 857 | enum theme_location location; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 858 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 859 | if (input->output->frame) { |
| 860 | location = frame_pointer_motion(input->output->frame, input, |
| 861 | wl_fixed_to_int(x), |
| 862 | wl_fixed_to_int(y)); |
| 863 | frame_interior(input->output->frame, &fx, &fy, NULL, NULL); |
| 864 | x -= wl_fixed_from_int(fx); |
| 865 | y -= wl_fixed_from_int(fy); |
| 866 | |
| 867 | if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT) |
| 868 | weston_output_schedule_repaint(&input->output->base); |
| 869 | } else { |
| 870 | location = THEME_LOCATION_CLIENT_AREA; |
| 871 | } |
| 872 | |
| 873 | x += wl_fixed_from_int(input->output->base.x); |
| 874 | y += wl_fixed_from_int(input->output->base.y); |
| 875 | |
| 876 | if (input->focus && location != THEME_LOCATION_CLIENT_AREA) { |
| 877 | input_set_cursor(input); |
| 878 | notify_pointer_focus(&input->base, NULL, 0, 0); |
| 879 | input->focus = 0; |
| 880 | } else if (!input->focus && location == THEME_LOCATION_CLIENT_AREA) { |
| 881 | wl_pointer_set_cursor(input->parent.pointer, |
| 882 | input->enter_serial, NULL, 0, 0); |
| 883 | notify_pointer_focus(&input->base, &input->output->base, x, y); |
| 884 | input->focus = 1; |
| 885 | } |
| 886 | |
| 887 | if (location == THEME_LOCATION_CLIENT_AREA) |
| 888 | notify_motion_absolute(&input->base, time, x, y); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | static void |
| 892 | input_handle_button(void *data, struct wl_pointer *pointer, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 893 | uint32_t serial, uint32_t time, uint32_t button, |
| 894 | uint32_t state_w) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 895 | { |
| 896 | struct wayland_input *input = data; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 897 | enum wl_pointer_button_state state = state_w; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 898 | enum frame_button_state fstate; |
| 899 | enum theme_location location; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 900 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 901 | if (input->output->frame) { |
| 902 | fstate = state == WL_POINTER_BUTTON_STATE_PRESSED ? |
| 903 | FRAME_BUTTON_PRESSED : FRAME_BUTTON_RELEASED; |
| 904 | |
| 905 | location = frame_pointer_button(input->output->frame, input, |
| 906 | button, fstate); |
| 907 | |
| 908 | if (frame_status(input->output->frame) & FRAME_STATUS_MOVE) { |
| 909 | |
| 910 | wl_shell_surface_move(input->output->parent.shell_surface, |
| 911 | input->parent.seat, serial); |
| 912 | frame_status_clear(input->output->frame, |
| 913 | FRAME_STATUS_MOVE); |
| 914 | return; |
| 915 | } |
| 916 | |
| 917 | if (frame_status(input->output->frame) & FRAME_STATUS_CLOSE) |
| 918 | wl_display_terminate(input->compositor->base.wl_display); |
| 919 | |
| 920 | if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT) |
| 921 | weston_output_schedule_repaint(&input->output->base); |
| 922 | } else { |
| 923 | location = THEME_LOCATION_CLIENT_AREA; |
| 924 | } |
| 925 | |
| 926 | if (location == THEME_LOCATION_CLIENT_AREA) |
| 927 | notify_button(&input->base, time, button, state); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | static void |
| 931 | input_handle_axis(void *data, struct wl_pointer *pointer, |
Daniel Stone | 2fce402 | 2012-05-30 16:32:00 +0100 | [diff] [blame] | 932 | uint32_t time, uint32_t axis, wl_fixed_t value) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 933 | { |
| 934 | struct wayland_input *input = data; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 935 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 936 | notify_axis(&input->base, time, axis, value); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | static const struct wl_pointer_listener pointer_listener = { |
| 940 | input_handle_pointer_enter, |
| 941 | input_handle_pointer_leave, |
| 942 | input_handle_motion, |
| 943 | input_handle_button, |
| 944 | input_handle_axis, |
| 945 | }; |
| 946 | |
| 947 | static void |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 948 | input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format, |
| 949 | int fd, uint32_t size) |
| 950 | { |
| 951 | struct wayland_input *input = data; |
| 952 | struct xkb_keymap *keymap; |
| 953 | char *map_str; |
| 954 | |
| 955 | if (!data) { |
| 956 | close(fd); |
| 957 | return; |
| 958 | } |
| 959 | |
| 960 | if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { |
| 961 | close(fd); |
| 962 | return; |
| 963 | } |
| 964 | |
| 965 | map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); |
| 966 | if (map_str == MAP_FAILED) { |
| 967 | close(fd); |
| 968 | return; |
| 969 | } |
| 970 | |
| 971 | keymap = xkb_map_new_from_string(input->compositor->base.xkb_context, |
| 972 | map_str, |
| 973 | XKB_KEYMAP_FORMAT_TEXT_V1, |
| 974 | 0); |
| 975 | munmap(map_str, size); |
| 976 | close(fd); |
| 977 | |
| 978 | if (!keymap) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 979 | weston_log("failed to compile keymap\n"); |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 980 | return; |
| 981 | } |
| 982 | |
Rui Matos | 0c194ce | 2013-10-10 19:44:21 +0200 | [diff] [blame] | 983 | if (input->base.keyboard) |
| 984 | weston_seat_update_keymap(&input->base, keymap); |
| 985 | else |
| 986 | weston_seat_init_keyboard(&input->base, keymap); |
| 987 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 988 | xkb_map_unref(keymap); |
| 989 | } |
| 990 | |
| 991 | static void |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 992 | input_handle_keyboard_enter(void *data, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 993 | struct wl_keyboard *keyboard, |
| 994 | uint32_t serial, |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 995 | struct wl_surface *surface, |
| 996 | struct wl_array *keys) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 997 | { |
Kristian Høgsberg | af82bea | 2011-01-27 20:18:17 -0500 | [diff] [blame] | 998 | struct wayland_input *input = data; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 999 | struct wayland_output *focus; |
| 1000 | |
| 1001 | focus = input->keyboard_focus; |
| 1002 | if (focus) { |
| 1003 | /* This shouldn't happen */ |
| 1004 | focus->keyboard_count--; |
| 1005 | if (!focus->keyboard_count && focus->frame) |
| 1006 | frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE); |
| 1007 | if (frame_status(focus->frame) & FRAME_STATUS_REPAINT) |
| 1008 | weston_output_schedule_repaint(&focus->base); |
| 1009 | } |
| 1010 | |
| 1011 | input->keyboard_focus = wl_surface_get_user_data(surface); |
| 1012 | input->keyboard_focus->keyboard_count++; |
| 1013 | |
| 1014 | focus = input->keyboard_focus; |
| 1015 | if (focus->frame) { |
| 1016 | frame_set_flag(focus->frame, FRAME_FLAG_ACTIVE); |
| 1017 | if (frame_status(focus->frame) & FRAME_STATUS_REPAINT) |
| 1018 | weston_output_schedule_repaint(&focus->base); |
| 1019 | } |
| 1020 | |
Kristian Høgsberg | af82bea | 2011-01-27 20:18:17 -0500 | [diff] [blame] | 1021 | |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1022 | /* XXX: If we get a modifier event immediately before the focus, |
| 1023 | * we should try to keep the same serial. */ |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1024 | notify_keyboard_focus_in(&input->base, keys, |
Daniel Stone | d6da09e | 2012-06-22 13:21:29 +0100 | [diff] [blame] | 1025 | STATE_UPDATE_AUTOMATIC); |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | static void |
| 1029 | input_handle_keyboard_leave(void *data, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1030 | struct wl_keyboard *keyboard, |
| 1031 | uint32_t serial, |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1032 | struct wl_surface *surface) |
| 1033 | { |
| 1034 | struct wayland_input *input = data; |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1035 | struct wayland_output *focus; |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1036 | |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1037 | notify_keyboard_focus_out(&input->base); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1038 | |
| 1039 | focus = input->keyboard_focus; |
| 1040 | if (!focus) |
| 1041 | return; /* This shouldn't happen */ |
| 1042 | |
| 1043 | focus->keyboard_count--; |
| 1044 | if (!focus->keyboard_count && focus->frame) { |
| 1045 | frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE); |
| 1046 | if (frame_status(focus->frame) & FRAME_STATUS_REPAINT) |
| 1047 | weston_output_schedule_repaint(&focus->base); |
| 1048 | } |
| 1049 | |
| 1050 | input->keyboard_focus = NULL; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1051 | } |
| 1052 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1053 | static void |
| 1054 | input_handle_key(void *data, struct wl_keyboard *keyboard, |
| 1055 | uint32_t serial, uint32_t time, uint32_t key, uint32_t state) |
| 1056 | { |
| 1057 | struct wayland_input *input = data; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1058 | |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1059 | input->key_serial = serial; |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1060 | notify_key(&input->base, time, key, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 1061 | state ? WL_KEYBOARD_KEY_STATE_PRESSED : |
Daniel Stone | 1b4e11f | 2012-06-22 13:21:37 +0100 | [diff] [blame] | 1062 | WL_KEYBOARD_KEY_STATE_RELEASED, |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1063 | STATE_UPDATE_NONE); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 1066 | static void |
| 1067 | input_handle_modifiers(void *data, struct wl_keyboard *keyboard, |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1068 | uint32_t serial_in, uint32_t mods_depressed, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 1069 | uint32_t mods_latched, uint32_t mods_locked, |
| 1070 | uint32_t group) |
| 1071 | { |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1072 | struct wayland_input *input = data; |
| 1073 | struct wayland_compositor *c = input->compositor; |
| 1074 | uint32_t serial_out; |
| 1075 | |
| 1076 | /* If we get a key event followed by a modifier event with the |
| 1077 | * same serial number, then we try to preserve those semantics by |
| 1078 | * reusing the same serial number on the way out too. */ |
| 1079 | if (serial_in == input->key_serial) |
| 1080 | serial_out = wl_display_get_serial(c->base.wl_display); |
| 1081 | else |
| 1082 | serial_out = wl_display_next_serial(c->base.wl_display); |
| 1083 | |
Kristian Høgsberg | 7af7ced | 2012-08-10 10:01:33 -0400 | [diff] [blame] | 1084 | xkb_state_update_mask(input->base.xkb_state.state, |
Daniel Stone | 5069280 | 2012-06-22 13:21:41 +0100 | [diff] [blame] | 1085 | mods_depressed, mods_latched, |
| 1086 | mods_locked, 0, 0, group); |
Kristian Høgsberg | cb3eaae | 2012-08-10 09:50:11 -0400 | [diff] [blame] | 1087 | notify_modifiers(&input->base, serial_out); |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 1088 | } |
| 1089 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1090 | static const struct wl_keyboard_listener keyboard_listener = { |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 1091 | input_handle_keymap, |
Kristian Høgsberg | 06d58b7 | 2012-02-23 09:59:05 -0500 | [diff] [blame] | 1092 | input_handle_keyboard_enter, |
| 1093 | input_handle_keyboard_leave, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1094 | input_handle_key, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 1095 | input_handle_modifiers, |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1096 | }; |
| 1097 | |
| 1098 | static void |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1099 | input_handle_capabilities(void *data, struct wl_seat *seat, |
| 1100 | enum wl_seat_capability caps) |
| 1101 | { |
| 1102 | struct wayland_input *input = data; |
| 1103 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 1104 | if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->parent.pointer) { |
| 1105 | input->parent.pointer = wl_seat_get_pointer(seat); |
| 1106 | wl_pointer_set_user_data(input->parent.pointer, input); |
| 1107 | wl_pointer_add_listener(input->parent.pointer, |
| 1108 | &pointer_listener, input); |
Kristian Høgsberg | 7af7ced | 2012-08-10 10:01:33 -0400 | [diff] [blame] | 1109 | weston_seat_init_pointer(&input->base); |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 1110 | } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->parent.pointer) { |
| 1111 | wl_pointer_destroy(input->parent.pointer); |
| 1112 | input->parent.pointer = NULL; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 1115 | if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->parent.keyboard) { |
| 1116 | input->parent.keyboard = wl_seat_get_keyboard(seat); |
| 1117 | wl_keyboard_set_user_data(input->parent.keyboard, input); |
| 1118 | wl_keyboard_add_listener(input->parent.keyboard, |
| 1119 | &keyboard_listener, input); |
| 1120 | } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->parent.keyboard) { |
| 1121 | wl_keyboard_destroy(input->parent.keyboard); |
| 1122 | input->parent.keyboard = NULL; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | static const struct wl_seat_listener seat_listener = { |
| 1127 | input_handle_capabilities, |
| 1128 | }; |
| 1129 | |
| 1130 | static void |
| 1131 | display_add_seat(struct wayland_compositor *c, uint32_t id) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1132 | { |
| 1133 | struct wayland_input *input; |
| 1134 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 1135 | input = zalloc(sizeof *input); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1136 | if (input == NULL) |
| 1137 | return; |
| 1138 | |
Rob Bradford | 9af5f9e | 2013-05-31 18:09:50 +0100 | [diff] [blame] | 1139 | weston_seat_init(&input->base, &c->base, "default"); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1140 | input->compositor = c; |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 1141 | input->parent.seat = wl_registry_bind(c->parent.registry, id, |
| 1142 | &wl_seat_interface, 1); |
| 1143 | wl_list_insert(c->inputs.prev, &input->link); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1144 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 1145 | wl_seat_add_listener(input->parent.seat, &seat_listener, input); |
| 1146 | wl_seat_set_user_data(input->parent.seat, input); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1147 | |
| 1148 | input->parent.cursor.surface = |
| 1149 | wl_compositor_create_surface(c->parent.compositor); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static void |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1153 | registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, |
| 1154 | const char *interface, uint32_t version) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1155 | { |
| 1156 | struct wayland_compositor *c = data; |
| 1157 | |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 1158 | if (strcmp(interface, "wl_compositor") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 1159 | c->parent.compositor = |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1160 | wl_registry_bind(registry, name, |
| 1161 | &wl_compositor_interface, 1); |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 1162 | } else if (strcmp(interface, "wl_output") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 1163 | c->parent.output = |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1164 | wl_registry_bind(registry, name, |
| 1165 | &wl_output_interface, 1); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1166 | wl_output_add_listener(c->parent.output, &output_listener, c); |
Benjamin Franzke | 080ab6c | 2011-04-30 10:41:27 +0200 | [diff] [blame] | 1167 | } else if (strcmp(interface, "wl_shell") == 0) { |
Kristian Høgsberg | f790c79 | 2011-08-19 14:41:57 -0400 | [diff] [blame] | 1168 | c->parent.shell = |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1169 | wl_registry_bind(registry, name, |
| 1170 | &wl_shell_interface, 1); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 1171 | } else if (strcmp(interface, "wl_seat") == 0) { |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1172 | display_add_seat(c, name); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 1173 | } else if (strcmp(interface, "wl_shm") == 0) { |
| 1174 | c->parent.shm = |
| 1175 | wl_registry_bind(registry, name, &wl_shm_interface, 1); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1179 | static const struct wl_registry_listener registry_listener = { |
| 1180 | registry_handle_global |
| 1181 | }; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1182 | |
Kristian Høgsberg | 95d843d | 2011-04-22 13:01:26 -0400 | [diff] [blame] | 1183 | static int |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1184 | wayland_compositor_handle_event(int fd, uint32_t mask, void *data) |
| 1185 | { |
| 1186 | struct wayland_compositor *c = data; |
Kristian Høgsberg | feb3c1d | 2012-10-15 12:56:11 -0400 | [diff] [blame] | 1187 | int count = 0; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1188 | |
Kristian Høgsberg | 453de7a | 2013-10-30 23:15:44 -0700 | [diff] [blame] | 1189 | if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) { |
| 1190 | wl_display_terminate(c->base.wl_display); |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1194 | if (mask & WL_EVENT_READABLE) |
Kristian Høgsberg | feb3c1d | 2012-10-15 12:56:11 -0400 | [diff] [blame] | 1195 | count = wl_display_dispatch(c->parent.wl_display); |
Kristian Høgsberg | f258a31 | 2011-12-28 22:51:20 -0500 | [diff] [blame] | 1196 | if (mask & WL_EVENT_WRITABLE) |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1197 | wl_display_flush(c->parent.wl_display); |
Kristian Høgsberg | 95d843d | 2011-04-22 13:01:26 -0400 | [diff] [blame] | 1198 | |
Kristian Høgsberg | feb3c1d | 2012-10-15 12:56:11 -0400 | [diff] [blame] | 1199 | if (mask == 0) { |
| 1200 | count = wl_display_dispatch_pending(c->parent.wl_display); |
| 1201 | wl_display_flush(c->parent.wl_display); |
| 1202 | } |
| 1203 | |
| 1204 | return count; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1205 | } |
| 1206 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1207 | static void |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 1208 | wayland_restore(struct weston_compositor *ec) |
| 1209 | { |
| 1210 | } |
| 1211 | |
| 1212 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1213 | wayland_destroy(struct weston_compositor *ec) |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1214 | { |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 1215 | struct wayland_compositor *c = (struct wayland_compositor *) ec; |
| 1216 | |
Vasily Khoruzhick | 52cfd61 | 2013-01-08 19:09:01 +0300 | [diff] [blame] | 1217 | ec->renderer->destroy(ec); |
Kristian Høgsberg | 3a0de88 | 2012-09-06 21:44:24 -0400 | [diff] [blame] | 1218 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1219 | weston_compositor_shutdown(ec); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 1220 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 1221 | if (c->parent.shm) |
| 1222 | wl_shm_destroy(c->parent.shm); |
| 1223 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 1224 | free(ec); |
| 1225 | } |
| 1226 | |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1227 | static const char *left_ptrs[] = { |
| 1228 | "left_ptr", |
| 1229 | "default", |
| 1230 | "top_left_arrow", |
| 1231 | "left-arrow" |
| 1232 | }; |
| 1233 | |
| 1234 | static void |
| 1235 | create_cursor(struct wayland_compositor *c, struct weston_config *config) |
| 1236 | { |
| 1237 | struct weston_config_section *s; |
| 1238 | int size; |
| 1239 | char *theme = NULL; |
| 1240 | unsigned int i; |
| 1241 | |
| 1242 | s = weston_config_get_section(config, "shell", NULL, NULL); |
| 1243 | weston_config_section_get_string(s, "cursor-theme", &theme, NULL); |
| 1244 | weston_config_section_get_int(s, "cursor-size", &size, 32); |
| 1245 | |
| 1246 | c->cursor_theme = wl_cursor_theme_load(theme, size, c->parent.shm); |
| 1247 | |
| 1248 | c->cursor = NULL; |
| 1249 | for (i = 0; !c->cursor && i < ARRAY_LENGTH(left_ptrs); ++i) |
| 1250 | c->cursor = wl_cursor_theme_get_cursor(c->cursor_theme, |
| 1251 | left_ptrs[i]); |
| 1252 | if (!c->cursor) { |
| 1253 | fprintf(stderr, "could not load left cursor\n"); |
| 1254 | return; |
| 1255 | } |
| 1256 | } |
| 1257 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1258 | static struct weston_compositor * |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 1259 | wayland_compositor_create(struct wl_display *display, int use_pixman, |
Daniel Stone | baf4359 | 2012-06-01 11:11:10 -0400 | [diff] [blame] | 1260 | int width, int height, const char *display_name, |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 1261 | int *argc, char *argv[], |
| 1262 | struct weston_config *config) |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1263 | { |
| 1264 | struct wayland_compositor *c; |
| 1265 | struct wl_event_loop *loop; |
| 1266 | int fd; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1267 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 1268 | c = zalloc(sizeof *c); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1269 | if (c == NULL) |
| 1270 | return NULL; |
| 1271 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 1272 | if (weston_compositor_init(&c->base, display, argc, argv, |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 1273 | config) < 0) |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 1274 | goto err_free; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 1275 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 1276 | c->parent.wl_display = wl_display_connect(display_name); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1277 | |
Kristian Høgsberg | 362b672 | 2012-06-18 15:13:51 -0400 | [diff] [blame] | 1278 | if (c->parent.wl_display == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1279 | weston_log("failed to create display: %m\n"); |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 1280 | goto err_compositor; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1281 | } |
| 1282 | |
Jason Ekstrand | 8f89fcb | 2013-10-27 22:24:53 -0500 | [diff] [blame] | 1283 | wl_list_init(&c->inputs); |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1284 | c->parent.registry = wl_display_get_registry(c->parent.wl_display); |
| 1285 | wl_registry_add_listener(c->parent.registry, ®istry_listener, c); |
Jason Ekstrand | 7744f71 | 2013-10-27 22:24:55 -0500 | [diff] [blame] | 1286 | wl_display_roundtrip(c->parent.wl_display); |
| 1287 | |
| 1288 | create_cursor(c, config); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1289 | |
| 1290 | c->base.wl_display = display; |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 1291 | |
| 1292 | gl_renderer = weston_load_module("gl-renderer.so", |
| 1293 | "gl_renderer_interface"); |
| 1294 | if (!gl_renderer) |
| 1295 | goto err_display; |
| 1296 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 1297 | c->use_pixman = use_pixman; |
| 1298 | if (!use_pixman) { |
| 1299 | if (gl_renderer->create(&c->base, c->parent.wl_display, |
| 1300 | gl_renderer->alpha_attribs, |
| 1301 | NULL) < 0) { |
| 1302 | weston_log("Failed to initialize the GL renderer; " |
| 1303 | "falling back to pixman.\n"); |
| 1304 | c->use_pixman = 1; |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | if (c->use_pixman) { |
| 1309 | if (pixman_renderer_init(&c->base) < 0) { |
| 1310 | weston_log("Failed to initialize pixman renderer\n"); |
| 1311 | goto err_display; |
| 1312 | } |
| 1313 | } |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1314 | |
Benjamin Franzke | ecfb2b9 | 2011-01-15 12:34:48 +0100 | [diff] [blame] | 1315 | c->base.destroy = wayland_destroy; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 1316 | c->base.restore = wayland_restore; |
Benjamin Franzke | ecfb2b9 | 2011-01-15 12:34:48 +0100 | [diff] [blame] | 1317 | |
John Kåre Alsaker | b9b8712 | 2012-10-04 20:42:16 +0200 | [diff] [blame] | 1318 | /* requires border fields */ |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1319 | if (wayland_compositor_create_output(c, width, height) < 0) |
John Kåre Alsaker | 779b52a | 2012-11-13 19:10:29 +0100 | [diff] [blame] | 1320 | goto err_gl; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1321 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1322 | loop = wl_display_get_event_loop(c->base.wl_display); |
| 1323 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1324 | fd = wl_display_get_fd(c->parent.wl_display); |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1325 | c->parent.wl_source = |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 1326 | wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1327 | wayland_compositor_handle_event, c); |
| 1328 | if (c->parent.wl_source == NULL) |
John Kåre Alsaker | 779b52a | 2012-11-13 19:10:29 +0100 | [diff] [blame] | 1329 | goto err_gl; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1330 | |
Kristian Høgsberg | feb3c1d | 2012-10-15 12:56:11 -0400 | [diff] [blame] | 1331 | wl_event_source_check(c->parent.wl_source); |
| 1332 | |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1333 | return &c->base; |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 1334 | |
John Kåre Alsaker | 779b52a | 2012-11-13 19:10:29 +0100 | [diff] [blame] | 1335 | err_gl: |
Vasily Khoruzhick | 52cfd61 | 2013-01-08 19:09:01 +0300 | [diff] [blame] | 1336 | c->base.renderer->destroy(&c->base); |
Martin Olsson | c5db50f | 2012-07-08 03:03:43 +0200 | [diff] [blame] | 1337 | err_display: |
| 1338 | wl_display_disconnect(c->parent.wl_display); |
| 1339 | err_compositor: |
| 1340 | weston_compositor_shutdown(&c->base); |
| 1341 | err_free: |
| 1342 | free(c); |
| 1343 | return NULL; |
Benjamin Franzke | ec2e642 | 2010-11-27 19:04:12 +0100 | [diff] [blame] | 1344 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1345 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1346 | WL_EXPORT struct weston_compositor * |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 1347 | backend_init(struct wl_display *display, int *argc, char *argv[], |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 1348 | struct weston_config *config) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1349 | { |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1350 | int width = 1024, height = 640; |
| 1351 | char *display_name = NULL; |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 1352 | int use_pixman = 0; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1353 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1354 | const struct weston_option wayland_options[] = { |
| 1355 | { WESTON_OPTION_INTEGER, "width", 0, &width }, |
| 1356 | { WESTON_OPTION_INTEGER, "height", 0, &height }, |
| 1357 | { WESTON_OPTION_STRING, "display", 0, &display_name }, |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 1358 | { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman }, |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 1359 | }; |
| 1360 | |
| 1361 | parse_options(wayland_options, |
| 1362 | ARRAY_LENGTH(wayland_options), argc, argv); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1363 | |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 1364 | return wayland_compositor_create(display, use_pixman, width, height, |
| 1365 | display_name, argc, argv, config); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1366 | } |