aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/wayland-server-core.h10
-rw-r--r--src/wayland-server.c46
2 files changed, 56 insertions, 0 deletions
diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h
index df95821..00a5443 100644
--- a/src/wayland-server-core.h
+++ b/src/wayland-server-core.h
@@ -365,6 +365,16 @@ wl_client_for_each_resource(struct wl_client *client,
wl_client_for_each_resource_iterator_func_t iterator,
void *user_data);
+typedef void (*wl_user_data_destroy_func_t)(void *data);
+
+void
+wl_client_set_user_data(struct wl_client *client,
+ void *data,
+ wl_user_data_destroy_func_t dtor);
+
+void *
+wl_client_get_user_data(struct wl_client *client);
+
/** \class wl_listener
*
* \brief A single listener for Wayland signals
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 9fd1227..1e079a3 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -85,6 +85,8 @@ struct wl_client {
gid_t gid;
bool error;
struct wl_priv_signal resource_created_signal;
+ void *data;
+ wl_user_data_destroy_func_t data_dtor;
};
struct wl_display {
@@ -943,6 +945,10 @@ wl_client_destroy(struct wl_client *client)
wl_list_remove(&client->link);
wl_list_remove(&client->resource_created_signal.listener_list);
+
+ if (client->data_dtor)
+ client->data_dtor(client->data);
+
free(client);
}
@@ -2469,6 +2475,46 @@ wl_client_new_object(struct wl_client *client,
return resource;
}
+/** Set the client's user data
+ *
+ * User data is whatever the caller wants to store. Use dtor if
+ * the user data needs freeing as the very last step of destroying
+ * the client.
+ *
+ * \param client The client object
+ * \param data The user data pointer
+ * \param dtor Destroy function to be called after all resources have been
+ * destroyed and all destroy listeners have been called. Can be NULL.
+ *
+ * The argument to the destroy function is the user data pointer. If the
+ * destroy function is not NULL, it will be called even if user data is NULL.
+ *
+ * \since 1.22.90
+ * \sa wl_client_get_user_data
+ */
+WL_EXPORT void
+wl_client_set_user_data(struct wl_client *client,
+ void *data,
+ wl_user_data_destroy_func_t dtor)
+{
+ client->data = data;
+ client->data_dtor = dtor;
+}
+
+/** Get the client's user data
+ *
+ * \param client The client object
+ * \return The user data pointer
+ *
+ * \since 1.22.90
+ * \sa wl_client_set_user_data
+ */
+WL_EXPORT void *
+wl_client_get_user_data(struct wl_client *client)
+{
+ return client->data;
+}
+
struct wl_global *
wl_display_add_global(struct wl_display *display,
const struct wl_interface *interface,