2010-11-27 21:04:12 +03:00
|
|
|
/*
|
Change remaining GPLv2 headers to MIT
The files in question are copyright Benjamin Franzke (who agrees),
Intel Corporation, Red Hat and myself. On behalf of Red Hat,
Richard Fontana says:
"Therefore, to the extent that Red Hat, Inc. has any copyright
interest in the files you cited as of this date (compositor-drm.c,
compositor.c, compositor.h, screenshooter.c in
http://cgit.freedesktop.org/wayland/wayland-demos/tree/compositor),
Red Hat hereby elects to apply the CC0 1.0 Universal Public Domain
Dedication to such copyrighted material. See:
http://creativecommons.org/publicdomain/zero/1.0/legalcode .
Thanks,
Richard E. Fontana
Open Source Licensing and Patent Counsel
Red Hat, Inc."
2011-09-15 23:43:14 +04:00
|
|
|
* Copyright © 2010-2011 Benjamin Franzke
|
2013-10-28 07:24:58 +04:00
|
|
|
* Copyright © 2013 Jason Ekstrand
|
2010-11-27 21:04:12 +03:00
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2010-11-27 21:04:12 +03:00
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-11-27 21:04:12 +03:00
|
|
|
*/
|
|
|
|
|
2013-05-22 19:03:19 +04:00
|
|
|
#include "config.h"
|
2010-11-27 21:04:12 +03:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2012-06-01 15:14:06 +04:00
|
|
|
#include <sys/mman.h>
|
2013-11-08 06:13:33 +04:00
|
|
|
#include <linux/input.h>
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2011-02-18 19:04:24 +03:00
|
|
|
#include <wayland-client.h>
|
|
|
|
#include <wayland-egl.h>
|
2013-10-28 07:24:55 +04:00
|
|
|
#include <wayland-cursor.h>
|
2010-11-27 21:04:12 +03:00
|
|
|
|
|
|
|
#include "compositor.h"
|
2016-04-28 21:33:15 +03:00
|
|
|
#include "compositor-wayland.h"
|
2012-11-13 22:10:28 +04:00
|
|
|
#include "gl-renderer.h"
|
2013-10-28 07:24:58 +04:00
|
|
|
#include "pixman-renderer.h"
|
2015-06-16 01:37:08 +03:00
|
|
|
#include "shared/helpers.h"
|
2015-06-16 01:37:07 +03:00
|
|
|
#include "shared/image-loader.h"
|
|
|
|
#include "shared/os-compatibility.h"
|
|
|
|
#include "shared/cairo-util.h"
|
2015-11-17 11:00:27 +03:00
|
|
|
#include "fullscreen-shell-unstable-v1-client-protocol.h"
|
2016-02-18 17:53:27 +03:00
|
|
|
#include "presentation-time-server-protocol.h"
|
2015-09-25 12:58:40 +03:00
|
|
|
#include "linux-dmabuf.h"
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2013-10-28 07:25:02 +04:00
|
|
|
#define WINDOW_TITLE "Weston Compositor"
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend {
|
|
|
|
struct weston_backend base;
|
|
|
|
struct weston_compositor *compositor;
|
2010-11-27 21:04:12 +03:00
|
|
|
|
|
|
|
struct {
|
2012-06-18 23:13:51 +04:00
|
|
|
struct wl_display *wl_display;
|
2012-10-11 05:34:26 +04:00
|
|
|
struct wl_registry *registry;
|
2010-11-27 21:04:12 +03:00
|
|
|
struct wl_compositor *compositor;
|
|
|
|
struct wl_shell *shell;
|
2015-11-17 11:00:27 +03:00
|
|
|
struct zwp_fullscreen_shell_v1 *fshell;
|
2013-04-06 01:07:11 +04:00
|
|
|
struct wl_shm *shm;
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2014-04-03 04:53:54 +04:00
|
|
|
struct wl_list output_list;
|
|
|
|
|
2010-11-27 21:04:12 +03:00
|
|
|
struct wl_event_source *wl_source;
|
|
|
|
uint32_t event_mask;
|
|
|
|
} parent;
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
int use_pixman;
|
2014-04-03 04:53:55 +04:00
|
|
|
int sprawl_across_outputs;
|
2013-10-28 07:24:58 +04:00
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
struct theme *theme;
|
|
|
|
cairo_device_t *frame_device;
|
|
|
|
struct wl_cursor_theme *cursor_theme;
|
|
|
|
struct wl_cursor *cursor;
|
2012-02-01 16:45:51 +04:00
|
|
|
|
2013-11-08 06:13:29 +04:00
|
|
|
struct wl_list input_list;
|
2010-11-27 21:04:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct wayland_output {
|
2013-10-28 07:24:53 +04:00
|
|
|
struct weston_output base;
|
|
|
|
|
2010-11-27 21:04:12 +03:00
|
|
|
struct {
|
2013-10-28 07:24:53 +04:00
|
|
|
int draw_initial_frame;
|
|
|
|
struct wl_surface *surface;
|
2014-04-03 04:53:54 +04:00
|
|
|
|
|
|
|
struct wl_output *output;
|
|
|
|
uint32_t global_id;
|
|
|
|
|
2013-10-28 07:24:53 +04:00
|
|
|
struct wl_shell_surface *shell_surface;
|
2013-11-08 06:13:33 +04:00
|
|
|
int configure_width, configure_height;
|
2010-11-27 21:04:12 +03:00
|
|
|
} parent;
|
2013-10-28 07:24:53 +04:00
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
int keyboard_count;
|
|
|
|
|
2013-11-08 06:13:33 +04:00
|
|
|
char *name;
|
2013-10-28 07:24:55 +04:00
|
|
|
struct frame *frame;
|
2013-10-28 07:24:58 +04:00
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
struct {
|
2013-10-28 07:24:58 +04:00
|
|
|
struct wl_egl_window *egl_window;
|
|
|
|
struct {
|
|
|
|
cairo_surface_t *top;
|
|
|
|
cairo_surface_t *left;
|
|
|
|
cairo_surface_t *right;
|
|
|
|
cairo_surface_t *bottom;
|
|
|
|
} border;
|
|
|
|
} gl;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
struct wl_list buffers;
|
|
|
|
struct wl_list free_buffers;
|
|
|
|
} shm;
|
2013-10-28 07:24:55 +04:00
|
|
|
|
2013-10-28 07:24:53 +04:00
|
|
|
struct weston_mode mode;
|
2013-10-28 07:25:02 +04:00
|
|
|
uint32_t scale;
|
2010-11-27 21:04:12 +03:00
|
|
|
};
|
|
|
|
|
2014-04-03 04:53:54 +04:00
|
|
|
struct wayland_parent_output {
|
|
|
|
struct wayland_output *output;
|
|
|
|
struct wl_list link;
|
|
|
|
|
|
|
|
struct wl_output *global;
|
|
|
|
uint32_t id;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char *make;
|
|
|
|
char *model;
|
|
|
|
int32_t width, height;
|
|
|
|
uint32_t subpixel;
|
|
|
|
} physical;
|
|
|
|
|
|
|
|
int32_t x, y;
|
|
|
|
uint32_t transform;
|
|
|
|
uint32_t scale;
|
|
|
|
|
|
|
|
struct wl_list mode_list;
|
|
|
|
struct weston_mode *preferred_mode;
|
|
|
|
struct weston_mode *current_mode;
|
|
|
|
};
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
struct wayland_shm_buffer {
|
|
|
|
struct wayland_output *output;
|
|
|
|
struct wl_list link;
|
|
|
|
struct wl_list free_link;
|
|
|
|
|
|
|
|
struct wl_buffer *buffer;
|
|
|
|
void *data;
|
|
|
|
size_t size;
|
|
|
|
pixman_region32_t damage;
|
|
|
|
int frame_damaged;
|
|
|
|
|
|
|
|
pixman_image_t *pm_image;
|
|
|
|
cairo_surface_t *c_surface;
|
|
|
|
};
|
|
|
|
|
2010-11-27 21:04:12 +03:00
|
|
|
struct wayland_input {
|
2012-08-10 18:01:33 +04:00
|
|
|
struct weston_seat base;
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *backend;
|
2010-11-27 21:04:12 +03:00
|
|
|
struct wl_list link;
|
2013-10-28 07:24:53 +04:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct wl_seat *seat;
|
|
|
|
struct wl_pointer *pointer;
|
|
|
|
struct wl_keyboard *keyboard;
|
|
|
|
struct wl_touch *touch;
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct wl_surface *surface;
|
|
|
|
int32_t hx, hy;
|
|
|
|
} cursor;
|
2013-10-28 07:24:53 +04:00
|
|
|
} parent;
|
|
|
|
|
2014-04-03 04:53:57 +04:00
|
|
|
enum weston_key_state_update keyboard_state_update;
|
2012-06-22 16:21:41 +04:00
|
|
|
uint32_t key_serial;
|
2012-08-14 07:29:53 +04:00
|
|
|
uint32_t enter_serial;
|
2015-11-07 00:56:10 +03:00
|
|
|
uint32_t touch_points;
|
|
|
|
bool touch_active;
|
2015-11-07 00:56:06 +03:00
|
|
|
bool has_focus;
|
2015-11-07 00:56:08 +03:00
|
|
|
int seat_version;
|
2015-11-07 00:56:06 +03:00
|
|
|
|
2012-08-14 07:29:53 +04:00
|
|
|
struct wayland_output *output;
|
2015-11-07 00:56:10 +03:00
|
|
|
struct wayland_output *touch_focus;
|
2013-10-28 07:24:55 +04:00
|
|
|
struct wayland_output *keyboard_focus;
|
2016-01-18 09:38:22 +03:00
|
|
|
|
|
|
|
struct weston_pointer_axis_event vert, horiz;
|
2010-11-27 21:04:12 +03:00
|
|
|
};
|
|
|
|
|
2013-10-14 16:57:11 +04:00
|
|
|
struct gl_renderer_interface *gl_renderer;
|
|
|
|
|
2011-08-17 07:01:28 +04:00
|
|
|
static void
|
2013-10-28 07:24:58 +04:00
|
|
|
wayland_shm_buffer_destroy(struct wayland_shm_buffer *buffer)
|
2011-08-17 07:01:28 +04:00
|
|
|
{
|
2013-10-28 07:24:58 +04:00
|
|
|
cairo_surface_destroy(buffer->c_surface);
|
|
|
|
pixman_image_unref(buffer->pm_image);
|
2011-08-17 07:01:28 +04:00
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
wl_buffer_destroy(buffer->buffer);
|
|
|
|
munmap(buffer->data, buffer->size);
|
2011-08-17 07:01:28 +04:00
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
pixman_region32_fini(&buffer->damage);
|
|
|
|
|
|
|
|
wl_list_remove(&buffer->link);
|
|
|
|
wl_list_remove(&buffer->free_link);
|
|
|
|
free(buffer);
|
|
|
|
}
|
2011-08-17 07:01:28 +04:00
|
|
|
|
2013-04-06 01:07:11 +04:00
|
|
|
static void
|
|
|
|
buffer_release(void *data, struct wl_buffer *buffer)
|
|
|
|
{
|
2013-10-28 07:24:58 +04:00
|
|
|
struct wayland_shm_buffer *sb = data;
|
|
|
|
|
|
|
|
if (sb->output) {
|
|
|
|
wl_list_insert(&sb->output->shm.free_buffers, &sb->free_link);
|
|
|
|
} else {
|
|
|
|
wayland_shm_buffer_destroy(sb);
|
|
|
|
}
|
2013-04-06 01:07:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_buffer_listener buffer_listener = {
|
|
|
|
buffer_release
|
|
|
|
};
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
static struct wayland_shm_buffer *
|
|
|
|
wayland_output_get_shm_buffer(struct wayland_output *output)
|
2013-04-06 01:07:11 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b =
|
|
|
|
(struct wayland_backend *) output->base.compositor->backend;
|
|
|
|
struct wl_shm *shm = b->parent.shm;
|
2013-10-28 07:24:58 +04:00
|
|
|
struct wayland_shm_buffer *sb;
|
2013-04-06 01:07:11 +04:00
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
struct wl_shm_pool *pool;
|
2013-04-06 01:07:11 +04:00
|
|
|
int width, height, stride;
|
2013-10-28 07:24:58 +04:00
|
|
|
int32_t fx, fy;
|
2013-04-06 01:07:11 +04:00
|
|
|
int fd;
|
2013-10-28 07:24:58 +04:00
|
|
|
unsigned char *data;
|
|
|
|
|
|
|
|
if (!wl_list_empty(&output->shm.free_buffers)) {
|
|
|
|
sb = container_of(output->shm.free_buffers.next,
|
|
|
|
struct wayland_shm_buffer, free_link);
|
|
|
|
wl_list_remove(&sb->free_link);
|
|
|
|
wl_list_init(&sb->free_link);
|
|
|
|
|
|
|
|
return sb;
|
|
|
|
}
|
2013-04-06 01:07:11 +04:00
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
if (output->frame) {
|
|
|
|
width = frame_width(output->frame);
|
|
|
|
height = frame_height(output->frame);
|
|
|
|
} else {
|
2013-10-28 07:25:02 +04:00
|
|
|
width = output->base.current_mode->width;
|
|
|
|
height = output->base.current_mode->height;
|
2013-10-28 07:24:55 +04:00
|
|
|
}
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
|
2013-04-06 01:07:11 +04:00
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
fd = os_create_anonymous_file(height * stride);
|
2013-04-06 01:07:11 +04:00
|
|
|
if (fd < 0) {
|
2014-03-21 09:54:02 +04:00
|
|
|
weston_log("could not create an anonymous file buffer: %m\n");
|
2013-10-28 07:24:58 +04:00
|
|
|
return NULL;
|
2013-04-06 01:07:11 +04:00
|
|
|
}
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
data = mmap(NULL, height * stride, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
2013-04-06 01:07:11 +04:00
|
|
|
if (data == MAP_FAILED) {
|
2014-03-21 09:54:02 +04:00
|
|
|
weston_log("could not mmap %d memory for data: %m\n", height * stride);
|
2013-04-06 01:07:11 +04:00
|
|
|
close(fd);
|
2013-10-28 07:24:58 +04:00
|
|
|
return NULL;
|
2013-04-06 01:07:11 +04:00
|
|
|
}
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
sb = zalloc(sizeof *sb);
|
2014-04-22 03:51:02 +04:00
|
|
|
if (sb == NULL) {
|
2014-05-27 11:08:29 +04:00
|
|
|
weston_log("could not zalloc %zu memory for sb: %m\n", sizeof *sb);
|
2014-04-22 03:51:02 +04:00
|
|
|
close(fd);
|
|
|
|
free(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-10-28 07:24:58 +04:00
|
|
|
|
|
|
|
sb->output = output;
|
|
|
|
wl_list_init(&sb->free_link);
|
|
|
|
wl_list_insert(&output->shm.buffers, &sb->link);
|
|
|
|
|
|
|
|
pixman_region32_init_rect(&sb->damage, 0, 0,
|
|
|
|
output->base.width, output->base.height);
|
|
|
|
sb->frame_damaged = 1;
|
2013-04-06 01:07:11 +04:00
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
sb->data = data;
|
|
|
|
sb->size = height * stride;
|
|
|
|
|
|
|
|
pool = wl_shm_create_pool(shm, fd, sb->size);
|
|
|
|
|
|
|
|
sb->buffer = wl_shm_pool_create_buffer(pool, 0,
|
|
|
|
width, height,
|
|
|
|
stride,
|
|
|
|
WL_SHM_FORMAT_ARGB8888);
|
|
|
|
wl_buffer_add_listener(sb->buffer, &buffer_listener, sb);
|
2013-04-06 01:07:11 +04:00
|
|
|
wl_shm_pool_destroy(pool);
|
|
|
|
close(fd);
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
memset(data, 0, sb->size);
|
|
|
|
|
|
|
|
sb->c_surface =
|
|
|
|
cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32,
|
|
|
|
width, height, stride);
|
2013-04-06 01:07:11 +04:00
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
fx = 0;
|
|
|
|
fy = 0;
|
|
|
|
if (output->frame)
|
|
|
|
frame_interior(output->frame, &fx, &fy, 0, 0);
|
|
|
|
sb->pm_image =
|
|
|
|
pixman_image_create_bits(PIXMAN_a8r8g8b8, width, height,
|
|
|
|
(uint32_t *)(data + fy * stride) + fx,
|
|
|
|
stride);
|
|
|
|
|
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_done(void *data, struct wl_callback *callback, uint32_t time)
|
|
|
|
{
|
|
|
|
struct weston_output *output = data;
|
2014-09-24 06:08:45 +04:00
|
|
|
struct timespec ts;
|
2013-10-28 07:24:58 +04:00
|
|
|
|
|
|
|
wl_callback_destroy(callback);
|
2014-09-24 06:08:45 +04:00
|
|
|
|
|
|
|
/* XXX: use the presentation extension for proper timings */
|
2015-04-02 16:26:06 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the fallback case, where Presentation extension is not
|
|
|
|
* available from the parent compositor. We do not know the base for
|
|
|
|
* 'time', so we cannot feed it to finish_frame(). Do the only thing
|
|
|
|
* we can, and pretend finish_frame time is when we process this
|
|
|
|
* event.
|
|
|
|
*/
|
|
|
|
weston_compositor_read_presentation_clock(output->compositor, &ts);
|
compositor: set presentation.presented flags
Change weston_output_finish_frame() signature so that backends are
required to set the flags, that will be reported on the Presentation
'presented' event. This is meant for output-wide feedback flags. Flags
that vary per wl_surface are subject for the following patch.
All start_repaint_loop functions use the special private flag
PRESENTATION_FEEDBACK_INVALID to mark, that this call of
weston_output_finish_frame() cannot trigger the 'presented' event. If it
does, we now hit an assert, and should then investigate why a fake update
triggered Presentation feedback.
DRM:
Page flip is always vsync'd, and always gets the completion timestamp
from the kernel which should correspond well to hardware. Completion is
triggered by the kernel/hardware.
Vblank handler is only used with the broken planes path, therefore do
not report VSYNC, because we cannot guarantee all the planes updated at
the same time. We cannot set the INVALID, because it would abort the
compositor if the broken planes path was ever used. This is a hack that
will get fixed with nuclear pageflip support in the future.
fbdev:
No vsync, update done by copy, no completion event from hardware, and
completion time is totally fake.
headless:
No real output to update.
RDP:
Guessing that maybe no vsync, fake time, and copy make sense (pixels
sent over network). Also no event that the pixels have been shown?
RPI:
Presumably Dispmanx updates are vsync'd. We get a completion event from
the driver, but need to read the clock ourselves, so the completion time
is somewhat unreliable. Zero-copy flag not implemented though it would
be theoretically possible with EGL clients (zero-copy is a per-surface
flag anyway, so in this patch).
Wayland:
No information how the host compositor is doing updates, so make a safe
guess without assuming vsync or hardware completion event. While we do
get some timestamp from the host compositor, it is not the completion
time. Would need to hook to the Presentation extension of the host
compositor to get more accurate flags.
X11:
No idea about vsync, completion event, or copying. Also the timestamp is
a fake.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Tested-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Acked-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2014-12-17 17:20:40 +03:00
|
|
|
weston_output_finish_frame(output, &ts, 0);
|
2013-10-28 07:24:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener frame_listener = {
|
|
|
|
frame_done
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_initial_frame(struct wayland_output *output)
|
|
|
|
{
|
|
|
|
struct wayland_shm_buffer *sb;
|
|
|
|
|
|
|
|
sb = wayland_output_get_shm_buffer(output);
|
|
|
|
|
|
|
|
/* If we are rendering with GL, then orphan it so that it gets
|
|
|
|
* destroyed immediately */
|
|
|
|
if (output->gl.egl_window)
|
|
|
|
sb->output = NULL;
|
|
|
|
|
|
|
|
wl_surface_attach(output->parent.surface, sb->buffer, 0, 0);
|
2014-04-03 04:53:54 +04:00
|
|
|
wl_surface_damage(output->parent.surface, 0, 0,
|
|
|
|
output->base.current_mode->width,
|
|
|
|
output->base.current_mode->height);
|
2013-04-06 01:07:11 +04:00
|
|
|
}
|
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
static void
|
|
|
|
wayland_output_update_gl_border(struct wayland_output *output)
|
|
|
|
{
|
|
|
|
int32_t ix, iy, iwidth, iheight, fwidth, fheight;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
if (!output->frame)
|
|
|
|
return;
|
|
|
|
if (!(frame_status(output->frame) & FRAME_STATUS_REPAINT))
|
|
|
|
return;
|
|
|
|
|
|
|
|
fwidth = frame_width(output->frame);
|
|
|
|
fheight = frame_height(output->frame);
|
|
|
|
frame_interior(output->frame, &ix, &iy, &iwidth, &iheight);
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
if (!output->gl.border.top)
|
|
|
|
output->gl.border.top =
|
2013-10-28 07:24:55 +04:00
|
|
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
|
|
|
fwidth, iy);
|
2013-10-28 07:24:58 +04:00
|
|
|
cr = cairo_create(output->gl.border.top);
|
2013-10-28 07:24:55 +04:00
|
|
|
frame_repaint(output->frame, cr);
|
|
|
|
cairo_destroy(cr);
|
|
|
|
gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_TOP,
|
|
|
|
fwidth, iy,
|
2013-10-28 07:24:58 +04:00
|
|
|
cairo_image_surface_get_stride(output->gl.border.top) / 4,
|
|
|
|
cairo_image_surface_get_data(output->gl.border.top));
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
if (!output->gl.border.left)
|
|
|
|
output->gl.border.left =
|
2013-10-28 07:24:55 +04:00
|
|
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
|
|
|
ix, 1);
|
2013-10-28 07:24:58 +04:00
|
|
|
cr = cairo_create(output->gl.border.left);
|
2013-10-28 07:24:55 +04:00
|
|
|
cairo_translate(cr, 0, -iy);
|
|
|
|
frame_repaint(output->frame, cr);
|
|
|
|
cairo_destroy(cr);
|
|
|
|
gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_LEFT,
|
|
|
|
ix, 1,
|
2013-10-28 07:24:58 +04:00
|
|
|
cairo_image_surface_get_stride(output->gl.border.left) / 4,
|
|
|
|
cairo_image_surface_get_data(output->gl.border.left));
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
if (!output->gl.border.right)
|
|
|
|
output->gl.border.right =
|
2013-10-28 07:24:55 +04:00
|
|
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
|
|
|
fwidth - (ix + iwidth), 1);
|
2013-10-28 07:24:58 +04:00
|
|
|
cr = cairo_create(output->gl.border.right);
|
2013-10-28 07:24:55 +04:00
|
|
|
cairo_translate(cr, -(iwidth + ix), -iy);
|
|
|
|
frame_repaint(output->frame, cr);
|
|
|
|
cairo_destroy(cr);
|
|
|
|
gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_RIGHT,
|
|
|
|
fwidth - (ix + iwidth), 1,
|
2013-10-28 07:24:58 +04:00
|
|
|
cairo_image_surface_get_stride(output->gl.border.right) / 4,
|
|
|
|
cairo_image_surface_get_data(output->gl.border.right));
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
if (!output->gl.border.bottom)
|
|
|
|
output->gl.border.bottom =
|
2013-10-28 07:24:55 +04:00
|
|
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
|
|
|
fwidth, fheight - (iy + iheight));
|
2013-10-28 07:24:58 +04:00
|
|
|
cr = cairo_create(output->gl.border.bottom);
|
2013-10-28 07:24:55 +04:00
|
|
|
cairo_translate(cr, 0, -(iy + iheight));
|
|
|
|
frame_repaint(output->frame, cr);
|
|
|
|
cairo_destroy(cr);
|
|
|
|
gl_renderer->output_set_border(&output->base, GL_RENDERER_BORDER_BOTTOM,
|
|
|
|
fwidth, fheight - (iy + iheight),
|
2013-10-28 07:24:58 +04:00
|
|
|
cairo_image_surface_get_stride(output->gl.border.bottom) / 4,
|
|
|
|
cairo_image_surface_get_data(output->gl.border.bottom));
|
2013-10-28 07:24:55 +04:00
|
|
|
}
|
|
|
|
|
2013-04-06 01:07:11 +04:00
|
|
|
static void
|
|
|
|
wayland_output_start_repaint_loop(struct weston_output *output_base)
|
|
|
|
{
|
|
|
|
struct wayland_output *output = (struct wayland_output *) output_base;
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *wb =
|
|
|
|
(struct wayland_backend *)output->base.compositor->backend;
|
2013-04-06 01:07:11 +04:00
|
|
|
struct wl_callback *callback;
|
|
|
|
|
|
|
|
/* If this is the initial frame, we need to attach a buffer so that
|
|
|
|
* the compositor can map the surface and include it in its render
|
|
|
|
* loop. If the surface doesn't end up in the render loop, the frame
|
|
|
|
* callback won't be invoked. The buffer is transparent and of the
|
|
|
|
* same size as the future real output buffer. */
|
|
|
|
if (output->parent.draw_initial_frame) {
|
|
|
|
output->parent.draw_initial_frame = 0;
|
|
|
|
|
|
|
|
draw_initial_frame(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
callback = wl_surface_frame(output->parent.surface);
|
|
|
|
wl_callback_add_listener(callback, &frame_listener, output);
|
|
|
|
wl_surface_commit(output->parent.surface);
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_display_flush(wb->parent.wl_display);
|
2013-04-06 01:07:11 +04:00
|
|
|
}
|
|
|
|
|
2013-10-22 19:11:26 +04:00
|
|
|
static int
|
2013-10-28 07:24:58 +04:00
|
|
|
wayland_output_repaint_gl(struct weston_output *output_base,
|
|
|
|
pixman_region32_t *damage)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
2011-03-14 14:07:26 +03:00
|
|
|
struct wayland_output *output = (struct wayland_output *) output_base;
|
2012-09-06 06:49:55 +04:00
|
|
|
struct weston_compositor *ec = output->base.compositor;
|
2011-08-17 07:01:28 +04:00
|
|
|
struct wl_callback *callback;
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2011-08-17 07:01:28 +04:00
|
|
|
callback = wl_surface_frame(output->parent.surface);
|
|
|
|
wl_callback_add_listener(callback, &frame_listener, output);
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
wayland_output_update_gl_border(output);
|
|
|
|
|
2012-10-10 13:49:31 +04:00
|
|
|
ec->renderer->repaint_output(&output->base, damage);
|
2012-11-22 17:57:00 +04:00
|
|
|
|
|
|
|
pixman_region32_subtract(&ec->primary_plane.damage,
|
|
|
|
&ec->primary_plane.damage, damage);
|
2013-10-22 19:11:26 +04:00
|
|
|
return 0;
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
static void
|
|
|
|
wayland_output_update_shm_border(struct wayland_shm_buffer *buffer)
|
|
|
|
{
|
|
|
|
int32_t ix, iy, iwidth, iheight, fwidth, fheight;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
if (!buffer->output->frame || !buffer->frame_damaged)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cr = cairo_create(buffer->c_surface);
|
|
|
|
|
|
|
|
frame_interior(buffer->output->frame, &ix, &iy, &iwidth, &iheight);
|
|
|
|
fwidth = frame_width(buffer->output->frame);
|
|
|
|
fheight = frame_height(buffer->output->frame);
|
|
|
|
|
|
|
|
/* Set the clip so we don't unnecisaraly damage the surface */
|
|
|
|
cairo_move_to(cr, ix, iy);
|
|
|
|
cairo_rel_line_to(cr, iwidth, 0);
|
|
|
|
cairo_rel_line_to(cr, 0, iheight);
|
|
|
|
cairo_rel_line_to(cr, -iwidth, 0);
|
|
|
|
cairo_line_to(cr, ix, iy);
|
|
|
|
cairo_line_to(cr, 0, iy);
|
|
|
|
cairo_line_to(cr, 0, fheight);
|
|
|
|
cairo_line_to(cr, fwidth, fheight);
|
|
|
|
cairo_line_to(cr, fwidth, 0);
|
|
|
|
cairo_line_to(cr, 0, 0);
|
|
|
|
cairo_line_to(cr, 0, iy);
|
|
|
|
cairo_close_path(cr);
|
|
|
|
cairo_clip(cr);
|
|
|
|
|
|
|
|
/* Draw using a pattern so that the final result gets clipped */
|
|
|
|
cairo_push_group(cr);
|
|
|
|
frame_repaint(buffer->output->frame, cr);
|
|
|
|
cairo_pop_group_to_source(cr);
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
cairo_paint(cr);
|
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wayland_shm_buffer_attach(struct wayland_shm_buffer *sb)
|
|
|
|
{
|
|
|
|
pixman_region32_t damage;
|
|
|
|
pixman_box32_t *rects;
|
|
|
|
int32_t ix, iy, iwidth, iheight, fwidth, fheight;
|
|
|
|
int i, n;
|
|
|
|
|
2013-10-28 07:25:02 +04:00
|
|
|
pixman_region32_init(&damage);
|
|
|
|
weston_transformed_region(sb->output->base.width,
|
|
|
|
sb->output->base.height,
|
|
|
|
sb->output->base.transform,
|
|
|
|
sb->output->base.current_scale,
|
|
|
|
&sb->damage, &damage);
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
if (sb->output->frame) {
|
|
|
|
frame_interior(sb->output->frame, &ix, &iy, &iwidth, &iheight);
|
|
|
|
fwidth = frame_width(sb->output->frame);
|
|
|
|
fheight = frame_height(sb->output->frame);
|
|
|
|
|
|
|
|
pixman_region32_translate(&damage, ix, iy);
|
|
|
|
|
|
|
|
if (sb->frame_damaged) {
|
|
|
|
pixman_region32_union_rect(&damage, &damage,
|
|
|
|
0, 0, fwidth, iy);
|
|
|
|
pixman_region32_union_rect(&damage, &damage,
|
|
|
|
0, iy, ix, iheight);
|
|
|
|
pixman_region32_union_rect(&damage, &damage,
|
|
|
|
ix + iwidth, iy,
|
|
|
|
fwidth - (ix + iwidth), iheight);
|
|
|
|
pixman_region32_union_rect(&damage, &damage,
|
|
|
|
0, iy + iheight,
|
|
|
|
fwidth, fheight - (iy + iheight));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-28 07:25:02 +04:00
|
|
|
rects = pixman_region32_rectangles(&damage, &n);
|
2013-10-28 07:24:58 +04:00
|
|
|
wl_surface_attach(sb->output->parent.surface, sb->buffer, 0, 0);
|
|
|
|
for (i = 0; i < n; ++i)
|
|
|
|
wl_surface_damage(sb->output->parent.surface, rects[i].x1,
|
|
|
|
rects[i].y1, rects[i].x2 - rects[i].x1,
|
|
|
|
rects[i].y2 - rects[i].y1);
|
|
|
|
|
|
|
|
if (sb->output->frame)
|
|
|
|
pixman_region32_fini(&damage);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
wayland_output_repaint_pixman(struct weston_output *output_base,
|
|
|
|
pixman_region32_t *damage)
|
|
|
|
{
|
|
|
|
struct wayland_output *output = (struct wayland_output *) output_base;
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b =
|
|
|
|
(struct wayland_backend *)output->base.compositor->backend;
|
2013-10-28 07:24:58 +04:00
|
|
|
struct wl_callback *callback;
|
|
|
|
struct wayland_shm_buffer *sb;
|
|
|
|
|
|
|
|
if (output->frame) {
|
|
|
|
if (frame_status(output->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
wl_list_for_each(sb, &output->shm.buffers, link)
|
|
|
|
sb->frame_damaged = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_for_each(sb, &output->shm.buffers, link)
|
|
|
|
pixman_region32_union(&sb->damage, &sb->damage, damage);
|
|
|
|
|
|
|
|
sb = wayland_output_get_shm_buffer(output);
|
|
|
|
|
|
|
|
wayland_output_update_shm_border(sb);
|
|
|
|
pixman_renderer_output_set_buffer(output_base, sb->pm_image);
|
2014-10-11 19:27:30 +04:00
|
|
|
b->compositor->renderer->repaint_output(output_base, &sb->damage);
|
2013-10-28 07:24:58 +04:00
|
|
|
|
|
|
|
wayland_shm_buffer_attach(sb);
|
|
|
|
|
|
|
|
callback = wl_surface_frame(output->parent.surface);
|
|
|
|
wl_callback_add_listener(callback, &frame_listener, output);
|
|
|
|
wl_surface_commit(output->parent.surface);
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_display_flush(b->parent.wl_display);
|
2013-10-28 07:24:58 +04:00
|
|
|
|
|
|
|
pixman_region32_fini(&sb->damage);
|
|
|
|
pixman_region32_init(&sb->damage);
|
|
|
|
sb->frame_damaged = 0;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
pixman_region32_subtract(&b->compositor->primary_plane.damage,
|
|
|
|
&b->compositor->primary_plane.damage, damage);
|
2013-10-28 07:24:58 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-30 00:52:23 +04:00
|
|
|
static void
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
wayland_output_destroy(struct weston_output *output_base)
|
2011-08-30 00:52:23 +04:00
|
|
|
{
|
|
|
|
struct wayland_output *output = (struct wayland_output *) output_base;
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b =
|
|
|
|
(struct wayland_backend *) output->base.compositor->backend;
|
2011-08-30 00:52:23 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->use_pixman) {
|
2013-10-28 07:24:58 +04:00
|
|
|
pixman_renderer_output_destroy(output_base);
|
|
|
|
} else {
|
|
|
|
gl_renderer->output_destroy(output_base);
|
|
|
|
}
|
2012-11-13 22:10:18 +04:00
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
wl_egl_window_destroy(output->gl.egl_window);
|
2013-10-28 07:24:55 +04:00
|
|
|
wl_surface_destroy(output->parent.surface);
|
2014-04-03 04:53:54 +04:00
|
|
|
if (output->parent.shell_surface)
|
|
|
|
wl_shell_surface_destroy(output->parent.shell_surface);
|
2013-10-28 07:24:55 +04:00
|
|
|
|
2013-11-08 06:13:33 +04:00
|
|
|
if (output->frame)
|
2013-10-28 07:24:55 +04:00
|
|
|
frame_destroy(output->frame);
|
2013-11-08 06:13:33 +04:00
|
|
|
|
|
|
|
cairo_surface_destroy(output->gl.border.top);
|
|
|
|
cairo_surface_destroy(output->gl.border.left);
|
|
|
|
cairo_surface_destroy(output->gl.border.right);
|
|
|
|
cairo_surface_destroy(output->gl.border.bottom);
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
weston_output_destroy(&output->base);
|
2011-08-30 00:52:23 +04:00
|
|
|
free(output);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-18 18:36:21 +04:00
|
|
|
static const struct wl_shell_surface_listener shell_surface_listener;
|
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
static int
|
|
|
|
wayland_output_init_gl_renderer(struct wayland_output *output)
|
|
|
|
{
|
2013-10-28 07:24:59 +04:00
|
|
|
int32_t fwidth = 0, fheight = 0;
|
2013-10-28 07:24:58 +04:00
|
|
|
|
|
|
|
if (output->frame) {
|
|
|
|
fwidth = frame_width(output->frame);
|
|
|
|
fheight = frame_height(output->frame);
|
|
|
|
} else {
|
2013-10-28 07:25:02 +04:00
|
|
|
fwidth = output->base.current_mode->width;
|
|
|
|
fheight = output->base.current_mode->height;
|
2013-10-28 07:24:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
output->gl.egl_window =
|
|
|
|
wl_egl_window_create(output->parent.surface,
|
|
|
|
fwidth, fheight);
|
|
|
|
if (!output->gl.egl_window) {
|
|
|
|
weston_log("failure to create wl_egl_window\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_renderer->output_create(&output->base,
|
2015-03-20 17:26:52 +03:00
|
|
|
output->gl.egl_window,
|
2014-03-07 22:05:50 +04:00
|
|
|
output->gl.egl_window,
|
|
|
|
gl_renderer->alpha_attribs,
|
2015-05-15 20:12:39 +03:00
|
|
|
NULL,
|
|
|
|
0) < 0)
|
2013-10-28 07:24:58 +04:00
|
|
|
goto cleanup_window;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup_window:
|
|
|
|
wl_egl_window_destroy(output->gl.egl_window);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
wayland_output_init_pixman_renderer(struct wayland_output *output)
|
|
|
|
{
|
|
|
|
return pixman_renderer_output_create(&output->base);
|
|
|
|
}
|
|
|
|
|
2013-11-08 06:13:33 +04:00
|
|
|
static void
|
|
|
|
wayland_output_resize_surface(struct wayland_output *output)
|
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b =
|
|
|
|
(struct wayland_backend *)output->base.compositor->backend;
|
2013-11-08 06:13:33 +04:00
|
|
|
struct wayland_shm_buffer *buffer, *next;
|
|
|
|
int32_t ix, iy, iwidth, iheight;
|
|
|
|
int32_t width, height;
|
|
|
|
struct wl_region *region;
|
|
|
|
|
|
|
|
width = output->base.current_mode->width;
|
|
|
|
height = output->base.current_mode->height;
|
|
|
|
|
|
|
|
if (output->frame) {
|
|
|
|
frame_resize_inside(output->frame, width, height);
|
|
|
|
|
|
|
|
frame_input_rect(output->frame, &ix, &iy, &iwidth, &iheight);
|
2014-10-11 19:27:30 +04:00
|
|
|
region = wl_compositor_create_region(b->parent.compositor);
|
2013-11-08 06:13:33 +04:00
|
|
|
wl_region_add(region, ix, iy, iwidth, iheight);
|
|
|
|
wl_surface_set_input_region(output->parent.surface, region);
|
|
|
|
wl_region_destroy(region);
|
|
|
|
|
|
|
|
frame_opaque_rect(output->frame, &ix, &iy, &iwidth, &iheight);
|
2014-10-11 19:27:30 +04:00
|
|
|
region = wl_compositor_create_region(b->parent.compositor);
|
2013-11-08 06:13:33 +04:00
|
|
|
wl_region_add(region, ix, iy, iwidth, iheight);
|
|
|
|
wl_surface_set_opaque_region(output->parent.surface, region);
|
|
|
|
wl_region_destroy(region);
|
|
|
|
|
|
|
|
width = frame_width(output->frame);
|
|
|
|
height = frame_height(output->frame);
|
|
|
|
} else {
|
2014-10-11 19:27:30 +04:00
|
|
|
region = wl_compositor_create_region(b->parent.compositor);
|
2013-11-08 06:13:33 +04:00
|
|
|
wl_region_add(region, 0, 0, width, height);
|
|
|
|
wl_surface_set_input_region(output->parent.surface, region);
|
|
|
|
wl_region_destroy(region);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
region = wl_compositor_create_region(b->parent.compositor);
|
2013-11-08 06:13:33 +04:00
|
|
|
wl_region_add(region, 0, 0, width, height);
|
|
|
|
wl_surface_set_opaque_region(output->parent.surface, region);
|
|
|
|
wl_region_destroy(region);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (output->gl.egl_window) {
|
|
|
|
wl_egl_window_resize(output->gl.egl_window,
|
|
|
|
width, height, 0, 0);
|
|
|
|
|
|
|
|
/* These will need to be re-created due to the resize */
|
|
|
|
gl_renderer->output_set_border(&output->base,
|
|
|
|
GL_RENDERER_BORDER_TOP,
|
|
|
|
0, 0, 0, NULL);
|
|
|
|
cairo_surface_destroy(output->gl.border.top);
|
|
|
|
output->gl.border.top = NULL;
|
|
|
|
gl_renderer->output_set_border(&output->base,
|
|
|
|
GL_RENDERER_BORDER_LEFT,
|
|
|
|
0, 0, 0, NULL);
|
|
|
|
cairo_surface_destroy(output->gl.border.left);
|
|
|
|
output->gl.border.left = NULL;
|
|
|
|
gl_renderer->output_set_border(&output->base,
|
|
|
|
GL_RENDERER_BORDER_RIGHT,
|
|
|
|
0, 0, 0, NULL);
|
|
|
|
cairo_surface_destroy(output->gl.border.right);
|
|
|
|
output->gl.border.right = NULL;
|
|
|
|
gl_renderer->output_set_border(&output->base,
|
|
|
|
GL_RENDERER_BORDER_BOTTOM,
|
|
|
|
0, 0, 0, NULL);
|
|
|
|
cairo_surface_destroy(output->gl.border.bottom);
|
|
|
|
output->gl.border.bottom = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Throw away any remaining SHM buffers */
|
2015-05-30 00:32:52 +03:00
|
|
|
wl_list_for_each_safe(buffer, next, &output->shm.free_buffers, free_link)
|
2013-11-08 06:13:33 +04:00
|
|
|
wayland_shm_buffer_destroy(buffer);
|
|
|
|
/* These will get thrown away when they get released */
|
|
|
|
wl_list_for_each(buffer, &output->shm.buffers, link)
|
|
|
|
buffer->output = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
wayland_output_set_windowed(struct wayland_output *output)
|
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b =
|
|
|
|
(struct wayland_backend *)output->base.compositor->backend;
|
2013-11-08 06:13:33 +04:00
|
|
|
int tlen;
|
|
|
|
char *title;
|
|
|
|
|
|
|
|
if (output->frame)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (output->name) {
|
|
|
|
tlen = strlen(output->name) + strlen(WINDOW_TITLE " - ");
|
|
|
|
title = malloc(tlen + 1);
|
|
|
|
if (!title)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
snprintf(title, tlen + 1, WINDOW_TITLE " - %s", output->name);
|
|
|
|
} else {
|
|
|
|
title = strdup(WINDOW_TITLE);
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->theme) {
|
|
|
|
b->theme = theme_create();
|
|
|
|
if (!b->theme) {
|
2013-11-08 06:13:33 +04:00
|
|
|
free(title);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2014-10-11 19:27:30 +04:00
|
|
|
output->frame = frame_create(b->theme, 100, 100,
|
2013-11-08 06:13:33 +04:00
|
|
|
FRAME_BUTTON_CLOSE, title);
|
|
|
|
free(title);
|
|
|
|
if (!output->frame)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (output->keyboard_count)
|
|
|
|
frame_set_flag(output->frame, FRAME_FLAG_ACTIVE);
|
|
|
|
|
|
|
|
wayland_output_resize_surface(output);
|
|
|
|
|
|
|
|
wl_shell_surface_set_toplevel(output->parent.shell_surface);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wayland_output_set_fullscreen(struct wayland_output *output,
|
|
|
|
enum wl_shell_surface_fullscreen_method method,
|
|
|
|
uint32_t framerate, struct wl_output *target)
|
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b =
|
|
|
|
(struct wayland_backend *)output->base.compositor->backend;
|
2014-04-03 04:53:54 +04:00
|
|
|
|
2013-11-08 06:13:33 +04:00
|
|
|
if (output->frame) {
|
|
|
|
frame_destroy(output->frame);
|
|
|
|
output->frame = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wayland_output_resize_surface(output);
|
|
|
|
|
2014-04-03 04:53:54 +04:00
|
|
|
if (output->parent.shell_surface) {
|
|
|
|
wl_shell_surface_set_fullscreen(output->parent.shell_surface,
|
|
|
|
method, framerate, target);
|
2014-10-11 19:27:30 +04:00
|
|
|
} else if (b->parent.fshell) {
|
2015-11-17 11:00:27 +03:00
|
|
|
zwp_fullscreen_shell_v1_present_surface(b->parent.fshell,
|
|
|
|
output->parent.surface,
|
|
|
|
method, target);
|
2014-04-03 04:53:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct weston_mode *
|
|
|
|
wayland_output_choose_mode(struct wayland_output *output,
|
|
|
|
struct weston_mode *ref_mode)
|
|
|
|
{
|
|
|
|
struct weston_mode *mode;
|
|
|
|
|
|
|
|
/* First look for an exact match */
|
|
|
|
wl_list_for_each(mode, &output->base.mode_list, link)
|
|
|
|
if (mode->width == ref_mode->width &&
|
|
|
|
mode->height == ref_mode->height &&
|
|
|
|
mode->refresh == ref_mode->refresh)
|
|
|
|
return mode;
|
|
|
|
|
|
|
|
/* If we can't find an exact match, ignore refresh and try again */
|
|
|
|
wl_list_for_each(mode, &output->base.mode_list, link)
|
|
|
|
if (mode->width == ref_mode->width &&
|
|
|
|
mode->height == ref_mode->height)
|
|
|
|
return mode;
|
|
|
|
|
|
|
|
/* Yeah, we failed */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum mode_status {
|
|
|
|
MODE_STATUS_UNKNOWN,
|
|
|
|
MODE_STATUS_SUCCESS,
|
|
|
|
MODE_STATUS_FAIL,
|
|
|
|
MODE_STATUS_CANCEL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
mode_feedback_successful(void *data,
|
2015-11-17 11:00:27 +03:00
|
|
|
struct zwp_fullscreen_shell_mode_feedback_v1 *fb)
|
2014-04-03 04:53:54 +04:00
|
|
|
{
|
|
|
|
enum mode_status *value = data;
|
|
|
|
|
|
|
|
printf("Mode switch successful\n");
|
|
|
|
|
|
|
|
*value = MODE_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-11-17 11:00:27 +03:00
|
|
|
mode_feedback_failed(void *data, struct zwp_fullscreen_shell_mode_feedback_v1 *fb)
|
2014-04-03 04:53:54 +04:00
|
|
|
{
|
|
|
|
enum mode_status *value = data;
|
|
|
|
|
|
|
|
printf("Mode switch failed\n");
|
|
|
|
|
|
|
|
*value = MODE_STATUS_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-11-17 11:00:27 +03:00
|
|
|
mode_feedback_cancelled(void *data, struct zwp_fullscreen_shell_mode_feedback_v1 *fb)
|
2014-04-03 04:53:54 +04:00
|
|
|
{
|
|
|
|
enum mode_status *value = data;
|
|
|
|
|
|
|
|
printf("Mode switch cancelled\n");
|
|
|
|
|
|
|
|
*value = MODE_STATUS_CANCEL;
|
|
|
|
}
|
|
|
|
|
2015-11-17 11:00:27 +03:00
|
|
|
struct zwp_fullscreen_shell_mode_feedback_v1_listener mode_feedback_listener = {
|
2014-04-03 04:53:54 +04:00
|
|
|
mode_feedback_successful,
|
|
|
|
mode_feedback_failed,
|
|
|
|
mode_feedback_cancelled,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
wayland_output_switch_mode(struct weston_output *output_base,
|
|
|
|
struct weston_mode *mode)
|
|
|
|
{
|
|
|
|
struct wayland_output *output = (struct wayland_output *) output_base;
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b;
|
2014-04-03 04:53:54 +04:00
|
|
|
struct wl_surface *old_surface;
|
|
|
|
struct weston_mode *old_mode;
|
2015-11-17 11:00:27 +03:00
|
|
|
struct zwp_fullscreen_shell_mode_feedback_v1 *mode_feedback;
|
2014-04-03 04:53:54 +04:00
|
|
|
enum mode_status mode_status;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (output_base == NULL) {
|
|
|
|
weston_log("output is NULL.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == NULL) {
|
|
|
|
weston_log("mode is NULL.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b = (struct wayland_backend *)output_base->compositor->backend;
|
2014-04-03 04:53:54 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (output->parent.shell_surface || !b->parent.fshell)
|
2014-04-03 04:53:54 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
mode = wayland_output_choose_mode(output, mode);
|
|
|
|
if (mode == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (output->base.current_mode == mode)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
old_mode = output->base.current_mode;
|
|
|
|
old_surface = output->parent.surface;
|
|
|
|
output->base.current_mode = mode;
|
|
|
|
output->parent.surface =
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_compositor_create_surface(b->parent.compositor);
|
2014-04-03 04:53:54 +04:00
|
|
|
wl_surface_set_user_data(output->parent.surface, output);
|
|
|
|
|
|
|
|
/* Blow the old buffers because we changed size/surfaces */
|
|
|
|
wayland_output_resize_surface(output);
|
|
|
|
|
|
|
|
mode_feedback =
|
2015-11-17 11:00:27 +03:00
|
|
|
zwp_fullscreen_shell_v1_present_surface_for_mode(b->parent.fshell,
|
|
|
|
output->parent.surface,
|
|
|
|
output->parent.output,
|
|
|
|
mode->refresh);
|
|
|
|
zwp_fullscreen_shell_mode_feedback_v1_add_listener(mode_feedback,
|
|
|
|
&mode_feedback_listener,
|
|
|
|
&mode_status);
|
2014-04-03 04:53:54 +04:00
|
|
|
|
|
|
|
/* This should kick-start things again */
|
|
|
|
output->parent.draw_initial_frame = 1;
|
|
|
|
wayland_output_start_repaint_loop(&output->base);
|
|
|
|
|
|
|
|
mode_status = MODE_STATUS_UNKNOWN;
|
|
|
|
while (mode_status == MODE_STATUS_UNKNOWN && ret >= 0)
|
2014-10-11 19:27:30 +04:00
|
|
|
ret = wl_display_dispatch(b->parent.wl_display);
|
2014-04-03 04:53:54 +04:00
|
|
|
|
2015-11-17 11:00:27 +03:00
|
|
|
zwp_fullscreen_shell_mode_feedback_v1_destroy(mode_feedback);
|
2014-04-03 04:53:54 +04:00
|
|
|
|
|
|
|
if (mode_status == MODE_STATUS_FAIL) {
|
|
|
|
output->base.current_mode = old_mode;
|
|
|
|
wl_surface_destroy(output->parent.surface);
|
|
|
|
output->parent.surface = old_surface;
|
|
|
|
wayland_output_resize_surface(output);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
old_mode->flags &= ~WL_OUTPUT_MODE_CURRENT;
|
|
|
|
output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->use_pixman) {
|
2014-04-03 04:53:54 +04:00
|
|
|
pixman_renderer_output_destroy(output_base);
|
|
|
|
if (wayland_output_init_pixman_renderer(output) < 0)
|
|
|
|
goto err_output;
|
|
|
|
} else {
|
|
|
|
gl_renderer->output_destroy(output_base);
|
|
|
|
wl_egl_window_destroy(output->gl.egl_window);
|
|
|
|
if (wayland_output_init_gl_renderer(output) < 0)
|
|
|
|
goto err_output;
|
|
|
|
}
|
|
|
|
wl_surface_destroy(old_surface);
|
|
|
|
|
|
|
|
weston_output_schedule_repaint(&output->base);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_output:
|
|
|
|
/* XXX */
|
|
|
|
return -1;
|
2013-11-08 06:13:33 +04:00
|
|
|
}
|
|
|
|
|
2013-10-28 07:25:02 +04:00
|
|
|
static struct wayland_output *
|
2014-10-11 19:27:30 +04:00
|
|
|
wayland_output_create(struct wayland_backend *b, int x, int y,
|
2013-11-08 06:13:33 +04:00
|
|
|
int width, int height, const char *name, int fullscreen,
|
2013-10-28 07:25:02 +04:00
|
|
|
uint32_t transform, int32_t scale)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
|
|
|
struct wayland_output *output;
|
2013-10-28 07:25:02 +04:00
|
|
|
int output_width, output_height;
|
2013-11-08 06:13:33 +04:00
|
|
|
|
|
|
|
weston_log("Creating %dx%d wayland output at (%d, %d)\n",
|
|
|
|
width, height, x, y);
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2013-08-08 05:57:05 +04:00
|
|
|
output = zalloc(sizeof *output);
|
2010-11-27 21:04:12 +03:00
|
|
|
if (output == NULL)
|
2013-10-28 07:25:02 +04:00
|
|
|
return NULL;
|
|
|
|
|
2013-11-08 06:13:33 +04:00
|
|
|
output->name = name ? strdup(name) : NULL;
|
2016-06-05 19:01:17 +03:00
|
|
|
output->base.make = "wayland";
|
2013-11-08 06:13:33 +04:00
|
|
|
output->base.model = "none";
|
|
|
|
|
2013-10-28 07:25:02 +04:00
|
|
|
output_width = width * scale;
|
|
|
|
output_height = height * scale;
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2013-11-08 06:13:33 +04:00
|
|
|
output->parent.surface =
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_compositor_create_surface(b->parent.compositor);
|
2013-11-08 06:13:33 +04:00
|
|
|
if (!output->parent.surface)
|
|
|
|
goto err_name;
|
|
|
|
wl_surface_set_user_data(output->parent.surface, output);
|
|
|
|
|
|
|
|
output->parent.draw_initial_frame = 1;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->parent.shell) {
|
2014-04-03 04:53:54 +04:00
|
|
|
output->parent.shell_surface =
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_shell_get_shell_surface(b->parent.shell,
|
2014-04-03 04:53:54 +04:00
|
|
|
output->parent.surface);
|
|
|
|
if (!output->parent.shell_surface)
|
|
|
|
goto err_surface;
|
|
|
|
wl_shell_surface_add_listener(output->parent.shell_surface,
|
|
|
|
&shell_surface_listener, output);
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (fullscreen && b->parent.shell) {
|
2013-11-08 06:13:33 +04:00
|
|
|
wl_shell_surface_set_fullscreen(output->parent.shell_surface,
|
|
|
|
0, 0, NULL);
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_display_roundtrip(b->parent.wl_display);
|
2013-11-08 06:13:33 +04:00
|
|
|
if (!width)
|
|
|
|
output_width = output->parent.configure_width;
|
|
|
|
if (!height)
|
|
|
|
output_height = output->parent.configure_height;
|
|
|
|
}
|
|
|
|
|
2011-06-21 19:16:58 +04:00
|
|
|
output->mode.flags =
|
|
|
|
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
|
2013-10-28 07:25:02 +04:00
|
|
|
output->mode.width = output_width;
|
|
|
|
output->mode.height = output_height;
|
|
|
|
output->mode.refresh = 60000;
|
|
|
|
output->scale = scale;
|
2011-06-21 19:16:58 +04:00
|
|
|
wl_list_init(&output->base.mode_list);
|
|
|
|
wl_list_insert(&output->base.mode_list, &output->mode.link);
|
2013-09-19 01:56:35 +04:00
|
|
|
output->base.current_mode = &output->mode;
|
2012-02-01 16:45:51 +04:00
|
|
|
|
2013-10-28 07:24:58 +04:00
|
|
|
wl_list_init(&output->shm.buffers);
|
|
|
|
wl_list_init(&output->shm.free_buffers);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_output_init(&output->base, b->compositor, x, y, width, height,
|
2013-11-08 06:13:33 +04:00
|
|
|
transform, scale);
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->use_pixman) {
|
2013-10-28 07:24:58 +04:00
|
|
|
if (wayland_output_init_pixman_renderer(output) < 0)
|
2013-11-08 06:13:33 +04:00
|
|
|
goto err_output;
|
2013-10-28 07:24:58 +04:00
|
|
|
output->base.repaint = wayland_output_repaint_pixman;
|
|
|
|
} else {
|
|
|
|
if (wayland_output_init_gl_renderer(output) < 0)
|
2013-11-08 06:13:33 +04:00
|
|
|
goto err_output;
|
2013-10-28 07:24:58 +04:00
|
|
|
output->base.repaint = wayland_output_repaint_gl;
|
2011-02-18 19:04:24 +03:00
|
|
|
}
|
|
|
|
|
2013-04-06 01:07:11 +04:00
|
|
|
output->base.start_repaint_loop = wayland_output_start_repaint_loop;
|
2011-08-30 00:52:23 +04:00
|
|
|
output->base.destroy = wayland_output_destroy;
|
2012-02-10 01:12:57 +04:00
|
|
|
output->base.assign_planes = NULL;
|
2012-02-29 21:53:50 +04:00
|
|
|
output->base.set_backlight = NULL;
|
|
|
|
output->base.set_dpms = NULL;
|
2014-04-03 04:53:54 +04:00
|
|
|
output->base.switch_mode = wayland_output_switch_mode;
|
2011-03-11 18:39:20 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_compositor_add_output(b->compositor, &output->base);
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2013-10-28 07:25:02 +04:00
|
|
|
return output;
|
2011-02-18 19:04:24 +03:00
|
|
|
|
2013-11-08 06:13:33 +04:00
|
|
|
err_output:
|
|
|
|
weston_output_destroy(&output->base);
|
2014-04-03 04:53:54 +04:00
|
|
|
if (output->parent.shell_surface)
|
|
|
|
wl_shell_surface_destroy(output->parent.shell_surface);
|
2013-11-08 06:13:33 +04:00
|
|
|
err_surface:
|
|
|
|
wl_surface_destroy(output->parent.surface);
|
|
|
|
err_name:
|
|
|
|
free(output->name);
|
|
|
|
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
/* FIXME: cleanup weston_output */
|
2011-02-18 19:04:24 +03:00
|
|
|
free(output);
|
|
|
|
|
2013-10-28 07:25:02 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-28 21:33:12 +03:00
|
|
|
static struct wayland_output *
|
|
|
|
wayland_output_create_for_config(struct wayland_backend *b,
|
|
|
|
struct weston_wayland_backend_output_config *oc,
|
|
|
|
int fullscreen, int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
struct wayland_output *output;
|
|
|
|
|
|
|
|
output = wayland_output_create(b, x, y, oc->width, oc->height, oc->name,
|
|
|
|
fullscreen, oc->transform, oc->scale);
|
2013-10-28 07:25:02 +04:00
|
|
|
|
|
|
|
return output;
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
|
2014-04-03 04:53:54 +04:00
|
|
|
static struct wayland_output *
|
2014-10-11 19:27:30 +04:00
|
|
|
wayland_output_create_for_parent_output(struct wayland_backend *b,
|
2014-04-03 04:53:54 +04:00
|
|
|
struct wayland_parent_output *poutput)
|
|
|
|
{
|
|
|
|
struct wayland_output *output;
|
|
|
|
struct weston_mode *mode;
|
|
|
|
int32_t x;
|
|
|
|
|
|
|
|
if (poutput->current_mode) {
|
|
|
|
mode = poutput->current_mode;
|
|
|
|
} else if (poutput->preferred_mode) {
|
2014-05-07 01:50:02 +04:00
|
|
|
mode = poutput->preferred_mode;
|
2014-04-03 04:53:54 +04:00
|
|
|
} else if (!wl_list_empty(&poutput->mode_list)) {
|
|
|
|
mode = container_of(poutput->mode_list.next,
|
|
|
|
struct weston_mode, link);
|
|
|
|
} else {
|
2015-09-29 17:03:20 +03:00
|
|
|
weston_log("No valid modes found. Skipping output\n");
|
2014-04-03 04:53:54 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!wl_list_empty(&b->compositor->output_list)) {
|
|
|
|
output = container_of(b->compositor->output_list.prev,
|
2014-04-03 04:53:54 +04:00
|
|
|
struct wayland_output, base.link);
|
|
|
|
x = output->base.x + output->base.current_mode->width;
|
|
|
|
} else {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
output = wayland_output_create(b, x, 0, mode->width, mode->height,
|
2014-04-03 04:53:54 +04:00
|
|
|
NULL, 0,
|
|
|
|
WL_OUTPUT_TRANSFORM_NORMAL, 1);
|
|
|
|
if (!output)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
output->parent.output = poutput->global;
|
|
|
|
|
|
|
|
output->base.make = poutput->physical.make;
|
|
|
|
output->base.model = poutput->physical.model;
|
|
|
|
wl_list_init(&output->base.mode_list);
|
|
|
|
wl_list_insert_list(&output->base.mode_list, &poutput->mode_list);
|
|
|
|
wl_list_init(&poutput->mode_list);
|
|
|
|
|
|
|
|
wayland_output_set_fullscreen(output,
|
|
|
|
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER,
|
|
|
|
mode->refresh, poutput->global);
|
|
|
|
|
|
|
|
if (output->parent.shell_surface) {
|
|
|
|
wl_shell_surface_set_fullscreen(output->parent.shell_surface,
|
|
|
|
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER,
|
|
|
|
mode->refresh, poutput->global);
|
2014-10-11 19:27:30 +04:00
|
|
|
} else if (b->parent.fshell) {
|
2015-11-17 11:00:27 +03:00
|
|
|
zwp_fullscreen_shell_v1_present_surface(b->parent.fshell,
|
|
|
|
output->parent.surface,
|
|
|
|
ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_CENTER,
|
|
|
|
poutput->global);
|
|
|
|
zwp_fullscreen_shell_mode_feedback_v1_destroy(
|
|
|
|
zwp_fullscreen_shell_v1_present_surface_for_mode(b->parent.fshell,
|
|
|
|
output->parent.surface,
|
|
|
|
poutput->global,
|
|
|
|
mode->refresh));
|
2014-04-03 04:53:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2012-06-18 18:36:21 +04:00
|
|
|
static void
|
|
|
|
shell_surface_ping(void *data, struct wl_shell_surface *shell_surface,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
wl_shell_surface_pong(shell_surface, serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_surface_configure(void *data, struct wl_shell_surface *shell_surface,
|
|
|
|
uint32_t edges, int32_t width, int32_t height)
|
|
|
|
{
|
2013-11-08 06:13:33 +04:00
|
|
|
struct wayland_output *output = data;
|
|
|
|
|
|
|
|
output->parent.configure_width = width;
|
|
|
|
output->parent.configure_height = height;
|
|
|
|
|
2012-06-18 18:36:21 +04:00
|
|
|
/* FIXME: implement resizing */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_surface_popup_done(void *data, struct wl_shell_surface *shell_surface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_shell_surface_listener shell_surface_listener = {
|
|
|
|
shell_surface_ping,
|
|
|
|
shell_surface_configure,
|
|
|
|
shell_surface_popup_done
|
|
|
|
};
|
|
|
|
|
2010-11-27 21:04:12 +03:00
|
|
|
/* Events received from the wayland-server this compositor is client of: */
|
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
/* parent input interface */
|
2012-08-14 07:29:53 +04:00
|
|
|
static void
|
2013-10-28 07:24:55 +04:00
|
|
|
input_set_cursor(struct wayland_input *input)
|
2012-08-14 07:29:53 +04:00
|
|
|
{
|
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
struct wl_buffer *buffer;
|
|
|
|
struct wl_cursor_image *image;
|
2012-08-14 07:29:53 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!input->backend->cursor)
|
2013-10-28 07:24:55 +04:00
|
|
|
return; /* Couldn't load the cursor. Can't set it */
|
2012-08-14 07:29:53 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
image = input->backend->cursor->images[0];
|
2013-10-28 07:24:55 +04:00
|
|
|
buffer = wl_cursor_image_get_buffer(image);
|
2014-03-18 17:12:50 +04:00
|
|
|
if (!buffer)
|
|
|
|
return;
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
wl_pointer_set_cursor(input->parent.pointer, input->enter_serial,
|
|
|
|
input->parent.cursor.surface,
|
|
|
|
image->hotspot_x, image->hotspot_y);
|
|
|
|
|
|
|
|
wl_surface_attach(input->parent.cursor.surface, buffer, 0, 0);
|
|
|
|
wl_surface_damage(input->parent.cursor.surface, 0, 0,
|
|
|
|
image->width, image->height);
|
|
|
|
wl_surface_commit(input->parent.cursor.surface);
|
2012-08-14 07:29:53 +04:00
|
|
|
}
|
|
|
|
|
2010-11-27 21:04:12 +03:00
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
input_handle_pointer_enter(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t serial, struct wl_surface *surface,
|
2016-03-22 18:44:54 +03:00
|
|
|
wl_fixed_t fixed_x, wl_fixed_t fixed_y)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
2013-10-28 07:24:55 +04:00
|
|
|
int32_t fx, fy;
|
|
|
|
enum theme_location location;
|
2016-03-22 18:44:54 +03:00
|
|
|
double x, y;
|
|
|
|
|
|
|
|
x = wl_fixed_to_double(fixed_x);
|
|
|
|
y = wl_fixed_to_double(fixed_y);
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2012-06-22 16:21:41 +04:00
|
|
|
/* XXX: If we get a modifier event immediately before the focus,
|
|
|
|
* we should try to keep the same serial. */
|
2012-08-14 07:29:53 +04:00
|
|
|
input->enter_serial = serial;
|
|
|
|
input->output = wl_surface_get_user_data(surface);
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
if (input->output->frame) {
|
|
|
|
location = frame_pointer_enter(input->output->frame, input,
|
2016-03-22 18:44:54 +03:00
|
|
|
x, y);
|
2013-10-28 07:24:55 +04:00
|
|
|
frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
|
2016-03-22 18:44:54 +03:00
|
|
|
x -= fx;
|
|
|
|
y -= fy;
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
weston_output_schedule_repaint(&input->output->base);
|
|
|
|
} else {
|
|
|
|
location = THEME_LOCATION_CLIENT_AREA;
|
|
|
|
}
|
|
|
|
|
2013-10-28 07:25:02 +04:00
|
|
|
weston_output_transform_coordinate(&input->output->base, x, y, &x, &y);
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
if (location == THEME_LOCATION_CLIENT_AREA) {
|
2015-11-07 00:56:06 +03:00
|
|
|
input->has_focus = true;
|
2013-10-28 07:24:55 +04:00
|
|
|
notify_pointer_focus(&input->base, &input->output->base, x, y);
|
|
|
|
wl_pointer_set_cursor(input->parent.pointer,
|
|
|
|
input->enter_serial, NULL, 0, 0);
|
|
|
|
} else {
|
2015-11-07 00:56:06 +03:00
|
|
|
input->has_focus = false;
|
2013-10-28 07:24:55 +04:00
|
|
|
notify_pointer_focus(&input->base, NULL, 0, 0);
|
|
|
|
input_set_cursor(input);
|
|
|
|
}
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
input_handle_pointer_leave(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t serial, struct wl_surface *surface)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
|
2015-05-19 09:14:16 +03:00
|
|
|
if (!input->output)
|
|
|
|
return;
|
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
if (input->output->frame) {
|
|
|
|
frame_pointer_leave(input->output->frame, input);
|
|
|
|
|
|
|
|
if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
weston_output_schedule_repaint(&input->output->base);
|
|
|
|
}
|
|
|
|
|
2012-08-10 17:50:11 +04:00
|
|
|
notify_pointer_focus(&input->base, NULL, 0, 0);
|
2012-08-14 07:29:53 +04:00
|
|
|
input->output = NULL;
|
2015-11-07 00:56:06 +03:00
|
|
|
input->has_focus = false;
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
|
2012-03-22 20:47:01 +04:00
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
input_handle_motion(void *data, struct wl_pointer *pointer,
|
2016-03-22 18:44:54 +03:00
|
|
|
uint32_t time, wl_fixed_t fixed_x, wl_fixed_t fixed_y)
|
2012-03-22 20:47:01 +04:00
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
2013-10-28 07:24:55 +04:00
|
|
|
int32_t fx, fy;
|
|
|
|
enum theme_location location;
|
2016-01-18 09:38:22 +03:00
|
|
|
bool want_frame = false;
|
2016-03-22 18:44:54 +03:00
|
|
|
double x, y;
|
2013-10-28 07:24:55 +04:00
|
|
|
|
2015-05-19 09:14:16 +03:00
|
|
|
if (!input->output)
|
|
|
|
return;
|
|
|
|
|
2016-03-22 18:44:54 +03:00
|
|
|
x = wl_fixed_to_double(fixed_x);
|
|
|
|
y = wl_fixed_to_double(fixed_y);
|
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
if (input->output->frame) {
|
|
|
|
location = frame_pointer_motion(input->output->frame, input,
|
2016-03-22 18:44:54 +03:00
|
|
|
x, y);
|
2013-10-28 07:24:55 +04:00
|
|
|
frame_interior(input->output->frame, &fx, &fy, NULL, NULL);
|
2016-03-22 18:44:54 +03:00
|
|
|
x -= fx;
|
|
|
|
y -= fy;
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
weston_output_schedule_repaint(&input->output->base);
|
|
|
|
} else {
|
|
|
|
location = THEME_LOCATION_CLIENT_AREA;
|
|
|
|
}
|
2012-03-22 20:47:01 +04:00
|
|
|
|
2013-10-28 07:25:02 +04:00
|
|
|
weston_output_transform_coordinate(&input->output->base, x, y, &x, &y);
|
2013-10-28 07:24:55 +04:00
|
|
|
|
2015-11-07 00:56:06 +03:00
|
|
|
if (input->has_focus && location != THEME_LOCATION_CLIENT_AREA) {
|
2013-10-28 07:24:55 +04:00
|
|
|
input_set_cursor(input);
|
|
|
|
notify_pointer_focus(&input->base, NULL, 0, 0);
|
2015-11-07 00:56:06 +03:00
|
|
|
input->has_focus = false;
|
2016-01-18 09:38:22 +03:00
|
|
|
want_frame = true;
|
2015-11-07 00:56:06 +03:00
|
|
|
} else if (!input->has_focus &&
|
|
|
|
location == THEME_LOCATION_CLIENT_AREA) {
|
2013-10-28 07:24:55 +04:00
|
|
|
wl_pointer_set_cursor(input->parent.pointer,
|
|
|
|
input->enter_serial, NULL, 0, 0);
|
|
|
|
notify_pointer_focus(&input->base, &input->output->base, x, y);
|
2015-11-07 00:56:06 +03:00
|
|
|
input->has_focus = true;
|
2016-01-18 09:38:22 +03:00
|
|
|
want_frame = true;
|
2013-10-28 07:24:55 +04:00
|
|
|
}
|
|
|
|
|
2016-01-18 09:38:22 +03:00
|
|
|
if (location == THEME_LOCATION_CLIENT_AREA) {
|
2013-10-28 07:24:55 +04:00
|
|
|
notify_motion_absolute(&input->base, time, x, y);
|
2016-01-18 09:38:22 +03:00
|
|
|
want_frame = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (want_frame && input->seat_version < WL_POINTER_FRAME_SINCE_VERSION)
|
|
|
|
notify_pointer_frame(&input->base);
|
2012-03-22 20:47:01 +04:00
|
|
|
}
|
|
|
|
|
2010-11-27 21:04:12 +03:00
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
input_handle_button(void *data, struct wl_pointer *pointer,
|
2012-05-30 19:31:51 +04:00
|
|
|
uint32_t serial, uint32_t time, uint32_t button,
|
|
|
|
uint32_t state_w)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
2012-05-30 19:31:51 +04:00
|
|
|
enum wl_pointer_button_state state = state_w;
|
2013-10-28 07:24:55 +04:00
|
|
|
enum frame_button_state fstate;
|
|
|
|
enum theme_location location;
|
|
|
|
|
2015-05-19 09:14:16 +03:00
|
|
|
if (!input->output)
|
|
|
|
return;
|
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
if (input->output->frame) {
|
|
|
|
fstate = state == WL_POINTER_BUTTON_STATE_PRESSED ?
|
|
|
|
FRAME_BUTTON_PRESSED : FRAME_BUTTON_RELEASED;
|
|
|
|
|
|
|
|
location = frame_pointer_button(input->output->frame, input,
|
|
|
|
button, fstate);
|
|
|
|
|
|
|
|
if (frame_status(input->output->frame) & FRAME_STATUS_MOVE) {
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
wl_shell_surface_move(input->output->parent.shell_surface,
|
|
|
|
input->parent.seat, serial);
|
|
|
|
frame_status_clear(input->output->frame,
|
|
|
|
FRAME_STATUS_MOVE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-19 09:14:16 +03:00
|
|
|
if (frame_status(input->output->frame) & FRAME_STATUS_CLOSE) {
|
|
|
|
wayland_output_destroy(&input->output->base);
|
2015-05-20 11:03:53 +03:00
|
|
|
input->output = NULL;
|
|
|
|
input->keyboard_focus = NULL;
|
2015-05-19 09:14:16 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (wl_list_empty(&input->backend->compositor->output_list))
|
2014-10-12 00:56:24 +04:00
|
|
|
weston_compositor_exit(input->backend->compositor);
|
2015-05-19 09:14:16 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
if (frame_status(input->output->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
weston_output_schedule_repaint(&input->output->base);
|
|
|
|
} else {
|
|
|
|
location = THEME_LOCATION_CLIENT_AREA;
|
|
|
|
}
|
|
|
|
|
2016-01-18 09:38:22 +03:00
|
|
|
if (location == THEME_LOCATION_CLIENT_AREA) {
|
2013-10-28 07:24:55 +04:00
|
|
|
notify_button(&input->base, time, button, state);
|
2016-01-18 09:38:22 +03:00
|
|
|
if (input->seat_version < WL_POINTER_FRAME_SINCE_VERSION)
|
|
|
|
notify_pointer_frame(&input->base);
|
|
|
|
}
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
input_handle_axis(void *data, struct wl_pointer *pointer,
|
2012-05-30 19:32:00 +04:00
|
|
|
uint32_t time, uint32_t axis, wl_fixed_t value)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
2016-01-18 08:58:17 +03:00
|
|
|
struct weston_pointer_axis_event weston_event;
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2016-01-18 08:58:17 +03:00
|
|
|
weston_event.axis = axis;
|
2016-03-22 18:44:54 +03:00
|
|
|
weston_event.value = wl_fixed_to_double(value);
|
2016-01-18 08:58:17 +03:00
|
|
|
|
2016-01-18 09:38:22 +03:00
|
|
|
if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL &&
|
|
|
|
input->vert.has_discrete) {
|
|
|
|
weston_event.has_discrete = true;
|
|
|
|
weston_event.discrete = input->vert.discrete;
|
|
|
|
input->vert.has_discrete = false;
|
|
|
|
} else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL &&
|
|
|
|
input->horiz.has_discrete) {
|
|
|
|
weston_event.has_discrete = true;
|
|
|
|
weston_event.discrete = input->horiz.discrete;
|
|
|
|
input->horiz.has_discrete = false;
|
|
|
|
}
|
|
|
|
|
2016-01-18 08:58:17 +03:00
|
|
|
notify_axis(&input->base, time, &weston_event);
|
2016-01-18 09:38:22 +03:00
|
|
|
|
|
|
|
if (input->seat_version < WL_POINTER_FRAME_SINCE_VERSION)
|
|
|
|
notify_pointer_frame(&input->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_handle_frame(void *data, struct wl_pointer *pointer)
|
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
|
|
|
|
notify_pointer_frame(&input->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_handle_axis_source(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t source)
|
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
|
|
|
|
notify_axis_source(&input->base, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_handle_axis_stop(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t time, uint32_t axis)
|
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
struct weston_pointer_axis_event weston_event;
|
|
|
|
|
|
|
|
weston_event.axis = axis;
|
|
|
|
weston_event.value = 0;
|
|
|
|
|
|
|
|
notify_axis(&input->base, time, &weston_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_handle_axis_discrete(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t axis, int32_t discrete)
|
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
|
|
|
|
if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
|
|
|
|
input->vert.has_discrete = true;
|
|
|
|
input->vert.discrete = discrete;
|
|
|
|
} else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
|
|
|
|
input->horiz.has_discrete = true;
|
|
|
|
input->horiz.discrete = discrete;
|
|
|
|
}
|
2012-02-23 18:59:05 +04:00
|
|
|
}
|
2012-02-07 18:56:51 +04:00
|
|
|
|
2012-05-16 21:45:18 +04:00
|
|
|
static const struct wl_pointer_listener pointer_listener = {
|
|
|
|
input_handle_pointer_enter,
|
|
|
|
input_handle_pointer_leave,
|
|
|
|
input_handle_motion,
|
|
|
|
input_handle_button,
|
|
|
|
input_handle_axis,
|
2016-01-18 09:38:22 +03:00
|
|
|
input_handle_frame,
|
|
|
|
input_handle_axis_source,
|
|
|
|
input_handle_axis_stop,
|
|
|
|
input_handle_axis_discrete,
|
2012-05-16 21:45:18 +04:00
|
|
|
};
|
|
|
|
|
2012-06-01 15:14:06 +04:00
|
|
|
static void
|
|
|
|
input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
|
|
|
|
int fd, uint32_t size)
|
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
struct xkb_keymap *keymap;
|
|
|
|
char *map_str;
|
|
|
|
|
2014-05-07 01:50:03 +04:00
|
|
|
if (!data) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-01 15:14:06 +04:00
|
|
|
|
2014-04-03 04:53:57 +04:00
|
|
|
if (format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
|
|
|
|
map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
|
|
|
if (map_str == MAP_FAILED) {
|
|
|
|
weston_log("mmap failed: %m\n");
|
|
|
|
goto error;
|
|
|
|
}
|
2012-06-01 15:14:06 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
keymap = xkb_keymap_new_from_string(input->backend->compositor->xkb_context,
|
2014-08-20 00:59:51 +04:00
|
|
|
map_str,
|
|
|
|
XKB_KEYMAP_FORMAT_TEXT_V1,
|
|
|
|
0);
|
2014-04-03 04:53:57 +04:00
|
|
|
munmap(map_str, size);
|
2012-06-01 15:14:06 +04:00
|
|
|
|
2014-04-03 04:53:57 +04:00
|
|
|
if (!keymap) {
|
|
|
|
weston_log("failed to compile keymap\n");
|
|
|
|
goto error;
|
|
|
|
}
|
2012-06-01 15:14:06 +04:00
|
|
|
|
2014-04-03 04:53:57 +04:00
|
|
|
input->keyboard_state_update = STATE_UPDATE_NONE;
|
|
|
|
} else if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP) {
|
|
|
|
weston_log("No keymap provided; falling back to defalt\n");
|
|
|
|
keymap = NULL;
|
|
|
|
input->keyboard_state_update = STATE_UPDATE_AUTOMATIC;
|
|
|
|
} else {
|
|
|
|
weston_log("Invalid keymap\n");
|
|
|
|
goto error;
|
2012-06-01 15:14:06 +04:00
|
|
|
}
|
|
|
|
|
2014-04-03 04:53:57 +04:00
|
|
|
close(fd);
|
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
if (weston_seat_get_keyboard(&input->base))
|
2013-10-10 21:44:21 +04:00
|
|
|
weston_seat_update_keymap(&input->base, keymap);
|
|
|
|
else
|
|
|
|
weston_seat_init_keyboard(&input->base, keymap);
|
|
|
|
|
2014-08-20 00:59:52 +04:00
|
|
|
xkb_keymap_unref(keymap);
|
2014-04-03 04:53:57 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
wl_keyboard_release(input->parent.keyboard);
|
|
|
|
close(fd);
|
2012-06-01 15:14:06 +04:00
|
|
|
}
|
|
|
|
|
2012-02-23 18:59:05 +04:00
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
input_handle_keyboard_enter(void *data,
|
|
|
|
struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial,
|
|
|
|
struct wl_surface *surface,
|
|
|
|
struct wl_array *keys)
|
2012-02-23 18:59:05 +04:00
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
2013-10-28 07:24:55 +04:00
|
|
|
struct wayland_output *focus;
|
|
|
|
|
|
|
|
focus = input->keyboard_focus;
|
|
|
|
if (focus) {
|
|
|
|
/* This shouldn't happen */
|
|
|
|
focus->keyboard_count--;
|
|
|
|
if (!focus->keyboard_count && focus->frame)
|
|
|
|
frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE);
|
|
|
|
if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
weston_output_schedule_repaint(&focus->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
input->keyboard_focus = wl_surface_get_user_data(surface);
|
|
|
|
input->keyboard_focus->keyboard_count++;
|
|
|
|
|
|
|
|
focus = input->keyboard_focus;
|
|
|
|
if (focus->frame) {
|
|
|
|
frame_set_flag(focus->frame, FRAME_FLAG_ACTIVE);
|
|
|
|
if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
weston_output_schedule_repaint(&focus->base);
|
|
|
|
}
|
|
|
|
|
2012-02-23 18:59:05 +04:00
|
|
|
|
2012-06-22 16:21:41 +04:00
|
|
|
/* XXX: If we get a modifier event immediately before the focus,
|
|
|
|
* we should try to keep the same serial. */
|
2012-08-10 17:50:11 +04:00
|
|
|
notify_keyboard_focus_in(&input->base, keys,
|
2012-06-22 16:21:29 +04:00
|
|
|
STATE_UPDATE_AUTOMATIC);
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
input_handle_keyboard_leave(void *data,
|
|
|
|
struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial,
|
|
|
|
struct wl_surface *surface)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
2011-01-28 04:18:17 +03:00
|
|
|
struct wayland_input *input = data;
|
2013-10-28 07:24:55 +04:00
|
|
|
struct wayland_output *focus;
|
2011-01-28 04:18:17 +03:00
|
|
|
|
2012-08-10 17:50:11 +04:00
|
|
|
notify_keyboard_focus_out(&input->base);
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
focus = input->keyboard_focus;
|
|
|
|
if (!focus)
|
2015-05-19 09:14:16 +03:00
|
|
|
return;
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
focus->keyboard_count--;
|
|
|
|
if (!focus->keyboard_count && focus->frame) {
|
|
|
|
frame_unset_flag(focus->frame, FRAME_FLAG_ACTIVE);
|
|
|
|
if (frame_status(focus->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
weston_output_schedule_repaint(&focus->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
input->keyboard_focus = NULL;
|
2012-02-23 18:59:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 21:45:18 +04:00
|
|
|
input_handle_key(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
|
2012-02-23 18:59:05 +04:00
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
|
2012-06-22 16:21:41 +04:00
|
|
|
input->key_serial = serial;
|
2012-08-10 17:50:11 +04:00
|
|
|
notify_key(&input->base, time, key,
|
2012-05-30 19:31:52 +04:00
|
|
|
state ? WL_KEYBOARD_KEY_STATE_PRESSED :
|
2012-06-22 16:21:37 +04:00
|
|
|
WL_KEYBOARD_KEY_STATE_RELEASED,
|
2014-04-03 04:53:57 +04:00
|
|
|
input->keyboard_state_update);
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
|
2012-05-31 23:27:47 +04:00
|
|
|
static void
|
2015-08-01 00:55:32 +03:00
|
|
|
input_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard,
|
2012-06-22 16:21:41 +04:00
|
|
|
uint32_t serial_in, uint32_t mods_depressed,
|
2012-05-31 23:27:47 +04:00
|
|
|
uint32_t mods_latched, uint32_t mods_locked,
|
|
|
|
uint32_t group)
|
|
|
|
{
|
2015-08-01 00:55:32 +03:00
|
|
|
struct weston_keyboard *keyboard;
|
2012-06-22 16:21:41 +04:00
|
|
|
struct wayland_input *input = data;
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b = input->backend;
|
2012-06-22 16:21:41 +04:00
|
|
|
uint32_t serial_out;
|
|
|
|
|
|
|
|
/* If we get a key event followed by a modifier event with the
|
|
|
|
* same serial number, then we try to preserve those semantics by
|
|
|
|
* reusing the same serial number on the way out too. */
|
|
|
|
if (serial_in == input->key_serial)
|
2014-10-11 19:27:30 +04:00
|
|
|
serial_out = wl_display_get_serial(b->compositor->wl_display);
|
2012-06-22 16:21:41 +04:00
|
|
|
else
|
2014-10-11 19:27:30 +04:00
|
|
|
serial_out = wl_display_next_serial(b->compositor->wl_display);
|
2012-06-22 16:21:41 +04:00
|
|
|
|
2015-08-01 00:55:32 +03:00
|
|
|
keyboard = weston_seat_get_keyboard(&input->base);
|
|
|
|
xkb_state_update_mask(keyboard->xkb_state.state,
|
2012-06-22 16:21:41 +04:00
|
|
|
mods_depressed, mods_latched,
|
|
|
|
mods_locked, 0, 0, group);
|
2012-08-10 17:50:11 +04:00
|
|
|
notify_modifiers(&input->base, serial_out);
|
2012-05-31 23:27:47 +04:00
|
|
|
}
|
|
|
|
|
2014-08-12 16:58:26 +04:00
|
|
|
static void
|
|
|
|
input_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
|
|
|
|
int32_t rate, int32_t delay)
|
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b = input->backend;
|
2014-08-12 16:58:26 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->compositor->kb_repeat_rate = rate;
|
|
|
|
b->compositor->kb_repeat_delay = delay;
|
2014-08-12 16:58:26 +04:00
|
|
|
}
|
|
|
|
|
2012-05-16 21:45:18 +04:00
|
|
|
static const struct wl_keyboard_listener keyboard_listener = {
|
2012-06-01 15:14:06 +04:00
|
|
|
input_handle_keymap,
|
2012-02-23 18:59:05 +04:00
|
|
|
input_handle_keyboard_enter,
|
|
|
|
input_handle_keyboard_leave,
|
2012-05-16 21:45:18 +04:00
|
|
|
input_handle_key,
|
2012-05-31 23:27:47 +04:00
|
|
|
input_handle_modifiers,
|
2014-08-12 16:58:26 +04:00
|
|
|
input_handle_repeat_info,
|
2012-05-16 21:45:18 +04:00
|
|
|
};
|
|
|
|
|
2015-11-07 00:56:10 +03:00
|
|
|
static void
|
|
|
|
input_handle_touch_down(void *data, struct wl_touch *wl_touch,
|
|
|
|
uint32_t serial, uint32_t time,
|
2016-03-22 18:44:54 +03:00
|
|
|
struct wl_surface *surface, int32_t id,
|
|
|
|
wl_fixed_t fixed_x, wl_fixed_t fixed_y)
|
2015-11-07 00:56:10 +03:00
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
struct wayland_output *output;
|
|
|
|
enum theme_location location;
|
|
|
|
bool first_touch;
|
|
|
|
int32_t fx, fy;
|
2016-03-22 18:44:54 +03:00
|
|
|
double x, y;
|
|
|
|
|
|
|
|
x = wl_fixed_to_double(fixed_x);
|
|
|
|
y = wl_fixed_to_double(fixed_y);
|
2015-11-07 00:56:10 +03:00
|
|
|
|
|
|
|
first_touch = (input->touch_points == 0);
|
|
|
|
input->touch_points++;
|
|
|
|
|
|
|
|
input->touch_focus = wl_surface_get_user_data(surface);
|
|
|
|
output = input->touch_focus;
|
|
|
|
if (!first_touch && !input->touch_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (output->frame) {
|
2016-03-22 18:44:54 +03:00
|
|
|
location = frame_touch_down(output->frame, input, id, x, y);
|
2015-11-07 00:56:10 +03:00
|
|
|
|
|
|
|
frame_interior(output->frame, &fx, &fy, NULL, NULL);
|
2016-03-22 18:44:54 +03:00
|
|
|
x -= fx;
|
|
|
|
y -= fy;
|
2015-11-07 00:56:10 +03:00
|
|
|
|
|
|
|
if (frame_status(output->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
weston_output_schedule_repaint(&output->base);
|
|
|
|
|
|
|
|
if (first_touch && (frame_status(output->frame) & FRAME_STATUS_MOVE)) {
|
|
|
|
input->touch_points--;
|
|
|
|
wl_shell_surface_move(output->parent.shell_surface,
|
|
|
|
input->parent.seat, serial);
|
|
|
|
frame_status_clear(output->frame,
|
|
|
|
FRAME_STATUS_MOVE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (first_touch && location != THEME_LOCATION_CLIENT_AREA)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
weston_output_transform_coordinate(&output->base, x, y, &x, &y);
|
|
|
|
|
|
|
|
notify_touch(&input->base, time, id, x, y, WL_TOUCH_DOWN);
|
|
|
|
input->touch_active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_handle_touch_up(void *data, struct wl_touch *wl_touch,
|
|
|
|
uint32_t serial, uint32_t time, int32_t id)
|
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
struct wayland_output *output = input->touch_focus;
|
|
|
|
bool active = input->touch_active;
|
|
|
|
|
|
|
|
input->touch_points--;
|
|
|
|
if (input->touch_points == 0) {
|
|
|
|
input->touch_focus = NULL;
|
|
|
|
input->touch_active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!output)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (output->frame) {
|
|
|
|
frame_touch_up(output->frame, input, id);
|
|
|
|
|
|
|
|
if (frame_status(output->frame) & FRAME_STATUS_CLOSE) {
|
|
|
|
wayland_output_destroy(&output->base);
|
|
|
|
input->touch_focus = NULL;
|
|
|
|
input->keyboard_focus = NULL;
|
|
|
|
if (wl_list_empty(&input->backend->compositor->output_list))
|
|
|
|
weston_compositor_exit(input->backend->compositor);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (frame_status(output->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
weston_output_schedule_repaint(&output->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (active)
|
|
|
|
notify_touch(&input->base, time, id, 0, 0, WL_TOUCH_UP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_handle_touch_motion(void *data, struct wl_touch *wl_touch,
|
2016-03-22 18:44:54 +03:00
|
|
|
uint32_t time, int32_t id,
|
|
|
|
wl_fixed_t fixed_x, wl_fixed_t fixed_y)
|
2015-11-07 00:56:10 +03:00
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
struct wayland_output *output = input->touch_focus;
|
|
|
|
int32_t fx, fy;
|
2016-03-22 18:44:54 +03:00
|
|
|
double x, y;
|
|
|
|
|
|
|
|
x = wl_fixed_to_double(fixed_x);
|
|
|
|
y = wl_fixed_to_double(fixed_y);
|
2015-11-07 00:56:10 +03:00
|
|
|
|
|
|
|
if (!output || !input->touch_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (output->frame) {
|
|
|
|
frame_interior(output->frame, &fx, &fy, NULL, NULL);
|
2016-03-22 18:44:54 +03:00
|
|
|
x -= fx;
|
|
|
|
y -= fy;
|
2015-11-07 00:56:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
weston_output_transform_coordinate(&output->base, x, y, &x, &y);
|
|
|
|
|
|
|
|
notify_touch(&input->base, time, id, x, y, WL_TOUCH_MOTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_handle_touch_frame(void *data, struct wl_touch *wl_touch)
|
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
|
|
|
|
if (!input->touch_focus || !input->touch_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
notify_touch_frame(&input->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
input_handle_touch_cancel(void *data, struct wl_touch *wl_touch)
|
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
|
|
|
|
if (!input->touch_focus || !input->touch_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
notify_touch_cancel(&input->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_touch_listener touch_listener = {
|
|
|
|
input_handle_touch_down,
|
|
|
|
input_handle_touch_up,
|
|
|
|
input_handle_touch_motion,
|
|
|
|
input_handle_touch_frame,
|
|
|
|
input_handle_touch_cancel,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-05-16 21:45:18 +04:00
|
|
|
static void
|
|
|
|
input_handle_capabilities(void *data, struct wl_seat *seat,
|
|
|
|
enum wl_seat_capability caps)
|
|
|
|
{
|
|
|
|
struct wayland_input *input = data;
|
|
|
|
|
2013-10-28 07:24:53 +04:00
|
|
|
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->parent.pointer) {
|
|
|
|
input->parent.pointer = wl_seat_get_pointer(seat);
|
|
|
|
wl_pointer_set_user_data(input->parent.pointer, input);
|
|
|
|
wl_pointer_add_listener(input->parent.pointer,
|
|
|
|
&pointer_listener, input);
|
2012-08-10 18:01:33 +04:00
|
|
|
weston_seat_init_pointer(&input->base);
|
2013-10-28 07:24:53 +04:00
|
|
|
} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->parent.pointer) {
|
2015-11-07 00:56:08 +03:00
|
|
|
if (input->seat_version >= WL_POINTER_RELEASE_SINCE_VERSION)
|
|
|
|
wl_pointer_release(input->parent.pointer);
|
|
|
|
else
|
|
|
|
wl_pointer_destroy(input->parent.pointer);
|
2013-10-28 07:24:53 +04:00
|
|
|
input->parent.pointer = NULL;
|
2015-11-07 00:56:08 +03:00
|
|
|
weston_seat_release_pointer(&input->base);
|
2012-05-16 21:45:18 +04:00
|
|
|
}
|
|
|
|
|
2013-10-28 07:24:53 +04:00
|
|
|
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->parent.keyboard) {
|
|
|
|
input->parent.keyboard = wl_seat_get_keyboard(seat);
|
|
|
|
wl_keyboard_set_user_data(input->parent.keyboard, input);
|
|
|
|
wl_keyboard_add_listener(input->parent.keyboard,
|
|
|
|
&keyboard_listener, input);
|
|
|
|
} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->parent.keyboard) {
|
2015-11-07 00:56:08 +03:00
|
|
|
if (input->seat_version >= WL_KEYBOARD_RELEASE_SINCE_VERSION)
|
|
|
|
wl_keyboard_release(input->parent.keyboard);
|
|
|
|
else
|
|
|
|
wl_keyboard_destroy(input->parent.keyboard);
|
2013-10-28 07:24:53 +04:00
|
|
|
input->parent.keyboard = NULL;
|
2015-11-07 00:56:08 +03:00
|
|
|
weston_seat_release_keyboard(&input->base);
|
2012-05-16 21:45:18 +04:00
|
|
|
}
|
2015-11-07 00:56:10 +03:00
|
|
|
|
|
|
|
if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->parent.touch) {
|
|
|
|
input->parent.touch = wl_seat_get_touch(seat);
|
|
|
|
wl_touch_set_user_data(input->parent.touch, input);
|
|
|
|
wl_touch_add_listener(input->parent.touch,
|
|
|
|
&touch_listener, input);
|
|
|
|
weston_seat_init_touch(&input->base);
|
|
|
|
} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->parent.touch) {
|
|
|
|
if (input->seat_version >= WL_TOUCH_RELEASE_SINCE_VERSION)
|
|
|
|
wl_touch_release(input->parent.touch);
|
|
|
|
else
|
|
|
|
wl_touch_destroy(input->parent.touch);
|
|
|
|
input->parent.touch = NULL;
|
|
|
|
weston_seat_release_touch(&input->base);
|
|
|
|
}
|
2012-05-16 21:45:18 +04:00
|
|
|
}
|
|
|
|
|
2014-08-12 16:58:26 +04:00
|
|
|
static void
|
|
|
|
input_handle_name(void *data, struct wl_seat *seat,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-16 21:45:18 +04:00
|
|
|
static const struct wl_seat_listener seat_listener = {
|
|
|
|
input_handle_capabilities,
|
2014-08-12 16:58:26 +04:00
|
|
|
input_handle_name,
|
2010-11-27 21:04:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2015-11-07 00:56:08 +03:00
|
|
|
display_add_seat(struct wayland_backend *b, uint32_t id, uint32_t available_version)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
|
|
|
struct wayland_input *input;
|
2015-11-07 00:56:08 +03:00
|
|
|
uint32_t version = MIN(available_version, 4);
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2013-08-08 05:57:05 +04:00
|
|
|
input = zalloc(sizeof *input);
|
2010-11-27 21:04:12 +03:00
|
|
|
if (input == NULL)
|
|
|
|
return;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_seat_init(&input->base, b->compositor, "default");
|
|
|
|
input->backend = b;
|
|
|
|
input->parent.seat = wl_registry_bind(b->parent.registry, id,
|
2015-11-07 00:56:08 +03:00
|
|
|
&wl_seat_interface, version);
|
|
|
|
input->seat_version = version;
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_list_insert(b->input_list.prev, &input->link);
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2013-10-28 07:24:53 +04:00
|
|
|
wl_seat_add_listener(input->parent.seat, &seat_listener, input);
|
|
|
|
wl_seat_set_user_data(input->parent.seat, input);
|
2013-10-28 07:24:55 +04:00
|
|
|
|
|
|
|
input->parent.cursor.surface =
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_compositor_create_surface(b->parent.compositor);
|
2016-01-18 09:38:22 +03:00
|
|
|
|
|
|
|
input->vert.axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
|
|
|
|
input->horiz.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
|
2014-04-03 04:53:54 +04:00
|
|
|
static void
|
|
|
|
wayland_parent_output_geometry(void *data, struct wl_output *output_proxy,
|
|
|
|
int32_t x, int32_t y,
|
|
|
|
int32_t physical_width, int32_t physical_height,
|
|
|
|
int32_t subpixel, const char *make,
|
|
|
|
const char *model, int32_t transform)
|
|
|
|
{
|
|
|
|
struct wayland_parent_output *output = data;
|
|
|
|
|
|
|
|
output->x = x;
|
|
|
|
output->y = y;
|
|
|
|
output->physical.width = physical_width;
|
|
|
|
output->physical.height = physical_height;
|
|
|
|
output->physical.subpixel = subpixel;
|
|
|
|
|
|
|
|
free(output->physical.make);
|
|
|
|
output->physical.make = strdup(make);
|
|
|
|
free(output->physical.model);
|
|
|
|
output->physical.model = strdup(model);
|
|
|
|
|
|
|
|
output->transform = transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct weston_mode *
|
|
|
|
find_mode(struct wl_list *list, int32_t width, int32_t height, uint32_t refresh)
|
|
|
|
{
|
|
|
|
struct weston_mode *mode;
|
|
|
|
|
|
|
|
wl_list_for_each(mode, list, link) {
|
|
|
|
if (mode->width == width && mode->height == height &&
|
|
|
|
mode->refresh == refresh)
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = zalloc(sizeof *mode);
|
|
|
|
if (!mode)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
mode->width = width;
|
|
|
|
mode->height = height;
|
|
|
|
mode->refresh = refresh;
|
|
|
|
wl_list_insert(list, &mode->link);
|
|
|
|
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wayland_parent_output_mode(void *data, struct wl_output *wl_output_proxy,
|
|
|
|
uint32_t flags, int32_t width, int32_t height,
|
|
|
|
int32_t refresh)
|
|
|
|
{
|
|
|
|
struct wayland_parent_output *output = data;
|
|
|
|
struct weston_mode *mode;
|
|
|
|
|
|
|
|
if (output->output) {
|
|
|
|
mode = find_mode(&output->output->base.mode_list,
|
|
|
|
width, height, refresh);
|
|
|
|
if (!mode)
|
|
|
|
return;
|
|
|
|
mode->flags = flags;
|
|
|
|
/* Do a mode-switch on current mode change? */
|
|
|
|
} else {
|
|
|
|
mode = find_mode(&output->mode_list, width, height, refresh);
|
|
|
|
if (!mode)
|
|
|
|
return;
|
|
|
|
mode->flags = flags;
|
|
|
|
if (flags & WL_OUTPUT_MODE_CURRENT)
|
|
|
|
output->current_mode = mode;
|
|
|
|
if (flags & WL_OUTPUT_MODE_PREFERRED)
|
|
|
|
output->preferred_mode = mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_output_listener output_listener = {
|
|
|
|
wayland_parent_output_geometry,
|
|
|
|
wayland_parent_output_mode
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
wayland_backend_register_output(struct wayland_backend *b, uint32_t id)
|
2014-04-03 04:53:54 +04:00
|
|
|
{
|
|
|
|
struct wayland_parent_output *output;
|
|
|
|
|
|
|
|
output = zalloc(sizeof *output);
|
|
|
|
if (!output)
|
|
|
|
return;
|
|
|
|
|
|
|
|
output->id = id;
|
2014-10-11 19:27:30 +04:00
|
|
|
output->global = wl_registry_bind(b->parent.registry, id,
|
2014-04-03 04:53:54 +04:00
|
|
|
&wl_output_interface, 1);
|
2014-05-07 01:50:01 +04:00
|
|
|
if (!output->global) {
|
|
|
|
free(output);
|
2014-04-03 04:53:54 +04:00
|
|
|
return;
|
2014-05-07 01:50:01 +04:00
|
|
|
}
|
|
|
|
|
2014-04-03 04:53:54 +04:00
|
|
|
wl_output_add_listener(output->global, &output_listener, output);
|
|
|
|
|
|
|
|
output->scale = 0;
|
|
|
|
output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
|
|
|
output->physical.subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
|
|
|
|
wl_list_init(&output->mode_list);
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_list_insert(&b->parent.output_list, &output->link);
|
2014-04-03 04:53:54 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->sprawl_across_outputs) {
|
|
|
|
wl_display_roundtrip(b->parent.wl_display);
|
|
|
|
wayland_output_create_for_parent_output(b, output);
|
2014-04-03 04:53:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wayland_parent_output_destroy(struct wayland_parent_output *output)
|
|
|
|
{
|
|
|
|
struct weston_mode *mode, *next;
|
|
|
|
|
|
|
|
if (output->output)
|
|
|
|
wayland_output_destroy(&output->output->base);
|
|
|
|
|
|
|
|
wl_output_destroy(output->global);
|
|
|
|
free(output->physical.make);
|
|
|
|
free(output->physical.model);
|
|
|
|
|
|
|
|
wl_list_for_each_safe(mode, next, &output->mode_list, link) {
|
|
|
|
wl_list_remove(&mode->link);
|
|
|
|
free(mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-27 21:04:12 +03:00
|
|
|
static void
|
2012-10-11 05:34:26 +04:00
|
|
|
registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
|
|
|
const char *interface, uint32_t version)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b = data;
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2011-04-30 12:41:27 +04:00
|
|
|
if (strcmp(interface, "wl_compositor") == 0) {
|
2014-10-11 19:27:30 +04:00
|
|
|
b->parent.compositor =
|
2012-10-11 05:34:26 +04:00
|
|
|
wl_registry_bind(registry, name,
|
|
|
|
&wl_compositor_interface, 1);
|
2011-04-30 12:41:27 +04:00
|
|
|
} else if (strcmp(interface, "wl_shell") == 0) {
|
2014-10-11 19:27:30 +04:00
|
|
|
b->parent.shell =
|
2012-10-11 05:34:26 +04:00
|
|
|
wl_registry_bind(registry, name,
|
|
|
|
&wl_shell_interface, 1);
|
2015-11-17 11:00:27 +03:00
|
|
|
} else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) {
|
2014-10-11 19:27:30 +04:00
|
|
|
b->parent.fshell =
|
2014-04-03 04:53:54 +04:00
|
|
|
wl_registry_bind(registry, name,
|
2015-11-17 11:00:27 +03:00
|
|
|
&zwp_fullscreen_shell_v1_interface, 1);
|
2012-06-22 17:04:36 +04:00
|
|
|
} else if (strcmp(interface, "wl_seat") == 0) {
|
2014-10-11 19:27:30 +04:00
|
|
|
display_add_seat(b, name, version);
|
2014-04-03 04:53:54 +04:00
|
|
|
} else if (strcmp(interface, "wl_output") == 0) {
|
2014-10-11 19:27:30 +04:00
|
|
|
wayland_backend_register_output(b, name);
|
2013-04-06 01:07:11 +04:00
|
|
|
} else if (strcmp(interface, "wl_shm") == 0) {
|
2014-10-11 19:27:30 +04:00
|
|
|
b->parent.shm =
|
2013-04-06 01:07:11 +04:00
|
|
|
wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 04:53:54 +04:00
|
|
|
static void
|
|
|
|
registry_handle_global_remove(void *data, struct wl_registry *registry,
|
|
|
|
uint32_t name)
|
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b = data;
|
2014-04-03 04:53:54 +04:00
|
|
|
struct wayland_parent_output *output;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_list_for_each(output, &b->parent.output_list, link)
|
2014-04-03 04:53:54 +04:00
|
|
|
if (output->id == name)
|
|
|
|
wayland_parent_output_destroy(output);
|
|
|
|
}
|
|
|
|
|
2012-10-11 05:34:26 +04:00
|
|
|
static const struct wl_registry_listener registry_listener = {
|
2014-04-03 04:53:54 +04:00
|
|
|
registry_handle_global,
|
|
|
|
registry_handle_global_remove
|
2012-10-11 05:34:26 +04:00
|
|
|
};
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2011-04-22 21:01:26 +04:00
|
|
|
static int
|
2014-10-11 19:27:30 +04:00
|
|
|
wayland_backend_handle_event(int fd, uint32_t mask, void *data)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b = data;
|
2012-10-15 20:56:11 +04:00
|
|
|
int count = 0;
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2013-10-31 10:15:44 +04:00
|
|
|
if ((mask & WL_EVENT_HANGUP) || (mask & WL_EVENT_ERROR)) {
|
2014-10-12 00:56:24 +04:00
|
|
|
weston_compositor_exit(b->compositor);
|
2013-10-31 10:15:44 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-27 21:04:12 +03:00
|
|
|
if (mask & WL_EVENT_READABLE)
|
2014-10-11 19:27:30 +04:00
|
|
|
count = wl_display_dispatch(b->parent.wl_display);
|
2011-12-29 07:51:20 +04:00
|
|
|
if (mask & WL_EVENT_WRITABLE)
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_display_flush(b->parent.wl_display);
|
2011-04-22 21:01:26 +04:00
|
|
|
|
2012-10-15 20:56:11 +04:00
|
|
|
if (mask == 0) {
|
2014-10-11 19:27:30 +04:00
|
|
|
count = wl_display_dispatch_pending(b->parent.wl_display);
|
|
|
|
wl_display_flush(b->parent.wl_display);
|
2012-10-15 20:56:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
|
2012-07-31 22:32:01 +04:00
|
|
|
static void
|
|
|
|
wayland_restore(struct weston_compositor *ec)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-02 00:52:15 +03:00
|
|
|
static void
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
wayland_destroy(struct weston_compositor *ec)
|
2010-12-02 00:52:15 +03:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b = (struct wayland_backend *) ec->backend;
|
2013-04-06 01:07:11 +04:00
|
|
|
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
weston_compositor_shutdown(ec);
|
2011-08-30 00:52:23 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->parent.shm)
|
|
|
|
wl_shm_destroy(b->parent.shm);
|
2013-04-06 01:07:11 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
free(b);
|
2010-12-02 00:52:15 +03:00
|
|
|
}
|
|
|
|
|
2013-10-28 07:24:55 +04:00
|
|
|
static const char *left_ptrs[] = {
|
|
|
|
"left_ptr",
|
|
|
|
"default",
|
|
|
|
"top_left_arrow",
|
|
|
|
"left-arrow"
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2016-04-28 21:33:11 +03:00
|
|
|
create_cursor(struct wayland_backend *b,
|
|
|
|
struct weston_wayland_backend_config *config)
|
2013-10-28 07:24:55 +04:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2016-04-28 21:33:11 +03:00
|
|
|
b->cursor_theme = wl_cursor_theme_load(config->cursor_theme,
|
|
|
|
config->cursor_size,
|
|
|
|
b->parent.shm);
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->cursor_theme) {
|
2014-03-18 17:12:50 +04:00
|
|
|
fprintf(stderr, "could not load cursor theme\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-10-28 07:24:55 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->cursor = NULL;
|
|
|
|
for (i = 0; !b->cursor && i < ARRAY_LENGTH(left_ptrs); ++i)
|
|
|
|
b->cursor = wl_cursor_theme_get_cursor(b->cursor_theme,
|
2013-10-28 07:24:55 +04:00
|
|
|
left_ptrs[i]);
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->cursor) {
|
2013-10-28 07:24:55 +04:00
|
|
|
fprintf(stderr, "could not load left cursor\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-08 06:13:33 +04:00
|
|
|
static void
|
2015-07-15 21:00:36 +03:00
|
|
|
fullscreen_binding(struct weston_keyboard *keyboard, uint32_t time,
|
|
|
|
uint32_t key, void *data)
|
2013-11-08 06:13:33 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b = data;
|
2013-11-08 06:13:33 +04:00
|
|
|
struct wayland_input *input = NULL;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_list_for_each(input, &b->input_list, link)
|
2015-07-15 21:00:36 +03:00
|
|
|
if (&input->base == keyboard->seat)
|
2013-11-08 06:13:33 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (!input || !input->output)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (input->output->frame)
|
|
|
|
wayland_output_set_fullscreen(input->output, 0, 0, NULL);
|
|
|
|
else
|
|
|
|
wayland_output_set_windowed(input->output);
|
|
|
|
|
|
|
|
weston_output_schedule_repaint(&input->output->base);
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
static struct wayland_backend *
|
2016-04-28 21:33:10 +03:00
|
|
|
wayland_backend_create(struct weston_compositor *compositor,
|
2016-06-03 14:56:18 +03:00
|
|
|
struct weston_wayland_backend_config *new_config)
|
2010-11-27 21:04:12 +03:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct wayland_backend *b;
|
2010-11-27 21:04:12 +03:00
|
|
|
struct wl_event_loop *loop;
|
2013-11-08 06:13:31 +04:00
|
|
|
int fd;
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b = zalloc(sizeof *b);
|
|
|
|
if (b == NULL)
|
2010-11-27 21:04:12 +03:00
|
|
|
return NULL;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->compositor = compositor;
|
|
|
|
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
|
2014-09-24 06:08:45 +04:00
|
|
|
goto err_compositor;
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2016-04-28 21:33:10 +03:00
|
|
|
b->parent.wl_display = wl_display_connect(new_config->display_name);
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->parent.wl_display == NULL) {
|
2012-06-07 20:01:59 +04:00
|
|
|
weston_log("failed to create display: %m\n");
|
2012-07-08 05:03:43 +04:00
|
|
|
goto err_compositor;
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_list_init(&b->parent.output_list);
|
|
|
|
wl_list_init(&b->input_list);
|
|
|
|
b->parent.registry = wl_display_get_registry(b->parent.wl_display);
|
|
|
|
wl_registry_add_listener(b->parent.registry, ®istry_listener, b);
|
|
|
|
wl_display_roundtrip(b->parent.wl_display);
|
2013-10-28 07:24:55 +04:00
|
|
|
|
2016-04-28 21:33:11 +03:00
|
|
|
create_cursor(b, new_config);
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2016-04-28 21:33:10 +03:00
|
|
|
b->use_pixman = new_config->use_pixman;
|
2013-10-14 16:57:11 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->use_pixman) {
|
2013-10-28 07:25:02 +04:00
|
|
|
gl_renderer = weston_load_module("gl-renderer.so",
|
|
|
|
"gl_renderer_interface");
|
|
|
|
if (!gl_renderer)
|
2014-10-11 19:27:30 +04:00
|
|
|
b->use_pixman = 1;
|
2013-10-28 07:25:02 +04:00
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (!b->use_pixman) {
|
|
|
|
if (gl_renderer->create(compositor,
|
2015-05-15 20:12:39 +03:00
|
|
|
EGL_PLATFORM_WAYLAND_KHR,
|
2014-10-11 19:27:30 +04:00
|
|
|
b->parent.wl_display,
|
2015-05-15 20:12:39 +03:00
|
|
|
gl_renderer->alpha_attribs,
|
|
|
|
NULL,
|
|
|
|
0) < 0) {
|
2013-10-28 07:24:58 +04:00
|
|
|
weston_log("Failed to initialize the GL renderer; "
|
|
|
|
"falling back to pixman.\n");
|
2014-10-11 19:27:30 +04:00
|
|
|
b->use_pixman = 1;
|
2013-10-28 07:24:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->use_pixman) {
|
|
|
|
if (pixman_renderer_init(compositor) < 0) {
|
2013-10-28 07:24:58 +04:00
|
|
|
weston_log("Failed to initialize pixman renderer\n");
|
|
|
|
goto err_display;
|
|
|
|
}
|
|
|
|
}
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->base.destroy = wayland_destroy;
|
|
|
|
b->base.restore = wayland_restore;
|
2011-01-15 14:34:48 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
loop = wl_display_get_event_loop(compositor->wl_display);
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
fd = wl_display_get_fd(b->parent.wl_display);
|
|
|
|
b->parent.wl_source =
|
2012-10-11 05:34:26 +04:00
|
|
|
wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
|
2014-10-11 19:27:30 +04:00
|
|
|
wayland_backend_handle_event, b);
|
|
|
|
if (b->parent.wl_source == NULL)
|
2015-07-31 06:02:28 +03:00
|
|
|
goto err_display;
|
2010-11-27 21:04:12 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_event_source_check(b->parent.wl_source);
|
2012-10-15 20:56:11 +04:00
|
|
|
|
2015-09-25 12:58:40 +03:00
|
|
|
if (compositor->renderer->import_dmabuf) {
|
|
|
|
if (linux_dmabuf_setup(compositor) < 0)
|
|
|
|
weston_log("Error: initializing dmabuf "
|
|
|
|
"support failed.\n");
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
compositor->backend = &b->base;
|
|
|
|
return b;
|
2012-07-08 05:03:43 +04:00
|
|
|
err_display:
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_display_disconnect(b->parent.wl_display);
|
2012-07-08 05:03:43 +04:00
|
|
|
err_compositor:
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_compositor_shutdown(compositor);
|
|
|
|
free(b);
|
2012-07-08 05:03:43 +04:00
|
|
|
return NULL;
|
2010-11-27 21:04:12 +03:00
|
|
|
}
|
2011-05-03 06:09:20 +04:00
|
|
|
|
2013-11-08 06:13:31 +04:00
|
|
|
static void
|
2014-10-11 19:27:30 +04:00
|
|
|
wayland_backend_destroy(struct wayland_backend *b)
|
2013-11-08 06:13:31 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
wl_display_disconnect(b->parent.wl_display);
|
2013-11-08 06:13:31 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b->theme)
|
|
|
|
theme_destroy(b->theme);
|
|
|
|
if (b->frame_device)
|
|
|
|
cairo_device_destroy(b->frame_device);
|
|
|
|
wl_cursor_theme_destroy(b->cursor_theme);
|
2013-11-08 06:13:31 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_compositor_shutdown(b->compositor);
|
|
|
|
free(b);
|
2013-11-08 06:13:31 +04:00
|
|
|
}
|
|
|
|
|
2016-05-10 23:47:48 +03:00
|
|
|
static void
|
|
|
|
config_init_to_defaults(struct weston_wayland_backend_config *config)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-04-28 21:33:14 +03:00
|
|
|
WL_EXPORT int
|
2016-06-03 14:56:18 +03:00
|
|
|
backend_init(struct weston_compositor *compositor,
|
2016-04-28 21:33:14 +03:00
|
|
|
struct weston_backend_config *config_base)
|
|
|
|
{
|
|
|
|
struct wayland_backend *b;
|
|
|
|
struct wayland_output *output;
|
|
|
|
struct wayland_parent_output *poutput;
|
|
|
|
struct weston_wayland_backend_config new_config;
|
|
|
|
int x, count;
|
|
|
|
|
2016-05-10 23:47:48 +03:00
|
|
|
if (config_base == NULL ||
|
|
|
|
config_base->struct_version != WESTON_WAYLAND_BACKEND_CONFIG_VERSION ||
|
|
|
|
config_base->struct_size > sizeof(struct weston_wayland_backend_config)) {
|
|
|
|
weston_log("wayland backend config structure is invalid\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
config_init_to_defaults(&new_config);
|
|
|
|
memcpy(&new_config, config_base, config_base->struct_size);
|
|
|
|
|
2016-06-03 14:56:18 +03:00
|
|
|
b = wayland_backend_create(compositor, &new_config);
|
2016-04-28 21:33:14 +03:00
|
|
|
|
|
|
|
if (!b)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (new_config.sprawl || b->parent.fshell) {
|
|
|
|
b->sprawl_across_outputs = 1;
|
|
|
|
wl_display_roundtrip(b->parent.wl_display);
|
|
|
|
|
|
|
|
wl_list_for_each(poutput, &b->parent.output_list, link)
|
|
|
|
wayland_output_create_for_parent_output(b, poutput);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_config.fullscreen) {
|
|
|
|
if (new_config.num_outputs != 1 || !new_config.outputs)
|
|
|
|
goto err_outputs;
|
|
|
|
|
|
|
|
output = wayland_output_create_for_config(b,
|
|
|
|
&new_config.outputs[0],
|
|
|
|
1, 0, 0);
|
|
|
|
if (!output)
|
|
|
|
goto err_outputs;
|
|
|
|
|
|
|
|
wayland_output_set_fullscreen(output, 0, 0, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = 0;
|
|
|
|
for (count = 0; count < new_config.num_outputs; ++count) {
|
|
|
|
output = wayland_output_create_for_config(b, &new_config.outputs[count],
|
2016-04-28 21:33:12 +03:00
|
|
|
0, x, 0);
|
2013-11-08 06:13:31 +04:00
|
|
|
if (!output)
|
|
|
|
goto err_outputs;
|
2013-11-08 06:13:33 +04:00
|
|
|
if (wayland_output_set_windowed(output))
|
|
|
|
goto err_outputs;
|
2013-11-08 06:13:31 +04:00
|
|
|
|
2016-04-28 21:33:14 +03:00
|
|
|
x += output->base.width;
|
2013-11-08 06:13:31 +04:00
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_compositor_add_key_binding(compositor, KEY_F,
|
2014-04-03 04:53:54 +04:00
|
|
|
MODIFIER_CTRL | MODIFIER_ALT,
|
2014-10-11 19:27:30 +04:00
|
|
|
fullscreen_binding, b);
|
|
|
|
return 0;
|
2013-11-08 06:13:31 +04:00
|
|
|
|
|
|
|
err_outputs:
|
2014-10-11 19:27:30 +04:00
|
|
|
wayland_backend_destroy(b);
|
|
|
|
return -1;
|
2011-05-03 06:09:20 +04:00
|
|
|
}
|