move wl_compositor into wlroots as wlr_compositor

This commit is contained in:
Dominique Martinet 2017-08-19 21:48:20 +02:00
parent b876bea288
commit 4110788159
5 changed files with 36 additions and 33 deletions

View file

@ -18,17 +18,17 @@
#include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_data_device_manager.h>
#include "wlr/types/wlr_compositor.h"
#include <xkbcommon/xkbcommon.h>
#include <wlr/util/log.h>
#include "shared.h"
#include "compositor.h"
// TODO: move to common header?
int os_create_anonymous_file(off_t size);
struct sample_state {
struct wlr_renderer *renderer;
struct wl_compositor_state compositor;
struct wlr_compositor compositor;
struct wlr_wl_shell *wl_shell;
struct wlr_seat *wl_seat;
struct wlr_xdg_shell_v6 *xdg_shell;
@ -153,7 +153,7 @@ int main() {
exit(EXIT_FAILURE);
}
wl_display_init_shm(compositor.display);
wl_compositor_init(compositor.display, &state.compositor, state.renderer);
wlr_compositor_init(&state.compositor, compositor.display, state.renderer);
state.wl_shell = wlr_wl_shell_create(compositor.display);
state.xdg_shell = wlr_xdg_shell_v6_create(compositor.display);
state.data_device_manager = wlr_data_device_manager_create(compositor.display);
@ -185,6 +185,7 @@ int main() {
wlr_data_device_manager_destroy(state.data_device_manager);
wlr_xdg_shell_v6_destroy(state.xdg_shell);
wlr_wl_shell_destroy(state.wl_shell);
wlr_compositor_finish(&state.compositor);
wlr_renderer_destroy(state.renderer);
compositor_fini(&compositor);
}

View file

@ -1,20 +0,0 @@
#ifndef _EXAMPLE_COMPOSITOR_H
#define _EXAMPLE_COMPOSITOR_H
#include <wayland-server.h>
#include <wlr/render.h>
struct wl_compositor_state {
struct wl_global *wl_global;
struct wl_list wl_resources;
struct wlr_renderer *renderer;
struct wl_list surfaces;
struct wl_listener destroy_surface_listener;
};
void wl_compositor_init(struct wl_display *display,
struct wl_compositor_state *state, struct wlr_renderer *renderer);
struct wlr_surface;
void wl_compositor_surface_destroyed(struct wl_compositor_state *compositor,
struct wlr_surface *surface);
#endif

View file

@ -1,72 +0,0 @@
#include <assert.h>
#include <stdlib.h>
#include <wayland-server.h>
#include <wlr/util/log.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_region.h>
#include "compositor.h"
static void destroy_surface_listener(struct wl_listener *listener, void *data) {
wl_list_remove(wl_resource_get_link(data));
}
static void wl_compositor_create_surface(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
struct wl_compositor_state *state = wl_resource_get_user_data(resource);
struct wl_resource *surface_resource = wl_resource_create(client,
&wl_surface_interface, wl_resource_get_version(resource), id);
struct wlr_surface *surface = wlr_surface_create(surface_resource, state->renderer);
surface->compositor_data = state;
surface->compositor_listener.notify = &destroy_surface_listener;
wl_resource_add_destroy_listener(surface_resource, &surface->compositor_listener);
wl_list_insert(&state->surfaces, wl_resource_get_link(surface_resource));
}
static void wl_compositor_create_region(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
wlr_region_create(client, resource, id);
}
struct wl_compositor_interface wl_compositor_impl = {
.create_surface = wl_compositor_create_surface,
.create_region = wl_compositor_create_region
};
static void wl_compositor_destroy(struct wl_resource *resource) {
struct wl_compositor_state *state = wl_resource_get_user_data(resource);
struct wl_resource *_resource = NULL;
wl_resource_for_each(_resource, &state->wl_resources) {
if (_resource == resource) {
struct wl_list *link = wl_resource_get_link(_resource);
wl_list_remove(link);
break;
}
}
}
static void wl_compositor_bind(struct wl_client *wl_client, void *_state,
uint32_t version, uint32_t id) {
struct wl_compositor_state *state = _state;
assert(wl_client && state);
if (version > 4) {
wlr_log(L_ERROR, "Client requested unsupported wl_compositor version, disconnecting");
wl_client_destroy(wl_client);
return;
}
struct wl_resource *wl_resource = wl_resource_create(
wl_client, &wl_compositor_interface, version, id);
wl_resource_set_implementation(wl_resource, &wl_compositor_impl,
state, wl_compositor_destroy);
wl_list_insert(&state->wl_resources, wl_resource_get_link(wl_resource));
}
void wl_compositor_init(struct wl_display *display,
struct wl_compositor_state *state, struct wlr_renderer *renderer) {
struct wl_global *wl_global = wl_global_create(display,
&wl_compositor_interface, 4, state, wl_compositor_bind);
state->wl_global = wl_global;
state->renderer = renderer;
wl_list_init(&state->wl_resources);
wl_list_init(&state->surfaces);
}

View file

@ -9,11 +9,6 @@ executable('touch', 'touch.c', dependencies: wlroots, link_with: lib_shared)
executable('tablet', 'tablet.c', dependencies: wlroots, link_with: lib_shared)
executable('output-layout', 'output-layout.c', dependencies: wlroots, link_with: lib_shared)
compositor_src = [
'compositor/main.c',
'compositor/wl_compositor.c',
]
executable('compositor', compositor_src,
executable('compositor', 'compositor.c',
dependencies: wlroots,
link_with: lib_shared)