1
0

Add server side decoration to the window

This commit is contained in:
Arti Zirk 2021-01-03 19:42:20 +02:00
parent 11fbabb326
commit 2c4e03cc82
3 changed files with 29 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea/ .idea/
surface surface
xdg-shell* xdg-shell*
xdg-decoration*

View File

@ -4,9 +4,10 @@ WAYLAND_SCANNER = $(shell pkg-config --variable=wayland_scanner wayland-scanner)
CFLAGS ?= -std=c11 -Wall -Wextra -Werror -Wno-unused-parameter -ggdb CFLAGS ?= -std=c11 -Wall -Wextra -Werror -Wno-unused-parameter -ggdb
XDG_SHELL_PROTOCOL = $(WAYLAND_PROTOCOLS_DIR)/stable/xdg-shell/xdg-shell.xml 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 HEADERS=xdg-shell-client-protocol.h xdg-decoration-client-protocol.h
SOURCES=surface.c xdg-shell-protocol.c SOURCES=surface.c xdg-shell-protocol.c xdg-decoration-protocol.c
all: surface all: surface
@ -19,7 +20,14 @@ xdg-shell-client-protocol.h:
xdg-shell-protocol.c: xdg-shell-protocol.c:
$(WAYLAND_SCANNER) private-code $(XDG_SHELL_PROTOCOL) 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 .PHONY: clean
clean: clean:
$(RM) surface xdg-shell-protocol.c xdg-shell-client-protocol.h $(RM) surface \
xdg-shell-protocol.c xdg-shell-client-protocol.h \
xdg-decoration-protocol.c xdg-decoration-client-protocol.h

View File

@ -6,6 +6,7 @@
//#include <wayland-server.h> //#include <wayland-server.h>
#include <wayland-client-protocol.h> #include <wayland-client-protocol.h>
#include "xdg-shell-client-protocol.h" #include "xdg-shell-client-protocol.h"
#include "xdg-decoration-client-protocol.h"
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <errno.h> #include <errno.h>
@ -20,6 +21,7 @@ struct client_state {
struct wl_compositor *wl_compositor; struct wl_compositor *wl_compositor;
struct wl_shm *wl_shm; struct wl_shm *wl_shm;
struct xdg_wm_base *xdg_wm_base; struct xdg_wm_base *xdg_wm_base;
struct zxdg_decoration_manager_v1 *zxdg_decoration_manager_v1;
/* Objects */ /* Objects */
struct wl_buffer *wl_buffer; struct wl_buffer *wl_buffer;
struct wl_surface *wl_surface; 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, state->xdg_wm_base = wl_registry_bind(registry, id,
&xdg_wm_base_interface, 1); &xdg_wm_base_interface, 1);
xdg_wm_base_add_listener(state->xdg_wm_base, &xdg_wm_base_listener, state); 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 { } else {
fprintf(stderr, "got xdg_toplevel\n"); 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_add_listener(state.xdg_toplevel, &xdg_toplevel_listener, &state);
xdg_toplevel_set_title(state.xdg_toplevel, "A surface"); xdg_toplevel_set_title(state.xdg_toplevel, "A surface");
wl_surface_commit(state.wl_surface); wl_surface_commit(state.wl_surface);