logo

inaban

Distrustful Wayland Compositor (inspired by XMonad and dwm) git clone https://hacktivis.me/git/inaban.git
commit: 0a6220950a69e878dc0cdb0967479202314dd590
parent 1db1ce82109a6fa6aa1605dc99fb8924e344d97e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun,  3 Jan 2021 04:42:21 +0100

Implement xdg-decoration

Based on https://github.com/Hjdskes/cage/commit/2166fbdcfb9e73fd6837c08366df24ae0b2772e0

Diffstat:

MMakefile2+-
Minaban.c11++++++++++-
Minaban.h5++++-
Axdg-decoration.c59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile @@ -19,7 +19,7 @@ PKGCONFIG ?= pkg-config DEPS = xkbcommon wlroots wayland-server EXE = inaban TRANS = -SRC = commands.c inaban.c +SRC = xdg-decoration.c commands.c inaban.c CDEPS = -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\" -D_POSIX_C_SOURCE=200809L -DWLR_USE_UNSTABLE -I. CDEPS += `pkg-config --cflags $(DEPS)` diff --git a/inaban.c b/inaban.c @@ -1,4 +1,4 @@ -// Copyright 2019-2020 Haelwenn (lanodan) Monnier <contact+inaban@hacktivis.me> +// Copyright 2019-2021 Haelwenn (lanodan) Monnier <contact+inaban@hacktivis.me> // SPDX-License-Identifier: BSD-3-Clause // Based on wlroots's TinyWL which is distributed under CC0 @@ -20,6 +20,9 @@ struct inaban_server server = {0}; +// xdg-decoration.c +extern void handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data); + /* event raised when a modifier key, such as shift or alt, is pressed. */ static void keyboard_handle_modifiers(struct wl_listener *listener, void *data) @@ -663,6 +666,7 @@ main(int argc, char *argv[]) int ret = 0; struct wlr_server_decoration_manager *server_decoration_manager = NULL; + struct wlr_xdg_decoration_manager_v1 *xdg_decoration_manager = NULL; if((getuid() * geteuid() * getgid() * getegid()) == 0) { @@ -779,6 +783,11 @@ main(int argc, char *argv[]) wlr_server_decoration_manager_set_default_mode(server_decoration_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); + xdg_decoration_manager = wlr_xdg_decoration_manager_v1_create(server.wl_display); + wl_signal_add(&xdg_decoration_manager->events.new_toplevel_decoration, + &server.xdg_toplevel_decoration); + server.xdg_toplevel_decoration.notify = handle_xdg_toplevel_decoration; + /* * Creates a cursor, which is a wlroots utility for tracking the cursor * image shown on screen. diff --git a/inaban.h b/inaban.h @@ -1,4 +1,4 @@ -// Copyright 2019-2020 Haelwenn (lanodan) Monnier +// Copyright 2019-2021 Haelwenn (lanodan) Monnier // Distributed under the terms of the BSD License // Based on wlroots's TinyWL which is distributed under CC0 #ifndef INABAN_H @@ -23,6 +23,7 @@ #include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_server_decoration.h> #include <wlr/types/wlr_xcursor_manager.h> +#include <wlr/types/wlr_xdg_decoration_v1.h> #include <wlr/types/wlr_xdg_shell.h> #include <wlr/util/log.h> #include <xkbcommon/xkbcommon.h> @@ -50,6 +51,8 @@ struct inaban_server struct wl_listener new_xdg_surface; struct wl_list views; + struct wl_listener xdg_toplevel_decoration; + struct wlr_cursor *cursor; struct wlr_xcursor_manager *cursor_mgr; struct wl_listener cursor_motion; diff --git a/xdg-decoration.c b/xdg-decoration.c @@ -0,0 +1,59 @@ +// Copyright 2019-2021 Haelwenn (lanodan) Monnier <contact+inaban@hacktivis.me> +// SPDX-License-Identifier: BSD-3-Clause + +#include <stdlib.h> // free() + +#include "inaban.h" + +struct inaban_xdg_decoration +{ + struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration; + struct inaban_server *server; + struct wl_listener destroy; + struct wl_listener request_mode; +}; + +static void +xdg_decoration_handle_destroy(struct wl_listener *listener, void *data) +{ + (void)data; + struct inaban_xdg_decoration *xdg_decoration = wl_container_of(listener, xdg_decoration, destroy); + + wl_list_remove(&xdg_decoration->destroy.link); + wl_list_remove(&xdg_decoration->request_mode.link); + free(xdg_decoration); +} + +static void +xdg_decoration_handle_request_mode(struct wl_listener *listener, void *data) +{ + (void)data; + struct inaban_xdg_decoration *xdg_decoration = + wl_container_of(listener, xdg_decoration, request_mode); + + wlr_xdg_toplevel_decoration_v1_set_mode(xdg_decoration->wlr_decoration, + WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); +} + +void +handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data) +{ + struct inaban_server *server = wl_container_of(listener, server, xdg_toplevel_decoration); + struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration = data; + + struct inaban_xdg_decoration *xdg_decoration = calloc(1, sizeof(struct inaban_xdg_decoration)); + if(!xdg_decoration) + { + return; + } + + xdg_decoration->wlr_decoration = wlr_decoration; + xdg_decoration->server = server; + + xdg_decoration->destroy.notify = xdg_decoration_handle_destroy; + wl_signal_add(&wlr_decoration->events.destroy, &xdg_decoration->destroy); + xdg_decoration->request_mode.notify = xdg_decoration_handle_request_mode; + wl_signal_add(&wlr_decoration->events.request_mode, &xdg_decoration->request_mode); + + xdg_decoration_handle_request_mode(&xdg_decoration->request_mode, wlr_decoration); +}