Skip to content

Commit

Permalink
implement xdg-decoration-unstable-v1
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Consolatis authored and ii8 committed Mar 27, 2023
1 parent 3a1c971 commit 5529664
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.a
xdg-shell.[ch]
gtk-primary-selection.[ch]
xdg-decoration-unstable-v1.[ch]
havoc
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions havoc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@
#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])

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;
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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 = {
Expand Down Expand Up @@ -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,
&gtk_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);
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5529664

Please sign in to comment.