# Maintainer: q234 rty <q23456yuiop at gmail dot com>
# Maintainer: moetayuko <loli at yuko dot moe>
# Contributor: FabioLolix
# Contributor: éclairevoyant
# Contributor: alba4k <blaskoazzolaaaron[at]gmail.com>
# Contributor: ThatOneCalculator <kainoa at t1c dot dev>
# Contributor: Aleksana QwQ <me@aleksana.moe>
# Contributor: lilydjwg <lilydjwg@gmail.com>

_pkgname="hyprland"
pkgname="$_pkgname-hidpi-xprop-git"
pkgver=0.56.0.r77.g91f29f2
pkgrel=1
pkgdesc="Hyprland is an independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks"
arch=("i686" "x86_64" "arm" "armv6h" "armv7h" "aarch64")
url="https://github.com/hyprwm/Hyprland"
license=('BSD-3-Clause')

depends=(
  aquamarine-git
  cairo
  gcc-libs
  glib2
  glibc
  glslang
  hyprcursor-git
  hyprgraphics-git
  hyprland-guiutils-git
  hyprlang-git
  hyprutils-git
  hyprwire-git
  lcms2
  libdisplay-info
  libdrm
  libglvnd
  libinput
  libliftoff
  libx11
  libxcb
  libxcomposite
  libxcursor
  libxfixes
  libxkbcommon
  libxrender
  lua
  mesa
  muparser
  opengl-driver
  pango
  pixman
  polkit
  re2
  seatd
  sdbus-cpp
  systemd-libs
  tomlplusplus
  util-linux-libs
  wayland
  wayland-protocols
  xcb-proto
  xcb-util
  xcb-util-errors
  xcb-util-image
  xcb-util-keysyms
  xcb-util-renderutil
  xcb-util-wm
  xorg-xwayland-hidpi-xprop
)
makedepends=(
  cmake
  git
  glaze
  hyprwayland-scanner-git
  ninja
  #patch
  #pkgconf
  python # required by udis86
  xorgproto
)
optdepends=(
  'cmake: to build and install plugins using hyprpm'
  'cpio: to build and install plugins using hyprpm'
  'glaze: to build and install plugins using hyprpm'
  'hyprqt6engine-git: the recommended way to manage qt styles'
  'meson: to build and install plugins using hyprpm'
  'uwsm: the recommended way to start Hyprland'
)

conflicts=("$_pkgname")
provides=("$_pkgname=${pkgver%%.r*}" "wayland-compositor")

_pkgsrc=$_pkgname
source=(
  "$_pkgsrc::git+$url.git"
  "udis86::git+https://github.com/canihavesomecoffee/udis86.git"
  "git+https://github.com/hyprwm/hyprland-protocols.git"
)
sha256sums=(
  'SKIP'
  'SKIP'
  'SKIP'
)

options=(debug)

pick_mr() {
  git pull origin pull/$1/head --no-ff --no-commit
}

prepare() {
  cd "$_pkgsrc"
  git submodule init
  git config submodule.subprojects/udis86.url "$srcdir/udis86"
  git config submodule.subprojects/hyprland-protocols.url "$srcdir/hyprland-protocols"
  git config submodule.subprojects/tracy.update none
  git -c protocol.file.allow=always submodule update

  if [[ -z "$(git config --get user.name)" ]]; then
    git config user.name local && git config user.email '<>' && git config commit.gpgsign false
  fi
  # Pick pull requests from github using `pick_mr <pull request number>`.
  pick_mr 6446
}

pkgver() {
  cd "$_pkgsrc"
  git describe --long --tags --abbrev=7 | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

build() {
  cd "$_pkgsrc"
  local cmake_options=(
    -B build
    -S .
    -G Ninja
    -W no-dev
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/usr
  )
  cmake "${cmake_options[@]}"
  cmake --build build
}

package() {
  cd "$_pkgsrc"
  DESTDIR="$pkgdir" cmake --install build
  install -Dm0644 LICENSE -t "$pkgdir/usr/share/licenses/${pkgname}/"
  install -Dm0644 subprojects/udis86/LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE-udis86"

  # Avoid conflict w/ extra/xdg-desktop-portal-hyprland
  rm -rf "$pkgdir/usr/share/xdg-desktop-portal"
}
replaces=("hyprland-nvidia-hidpi-git")
