# 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=8
pkgdesc='Highly configurable and lightweight X11 window manager'
arch=('x86_64')
url='http://openbox.org'
license=('GPL')
provides=(libobrender.so)
depends=('startup-notification' 'libxml2' 'libxinerama' 'libxrandr'
         'libxcursor' 'pango' 'imlib2' 'librsvg' 'libsm')
makedepends=('python')
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)
md5sums=('b72794996c6a3ad94634727b95f9d204'
         'SKIP'
         '0a11d7149da210a31ef88f8a9c717711'
         '7ca3b5244bb092d46f5bcf1e2bdf4a18'
         'f7df0df8c1d2da279e48d0fdc984fb71'
         '67ae9735c283637ef6d11b17a3f81953'
         '4ff275746641e840605e9a74043079fe'
         'bf629dfad2b4bef6330dd914922cae48')
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

  # 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
}
