From 2c4e03cc82d5c7779ba4436fbccc9ad5269ae583 Mon Sep 17 00:00:00 2001 From: Arti Zirk Date: Sun, 3 Jan 2021 19:42:20 +0200 Subject: [PATCH] Add server side decoration to the window --- .gitignore | 1 + Makefile | 14 +++++++++++--- surface.c | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 0057990..614b27d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ surface xdg-shell* +xdg-decoration* diff --git a/Makefile b/Makefile index 8be4cfb..22ec99f 100644 --- a/Makefile +++ b/Makefile @@ -4,9 +4,10 @@ WAYLAND_SCANNER = $(shell pkg-config --variable=wayland_scanner wayland-scanner) CFLAGS ?= -std=c11 -Wall -Wextra -Werror -Wno-unused-parameter -ggdb XDG_SHELL_PROTOCOL = $(WAYLAND_PROTOCOLS_DIR)/stable/xdg-shell/xdg-shell.xml +XDG_DECORATION_PROTOCOL = $(WAYLAND_PROTOCOLS_DIR)/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml -HEADERS=xdg-shell-client-protocol.h -SOURCES=surface.c xdg-shell-protocol.c +HEADERS=xdg-shell-client-protocol.h xdg-decoration-client-protocol.h +SOURCES=surface.c xdg-shell-protocol.c xdg-decoration-protocol.c all: surface @@ -19,7 +20,14 @@ xdg-shell-client-protocol.h: xdg-shell-protocol.c: $(WAYLAND_SCANNER) private-code $(XDG_SHELL_PROTOCOL) xdg-shell-protocol.c +xdg-decoration-client-protocol.h: + $(WAYLAND_SCANNER) client-header $(XDG_DECORATION_PROTOCOL) xdg-decoration-client-protocol.h + +xdg-decoration-protocol.c: + $(WAYLAND_SCANNER) private-code $(XDG_DECORATION_PROTOCOL) xdg-decoration-protocol.c .PHONY: clean clean: - $(RM) surface xdg-shell-protocol.c xdg-shell-client-protocol.h \ No newline at end of file + $(RM) surface \ + xdg-shell-protocol.c xdg-shell-client-protocol.h \ + xdg-decoration-protocol.c xdg-decoration-client-protocol.h \ No newline at end of file diff --git a/surface.c b/surface.c index 76659dc..8315a72 100644 --- a/surface.c +++ b/surface.c @@ -6,6 +6,7 @@ //#include #include #include "xdg-shell-client-protocol.h" +#include "xdg-decoration-client-protocol.h" #include #include #include @@ -20,6 +21,7 @@ struct client_state { struct wl_compositor *wl_compositor; struct wl_shm *wl_shm; struct xdg_wm_base *xdg_wm_base; + struct zxdg_decoration_manager_v1 *zxdg_decoration_manager_v1; /* Objects */ struct wl_buffer *wl_buffer; struct wl_surface *wl_surface; @@ -202,6 +204,9 @@ global_registry_handler(void *data, struct wl_registry *registry, uint32_t id, state->xdg_wm_base = wl_registry_bind(registry, id, &xdg_wm_base_interface, 1); xdg_wm_base_add_listener(state->xdg_wm_base, &xdg_wm_base_listener, state); + } else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) { + state->zxdg_decoration_manager_v1 = wl_registry_bind(registry, id, + &zxdg_decoration_manager_v1_interface, 1); } } @@ -304,6 +309,18 @@ int main(int argc, char **argv) { } else { fprintf(stderr, "got xdg_toplevel\n"); } + + if (state.zxdg_decoration_manager_v1 != NULL){ + struct zxdg_toplevel_decoration_v1 *decoration = \ + zxdg_decoration_manager_v1_get_toplevel_decoration(state.zxdg_decoration_manager_v1, + state.xdg_toplevel); + zxdg_toplevel_decoration_v1_set_mode(decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + fprintf(stderr, "Using serverside decorations"); + } else { + fprintf(stderr, "Serverside decoration not available"); + } + + xdg_toplevel_add_listener(state.xdg_toplevel, &xdg_toplevel_listener, &state); xdg_toplevel_set_title(state.xdg_toplevel, "A surface"); wl_surface_commit(state.wl_surface);