xdg-toplevel-tag-v1: new protocol

References: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/238
This commit is contained in:
Simon Ser 2025-04-03 15:21:15 +02:00 committed by Kenny Levinsen
parent 6aa654b728
commit f4327f52cf
4 changed files with 147 additions and 0 deletions

View file

@ -0,0 +1,41 @@
/*
* 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_XDG_TOPLEVEL_TAG_V1_H
#define WLR_TYPES_WLR_XDG_TOPLEVEL_TAG_V1_H
#include <wayland-server-core.h>
struct wlr_xdg_toplevel_tag_manager_v1 {
struct wl_global *global;
struct {
struct wl_signal set_tag; // struct wlr_xdg_toplevel_tag_manager_v1_set_tag_event
struct wl_signal set_description; // struct wlr_xdg_toplevel_tag_manager_v1_set_description_event
struct wl_signal destroy;
} events;
struct {
struct wl_listener display_destroy;
} WLR_PRIVATE;
};
struct wlr_xdg_toplevel_tag_manager_v1_set_tag_event {
struct wlr_xdg_toplevel *toplevel;
const char *tag;
};
struct wlr_xdg_toplevel_tag_manager_v1_set_description_event {
struct wlr_xdg_toplevel *toplevel;
const char *description;
};
struct wlr_xdg_toplevel_tag_manager_v1 *wlr_xdg_toplevel_tag_manager_v1_create(
struct wl_display *display, uint32_t version);
#endif

View file

@ -42,6 +42,7 @@ protocols = {
'xdg-dialog-v1': wl_protocol_dir / 'staging/xdg-dialog/xdg-dialog-v1.xml',
'xdg-system-bell-v1': wl_protocol_dir / 'staging/xdg-system-bell/xdg-system-bell-v1.xml',
'xdg-toplevel-icon-v1': wl_protocol_dir / 'staging/xdg-toplevel-icon/xdg-toplevel-icon-v1.xml',
'xdg-toplevel-tag-v1': wl_protocol_dir / 'staging/xdg-toplevel-tag/xdg-toplevel-tag-v1.xml',
'xwayland-shell-v1': wl_protocol_dir / 'staging/xwayland-shell/xwayland-shell-v1.xml',
'tearing-control-v1': wl_protocol_dir / 'staging/tearing-control/tearing-control-v1.xml',

View file

@ -103,6 +103,7 @@ wlr_files += files(
'wlr_xdg_output_v1.c',
'wlr_xdg_system_bell_v1.c',
'wlr_xdg_toplevel_icon_v1.c',
'wlr_xdg_toplevel_tag_v1.c',
)
if features.get('drm-backend')

View file

@ -0,0 +1,104 @@
#include <assert.h>
#include <stdlib.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/types/wlr_xdg_toplevel_tag_v1.h>
#include "xdg-toplevel-tag-v1-protocol.h"
#define MANAGER_VERSION 1
static const struct xdg_toplevel_tag_manager_v1_interface manager_impl;
static struct wlr_xdg_toplevel_tag_manager_v1 *manager_from_resource(
struct wl_resource *resource) {
assert(wl_resource_instance_of(resource, &xdg_toplevel_tag_manager_v1_interface, &manager_impl));
return wl_resource_get_user_data(resource);
}
static void manager_handle_set_tag(struct wl_client *client, struct wl_resource *manager_resource,
struct wl_resource *toplevel_resource, const char *tag) {
struct wlr_xdg_toplevel_tag_manager_v1 *manager = manager_from_resource(manager_resource);
struct wlr_xdg_toplevel *toplevel = wlr_xdg_toplevel_from_resource(toplevel_resource);
struct wlr_xdg_toplevel_tag_manager_v1_set_tag_event event = {
.toplevel = toplevel,
.tag = tag,
};
wl_signal_emit_mutable(&manager->events.set_tag, &event);
}
static void manager_handle_set_description(struct wl_client *client, struct wl_resource *manager_resource,
struct wl_resource *toplevel_resource, const char *description) {
struct wlr_xdg_toplevel_tag_manager_v1 *manager = manager_from_resource(manager_resource);
struct wlr_xdg_toplevel *toplevel = wlr_xdg_toplevel_from_resource(toplevel_resource);
struct wlr_xdg_toplevel_tag_manager_v1_set_description_event event = {
.toplevel = toplevel,
.description = description,
};
wl_signal_emit_mutable(&manager->events.set_description, &event);
}
static void manager_handle_destroy(struct wl_client *client, struct wl_resource *manager_resource) {
wl_resource_destroy(manager_resource);
}
static const struct xdg_toplevel_tag_manager_v1_interface manager_impl = {
.destroy = manager_handle_destroy,
.set_toplevel_tag = manager_handle_set_tag,
.set_toplevel_description = manager_handle_set_description,
};
static void manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id) {
struct wlr_xdg_toplevel_tag_manager_v1 *manager = data;
struct wl_resource *resource = wl_resource_create(client,
&xdg_toplevel_tag_manager_v1_interface, version, id);
if (resource == NULL) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource, &manager_impl, manager, NULL);
}
static void manager_handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_xdg_toplevel_tag_manager_v1 *manager =
wl_container_of(listener, manager, display_destroy);
wl_signal_emit_mutable(&manager->events.destroy, NULL);
assert(wl_list_empty(&manager->events.set_tag.listener_list));
assert(wl_list_empty(&manager->events.set_description.listener_list));
assert(wl_list_empty(&manager->events.destroy.listener_list));
wl_list_remove(&manager->display_destroy.link);
wl_global_destroy(manager->global);
free(manager);
}
struct wlr_xdg_toplevel_tag_manager_v1 *wlr_xdg_toplevel_tag_manager_v1_create(
struct wl_display *display, uint32_t version) {
assert(version <= MANAGER_VERSION);
struct wlr_xdg_toplevel_tag_manager_v1 *manager = calloc(1, sizeof(*manager));
if (manager == NULL) {
return NULL;
}
manager->global = wl_global_create(display, &xdg_toplevel_tag_manager_v1_interface,
version, manager, manager_bind);
if (manager->global == NULL) {
free(manager);
return NULL;
}
wl_signal_init(&manager->events.set_tag);
wl_signal_init(&manager->events.set_description);
wl_signal_init(&manager->events.destroy);
manager->display_destroy.notify = manager_handle_display_destroy;
wl_display_add_destroy_listener(display, &manager->display_destroy);
return manager;
}