mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-23 05:15:58 +01:00
compositor, surface: correctly destroy resources
This commit is contained in:
parent
8676155ae1
commit
6d569def6d
2 changed files with 68 additions and 48 deletions
|
@ -7,6 +7,9 @@
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
|
|
||||||
|
#define COMPOSITOR_VERSION 4
|
||||||
|
#define SUBCOMPOSITOR_VERSION 1
|
||||||
|
|
||||||
static const char *subsurface_role = "wl_subsurface";
|
static const char *subsurface_role = "wl_subsurface";
|
||||||
|
|
||||||
bool wlr_surface_is_subsurface(struct wlr_surface *surface) {
|
bool wlr_surface_is_subsurface(struct wlr_surface *surface) {
|
||||||
|
@ -105,7 +108,8 @@ static void subcompositor_bind(struct wl_client *client, void *data,
|
||||||
static void subcompositor_init(struct wlr_subcompositor *subcompositor,
|
static void subcompositor_init(struct wlr_subcompositor *subcompositor,
|
||||||
struct wl_display *display) {
|
struct wl_display *display) {
|
||||||
subcompositor->wl_global = wl_global_create(display,
|
subcompositor->wl_global = wl_global_create(display,
|
||||||
&wl_subcompositor_interface, 1, subcompositor, subcompositor_bind);
|
&wl_subcompositor_interface, SUBCOMPOSITOR_VERSION, subcompositor,
|
||||||
|
subcompositor_bind);
|
||||||
if (subcompositor->wl_global == NULL) {
|
if (subcompositor->wl_global == NULL) {
|
||||||
wlr_log_errno(L_ERROR, "Could not allocate subcompositor global");
|
wlr_log_errno(L_ERROR, "Could not allocate subcompositor global");
|
||||||
return;
|
return;
|
||||||
|
@ -136,7 +140,7 @@ static struct wlr_compositor *compositor_from_resource(
|
||||||
return wl_resource_get_user_data(resource);
|
return wl_resource_get_user_data(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wl_compositor_create_surface(struct wl_client *client,
|
static void compositor_create_surface(struct wl_client *client,
|
||||||
struct wl_resource *resource, uint32_t id) {
|
struct wl_resource *resource, uint32_t id) {
|
||||||
struct wlr_compositor *compositor = compositor_from_resource(resource);
|
struct wlr_compositor *compositor = compositor_from_resource(resource);
|
||||||
|
|
||||||
|
@ -150,7 +154,7 @@ static void wl_compositor_create_surface(struct wl_client *client,
|
||||||
wlr_signal_emit_safe(&compositor->events.new_surface, surface);
|
wlr_signal_emit_safe(&compositor->events.new_surface, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wl_compositor_create_region(struct wl_client *client,
|
static void compositor_create_region(struct wl_client *client,
|
||||||
struct wl_resource *resource, uint32_t id) {
|
struct wl_resource *resource, uint32_t id) {
|
||||||
struct wlr_compositor *compositor = compositor_from_resource(resource);
|
struct wlr_compositor *compositor = compositor_from_resource(resource);
|
||||||
|
|
||||||
|
@ -158,15 +162,15 @@ static void wl_compositor_create_region(struct wl_client *client,
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wl_compositor_interface compositor_impl = {
|
static const struct wl_compositor_interface compositor_impl = {
|
||||||
.create_surface = wl_compositor_create_surface,
|
.create_surface = compositor_create_surface,
|
||||||
.create_region = wl_compositor_create_region,
|
.create_region = compositor_create_region,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void compositor_resource_destroy(struct wl_resource *resource) {
|
static void compositor_resource_destroy(struct wl_resource *resource) {
|
||||||
wl_list_remove(wl_resource_get_link(resource));
|
wl_list_remove(wl_resource_get_link(resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wl_compositor_bind(struct wl_client *wl_client, void *data,
|
static void compositor_bind(struct wl_client *wl_client, void *data,
|
||||||
uint32_t version, uint32_t id) {
|
uint32_t version, uint32_t id) {
|
||||||
struct wlr_compositor *compositor = data;
|
struct wlr_compositor *compositor = data;
|
||||||
assert(wl_client && compositor);
|
assert(wl_client && compositor);
|
||||||
|
@ -218,14 +222,13 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wl_global *compositor_global = wl_global_create(display,
|
compositor->wl_global = wl_global_create(display, &wl_compositor_interface,
|
||||||
&wl_compositor_interface, 4, compositor, wl_compositor_bind);
|
COMPOSITOR_VERSION, compositor, compositor_bind);
|
||||||
if (!compositor_global) {
|
if (!compositor->wl_global) {
|
||||||
wlr_log_errno(L_ERROR, "Could not allocate compositor global");
|
|
||||||
free(compositor);
|
free(compositor);
|
||||||
|
wlr_log_errno(L_ERROR, "Could not allocate compositor global");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
compositor->wl_global = compositor_global;
|
|
||||||
compositor->renderer = renderer;
|
compositor->renderer = renderer;
|
||||||
|
|
||||||
wl_list_init(&compositor->wl_resources);
|
wl_list_init(&compositor->wl_resources);
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
#include <wlr/util/region.h>
|
#include <wlr/util/region.h>
|
||||||
#include "util/signal.h"
|
#include "util/signal.h"
|
||||||
|
|
||||||
|
#define CALLBACK_VERSION 1
|
||||||
|
#define SURFACE_VERSION 4
|
||||||
|
#define SUBSURFACE_VERSION 1
|
||||||
|
|
||||||
static void surface_state_reset_buffer(struct wlr_surface_state *state) {
|
static void surface_state_reset_buffer(struct wlr_surface_state *state) {
|
||||||
if (state->buffer) {
|
if (state->buffer) {
|
||||||
wl_list_remove(&state->buffer_destroy_listener.link);
|
wl_list_remove(&state->buffer_destroy_listener.link);
|
||||||
|
@ -18,29 +22,29 @@ static void surface_state_reset_buffer(struct wlr_surface_state *state) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buffer_destroy(struct wl_listener *listener, void *data) {
|
static void surface_handle_buffer_destroy(struct wl_listener *listener,
|
||||||
|
void *data) {
|
||||||
struct wlr_surface_state *state =
|
struct wlr_surface_state *state =
|
||||||
wl_container_of(listener, state, buffer_destroy_listener);
|
wl_container_of(listener, state, buffer_destroy_listener);
|
||||||
|
surface_state_reset_buffer(state);
|
||||||
wl_list_remove(&state->buffer_destroy_listener.link);
|
|
||||||
state->buffer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void surface_state_release_buffer(struct wlr_surface_state *state) {
|
static void surface_state_release_buffer(struct wlr_surface_state *state) {
|
||||||
if (state->buffer) {
|
if (state->buffer) {
|
||||||
wl_resource_post_event(state->buffer, WL_BUFFER_RELEASE);
|
wl_resource_post_event(state->buffer, WL_BUFFER_RELEASE);
|
||||||
wl_list_remove(&state->buffer_destroy_listener.link);
|
surface_state_reset_buffer(state);
|
||||||
state->buffer = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void surface_state_set_buffer(struct wlr_surface_state *state,
|
static void surface_state_set_buffer(struct wlr_surface_state *state,
|
||||||
struct wl_resource *buffer) {
|
struct wl_resource *buffer) {
|
||||||
|
surface_state_reset_buffer(state);
|
||||||
|
|
||||||
state->buffer = buffer;
|
state->buffer = buffer;
|
||||||
if (buffer) {
|
if (buffer) {
|
||||||
wl_resource_add_destroy_listener(buffer,
|
wl_resource_add_destroy_listener(buffer,
|
||||||
&state->buffer_destroy_listener);
|
&state->buffer_destroy_listener);
|
||||||
state->buffer_destroy_listener.notify = buffer_destroy;
|
state->buffer_destroy_listener.notify = surface_handle_buffer_destroy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +61,6 @@ static void surface_attach(struct wl_client *client,
|
||||||
surface->pending->invalid |= WLR_SURFACE_INVALID_BUFFER;
|
surface->pending->invalid |= WLR_SURFACE_INVALID_BUFFER;
|
||||||
surface->pending->sx = sx;
|
surface->pending->sx = sx;
|
||||||
surface->pending->sy = sy;
|
surface->pending->sy = sy;
|
||||||
surface_state_reset_buffer(surface->pending);
|
|
||||||
surface_state_set_buffer(surface->pending, buffer);
|
surface_state_set_buffer(surface->pending, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +83,7 @@ static struct wlr_frame_callback *frame_callback_from_resource(
|
||||||
return wl_resource_get_user_data(resource);
|
return wl_resource_get_user_data(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy_frame_callback(struct wl_resource *resource) {
|
static void callback_handle_resource_destroy(struct wl_resource *resource) {
|
||||||
struct wlr_frame_callback *cb = frame_callback_from_resource(resource);
|
struct wlr_frame_callback *cb = frame_callback_from_resource(resource);
|
||||||
wl_list_remove(&cb->link);
|
wl_list_remove(&cb->link);
|
||||||
free(cb);
|
free(cb);
|
||||||
|
@ -97,16 +100,15 @@ static void surface_frame(struct wl_client *client,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cb->resource = wl_resource_create(client, &wl_callback_interface, 1,
|
cb->resource = wl_resource_create(client, &wl_callback_interface,
|
||||||
callback);
|
CALLBACK_VERSION, callback);
|
||||||
if (cb->resource == NULL) {
|
if (cb->resource == NULL) {
|
||||||
free(cb);
|
free(cb);
|
||||||
wl_resource_post_no_memory(resource);
|
wl_resource_post_no_memory(resource);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_resource_set_implementation(cb->resource, NULL, cb,
|
wl_resource_set_implementation(cb->resource, NULL, cb,
|
||||||
destroy_frame_callback);
|
callback_handle_resource_destroy);
|
||||||
|
|
||||||
wl_list_insert(surface->pending->frame_callback_list.prev, &cb->link);
|
wl_list_insert(surface->pending->frame_callback_list.prev, &cb->link);
|
||||||
|
|
||||||
|
@ -548,7 +550,7 @@ static void surface_damage_buffer(struct wl_client *client,
|
||||||
x, y, width, height);
|
x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct wl_surface_interface surface_interface = {
|
static const struct wl_surface_interface surface_interface = {
|
||||||
.destroy = surface_destroy,
|
.destroy = surface_destroy,
|
||||||
.attach = surface_attach,
|
.attach = surface_attach,
|
||||||
.damage = surface_damage,
|
.damage = surface_damage,
|
||||||
|
@ -584,7 +586,6 @@ static struct wlr_surface_state *surface_state_create() {
|
||||||
pixman_region32_init_rect(&state->input,
|
pixman_region32_init_rect(&state->input,
|
||||||
INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX);
|
INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX);
|
||||||
|
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,6 +605,10 @@ static void surface_state_destroy(struct wlr_surface_state *state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void subsurface_destroy(struct wlr_subsurface *subsurface) {
|
static void subsurface_destroy(struct wlr_subsurface *subsurface) {
|
||||||
|
if (subsurface == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wlr_signal_emit_safe(&subsurface->events.destroy, subsurface);
|
wlr_signal_emit_safe(&subsurface->events.destroy, subsurface);
|
||||||
|
|
||||||
wl_list_remove(&subsurface->surface_destroy.link);
|
wl_list_remove(&subsurface->surface_destroy.link);
|
||||||
|
@ -615,8 +620,6 @@ static void subsurface_destroy(struct wlr_subsurface *subsurface) {
|
||||||
wl_list_remove(&subsurface->parent_destroy.link);
|
wl_list_remove(&subsurface->parent_destroy.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_list_remove(wl_resource_get_link(subsurface->resource));
|
|
||||||
|
|
||||||
wl_resource_set_user_data(subsurface->resource, NULL);
|
wl_resource_set_user_data(subsurface->resource, NULL);
|
||||||
if (subsurface->surface) {
|
if (subsurface->surface) {
|
||||||
subsurface->surface->role_data = NULL;
|
subsurface->surface->role_data = NULL;
|
||||||
|
@ -649,6 +652,8 @@ static void surface_handle_renderer_destroy(struct wl_listener *listener,
|
||||||
struct wlr_surface *wlr_surface_create(struct wl_client *client,
|
struct wlr_surface *wlr_surface_create(struct wl_client *client,
|
||||||
uint32_t version, uint32_t id, struct wlr_renderer *renderer,
|
uint32_t version, uint32_t id, struct wlr_renderer *renderer,
|
||||||
struct wl_list *resource_list) {
|
struct wl_list *resource_list) {
|
||||||
|
assert(version <= SURFACE_VERSION);
|
||||||
|
|
||||||
struct wlr_surface *surface = calloc(1, sizeof(struct wlr_surface));
|
struct wlr_surface *surface = calloc(1, sizeof(struct wlr_surface));
|
||||||
if (!surface) {
|
if (!surface) {
|
||||||
wl_client_post_no_memory(client);
|
wl_client_post_no_memory(client);
|
||||||
|
@ -726,24 +731,24 @@ static struct wlr_subsurface *subsurface_from_resource(
|
||||||
|
|
||||||
static void subsurface_resource_destroy(struct wl_resource *resource) {
|
static void subsurface_resource_destroy(struct wl_resource *resource) {
|
||||||
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
||||||
|
wl_list_remove(wl_resource_get_link(resource));
|
||||||
if (subsurface) {
|
|
||||||
subsurface_destroy(subsurface);
|
subsurface_destroy(subsurface);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void subsurface_handle_destroy(struct wl_client *client,
|
static void subsurface_handle_destroy(struct wl_client *client,
|
||||||
struct wl_resource *resource) {
|
struct wl_resource *resource) {
|
||||||
wl_resource_destroy(resource);
|
wl_resource_destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void subsurface_set_position(struct wl_client *client,
|
static void subsurface_handle_set_position(struct wl_client *client,
|
||||||
struct wl_resource *resource, int32_t x, int32_t y) {
|
struct wl_resource *resource, int32_t x, int32_t y) {
|
||||||
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
||||||
|
if (subsurface == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
struct wlr_surface *surface = subsurface->surface;
|
struct wlr_surface *surface = subsurface->surface;
|
||||||
|
|
||||||
surface->pending->invalid |= WLR_SURFACE_INVALID_SUBSURFACE_POSITION;
|
surface->pending->invalid |= WLR_SURFACE_INVALID_SUBSURFACE_POSITION;
|
||||||
|
|
||||||
surface->pending->subsurface_position.x = x;
|
surface->pending->subsurface_position.x = x;
|
||||||
surface->pending->subsurface_position.y = y;
|
surface->pending->subsurface_position.y = y;
|
||||||
}
|
}
|
||||||
|
@ -762,9 +767,12 @@ static struct wlr_subsurface *subsurface_find_sibling(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void subsurface_place_above(struct wl_client *client,
|
static void subsurface_handle_place_above(struct wl_client *client,
|
||||||
struct wl_resource *resource, struct wl_resource *sibling_resource) {
|
struct wl_resource *resource, struct wl_resource *sibling_resource) {
|
||||||
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
||||||
|
if (subsurface == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
struct wlr_surface *sibling_surface =
|
struct wlr_surface *sibling_surface =
|
||||||
wlr_surface_from_resource(sibling_resource);
|
wlr_surface_from_resource(sibling_resource);
|
||||||
|
@ -786,9 +794,12 @@ static void subsurface_place_above(struct wl_client *client,
|
||||||
subsurface->reordered = true;
|
subsurface->reordered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void subsurface_place_below(struct wl_client *client,
|
static void subsurface_handle_place_below(struct wl_client *client,
|
||||||
struct wl_resource *resource, struct wl_resource *sibling_resource) {
|
struct wl_resource *resource, struct wl_resource *sibling_resource) {
|
||||||
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
||||||
|
if (subsurface == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
struct wlr_surface *sibling_surface =
|
struct wlr_surface *sibling_surface =
|
||||||
wlr_surface_from_resource(sibling_resource);
|
wlr_surface_from_resource(sibling_resource);
|
||||||
|
@ -810,20 +821,24 @@ static void subsurface_place_below(struct wl_client *client,
|
||||||
subsurface->reordered = true;
|
subsurface->reordered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void subsurface_set_sync(struct wl_client *client,
|
static void subsurface_handle_set_sync(struct wl_client *client,
|
||||||
struct wl_resource *resource) {
|
struct wl_resource *resource) {
|
||||||
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
||||||
|
if (subsurface == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (subsurface) {
|
|
||||||
subsurface->synchronized = true;
|
subsurface->synchronized = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void subsurface_set_desync(struct wl_client *client,
|
static void subsurface_handle_set_desync(struct wl_client *client,
|
||||||
struct wl_resource *resource) {
|
struct wl_resource *resource) {
|
||||||
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
|
||||||
|
if (subsurface == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (subsurface && subsurface->synchronized) {
|
if (subsurface->synchronized) {
|
||||||
subsurface->synchronized = false;
|
subsurface->synchronized = false;
|
||||||
|
|
||||||
if (!subsurface_is_synchronized(subsurface)) {
|
if (!subsurface_is_synchronized(subsurface)) {
|
||||||
|
@ -835,11 +850,11 @@ static void subsurface_set_desync(struct wl_client *client,
|
||||||
|
|
||||||
static const struct wl_subsurface_interface subsurface_implementation = {
|
static const struct wl_subsurface_interface subsurface_implementation = {
|
||||||
.destroy = subsurface_handle_destroy,
|
.destroy = subsurface_handle_destroy,
|
||||||
.set_position = subsurface_set_position,
|
.set_position = subsurface_handle_set_position,
|
||||||
.place_above = subsurface_place_above,
|
.place_above = subsurface_handle_place_above,
|
||||||
.place_below = subsurface_place_below,
|
.place_below = subsurface_handle_place_below,
|
||||||
.set_sync = subsurface_set_sync,
|
.set_sync = subsurface_handle_set_sync,
|
||||||
.set_desync = subsurface_set_desync,
|
.set_desync = subsurface_handle_set_desync,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void subsurface_handle_parent_destroy(struct wl_listener *listener,
|
static void subsurface_handle_parent_destroy(struct wl_listener *listener,
|
||||||
|
@ -862,6 +877,8 @@ static void subsurface_handle_surface_destroy(struct wl_listener *listener,
|
||||||
struct wlr_subsurface *wlr_subsurface_create(struct wlr_surface *surface,
|
struct wlr_subsurface *wlr_subsurface_create(struct wlr_surface *surface,
|
||||||
struct wlr_surface *parent, uint32_t version, uint32_t id,
|
struct wlr_surface *parent, uint32_t version, uint32_t id,
|
||||||
struct wl_list *resource_list) {
|
struct wl_list *resource_list) {
|
||||||
|
assert(version <= SUBSURFACE_VERSION);
|
||||||
|
|
||||||
struct wl_client *client = wl_resource_get_client(surface->resource);
|
struct wl_client *client = wl_resource_get_client(surface->resource);
|
||||||
|
|
||||||
struct wlr_subsurface *subsurface =
|
struct wlr_subsurface *subsurface =
|
||||||
|
|
Loading…
Reference in a new issue