2017-06-29 00:51:58 +02:00
|
|
|
#include <assert.h>
|
2017-08-09 15:33:30 +02:00
|
|
|
#include <stdlib.h>
|
2019-07-27 10:53:54 +02:00
|
|
|
#include <wayland-server-core.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
|
|
|
#include <wlr/types/wlr_surface.h>
|
2021-01-18 12:31:20 +01:00
|
|
|
#include "types/wlr_region.h"
|
2021-03-30 10:17:15 +02:00
|
|
|
#include "types/wlr_surface.h"
|
2018-02-12 19:45:58 +01:00
|
|
|
#include "util/signal.h"
|
2017-08-04 17:53:55 +02:00
|
|
|
|
2018-04-30 23:20:11 +02:00
|
|
|
#define COMPOSITOR_VERSION 4
|
2018-04-21 20:02:39 +02:00
|
|
|
|
2018-04-25 00:31:58 +02:00
|
|
|
static const struct wl_compositor_interface compositor_impl;
|
2018-02-13 23:48:46 +01:00
|
|
|
|
2018-04-21 20:02:39 +02:00
|
|
|
static struct wlr_compositor *compositor_from_resource(
|
|
|
|
struct wl_resource *resource) {
|
2018-02-13 23:48:46 +01:00
|
|
|
assert(wl_resource_instance_of(resource, &wl_compositor_interface,
|
2018-04-25 00:31:58 +02:00
|
|
|
&compositor_impl));
|
2018-02-13 23:48:46 +01:00
|
|
|
return wl_resource_get_user_data(resource);
|
|
|
|
}
|
|
|
|
|
2018-04-30 23:20:11 +02:00
|
|
|
static void compositor_create_surface(struct wl_client *client,
|
2017-08-03 15:50:45 +02:00
|
|
|
struct wl_resource *resource, uint32_t id) {
|
2018-02-13 23:48:46 +01:00
|
|
|
struct wlr_compositor *compositor = compositor_from_resource(resource);
|
2017-11-02 23:14:24 +01:00
|
|
|
|
2021-03-30 10:17:15 +02:00
|
|
|
struct wlr_surface *surface = surface_create(client,
|
2021-03-30 10:19:29 +02:00
|
|
|
wl_resource_get_version(resource), id, compositor->renderer);
|
2017-11-02 23:14:24 +01:00
|
|
|
if (surface == NULL) {
|
2019-09-17 23:25:00 +02:00
|
|
|
wl_client_post_no_memory(client);
|
2017-11-02 23:14:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-08-10 12:42:35 +02:00
|
|
|
|
2018-02-12 09:12:31 +01:00
|
|
|
wlr_signal_emit_safe(&compositor->events.new_surface, surface);
|
2017-06-29 00:51:58 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 23:20:11 +02:00
|
|
|
static void compositor_create_region(struct wl_client *client,
|
2017-08-03 15:50:45 +02:00
|
|
|
struct wl_resource *resource, uint32_t id) {
|
2021-01-18 12:33:37 +01:00
|
|
|
region_create(client, wl_resource_get_version(resource), id);
|
2017-06-29 00:51:58 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 00:31:58 +02:00
|
|
|
static const struct wl_compositor_interface compositor_impl = {
|
2018-04-30 23:20:11 +02:00
|
|
|
.create_surface = compositor_create_surface,
|
|
|
|
.create_region = compositor_create_region,
|
2017-06-29 00:51:58 +02:00
|
|
|
};
|
|
|
|
|
2018-04-30 23:20:11 +02:00
|
|
|
static void compositor_bind(struct wl_client *wl_client, void *data,
|
2017-06-29 00:51:58 +02:00
|
|
|
uint32_t version, uint32_t id) {
|
2017-11-02 23:14:24 +01:00
|
|
|
struct wlr_compositor *compositor = data;
|
2017-10-22 11:18:27 +02:00
|
|
|
|
2018-04-21 20:02:39 +02:00
|
|
|
struct wl_resource *resource =
|
2017-09-23 22:21:18 +02:00
|
|
|
wl_resource_create(wl_client, &wl_compositor_interface, version, id);
|
2018-04-21 20:02:39 +02:00
|
|
|
if (resource == NULL) {
|
2017-11-02 23:14:24 +01:00
|
|
|
wl_client_post_no_memory(wl_client);
|
|
|
|
return;
|
|
|
|
}
|
2019-11-16 18:31:33 +01:00
|
|
|
wl_resource_set_implementation(resource, &compositor_impl, compositor, NULL);
|
2017-06-29 00:51:58 +02:00
|
|
|
}
|
|
|
|
|
2022-01-13 09:55:09 +01:00
|
|
|
static void compositor_handle_display_destroy(
|
|
|
|
struct wl_listener *listener, void *data) {
|
2019-11-16 18:31:33 +01:00
|
|
|
struct wlr_compositor *compositor =
|
|
|
|
wl_container_of(listener, compositor, display_destroy);
|
2022-01-13 09:55:09 +01:00
|
|
|
wlr_signal_emit_safe(&compositor->events.destroy, NULL);
|
2017-12-07 00:44:45 +01:00
|
|
|
wl_list_remove(&compositor->display_destroy.link);
|
2018-07-08 20:21:31 +02:00
|
|
|
wl_global_destroy(compositor->global);
|
2017-08-19 23:16:19 +02:00
|
|
|
free(compositor);
|
2017-08-19 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2017-08-19 23:16:19 +02:00
|
|
|
struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
|
|
|
|
struct wlr_renderer *renderer) {
|
2022-01-13 09:55:09 +01:00
|
|
|
struct wlr_compositor *compositor = calloc(1, sizeof(*compositor));
|
2017-08-19 23:16:19 +02:00
|
|
|
if (!compositor) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-09-24 12:04:29 +02:00
|
|
|
|
2018-07-08 20:21:31 +02:00
|
|
|
compositor->global = wl_global_create(display, &wl_compositor_interface,
|
2018-04-30 23:20:11 +02:00
|
|
|
COMPOSITOR_VERSION, compositor, compositor_bind);
|
2018-07-08 20:21:31 +02:00
|
|
|
if (!compositor->global) {
|
2017-12-07 00:44:45 +01:00
|
|
|
free(compositor);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-19 21:48:20 +02:00
|
|
|
compositor->renderer = renderer;
|
2017-09-24 12:04:29 +02:00
|
|
|
|
2018-01-21 14:22:33 +01:00
|
|
|
wl_signal_init(&compositor->events.new_surface);
|
2018-02-23 10:20:53 +01:00
|
|
|
wl_signal_init(&compositor->events.destroy);
|
2017-09-24 12:04:29 +02:00
|
|
|
|
2022-01-13 09:55:09 +01:00
|
|
|
compositor->display_destroy.notify = compositor_handle_display_destroy;
|
2017-12-07 00:44:45 +01:00
|
|
|
wl_display_add_destroy_listener(display, &compositor->display_destroy);
|
|
|
|
|
2017-08-19 23:16:19 +02:00
|
|
|
return compositor;
|
2017-06-29 00:51:58 +02:00
|
|
|
}
|