From e08479afc9e38e648f0bd5b13994d508220aae60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
Date: Sun, 22 Jul 2018 15:25:03 +0200
Subject: [PATCH] Add wrapper to launch rootston and make it spawn
 gnome-session

gnome-session needs an X11 display so start rootston first and make it
spawn gnome-session (which will spawn phosh later on).
---
 data/meson.build | 13 +++++++++++++
 data/phosh.in    | 18 ++++++++++++++++++
 debian/rules     |  2 --
 meson.build      |  6 ++++++
 src/meson.build  |  2 +-
 5 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100755 data/phosh.in

diff --git a/data/meson.build b/data/meson.build
index 98c585753..7eb1cf12d 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,3 +1,16 @@
+runconf = configuration_data()
+runconf.set('bindir', bindir)
+runconf.set('libexecdir', libexecdir)
+runconf.set('pkgdatadir', pkgdatadir)
+runconf.set('wlrootsdir', join_paths(libexecdir, 'wlroots'))
+configure_file(
+  input: 'phosh.in',
+  output: 'phosh',
+  install_dir: bindir,
+  configuration: runconf,
+  install: true
+)
+
 schemas = ['sm.puri.phosh.gschema.xml']
 compiled = gnome.compile_schemas(
   build_by_default: true
diff --git a/data/phosh.in b/data/phosh.in
new file mode 100755
index 000000000..b0f47f2ad
--- /dev/null
+++ b/data/phosh.in
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+ROOTSTON="/usr/bin/rootston"
+ROOTSTON_INI="@pkgdatadir@/rootston.ini"
+
+if [ -x @wlrootsdir@/rootston ]; then
+  ROOTSTON=@wlrootsdir@/rootston
+elif [ -x @bindir@/rootston ]; then
+  ROOTSTON=@bindir@/rootston
+elif [ -x /usr/lib/wlroots/rootston ]; then
+  ROOTSTON=/usr/lib/wlroots/rootston
+fi
+
+if [ -f "/etc/phosh/rootston.ini" ]; then
+  ROOTSTON_INI=/etc/phosh/rootston.ini
+fi
+
+exec "${ROOTSTON}" -C "${ROOTSTON_INI}" -E "gnome-session --disable-acceleration-check --session=phosh"
diff --git a/debian/rules b/debian/rules
index 5ce4b2341..b2d064b1a 100755
--- a/debian/rules
+++ b/debian/rules
@@ -7,8 +7,6 @@ export DEB_BUILD_MAINT_OPTIONS = hardening=+all
 
 override_dh_auto_install:
 	dh_auto_install
-	# Move phosh to arch indep dir
-	mv debian/phosh/usr/lib/*/phosh debian/phosh/usr/lib/phosh/phosh
 	cp rootston.ini debian/phosh/usr/share/phosh/
 
 override_dh_installsystemd:
diff --git a/meson.build b/meson.build
index d93d05cf1..0543d12ee 100644
--- a/meson.build
+++ b/meson.build
@@ -5,6 +5,12 @@ project('phosh', 'c',
   default_options: [ 'warning_level=1', 'buildtype=debugoptimized', 'c_std=gnu11' ],
 )
 
+prefix = get_option('prefix')
+bindir = join_paths(prefix, get_option('bindir'))
+datadir = join_paths(prefix, get_option('datadir'))
+libexecdir = join_paths(prefix, get_option('libexecdir'))
+pkgdatadir = join_paths(datadir, meson.project_name())
+
 config_h = configuration_data()
 config_h.set_quoted('GETTEXT_PACKAGE', 'phosh')
 config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
diff --git a/src/meson.build b/src/meson.build
index 438923191..1e0a8fdec 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -87,6 +87,6 @@ phosh_deps = [
 phosh = executable('phosh', phosh_sources,
   dependencies: phosh_deps,
   install: true,
-  install_dir: get_option('libexecdir'),
+  install_dir: libexecdir,
 )
 
-- 
GitLab