From 55296643e9ba982c2c00a52e0066c4f3722706b6 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Mon, 27 Mar 2023 04:12:21 +0200 Subject: [PATCH] implement xdg-decoration-unstable-v1 This allows requesting server side decorations if supported by the compositor. Adds a new config option `window.decorations` with values - `yes` (always request server side decorations) - `no` (always request client side decorations, e.g. no decorations) - `auto` (tell the compositor to use whatever it prefers) The new setting defaults to `auto`. --- .gitignore | 1 + Makefile | 7 ++++--- havoc.cfg | 3 +++ main.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c0934ed..dbcb83c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.a xdg-shell.[ch] gtk-primary-selection.[ch] +xdg-decoration-unstable-v1.[ch] havoc diff --git a/Makefile b/Makefile index 53a1d5d..e3e2518 100644 --- a/Makefile +++ b/Makefile @@ -9,10 +9,11 @@ VERSION="0.4.0-git" CFLAGS ?= -Wall -Wextra -Wno-unused-parameter -Wno-parentheses override CFLAGS += -DVERSION=\"$(VERSION)\" -VPATH=$(WAYLAND_PROTOCOLS_DIR)/stable/xdg-shell +VPATH=$(WAYLAND_PROTOCOLS_DIR)/stable/xdg-shell:$(WAYLAND_PROTOCOLS_DIR)/unstable/xdg-decoration LIBS=-lrt -lm -lutil -lwayland-client -lwayland-cursor -lxkbcommon -Ltsm -lhtsm -OBJ=xdg-shell.o gtk-primary-selection.o glyph.o main.o -GEN=xdg-shell.c xdg-shell.h gtk-primary-selection.c gtk-primary-selection.h +OBJ=xdg-shell.o xdg-decoration-unstable-v1.o gtk-primary-selection.o glyph.o main.o +GEN=xdg-shell.c xdg-shell.h xdg-decoration-unstable-v1.c \ + xdg-decoration-unstable-v1.h gtk-primary-selection.c gtk-primary-selection.h havoc: tsm $(OBJ) $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) diff --git a/havoc.cfg b/havoc.cfg index abb3d59..f1d9150 100644 --- a/havoc.cfg +++ b/havoc.cfg @@ -9,6 +9,9 @@ opacity=230 # render a margin to exactly match window size hints from the compositor margin=no +# request server side decorations if available by the compositor [yes|no|auto] +decorations=auto + [terminal] # size of terminal rows=16 diff --git a/main.c b/main.c index 29064f7..97a2c0e 100644 --- a/main.c +++ b/main.c @@ -23,6 +23,7 @@ #include "tsm/libtsm.h" #include "xdg-shell.h" #include "gtk-primary-selection.h" +#include "xdg-decoration-unstable-v1.h" #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) @@ -30,6 +31,12 @@ int font_init(int, char *, int *, int *); void font_deinit(void); unsigned char *get_glyph(uint32_t, uint32_t, int); +enum deco { + DECO_AUTO, + DECO_SERVER, + DECO_NONE +}; + static struct { bool die; bool configured; @@ -132,6 +139,11 @@ static struct { bool active; } paste; + struct { + struct zxdg_decoration_manager_v1 *manager; + struct zxdg_toplevel_decoration_v1 *deco; + } deco; + struct { bool linger; char *config; @@ -152,6 +164,7 @@ static struct { int scrollback; bool margin; unsigned char opacity; + enum deco decorations; int font_size; char font_path[512]; uint8_t colors[TSM_COLOR_NUM][3]; @@ -163,6 +176,7 @@ static struct { .cfg.scrollback = 0, .cfg.margin = false, .cfg.opacity = 0xff, + .cfg.decorations = DECO_AUTO, .cfg.font_size = 18, .cfg.font_path = "", .cfg.colors = { @@ -1503,6 +1517,26 @@ static void registry_get(void *data, struct wl_registry *r, uint32_t id, } else if (strcmp(i, "gtk_primary_selection_device_manager") == 0) { term.ps_dm = wl_registry_bind(r, id, >k_primary_selection_device_manager_interface, 1); + } else if (strcmp(i, "zxdg_decoration_manager_v1") == 0) { + term.deco.manager = wl_registry_bind(r, id, + &zxdg_decoration_manager_v1_interface, 1); + } +} + +static void setup_deco(void) +{ + if (term.deco.manager) { + term.deco.deco = + zxdg_decoration_manager_v1_get_toplevel_decoration( + term.deco.manager, term.toplvl); + + if (term.cfg.decorations == DECO_AUTO) + zxdg_toplevel_decoration_v1_unset_mode(term.deco.deco); + else + zxdg_toplevel_decoration_v1_set_mode(term.deco.deco, + term.cfg.decorations == DECO_NONE + ? ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE + : ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); } } @@ -1626,6 +1660,9 @@ static void window_config(char *key, char *val) term.cfg.opacity = cfg_num(val, 10, 0, 255); else if (strcmp(key, "margin") == 0) term.cfg.margin = strcmp(val, "yes") == 0; + else if (strcmp(key, "decorations") == 0) + term.cfg.decorations = strcmp(val, "yes") == 0 ? DECO_SERVER + : (strcmp(val, "no") == 0 ? DECO_NONE : DECO_AUTO); } static void terminal_config(char *key, char *val) @@ -1937,6 +1974,8 @@ int main(int argc, char *argv[]) xdg_toplevel_set_title(term.toplvl, "havoc"); xdg_toplevel_set_app_id(term.toplvl, term.opt.app_id); + setup_deco(); + wl_surface_commit(term.surf); term.can_redraw = true; @@ -2005,6 +2044,12 @@ int main(int argc, char *argv[]) if (term.kbd) wl_keyboard_release(term.kbd); + if (term.deco.deco) + zxdg_toplevel_decoration_v1_destroy(term.deco.deco); + + if (term.deco.manager) + zxdg_decoration_manager_v1_destroy(term.deco.manager); + xdg_toplevel_destroy(term.toplvl); etoplvl: xdg_surface_destroy(term.xdgsurf);