mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 18:09:49 +01:00
subcompositor: split out from compositor
This commit is contained in:
parent
6cdf843a8c
commit
b6f43ab2e1
7 changed files with 168 additions and 123 deletions
|
@ -14,16 +14,10 @@
|
|||
|
||||
struct wlr_surface;
|
||||
|
||||
struct wlr_subcompositor {
|
||||
struct wl_global *global;
|
||||
};
|
||||
|
||||
struct wlr_compositor {
|
||||
struct wl_global *global;
|
||||
struct wlr_renderer *renderer;
|
||||
|
||||
struct wlr_subcompositor subcompositor;
|
||||
|
||||
struct wl_listener display_destroy;
|
||||
|
||||
struct {
|
||||
|
@ -35,13 +29,4 @@ struct wlr_compositor {
|
|||
struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
|
||||
struct wlr_renderer *renderer);
|
||||
|
||||
bool wlr_surface_is_subsurface(struct wlr_surface *surface);
|
||||
|
||||
/**
|
||||
* Get a subsurface from a surface. Can return NULL if the subsurface has been
|
||||
* destroyed.
|
||||
*/
|
||||
struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
|
||||
struct wlr_surface *surface);
|
||||
|
||||
#endif
|
||||
|
|
37
include/wlr/types/wlr_subcompositor.h
Normal file
37
include/wlr/types/wlr_subcompositor.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* This an unstable interface of wlroots. No guarantees are made regarding the
|
||||
* future consistency of this API.
|
||||
*/
|
||||
#ifndef WLR_USE_UNSTABLE
|
||||
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
|
||||
#endif
|
||||
|
||||
#ifndef WLR_TYPES_WLR_SUBCOMPOSITOR_H
|
||||
#define WLR_TYPES_WLR_SUBCOMPOSITOR_H
|
||||
|
||||
#include <wayland-server-core.h>
|
||||
|
||||
struct wlr_surface;
|
||||
|
||||
struct wlr_subcompositor {
|
||||
struct wl_global *global;
|
||||
|
||||
struct wl_listener display_destroy;
|
||||
|
||||
struct {
|
||||
struct wl_signal destroy;
|
||||
} events;
|
||||
};
|
||||
|
||||
bool wlr_surface_is_subsurface(struct wlr_surface *surface);
|
||||
|
||||
/**
|
||||
* Get a subsurface from a surface. Can return NULL if the subsurface has been
|
||||
* destroyed.
|
||||
*/
|
||||
struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
|
||||
struct wlr_surface *surface);
|
||||
|
||||
struct wlr_subcompositor *wlr_subcompositor_create(struct wl_display *display);
|
||||
|
||||
#endif
|
|
@ -20,6 +20,7 @@
|
|||
#include <wlr/types/wlr_pointer.h>
|
||||
#include <wlr/types/wlr_scene.h>
|
||||
#include <wlr/types/wlr_seat.h>
|
||||
#include <wlr/types/wlr_subcompositor.h>
|
||||
#include <wlr/types/wlr_xcursor_manager.h>
|
||||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
@ -756,12 +757,14 @@ int main(int argc, char *argv[]) {
|
|||
server.renderer);
|
||||
|
||||
/* This creates some hands-off wlroots interfaces. The compositor is
|
||||
* necessary for clients to allocate surfaces and the data device manager
|
||||
* necessary for clients to allocate surfaces, the subcompositor allows to
|
||||
* assign the role of subsurfaces to surfaces and the data device manager
|
||||
* handles the clipboard. Each of these wlroots interfaces has room for you
|
||||
* to dig your fingers in and play with their behavior if you want. Note that
|
||||
* the clients cannot set the selection directly without compositor approval,
|
||||
* see the handling of the request_set_selection event below.*/
|
||||
wlr_compositor_create(server.wl_display, server.renderer);
|
||||
wlr_subcompositor_create(server.wl_display);
|
||||
wlr_data_device_manager_create(server.wl_display);
|
||||
|
||||
/* Creates an output layout, which a wlroots utility for working with an
|
||||
|
|
|
@ -58,6 +58,7 @@ wlr_files += files(
|
|||
'wlr_relative_pointer_v1.c',
|
||||
'wlr_screencopy_v1.c',
|
||||
'wlr_server_decoration.c',
|
||||
'wlr_subcompositor.c',
|
||||
'wlr_surface.c',
|
||||
'wlr_switch.c',
|
||||
'wlr_tablet_pad.c',
|
||||
|
|
|
@ -3,108 +3,11 @@
|
|||
#include <wayland-server-core.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "types/wlr_region.h"
|
||||
#include "types/wlr_surface.h"
|
||||
#include "util/signal.h"
|
||||
|
||||
#define COMPOSITOR_VERSION 4
|
||||
#define SUBCOMPOSITOR_VERSION 1
|
||||
|
||||
extern const struct wlr_surface_role subsurface_role;
|
||||
|
||||
bool wlr_surface_is_subsurface(struct wlr_surface *surface) {
|
||||
return surface->role == &subsurface_role;
|
||||
}
|
||||
|
||||
struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
|
||||
struct wlr_surface *surface) {
|
||||
assert(wlr_surface_is_subsurface(surface));
|
||||
return (struct wlr_subsurface *)surface->role_data;
|
||||
}
|
||||
|
||||
static void subcompositor_handle_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static void subcompositor_handle_get_subsurface(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t id,
|
||||
struct wl_resource *surface_resource,
|
||||
struct wl_resource *parent_resource) {
|
||||
struct wlr_surface *surface = wlr_surface_from_resource(surface_resource);
|
||||
struct wlr_surface *parent = wlr_surface_from_resource(parent_resource);
|
||||
|
||||
static const char msg[] = "get_subsurface: wl_subsurface@";
|
||||
|
||||
if (surface == parent) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||
"%s%" PRIu32 ": wl_surface@%" PRIu32 " cannot be its own parent",
|
||||
msg, id, wl_resource_get_id(surface_resource));
|
||||
return;
|
||||
}
|
||||
|
||||
if (wlr_surface_is_subsurface(surface) &&
|
||||
wlr_subsurface_from_wlr_surface(surface) != NULL) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is already a sub-surface",
|
||||
msg, id, wl_resource_get_id(surface_resource));
|
||||
return;
|
||||
}
|
||||
|
||||
if (wlr_surface_get_root_surface(parent) == surface) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is an ancestor of parent",
|
||||
msg, id, wl_resource_get_id(surface_resource));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wlr_surface_set_role(surface, &subsurface_role, NULL,
|
||||
resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
subsurface_create(surface, parent, wl_resource_get_version(resource), id);
|
||||
}
|
||||
|
||||
static const struct wl_subcompositor_interface subcompositor_impl = {
|
||||
.destroy = subcompositor_handle_destroy,
|
||||
.get_subsurface = subcompositor_handle_get_subsurface,
|
||||
};
|
||||
|
||||
static void subcompositor_bind(struct wl_client *client, void *data,
|
||||
uint32_t version, uint32_t id) {
|
||||
struct wlr_subcompositor *subcompositor = data;
|
||||
struct wl_resource *resource =
|
||||
wl_resource_create(client, &wl_subcompositor_interface, 1, id);
|
||||
if (resource == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &subcompositor_impl,
|
||||
subcompositor, NULL);
|
||||
}
|
||||
|
||||
static bool subcompositor_init(struct wlr_subcompositor *subcompositor,
|
||||
struct wl_display *display) {
|
||||
subcompositor->global = wl_global_create(display,
|
||||
&wl_subcompositor_interface, SUBCOMPOSITOR_VERSION, subcompositor,
|
||||
subcompositor_bind);
|
||||
if (subcompositor->global == NULL) {
|
||||
wlr_log_errno(WLR_ERROR, "Could not allocate subcompositor global");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void subcompositor_finish(struct wlr_subcompositor *subcompositor) {
|
||||
wl_global_destroy(subcompositor->global);
|
||||
}
|
||||
|
||||
|
||||
static const struct wl_compositor_interface compositor_impl;
|
||||
|
||||
|
@ -152,11 +55,11 @@ static void compositor_bind(struct wl_client *wl_client, void *data,
|
|||
wl_resource_set_implementation(resource, &compositor_impl, compositor, NULL);
|
||||
}
|
||||
|
||||
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
||||
static void compositor_handle_display_destroy(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_compositor *compositor =
|
||||
wl_container_of(listener, compositor, display_destroy);
|
||||
wlr_signal_emit_safe(&compositor->events.destroy, compositor);
|
||||
subcompositor_finish(&compositor->subcompositor);
|
||||
wlr_signal_emit_safe(&compositor->events.destroy, NULL);
|
||||
wl_list_remove(&compositor->display_destroy.link);
|
||||
wl_global_destroy(compositor->global);
|
||||
free(compositor);
|
||||
|
@ -164,10 +67,8 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
|||
|
||||
struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
|
||||
struct wlr_renderer *renderer) {
|
||||
struct wlr_compositor *compositor =
|
||||
calloc(1, sizeof(struct wlr_compositor));
|
||||
struct wlr_compositor *compositor = calloc(1, sizeof(*compositor));
|
||||
if (!compositor) {
|
||||
wlr_log_errno(WLR_ERROR, "Could not allocate wlr compositor");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -175,7 +76,6 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
|
|||
COMPOSITOR_VERSION, compositor, compositor_bind);
|
||||
if (!compositor->global) {
|
||||
free(compositor);
|
||||
wlr_log_errno(WLR_ERROR, "Could not allocate compositor global");
|
||||
return NULL;
|
||||
}
|
||||
compositor->renderer = renderer;
|
||||
|
@ -183,9 +83,7 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
|
|||
wl_signal_init(&compositor->events.new_surface);
|
||||
wl_signal_init(&compositor->events.destroy);
|
||||
|
||||
subcompositor_init(&compositor->subcompositor, display);
|
||||
|
||||
compositor->display_destroy.notify = handle_display_destroy;
|
||||
compositor->display_destroy.notify = compositor_handle_display_destroy;
|
||||
wl_display_add_destroy_listener(display, &compositor->display_destroy);
|
||||
|
||||
return compositor;
|
||||
|
|
120
types/wlr_subcompositor.c
Normal file
120
types/wlr_subcompositor.c
Normal file
|
@ -0,0 +1,120 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-server-core.h>
|
||||
#include <wlr/types/wlr_subcompositor.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include "types/wlr_region.h"
|
||||
#include "types/wlr_surface.h"
|
||||
#include "util/signal.h"
|
||||
|
||||
#define SUBCOMPOSITOR_VERSION 1
|
||||
|
||||
extern const struct wlr_surface_role subsurface_role;
|
||||
|
||||
bool wlr_surface_is_subsurface(struct wlr_surface *surface) {
|
||||
return surface->role == &subsurface_role;
|
||||
}
|
||||
|
||||
struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
|
||||
struct wlr_surface *surface) {
|
||||
assert(wlr_surface_is_subsurface(surface));
|
||||
return (struct wlr_subsurface *)surface->role_data;
|
||||
}
|
||||
|
||||
static void subcompositor_handle_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static void subcompositor_handle_get_subsurface(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t id,
|
||||
struct wl_resource *surface_resource,
|
||||
struct wl_resource *parent_resource) {
|
||||
struct wlr_surface *surface = wlr_surface_from_resource(surface_resource);
|
||||
struct wlr_surface *parent = wlr_surface_from_resource(parent_resource);
|
||||
|
||||
static const char msg[] = "get_subsurface: wl_subsurface@";
|
||||
|
||||
if (surface == parent) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||
"%s%" PRIu32 ": wl_surface@%" PRIu32 " cannot be its own parent",
|
||||
msg, id, wl_resource_get_id(surface_resource));
|
||||
return;
|
||||
}
|
||||
|
||||
if (wlr_surface_is_subsurface(surface) &&
|
||||
wlr_subsurface_from_wlr_surface(surface) != NULL) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is already a sub-surface",
|
||||
msg, id, wl_resource_get_id(surface_resource));
|
||||
return;
|
||||
}
|
||||
|
||||
if (wlr_surface_get_root_surface(parent) == surface) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is an ancestor of parent",
|
||||
msg, id, wl_resource_get_id(surface_resource));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wlr_surface_set_role(surface, &subsurface_role, NULL,
|
||||
resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
subsurface_create(surface, parent, wl_resource_get_version(resource), id);
|
||||
}
|
||||
|
||||
static const struct wl_subcompositor_interface subcompositor_impl = {
|
||||
.destroy = subcompositor_handle_destroy,
|
||||
.get_subsurface = subcompositor_handle_get_subsurface,
|
||||
};
|
||||
|
||||
static void subcompositor_bind(struct wl_client *client, void *data,
|
||||
uint32_t version, uint32_t id) {
|
||||
struct wlr_subcompositor *subcompositor = data;
|
||||
struct wl_resource *resource =
|
||||
wl_resource_create(client, &wl_subcompositor_interface, 1, id);
|
||||
if (resource == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(resource, &subcompositor_impl,
|
||||
subcompositor, NULL);
|
||||
}
|
||||
|
||||
static void subcompositor_handle_display_destroy(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_subcompositor *subcompositor =
|
||||
wl_container_of(listener, subcompositor, display_destroy);
|
||||
wlr_signal_emit_safe(&subcompositor->events.destroy, NULL);
|
||||
wl_list_remove(&subcompositor->display_destroy.link);
|
||||
wl_global_destroy(subcompositor->global);
|
||||
free(subcompositor);
|
||||
}
|
||||
|
||||
struct wlr_subcompositor *wlr_subcompositor_create(struct wl_display *display) {
|
||||
struct wlr_subcompositor *subcompositor =
|
||||
calloc(1, sizeof(*subcompositor));
|
||||
if (!subcompositor) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
subcompositor->global = wl_global_create(display,
|
||||
&wl_subcompositor_interface, SUBCOMPOSITOR_VERSION,
|
||||
subcompositor, subcompositor_bind);
|
||||
if (!subcompositor->global) {
|
||||
free(subcompositor);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wl_signal_init(&subcompositor->events.destroy);
|
||||
|
||||
subcompositor->display_destroy.notify = subcompositor_handle_display_destroy;
|
||||
wl_display_add_destroy_listener(display, &subcompositor->display_destroy);
|
||||
|
||||
return subcompositor;
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_matrix.h>
|
||||
#include <wlr/types/wlr_region.h>
|
||||
#include <wlr/types/wlr_subcompositor.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
|
Loading…
Reference in a new issue