aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2021-11-03 14:22:35 +0100
committerSimon Zeni <simon@bl4ckb0ne.ca>2021-11-19 16:06:07 +0000
commit6bb897330980f65194b75547c3f909e614bdcd49 (patch)
tree93f8f6d72f34f76c78b0546523936df3420aae80
parent86f5ecf46867236d4b96a3ce1ad664a8963d6ae4 (diff)
drm-lease-v1: listen to lease destroy event
-rw-r--r--include/wlr/types/wlr_drm_lease_v1.h2
-rw-r--r--types/wlr_drm_lease_v1.c54
2 files changed, 29 insertions, 27 deletions
diff --git a/include/wlr/types/wlr_drm_lease_v1.h b/include/wlr/types/wlr_drm_lease_v1.h
index 5b4137c5..5a7827ea 100644
--- a/include/wlr/types/wlr_drm_lease_v1.h
+++ b/include/wlr/types/wlr_drm_lease_v1.h
@@ -90,6 +90,8 @@ struct wlr_drm_lease_v1 {
struct wl_list link; // wlr_drm_lease_device_v1::leases
+ struct wl_listener destroy;
+
void *data;
};
diff --git a/types/wlr_drm_lease_v1.c b/types/wlr_drm_lease_v1.c
index eaca8f17..7da40686 100644
--- a/types/wlr_drm_lease_v1.c
+++ b/types/wlr_drm_lease_v1.c
@@ -47,28 +47,6 @@ static struct wlr_drm_lease_v1 *drm_lease_v1_from_resource(
return wl_resource_get_user_data(resource);
}
-static void drm_lease_v1_destroy(struct wlr_drm_lease_v1 *lease) {
- if (!lease) {
- return;
- }
-
- wlr_log(WLR_DEBUG, "Destroying lease %"PRIu32, lease->drm_lease->lessee_id);
-
- wp_drm_lease_v1_send_finished(lease->resource);
-
- wlr_drm_lease_terminate(lease->drm_lease);
-
- for (size_t i = 0; i < lease->n_connectors; ++i) {
- lease->connectors[i]->active_lease = NULL;
- }
-
- wl_list_remove(&lease->link);
- wl_resource_set_user_data(lease->resource, NULL);
-
- free(lease->connectors);
- free(lease);
-}
-
static void drm_lease_request_v1_destroy(
struct wlr_drm_lease_request_v1 *request) {
if (!request) {
@@ -93,7 +71,7 @@ static void drm_lease_connector_v1_destroy(
wlr_log(WLR_DEBUG, "Destroying connector %s", connector->output->name);
if (connector->active_lease) {
- drm_lease_v1_destroy(connector->active_lease);
+ wlr_drm_lease_terminate(connector->active_lease->drm_lease);
}
struct wl_resource *resource, *tmp;
@@ -140,7 +118,7 @@ static void drm_lease_device_v1_destroy(
struct wlr_drm_lease_v1 *lease, *tmp_lease;
wl_list_for_each_safe(lease, tmp_lease, &device->leases, link) {
- drm_lease_v1_destroy(lease);
+ wlr_drm_lease_terminate(lease->drm_lease);
}
struct wlr_drm_lease_connector_v1 *connector, *tmp_connector;
@@ -154,6 +132,26 @@ static void drm_lease_device_v1_destroy(
free(device);
}
+static void lease_handle_destroy(struct wl_listener *listener, void *data) {
+ struct wlr_drm_lease_v1 *lease = wl_container_of(listener, lease, destroy);
+
+ wlr_log(WLR_DEBUG, "Destroying lease %"PRIu32, lease->drm_lease->lessee_id);
+
+ wp_drm_lease_v1_send_finished(lease->resource);
+
+ wl_list_remove(&lease->destroy.link);
+
+ for (size_t i = 0; i < lease->n_connectors; ++i) {
+ lease->connectors[i]->active_lease = NULL;
+ }
+
+ wl_list_remove(&lease->link);
+ wl_resource_set_user_data(lease->resource, NULL);
+
+ free(lease->connectors);
+ free(lease);
+}
+
struct wlr_drm_lease_v1 *wlr_drm_lease_request_v1_grant(
struct wlr_drm_lease_request_v1 *request) {
assert(request->lease);
@@ -191,6 +189,9 @@ struct wlr_drm_lease_v1 *wlr_drm_lease_request_v1_grant(
lease->connectors[i]->active_lease = lease;
}
+ lease->destroy.notify = lease_handle_destroy;
+ wl_signal_add(&lease->drm_lease->events.destroy, &lease->destroy);
+
wlr_log(WLR_DEBUG, "Granting request %p", request);
wp_drm_lease_v1_send_lease_fd(lease->resource, fd);
@@ -212,13 +213,12 @@ void wlr_drm_lease_request_v1_reject(
void wlr_drm_lease_v1_revoke(struct wlr_drm_lease_v1 *lease) {
assert(lease);
wlr_log(WLR_DEBUG, "Revoking lease %"PRIu32, lease->drm_lease->lessee_id);
-
- drm_lease_v1_destroy(lease);
+ wlr_drm_lease_terminate(lease->drm_lease);
}
static void drm_lease_v1_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_drm_lease_v1 *lease = drm_lease_v1_from_resource(resource);
- drm_lease_v1_destroy(lease);
+ wlr_drm_lease_terminate(lease->drm_lease);
}
static void drm_lease_v1_handle_destroy(