You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
588 lines
15 KiB
588 lines
15 KiB
14 years ago
|
/*
|
||
13 years ago
|
* Copyright © 2010-2011 Benjamin Franzke
|
||
14 years ago
|
*
|
||
13 years ago
|
* Permission to use, copy, modify, distribute, and sell this software and
|
||
|
* its documentation for any purpose is hereby granted without fee, provided
|
||
|
* that the above copyright notice appear in all copies and that both that
|
||
|
* copyright notice and this permission notice appear in supporting
|
||
|
* documentation, and that the name of the copyright holders not be used in
|
||
|
* advertising or publicity pertaining to distribution of the software
|
||
|
* without specific, written prior permission. The copyright holders make
|
||
|
* no representations about the suitability of this software for any
|
||
|
* purpose. It is provided "as is" without express or implied warranty.
|
||
14 years ago
|
*
|
||
13 years ago
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
||
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
||
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
||
|
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||
14 years ago
|
*/
|
||
|
|
||
|
#ifdef HAVE_CONFIG_H
|
||
|
#include <config.h>
|
||
|
#endif
|
||
|
|
||
|
#include <stddef.h>
|
||
|
#define _GNU_SOURCE
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
14 years ago
|
#include <wayland-client.h>
|
||
|
#include <wayland-egl.h>
|
||
14 years ago
|
|
||
|
#include <GLES2/gl2.h>
|
||
|
#include <GLES2/gl2ext.h>
|
||
|
#include <EGL/egl.h>
|
||
|
#include <EGL/eglext.h>
|
||
|
|
||
|
#include "compositor.h"
|
||
|
|
||
|
struct wayland_compositor {
|
||
13 years ago
|
struct weston_compositor base;
|
||
14 years ago
|
|
||
|
struct {
|
||
|
struct wl_display *display;
|
||
|
struct wl_compositor *compositor;
|
||
|
struct wl_shell *shell;
|
||
|
struct wl_output *output;
|
||
|
|
||
|
struct {
|
||
|
int32_t x, y, width, height;
|
||
|
} screen_allocation;
|
||
|
|
||
|
struct wl_event_source *wl_source;
|
||
|
uint32_t event_mask;
|
||
|
} parent;
|
||
|
|
||
|
struct wl_list input_list;
|
||
|
};
|
||
|
|
||
|
struct wayland_output {
|
||
13 years ago
|
struct weston_output base;
|
||
14 years ago
|
|
||
|
struct {
|
||
|
struct wl_surface *surface;
|
||
13 years ago
|
struct wl_shell_surface *shell_surface;
|
||
14 years ago
|
struct wl_egl_window *egl_window;
|
||
14 years ago
|
} parent;
|
||
14 years ago
|
EGLSurface egl_surface;
|
||
13 years ago
|
struct weston_mode mode;
|
||
14 years ago
|
};
|
||
|
|
||
|
struct wayland_input {
|
||
|
struct wayland_compositor *compositor;
|
||
|
struct wl_input_device *input_device;
|
||
|
struct wl_list link;
|
||
|
};
|
||
|
|
||
|
static int
|
||
|
wayland_input_create(struct wayland_compositor *c)
|
||
|
{
|
||
13 years ago
|
struct weston_input_device *input;
|
||
14 years ago
|
|
||
|
input = malloc(sizeof *input);
|
||
|
if (input == NULL)
|
||
|
return -1;
|
||
|
|
||
|
memset(input, 0, sizeof *input);
|
||
13 years ago
|
weston_input_device_init(input, &c->base);
|
||
14 years ago
|
|
||
14 years ago
|
c->base.input_device = &input->input_device;
|
||
14 years ago
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
static int
|
||
|
wayland_compositor_init_egl(struct wayland_compositor *c)
|
||
|
{
|
||
|
EGLint major, minor;
|
||
14 years ago
|
EGLint n;
|
||
14 years ago
|
const char *extensions;
|
||
14 years ago
|
EGLint config_attribs[] = {
|
||
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||
|
EGL_RED_SIZE, 1,
|
||
|
EGL_GREEN_SIZE, 1,
|
||
|
EGL_BLUE_SIZE, 1,
|
||
13 years ago
|
EGL_ALPHA_SIZE, 0,
|
||
14 years ago
|
EGL_DEPTH_SIZE, 1,
|
||
14 years ago
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||
14 years ago
|
EGL_NONE
|
||
|
};
|
||
14 years ago
|
static const EGLint context_attribs[] = {
|
||
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||
|
EGL_NONE
|
||
|
};
|
||
|
|
||
14 years ago
|
c->base.display = eglGetDisplay(c->parent.display);
|
||
14 years ago
|
if (c->base.display == NULL) {
|
||
|
fprintf(stderr, "failed to create display\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
if (!eglInitialize(c->base.display, &major, &minor)) {
|
||
|
fprintf(stderr, "failed to initialize display\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
extensions = eglQueryString(c->base.display, EGL_EXTENSIONS);
|
||
13 years ago
|
if (!strstr(extensions, "EGL_KHR_surfaceless_gles2")) {
|
||
|
fprintf(stderr, "EGL_KHR_surfaceless_gles2 not available\n");
|
||
14 years ago
|
return -1;
|
||
|
}
|
||
|
|
||
|
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
|
||
|
fprintf(stderr, "failed to bind EGL_OPENGL_ES_API\n");
|
||
|
return -1;
|
||
|
}
|
||
14 years ago
|
if (!eglChooseConfig(c->base.display, config_attribs,
|
||
|
&c->base.config, 1, &n) || n == 0) {
|
||
|
fprintf(stderr, "failed to choose config: %d\n", n);
|
||
|
return -1;
|
||
|
}
|
||
14 years ago
|
|
||
14 years ago
|
c->base.context = eglCreateContext(c->base.display, c->base.config,
|
||
14 years ago
|
EGL_NO_CONTEXT, context_attribs);
|
||
|
if (c->base.context == NULL) {
|
||
|
fprintf(stderr, "failed to create context\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
if (!eglMakeCurrent(c->base.display, EGL_NO_SURFACE,
|
||
|
EGL_NO_SURFACE, c->base.context)) {
|
||
|
fprintf(stderr, "failed to make context current\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
14 years ago
|
static int
|
||
13 years ago
|
wayland_output_prepare_render(struct weston_output *output_base)
|
||
14 years ago
|
{
|
||
|
struct wayland_output *output = (struct wayland_output *) output_base;
|
||
13 years ago
|
struct weston_compositor *ec = output->base.compositor;
|
||
14 years ago
|
|
||
|
if (!eglMakeCurrent(ec->display, output->egl_surface,
|
||
|
output->egl_surface, ec->context)) {
|
||
|
fprintf(stderr, "failed to make current\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
|
frame_done(void *data, struct wl_callback *wl_callback, uint32_t time)
|
||
|
{
|
||
13 years ago
|
struct weston_output *output = data;
|
||
13 years ago
|
|
||
13 years ago
|
weston_output_finish_frame(output, time);
|
||
13 years ago
|
}
|
||
|
|
||
|
static const struct wl_callback_listener frame_listener = {
|
||
|
frame_done
|
||
|
};
|
||
|
|
||
14 years ago
|
static int
|
||
13 years ago
|
wayland_output_present(struct weston_output *output_base)
|
||
14 years ago
|
{
|
||
14 years ago
|
struct wayland_output *output = (struct wayland_output *) output_base;
|
||
|
struct wayland_compositor *c =
|
||
|
(struct wayland_compositor *) output->base.compositor;
|
||
13 years ago
|
struct wl_callback *callback;
|
||
14 years ago
|
|
||
14 years ago
|
if (wayland_output_prepare_render(&output->base))
|
||
|
return -1;
|
||
14 years ago
|
|
||
14 years ago
|
eglSwapBuffers(c->base.display, output->egl_surface);
|
||
13 years ago
|
callback = wl_surface_frame(output->parent.surface);
|
||
|
wl_callback_add_listener(callback, &frame_listener, output);
|
||
14 years ago
|
|
||
14 years ago
|
return 0;
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
static int
|
||
13 years ago
|
wayland_output_prepare_scanout_surface(struct weston_output *output_base,
|
||
|
struct weston_surface *es)
|
||
14 years ago
|
{
|
||
14 years ago
|
return -1;
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
static int
|
||
13 years ago
|
wayland_output_set_cursor(struct weston_output *output_base,
|
||
|
struct weston_input_device *input)
|
||
14 years ago
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
13 years ago
|
static void
|
||
13 years ago
|
wayland_output_destroy(struct weston_output *output_base)
|
||
13 years ago
|
{
|
||
|
struct wayland_output *output = (struct wayland_output *) output_base;
|
||
13 years ago
|
struct weston_compositor *ec = output->base.compositor;
|
||
13 years ago
|
|
||
|
eglDestroySurface(ec->display, output->egl_surface);
|
||
|
wl_egl_window_destroy(output->parent.egl_window);
|
||
|
free(output);
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
14 years ago
|
static int
|
||
|
wayland_compositor_create_output(struct wayland_compositor *c,
|
||
|
int width, int height)
|
||
|
{
|
||
|
struct wayland_output *output;
|
||
|
|
||
|
output = malloc(sizeof *output);
|
||
|
if (output == NULL)
|
||
|
return -1;
|
||
|
memset(output, 0, sizeof *output);
|
||
|
|
||
14 years ago
|
output->mode.flags =
|
||
|
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
|
||
|
output->mode.width = width;
|
||
|
output->mode.height = height;
|
||
|
output->mode.refresh = 60;
|
||
|
wl_list_init(&output->base.mode_list);
|
||
|
wl_list_insert(&output->base.mode_list, &output->mode.link);
|
||
|
|
||
|
output->base.current = &output->mode;
|
||
13 years ago
|
weston_output_init(&output->base, &c->base, 0, 0, width, height,
|
||
14 years ago
|
WL_OUTPUT_FLIPPED);
|
||
14 years ago
|
|
||
14 years ago
|
output->parent.surface =
|
||
|
wl_compositor_create_surface(c->parent.compositor);
|
||
|
wl_surface_set_user_data(output->parent.surface, output);
|
||
|
|
||
14 years ago
|
output->parent.egl_window =
|
||
13 years ago
|
wl_egl_window_create(output->parent.surface, width, height);
|
||
14 years ago
|
if (!output->parent.egl_window) {
|
||
|
fprintf(stderr, "failure to create wl_egl_window\n");
|
||
|
goto cleanup_output;
|
||
|
}
|
||
|
|
||
|
output->egl_surface =
|
||
|
eglCreateWindowSurface(c->base.display, c->base.config,
|
||
|
output->parent.egl_window, NULL);
|
||
|
if (!output->egl_surface) {
|
||
|
fprintf(stderr, "failed to create window surface\n");
|
||
|
goto cleanup_window;
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
if (!eglMakeCurrent(c->base.display, output->egl_surface,
|
||
|
output->egl_surface, c->base.context)) {
|
||
|
fprintf(stderr, "failed to make surface current\n");
|
||
|
goto cleanup_surface;
|
||
|
return -1;
|
||
|
}
|
||
14 years ago
|
|
||
13 years ago
|
output->parent.shell_surface =
|
||
|
wl_shell_get_shell_surface(c->parent.shell,
|
||
|
output->parent.surface);
|
||
|
/* FIXME: add shell_surface listener for resizing */
|
||
|
wl_shell_surface_set_toplevel(output->parent.shell_surface);
|
||
14 years ago
|
|
||
|
glClearColor(0, 0, 0, 0.5);
|
||
|
|
||
14 years ago
|
output->base.prepare_render = wayland_output_prepare_render;
|
||
14 years ago
|
output->base.present = wayland_output_present;
|
||
14 years ago
|
output->base.prepare_scanout_surface =
|
||
|
wayland_output_prepare_scanout_surface;
|
||
14 years ago
|
output->base.set_hardware_cursor = wayland_output_set_cursor;
|
||
13 years ago
|
output->base.destroy = wayland_output_destroy;
|
||
14 years ago
|
|
||
14 years ago
|
wl_list_insert(c->base.output_list.prev, &output->base.link);
|
||
|
|
||
|
return 0;
|
||
14 years ago
|
|
||
|
cleanup_surface:
|
||
|
eglDestroySurface(c->base.display, output->egl_surface);
|
||
|
cleanup_window:
|
||
|
wl_egl_window_destroy(output->parent.egl_window);
|
||
|
cleanup_output:
|
||
13 years ago
|
/* FIXME: cleanup weston_output */
|
||
14 years ago
|
free(output);
|
||
|
|
||
|
return -1;
|
||
14 years ago
|
}
|
||
|
|
||
|
/* Events received from the wayland-server this compositor is client of: */
|
||
|
|
||
|
/* parent output interface */
|
||
|
static void
|
||
|
display_handle_geometry(void *data,
|
||
14 years ago
|
struct wl_output *wl_output,
|
||
|
int x,
|
||
|
int y,
|
||
|
int physical_width,
|
||
|
int physical_height,
|
||
|
int subpixel,
|
||
|
const char *make,
|
||
|
const char *model)
|
||
14 years ago
|
{
|
||
|
struct wayland_compositor *c = data;
|
||
|
|
||
14 years ago
|
c->parent.screen_allocation.x = x;
|
||
|
c->parent.screen_allocation.y = y;
|
||
14 years ago
|
}
|
||
|
|
||
|
static void
|
||
|
display_handle_mode(void *data,
|
||
|
struct wl_output *wl_output,
|
||
|
uint32_t flags,
|
||
|
int width,
|
||
|
int height,
|
||
|
int refresh)
|
||
|
{
|
||
|
struct wayland_compositor *c = data;
|
||
|
|
||
14 years ago
|
c->parent.screen_allocation.width = width;
|
||
|
c->parent.screen_allocation.height = height;
|
||
|
}
|
||
|
|
||
|
static const struct wl_output_listener output_listener = {
|
||
|
display_handle_geometry,
|
||
14 years ago
|
display_handle_mode
|
||
14 years ago
|
};
|
||
|
|
||
|
/* parent input interface */
|
||
|
static void
|
||
|
input_handle_motion(void *data, struct wl_input_device *input_device,
|
||
|
uint32_t time,
|
||
|
int32_t x, int32_t y, int32_t sx, int32_t sy)
|
||
|
{
|
||
|
struct wayland_input *input = data;
|
||
|
struct wayland_compositor *c = input->compositor;
|
||
|
|
||
|
notify_motion(c->base.input_device, time, sx, sy);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
input_handle_button(void *data,
|
||
|
struct wl_input_device *input_device,
|
||
|
uint32_t time, uint32_t button, uint32_t state)
|
||
|
{
|
||
|
struct wayland_input *input = data;
|
||
|
struct wayland_compositor *c = input->compositor;
|
||
|
|
||
|
notify_button(c->base.input_device, time, button, state);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
input_handle_key(void *data, struct wl_input_device *input_device,
|
||
|
uint32_t time, uint32_t key, uint32_t state)
|
||
|
{
|
||
|
struct wayland_input *input = data;
|
||
|
struct wayland_compositor *c = input->compositor;
|
||
|
|
||
|
notify_key(c->base.input_device, time, key, state);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
input_handle_pointer_focus(void *data,
|
||
|
struct wl_input_device *input_device,
|
||
|
uint32_t time, struct wl_surface *surface,
|
||
|
int32_t x, int32_t y, int32_t sx, int32_t sy)
|
||
|
{
|
||
|
struct wayland_input *input = data;
|
||
14 years ago
|
struct wayland_output *output;
|
||
14 years ago
|
struct wayland_compositor *c = input->compositor;
|
||
|
|
||
|
if (surface) {
|
||
14 years ago
|
output = wl_surface_get_user_data(surface);
|
||
|
notify_pointer_focus(c->base.input_device,
|
||
|
time, &output->base, sx, sy);
|
||
14 years ago
|
} else {
|
||
14 years ago
|
notify_pointer_focus(c->base.input_device, time, NULL, 0, 0);
|
||
14 years ago
|
}
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
input_handle_keyboard_focus(void *data,
|
||
|
struct wl_input_device *input_device,
|
||
|
uint32_t time,
|
||
|
struct wl_surface *surface,
|
||
|
struct wl_array *keys)
|
||
|
{
|
||
14 years ago
|
struct wayland_input *input = data;
|
||
|
struct wayland_compositor *c = input->compositor;
|
||
|
struct wayland_output *output;
|
||
|
|
||
|
if (surface) {
|
||
|
output = wl_surface_get_user_data(surface);
|
||
|
notify_keyboard_focus(c->base.input_device,
|
||
|
time, &output->base, keys);
|
||
|
} else {
|
||
|
notify_keyboard_focus(c->base.input_device, time, NULL, NULL);
|
||
|
}
|
||
14 years ago
|
}
|
||
|
|
||
|
static const struct wl_input_device_listener input_device_listener = {
|
||
|
input_handle_motion,
|
||
|
input_handle_button,
|
||
|
input_handle_key,
|
||
|
input_handle_pointer_focus,
|
||
|
input_handle_keyboard_focus,
|
||
|
};
|
||
|
|
||
|
static void
|
||
|
display_add_input(struct wayland_compositor *c, uint32_t id)
|
||
|
{
|
||
|
struct wayland_input *input;
|
||
|
|
||
|
input = malloc(sizeof *input);
|
||
|
if (input == NULL)
|
||
|
return;
|
||
|
|
||
|
memset(input, 0, sizeof *input);
|
||
|
|
||
|
input->compositor = c;
|
||
13 years ago
|
input->input_device = wl_display_bind(c->parent.display,
|
||
|
id, &wl_input_device_interface);
|
||
14 years ago
|
wl_list_insert(c->input_list.prev, &input->link);
|
||
|
|
||
|
wl_input_device_add_listener(input->input_device,
|
||
|
&input_device_listener, input);
|
||
|
wl_input_device_set_user_data(input->input_device, input);
|
||
|
}
|
||
|
|
||
|
static void
|
||
|
display_handle_global(struct wl_display *display, uint32_t id,
|
||
|
const char *interface, uint32_t version, void *data)
|
||
|
{
|
||
|
struct wayland_compositor *c = data;
|
||
|
|
||
14 years ago
|
if (strcmp(interface, "wl_compositor") == 0) {
|
||
13 years ago
|
c->parent.compositor =
|
||
|
wl_display_bind(display, id, &wl_compositor_interface);
|
||
14 years ago
|
} else if (strcmp(interface, "wl_output") == 0) {
|
||
13 years ago
|
c->parent.output =
|
||
|
wl_display_bind(display, id, &wl_output_interface);
|
||
14 years ago
|
wl_output_add_listener(c->parent.output, &output_listener, c);
|
||
14 years ago
|
} else if (strcmp(interface, "wl_input_device") == 0) {
|
||
14 years ago
|
display_add_input(c, id);
|
||
14 years ago
|
} else if (strcmp(interface, "wl_shell") == 0) {
|
||
13 years ago
|
c->parent.shell =
|
||
|
wl_display_bind(display, id, &wl_shell_interface);
|
||
14 years ago
|
}
|
||
|
}
|
||
|
|
||
|
static int
|
||
|
update_event_mask(uint32_t mask, void *data)
|
||
|
{
|
||
|
struct wayland_compositor *c = data;
|
||
|
|
||
|
c->parent.event_mask = mask;
|
||
|
if (c->parent.wl_source)
|
||
|
wl_event_source_fd_update(c->parent.wl_source, mask);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
14 years ago
|
static int
|
||
14 years ago
|
wayland_compositor_handle_event(int fd, uint32_t mask, void *data)
|
||
|
{
|
||
|
struct wayland_compositor *c = data;
|
||
|
|
||
|
if (mask & WL_EVENT_READABLE)
|
||
|
wl_display_iterate(c->parent.display, WL_DISPLAY_READABLE);
|
||
13 years ago
|
if (mask & WL_EVENT_WRITABLE)
|
||
14 years ago
|
wl_display_iterate(c->parent.display, WL_DISPLAY_WRITABLE);
|
||
14 years ago
|
|
||
|
return 1;
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
static void
|
||
13 years ago
|
wayland_destroy(struct weston_compositor *ec)
|
||
14 years ago
|
{
|
||
13 years ago
|
weston_compositor_shutdown(ec);
|
||
13 years ago
|
|
||
14 years ago
|
free(ec);
|
||
|
}
|
||
|
|
||
13 years ago
|
static struct weston_compositor *
|
||
14 years ago
|
wayland_compositor_create(struct wl_display *display, int width, int height)
|
||
|
{
|
||
|
struct wayland_compositor *c;
|
||
|
struct wl_event_loop *loop;
|
||
|
int fd;
|
||
|
|
||
|
c = malloc(sizeof *c);
|
||
|
if (c == NULL)
|
||
|
return NULL;
|
||
|
|
||
|
memset(c, 0, sizeof *c);
|
||
|
|
||
14 years ago
|
c->parent.display = wl_display_connect(NULL);
|
||
14 years ago
|
|
||
|
if (c->parent.display == NULL) {
|
||
|
fprintf(stderr, "failed to create display: %m\n");
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
wl_list_init(&c->input_list);
|
||
|
wl_display_add_global_listener(c->parent.display,
|
||
|
display_handle_global, c);
|
||
|
|
||
|
wl_display_iterate(c->parent.display, WL_DISPLAY_READABLE);
|
||
|
|
||
|
c->base.wl_display = display;
|
||
|
if (wayland_compositor_init_egl(c) < 0)
|
||
|
return NULL;
|
||
|
|
||
14 years ago
|
c->base.destroy = wayland_destroy;
|
||
|
|
||
14 years ago
|
/* Can't init base class until we have a current egl context */
|
||
13 years ago
|
if (weston_compositor_init(&c->base, display) < 0)
|
||
14 years ago
|
return NULL;
|
||
|
|
||
|
if (wayland_compositor_create_output(c, width, height) < 0)
|
||
|
return NULL;
|
||
|
|
||
|
if (wayland_input_create(c) < 0)
|
||
|
return NULL;
|
||
|
|
||
|
loop = wl_display_get_event_loop(c->base.wl_display);
|
||
|
|
||
|
fd = wl_display_get_fd(c->parent.display, update_event_mask, c);
|
||
|
c->parent.wl_source =
|
||
|
wl_event_loop_add_fd(loop, fd, c->parent.event_mask,
|
||
|
wayland_compositor_handle_event, c);
|
||
|
if (c->parent.wl_source == NULL)
|
||
|
return NULL;
|
||
|
|
||
|
return &c->base;
|
||
|
}
|
||
14 years ago
|
|
||
13 years ago
|
struct weston_compositor *
|
||
14 years ago
|
backend_init(struct wl_display *display, char *options);
|
||
|
|
||
13 years ago
|
WL_EXPORT struct weston_compositor *
|
||
14 years ago
|
backend_init(struct wl_display *display, char *options)
|
||
|
{
|
||
|
int width = 1024, height = 640, i;
|
||
|
char *p, *value;
|
||
|
|
||
|
static char * const tokens[] = { "width", "height", NULL };
|
||
|
|
||
|
p = options;
|
||
|
while (i = getsubopt(&p, tokens, &value), i != -1) {
|
||
|
switch (i) {
|
||
|
case 0:
|
||
|
width = strtol(value, NULL, 0);
|
||
|
break;
|
||
|
case 1:
|
||
|
height = strtol(value, NULL, 0);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return wayland_compositor_create(display, width, height);
|
||
|
}
|