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