# dwl - dwm's ideas, on Wayland. Patched and configured, suckless style.
name=dwl
version=0.8
release=1
desc="Dynamic window manager for Wayland, in the spirit of dwm"
url="https://codeberg.org/dwl/dwl"
license="GPL-3.0-only"
depend="glibc wayland wlroots libinput libxkbcommon"
makedepend="bmake clang lld pkgconf"
source="dwl-$version.tar.gz::https://codeberg.org/dwl/dwl/archive/v$version.tar.gz"
sha256="SKIP"

build() {
	cd dwl
	# Suckless software is configured by editing the source, so ScrapLinux ships a
	# config.h rather than patching at runtime.
	cp config.def.h config.h
	sed -i 's/"foot"/"foot"/' config.h
	# dwl 0.8's config.mk hardcodes wlroots-0.19 in its pkg-config calls -
	# ScrapLinux ships wlroots 0.20 (see ports/base/wlroots), so the version
	# pin needs updating or WLR_INCS/WLR_LIBS resolve to nothing and every
	# wlr/*.h include fails.
	sed -i 's/wlroots-0.19/wlroots-0.20/g' config.mk
	# client.h (dwl 0.8, written for wlroots 0.19) uses
	# XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION and
	# XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION - "use of undeclared
	# identifier" on wlroots 0.20, not because ScrapLinux's xdg-shell.xml or
	# wayland-scanner are wrong (confirmed: wayland-scanner server-header
	# against ScrapLinux's own xdg-shell.xml emits both correctly, 54
	# SINCE_VERSION constants total), but because wlroots 0.20's installed
	# wlr_xdg_shell.h pulls its constants from
	# <wayland-protocols/xdg-shell-enum.h> - a *separate*, more limited
	# header wayland-protocols pre-generates with wayland-scanner's
	# enum-header mode, which only covers enum *value* constants, not
	# per-message SINCE_VERSION guards for events like configure_bounds.
	# dwl 0.8 predates this wlroots 0.19->0.20 restructuring and has never
	# been adjusted for it (confirmed no newer tagged release exists).
	# Defining the two guards locally, at their real xdg-shell protocol
	# version numbers (checked directly against the xdg-shell.xml ScrapLinux
	# ships: configure_bounds since="4", wm_capabilities since="5"), is
	# the same fix dwl.c's own client.h would need from any downstream
	# consumer hitting this - not something wayland-protocols or wlroots
	# themselves need to change.
	sed -i '1i\
#ifndef XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION\
#define XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION 4\
#endif\
#ifndef XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION\
#define XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION 5\
#endif' client.h
	make -j"$JOBS" PREFIX=/usr
}

package() {
	cd dwl
	make PREFIX=/usr DESTDIR="$pkgdir" install
	install -Dm644 config.h "$pkgdir/usr/share/dwl/config.h"
}
