# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Chih-Hsuan Yen <yan12125@archlinux.org>
# Contributor: Florian pritz <bluewind@xinu.at>
# Contributor: Bartłomiej Piotrowski <nospam@bpiotrowski.pl>
# Contributor: Brad Fanella <bradfanella@archlinux.us>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: tobias <tobias@archlinux.org>

pkgname=openbox
pkgver=3.6.1
pkgrel=11
pkgdesc='Highly configurable and lightweight X11 window manager'
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url='http://openbox.org'
license=('GPL')
provides=(libobrender.so)
depends=('startup-notification' 'libxml2' 'libxinerama' 'libxrandr'
         'libxcursor' 'pango' 'imlib2' 'librsvg' 'libsm')
makedepends=('python-xdg')
optdepends=('plasma-workspace: for the KDE/Openbox xsession'
            'python-xdg: for the openbox-xdg-autostart script')
groups=('lxde' 'lxde-gtk3' 'lxqt')
backup=('etc/xdg/openbox/menu.xml' 'etc/xdg/openbox/rc.xml'
        'etc/xdg/openbox/autostart' 'etc/xdg/openbox/environment')
source=(http://openbox.org/dist/openbox/$pkgname-$pkgver.tar.gz{,.asc}
        openbox-3.5.0-title-matching.patch
        openbox-3.5.0-which-2.20.patch
        $pkgname-kde-paths.patch
        py3.patch
        debian-887908.patch
        https://github.com/mati75/openbox-debian/raw/debian/3.6.1-8/debian/patches/917204_undecorated_maximized_no_border.patch
        https://github.com/Mikachu/openbox/commit/9ed6fdd71890c5cc43747f105382d5677e5d37e7.patch)
md5sums=('b72794996c6a3ad94634727b95f9d204'
         'SKIP'
         '0a11d7149da210a31ef88f8a9c717711'
         '7ca3b5244bb092d46f5bcf1e2bdf4a18'
         'f7df0df8c1d2da279e48d0fdc984fb71'
         '67ae9735c283637ef6d11b17a3f81953'
         '4ff275746641e840605e9a74043079fe'
         'bf629dfad2b4bef6330dd914922cae48'
         '783f40691cc84e6a9e401677e0e10d01')
sha256sums=('8b4ac0760018c77c0044fab06a4f0c510ba87eae934d9983b10878483bde7ef7'
            'SKIP'
            'adc0820671e6ec42ff1bb4cbb04c65e19cdf74c62bcef3a3b727adb208eb82c7'
            '988acc655cf9a0fe4252c7e76d5ec2124a3f16c3ed26072fdcfd829ae9278c26'
            '40b6feb8fd83da0c9073ffc3ee4c009b5b036d105199bcaf6aa03cb18bf0b7e0'
            '4cd2708320ab3cdf4868bd66f20481dbad504d0e9aa43f13bca5c149b94a49cf'
            'f13d0aa857ea0a4304d8529b58cdda22d74b827cac78b991f92289f341a61fd8'
            '057761c75f9c3ccc799a2a3f453b729d950e6b78a271f5269d1b0f2b982d45c2'
            'a371d116483f37cd888bdeb1a5a1b594ddc9bf92c9c91478a1d5bff48a24b537')
validpgpkeys=(4B71379A9D5263D112A85620A5A4E99C711D3B61)

prepare() {
  cd $pkgname-$pkgver

  patch -Np1 -i "$srcdir"/openbox-3.5.0-title-matching.patch  # OB#5277
  patch -Np1 -i "$srcdir"/openbox-3.5.0-which-2.20.patch # FS#11455
  patch -Np1 -i "$srcdir"/$pkgname-kde-paths.patch # FS#64139
  # modified from https://github.com/troycurtisjr/openbox/commit/acfbbc4ea40932f183617bb7006700140fe5f61e
  patch -Np1 -i "$srcdir"/py3.patch
  # Taken from https://sources.debian.org/data/main/o/openbox/3.6.1-9/debian/patches/887908.patch
  # For https://bugs.archlinux.org/task/66738
  patch -Np1 -i "$srcdir"/debian-887908.patch
  # https://bugs.archlinux.org/task/72023
  patch -Np1 -i "$srcdir"/917204_undecorated_maximized_no_border.patch
  # https://bugs.archlinux.org/task/77853
  # The patch is proposed on https://bugzilla.icculus.org/show_bug.cgi?id=6669
  # and commited to a work branch in the upstream repo
  patch -Np1 -i "$srcdir"/9ed6fdd71890c5cc43747f105382d5677e5d37e7.patch

  # py3.patch modifies configure.ac
  autoreconf -ifv
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr \
    --with-x \
    --enable-startup-notification \
    --sysconfdir=/etc \
    --libexecdir=/usr/lib/openbox
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install

  # GNOME Panel is no longer available in the official repositories
  rm -r "$pkgdir"/usr/bin/{gdm-control,gnome-panel-control,openbox-gnome-session} \
    "$pkgdir"/usr/share/gnome{,-session} \
    "$pkgdir"/usr/share/man/man1/openbox-gnome-session.1 \
    "$pkgdir"/usr/share/xsessions/openbox-gnome.desktop
}
