From 0141206db69176cd7e26632df6968eadc17eacb3 Mon Sep 17 00:00:00 2001
From: c4pp4
Date: Tue, 20 Oct 2026 13:03:31 +0200
Subject: [PATCH 1/1] Fix environment variables, start indicators and PipeWire
 without systemd

Set the XDG_CURRENT_DESKTOP environment variable for gsettings overrides
per session. Import the DISPLAY environment variable into the systemd
manager environment block to show nm-applet notifications and to fix
the keyboard layout to correspond with the indicator-keyboard icon.
Import the XDG_SESSION_CLASS environment variable, which is used
by indicator-sound.

Without the 'systemd --user' process (e.g. on OpenRC), the indicator
services can not be started via systemctl, so launch them directly.
Skip importing environment variables into the systemd manager
environment block in that case.

Without systemd, PipeWire is not started for the greeter (the XDG
autostart entry is processed only by the session manager), so start
it via gentoo-pipewire-launcher to enable sound in the greeter.

Signed-off-by: c4pp4
---
 src/unity-greeter.vala | 83 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 71 insertions(+), 12 deletions(-)

diff --git a/src/unity-greeter.vala b/src/unity-greeter.vala
index 929fa2c..a1ebe70 100644
--- a/src/unity-greeter.vala
+++ b/src/unity-greeter.vala
@@ -538,8 +538,27 @@ public class UnityGreeter
         greeter_ready ();
     }
 
+    private static bool is_systemd_user_session ()
+    {
+        /* The 'systemd --user' process creates this directory when it is running */
+        return FileUtils.test (Path.build_filename (Environment.get_user_runtime_dir (), "systemd"), FileTest.IS_DIR);
+    }
+
     public static int main (string[] args)
     {
+        if (is_systemd_user_session ())
+        {
+            try
+            {
+                Process.spawn_command_line_sync ("systemctl --user import-environment DISPLAY XDG_SESSION_CLASS");
+            }
+            catch (Error e)
+            {
+                warning ("Error importing environment variables: %s", e.message);
+            }
+        }
+
+        Environment.set_variable ("XDG_CURRENT_DESKTOP", "unity-greeter", false);
 
         /* Disable the stupid global menubar */
         Environment.unset_variable ("UBUNTU_MENUPROXY");
@@ -638,21 +657,61 @@ public class UnityGreeter
             });
 
             /* Start the indicator services */
-            try
+            if (is_systemd_user_session ())
             {
-                string[] argv;
-
-                Shell.parse_argv ("systemctl --user start indicator-application indicator-power indicator-datetime indicator-keyboard indicator-session indicator-sound", out argv);
-                Process.spawn_async (null,
-                                     argv,
-                                     null,
-                                     SpawnFlags.SEARCH_PATH,
-                                     null,
-                                     null);
+                try
+                {
+                    string[] argv;
+
+                    Shell.parse_argv ("systemctl --user start indicator-application indicator-power indicator-datetime indicator-keyboard indicator-session indicator-sound", out argv);
+                    Process.spawn_async (null,
+                                         argv,
+                                         null,
+                                         SpawnFlags.SEARCH_PATH,
+                                         null,
+                                         null);
+                }
+                catch (Error e)
+                {
+                    warning ("Error starting indicators: %s", e.message);
+                }
             }
-            catch (Error e)
+            else
             {
-                warning ("Error starting indicators: %s", e.message);
+                /* Without systemd, start PipeWire via Gentoo's launcher script (the XDG autostart entry is not processed by the greeter) */
+                if (FileUtils.test ("/usr/bin/gentoo-pipewire-launcher", FileTest.IS_EXECUTABLE))
+                {
+                    try
+                    {
+                        Process.spawn_command_line_async ("/usr/bin/gentoo-pipewire-launcher restart");
+                    }
+                    catch (Error e)
+                    {
+                        warning ("Error starting PipeWire: %s", e.message);
+                    }
+                }
+
+                /* Without systemd, launch the indicator services directly */
+                string[] services = {
+                    "/usr/libexec/indicator-application/indicator-application-service",
+                    "/usr/libexec/indicator-power/indicator-power-service",
+                    "/usr/libexec/indicator-datetime/indicator-datetime-service",
+                    "/usr/libexec/indicator-keyboard/indicator-keyboard-service --use-gtk",
+                    "/usr/libexec/indicator-session/indicator-session-service",
+                    "/usr/libexec/indicator-sound/indicator-sound-service"
+                };
+
+                foreach (var service in services)
+                {
+                    try
+                    {
+                        Process.spawn_command_line_async (service);
+                    }
+                    catch (Error e)
+                    {
+                        warning ("Error starting indicator service %s: %s", service, e.message);
+                    }
+                }
             }
 
             /* Make nm-applet hide items the user does not have permissions to interact with */
