From: Mirko Günther <renegart@gmx.de>
Subject: Export the XWayland DISPLAY to systemd user units

qtmir sets DISPLAY for the XWayland server only in the environment of the
shell process. Apps launched by Lomiri inherit it, but systemd user units
do not, e.g. XDG autostart applications started by
xdg-desktop-autostart.target or spice-vdagent in the greeter. X11 clients
among them therefore cannot connect.

Import DISPLAY into the activation environment before signalling
readiness, so it is available to every unit ordered after
graphical-session.target and to units started by the greeter wrapper.

--- a/src/main.cpp
+++ b/src/main.cpp
@@ -23,10 +23,21 @@
 #include <QTranslator>
 #include <QLibraryInfo>
 #include <QLocale>
+#include <QProcess>
 #include <QTimer>
 
 #include <systemd/sd-daemon.h>
 
+static void exportX11DisplayToSystemdUserUnits()
+{
+    if (!qEnvironmentVariableIsSet("DISPLAY")) {
+        return;
+    }
+
+    QProcess::execute(QStringLiteral("dbus-update-activation-environment"),
+                      {QStringLiteral("--systemd"), QStringLiteral("DISPLAY")});
+}
+
 int main(int argc, const char *argv[])
 {
     qSetMessagePattern("[%{time yyyy-MM-dd:hh:mm:ss.zzz}] %{if-category}%{category}: %{endif}%{message}");
@@ -64,6 +75,8 @@
     // Shouldn't do anything if we're not under systemd or it's not waiting
     // for our answer.
     QTimer::singleShot(0 /* msec */, []() {
+        exportX11DisplayToSystemdUserUnits();
+
         sd_notify(
             /* unset_environment -- we'll do so using Qt's function */ false,
             /* state */ "READY=1\n"
