From 58236232cc08f87e17a5fa08bc8a143c7ea5f4f5 Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Tue, 21 Jul 2020 12:15:49 -0500
Subject: [PATCH] Reorganize dbus a bit more, explicitly update activation env

---
 firestarter | 75 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 42 insertions(+), 33 deletions(-)

diff --git a/firestarter b/firestarter
index e258b8f..78e76de 100755
--- a/firestarter
+++ b/firestarter
@@ -158,40 +158,7 @@ step_preexecute() {
 	[ -n "$FIRESTARTER" ] && [ "$FIRESTARTER_DISPLAY" == "$DISPLAY" ] error "Firestarter is already running on $DISPLAY: $FIRESTARTER" 55
 	export FIRESTARTER="$BASHPID"
 	export FIRESTARTER_DISPLAY="$DISPLAY"
-	# IME settings
-	if has uim; then
-		export GTK_IM_MODULE='uim'
-		export QT_IM_MODULE='uim'
-		export XMODIFIERS='@im=uim'
-	elif has ibus; then
-		export GTK_IM_MODULE='ibus'
-		export QT_IM_MODULE='ibus'
-		export XMODIFIERS='@im=ibus'
-	fi
-	# kcminit/Qt settings
-	if has qt5ct; then
-		log "Initializing qt5ct"
-		if [ -z "$QT_QPA_PLATFORMTHEME" ]; then
-			export QT_QPA_PLATFORMTHEME="qt5ct"
-			log "Exporting QT_QPA_PLATFORMTHEME as \"$QT_QPA_PLATFORMTHEME\"" 2
-		else
-			log "Using existing theme setting \"$QT_QPA_PLATFORMTHEME\"" 2
-		fi
-		if [ -z "$QT_AUTO_SCREEN_SCALE_FACTOR" ]; then
-			export QT_AUTO_SCREEN_SCALE_FACTOR="0"
-			log "Exporting QT_AUTO_SCREEN_SCALE_FACTOR as \"$QT_AUTO_SCREEN_SCALE_FACTOR\"" 2
-		else
-			log "Using existing scale factor \"$QT_AUTO_SCREEN_SCALE_FACTOR\"" 2
-		fi
-	fi
-	if has kcminit; then
-		log "Initializing KDE Control Module settings"
-		kcminit >/dev/null 2>&1
-		# Disabled here because an XDGCD of KDE implies kded and other KDE parts, breaking copypasta and other things
-		#export XDG_CURRENT_DESKTOP="KDE"
-	fi
 	# dbus
-	# We initialize this after setting envvars so it propogates to the whole session
 	if \
 		[ -z "$DBUS_SESSION_BUS_ADDRESS" ] && \
 		[ -n "$XDG_RUNTIME_DIR" ] && \
@@ -209,6 +176,48 @@ step_preexecute() {
 	else
 		warn "Did not start dbus; some applications may misbehave"
 	fi
+	# Nest protection
+	if [ -n "$_hasdbus" ]; then
+		dbus-update-activation-environment FIRESTARTER FIRESTARTER_DISPLAY
+	fi
+	# IME settings
+	if has uim; then
+		export GTK_IM_MODULE='uim'
+		export QT_IM_MODULE='uim'
+		export XMODIFIERS='@im=uim'
+	elif has ibus; then
+		export GTK_IM_MODULE='ibus'
+		export QT_IM_MODULE='ibus'
+		export XMODIFIERS='@im=ibus'
+	fi
+	if [ -n "$_hasdbus" ]; then
+		dbus-update-activation-environment GTK_IM_MODULE QT_IM_MODULE XMODIFIERS
+	fi
+	# kcminit/Qt settings
+	if has qt5ct; then
+		log "Initializing qt5ct"
+		if [ -z "$QT_QPA_PLATFORMTHEME" ]; then
+			export QT_QPA_PLATFORMTHEME="qt5ct"
+			log "Exporting QT_QPA_PLATFORMTHEME as \"$QT_QPA_PLATFORMTHEME\"" 2
+		else
+			log "Using existing theme setting \"$QT_QPA_PLATFORMTHEME\"" 2
+		fi
+		if [ -z "$QT_AUTO_SCREEN_SCALE_FACTOR" ]; then
+			export QT_AUTO_SCREEN_SCALE_FACTOR="0"
+			log "Exporting QT_AUTO_SCREEN_SCALE_FACTOR as \"$QT_AUTO_SCREEN_SCALE_FACTOR\"" 2
+		else
+			log "Using existing scale factor \"$QT_AUTO_SCREEN_SCALE_FACTOR\"" 2
+		fi
+		if [ -n "$_hasdbus" ]; then
+			dbus-update-activation-environment QT_QPA_PLATFORMTHEME QT_AUTO_SCREEN_SCALE_FACTOR
+		fi
+	fi
+	if has kcminit; then
+		log "Initializing KDE Control Module settings"
+		kcminit >/dev/null 2>&1
+		# Disabled here because an XDGCD of KDE implies kded and other KDE parts, breaking copypasta and other things
+		#export XDG_CURRENT_DESKTOP="KDE"
+	fi
 	# xhost
 	if has xhost; then
 		if xhost +si:localuser:"$(id -un)" >/dev/null 2>&1; then