AtlatestRepositorysigil-wm

sigil-wm / tree / testdecoration-client.h

1/* SPDX-License-Identifier: BSD-3-Clause */
2#include "server-decoration-client-protocol.h"
3#include "xdg-decoration-unstable-v1-client-protocol.h"
4static void legacy_default(void *data,struct org_kde_kwin_server_decoration_manager *manager,uint32_t mode) {
5 (void)data; (void)manager;
6 printf("LEGACY_DEFAULT=%u\n",mode); fflush(stdout);
7}
8static const struct org_kde_kwin_server_decoration_manager_listener legacy_manager_listener={.default_mode=legacy_default};
9static void legacy_mode(void *data,struct org_kde_kwin_server_decoration *decoration,uint32_t mode) {
10 (void)data; (void)decoration;
11 printf("LEGACY_MODE=%u\n",mode); fflush(stdout);
13static const struct org_kde_kwin_server_decoration_listener legacy_listener={.mode=legacy_mode};
14static void xdg_mode(void *data,struct zxdg_toplevel_decoration_v1 *decoration,uint32_t mode) {
15 (void)data; (void)decoration;
16 printf("XDG_DECORATION_MODE=%u\n",mode); fflush(stdout);
18static const struct zxdg_toplevel_decoration_v1_listener xdg_decoration_listener={.configure=xdg_mode};
19static bool decoration_global(struct client *client,struct wl_registry *registry,uint32_t name,const char *interface) {
20 if(!client->decoration_mode) return false;
21 if(!strcmp(interface,"org_kde_kwin_server_decoration_manager")) {
22 client->legacy_manager=wl_registry_bind(registry,name,&org_kde_kwin_server_decoration_manager_interface,1);
23 org_kde_kwin_server_decoration_manager_add_listener(client->legacy_manager,&legacy_manager_listener,client);
24 return true;
25 }
26 if(!strcmp(interface,"zxdg_decoration_manager_v1")) {
27 client->decoration_manager=wl_registry_bind(registry,name,&zxdg_decoration_manager_v1_interface,1);
28 return true;
29 }
30 return false;
32static void decoration_create(struct client *client,bool before_role) {
33 if(!client->decoration_mode) return;
34 if(before_role && !strncmp(client->decoration_mode,"legacy",6)) {
35 if(!client->legacy_manager) exit(38);
36 client->legacy_decoration=org_kde_kwin_server_decoration_manager_create(client->legacy_manager,client->surface);
37 org_kde_kwin_server_decoration_add_listener(client->legacy_decoration,&legacy_listener,client);
38 org_kde_kwin_server_decoration_request_mode(client->legacy_decoration,
39 !strcmp(client->decoration_mode,"legacy-client") ? 1 : 2);
40 }
41 if(!before_role && !strncmp(client->decoration_mode,"xdg",3)) {
42 if(!client->decoration_manager) exit(39);
43 client->xdg_decoration=zxdg_decoration_manager_v1_get_toplevel_decoration(client->decoration_manager,client->toplevel);
44 zxdg_toplevel_decoration_v1_add_listener(client->xdg_decoration,&xdg_decoration_listener,client);
45 if(!strcmp(client->decoration_mode,"xdg-default"))
46 zxdg_toplevel_decoration_v1_unset_mode(client->xdg_decoration);
47 else zxdg_toplevel_decoration_v1_set_mode(client->xdg_decoration,
48 !strcmp(client->decoration_mode,"xdg-server") ? 2 : 1);
49 }
51static void decoration_release(struct client *client) {
52 if(client->legacy_decoration) org_kde_kwin_server_decoration_release(client->legacy_decoration);
53 if(client->xdg_decoration) zxdg_toplevel_decoration_v1_destroy(client->xdg_decoration);
54 client->legacy_decoration=NULL;
55 client->xdg_decoration=NULL;
57static void decoration_command(struct client *client,char command) {
58 if(!client->decoration_mode) return;
59 if(command=='d' && client->legacy_decoration) org_kde_kwin_server_decoration_request_mode(client->legacy_decoration,1);
60 if(command=='s' && client->legacy_decoration) org_kde_kwin_server_decoration_request_mode(client->legacy_decoration,2);
61 if(command=='d' && client->xdg_decoration) zxdg_toplevel_decoration_v1_set_mode(client->xdg_decoration,1);
62 if(command=='s' && client->xdg_decoration) zxdg_toplevel_decoration_v1_set_mode(client->xdg_decoration,2);
63 if(command=='e') decoration_release(client);
64 if(command=='f') { printf("CLIENT_FRAMES=%u\n",client->frames); fflush(stdout); }
66static void decoration_finish(struct client *client) {
67 decoration_release(client);
68 if(client->legacy_manager) wl_proxy_destroy((struct wl_proxy *)client->legacy_manager);
69 if(client->decoration_manager) zxdg_decoration_manager_v1_destroy(client->decoration_manager);