The VM error persisted with polkit-kde installed: the package's autostart .desktop carries OnlyShowIn=KDE;, so XDG autostart (which niri honors via xdg-desktop-autostart.target) skips the agent in a niri session. Package present, agent never running — exactly the observed behavior. install_session_prereqs now rewrites the .desktop without the OnlyShowIn line in place (idempotent: only rewrites when the line is present).
108 lines
3.9 KiB
Bash
108 lines
3.9 KiB
Bash
# shellcheck shell=bash
|
|
#------------------------------------------
|
|
# lib/session.sh — display manager and graphical session wiring
|
|
#
|
|
# DM policy:
|
|
# * A DE module leaves its native DM alone (GNOME→gdm, Plasma→sddm, XFCE→sddm).
|
|
# * A TWM module enforces SDDM, because SDDM is the only DM that presents both
|
|
# Wayland compositors and X11 sessions in one menu. One greeter, no surprises.
|
|
#------------------------------------------
|
|
|
|
if [[ -n "${_SB_SESSION_LOADED:-}" ]]; then
|
|
return 0
|
|
fi
|
|
_SB_SESSION_LOADED=1
|
|
|
|
# Name of the active display manager ("sddm", "gdm", "lightdm"), or "" if none.
|
|
detect_display_manager() {
|
|
local link=/etc/systemd/system/display-manager.service
|
|
if [[ -L "$link" ]]; then
|
|
basename "$(readlink "$link")" | sed 's/\.service$//'
|
|
else
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
enable_graphical_target() {
|
|
sudo systemctl set-default graphical.target
|
|
}
|
|
|
|
# Make $1 the display manager, disabling whatever is active now.
|
|
switch_display_manager() {
|
|
local target="$1"
|
|
local current
|
|
current=$(detect_display_manager)
|
|
|
|
if [[ "$current" == "$target" ]]; then
|
|
ok "Display manager already $target."
|
|
else
|
|
if [[ -n "$current" ]]; then
|
|
info "Disabling current display manager: $current"
|
|
# disable may fail if the unit vanished; that is not fatal
|
|
sudo systemctl disable "$current" 2>/dev/null || true
|
|
fi
|
|
info "Enabling display manager: $target"
|
|
sudo systemctl enable "$target"
|
|
fi
|
|
|
|
enable_graphical_target
|
|
}
|
|
|
|
# Register a Wayland session so the DM can list it.
|
|
# $1 = identifier, $2 = display name, $3 = command
|
|
write_wayland_session() {
|
|
local id="$1" name="$2" exec_cmd="$3"
|
|
local file="/usr/share/wayland-sessions/${id}.desktop"
|
|
if [[ -f "$file" ]]; then
|
|
ok "Wayland session already registered: $id"
|
|
return 0
|
|
fi
|
|
info "Registering Wayland session: $id"
|
|
sudo mkdir -p "$(dirname "$file")"
|
|
printf '[Desktop Entry]\nName=%s\nComment=%s\nExec=%s\nType=Application\nDesktopNames=%s\n' \
|
|
"$name" "$name session" "$exec_cmd" "$id" | sudo tee "$file" >/dev/null
|
|
sudo chmod 644 "$file"
|
|
}
|
|
|
|
# Register an X11 session so the DM can list it.
|
|
write_x11_session() {
|
|
local id="$1" name="$2" exec_cmd="$3"
|
|
local file="/usr/share/xsessions/${id}.desktop"
|
|
if [[ -f "$file" ]]; then
|
|
ok "X11 session already registered: $id"
|
|
return 0
|
|
fi
|
|
info "Registering X11 session: $id"
|
|
# A bare Fedora has no X session yet, so the directory may not exist.
|
|
sudo mkdir -p "$(dirname "$file")"
|
|
printf '[Desktop Entry]\nName=%s\nComment=%s\nExec=%s\nType=Application\n' \
|
|
"$name" "$name session" "$exec_cmd" | sudo tee "$file" >/dev/null
|
|
sudo chmod 644 "$file"
|
|
}
|
|
|
|
# Common login-time plumbing every Wayland compositor wants on a bare install.
|
|
install_session_prereqs() {
|
|
# polkit-kde ships the agent (polkit-gnome is orphaned, EPEL-only).
|
|
# BUT its autostart file has OnlyShowIn=KDE; — XDG autostart SKIPS it in a
|
|
# niri/Hyprland/MangoWC session (VM-proven: package installed, error
|
|
# persisted). Copy the .desktop without the OnlyShowIn line so the agent
|
|
# starts in every session; the copy shadows the original by name.
|
|
install_packages \
|
|
xdg-desktop-portal \
|
|
polkit \
|
|
polkit-kde \
|
|
pipewire \
|
|
pipewire-pulseaudio \
|
|
wireplumber
|
|
|
|
local src="${POLKIT_AGENT_DESKTOP:-/etc/xdg/autostart/polkit-kde-authentication-agent-1.desktop}"
|
|
local dst="${XDG_AUTOSTART_DIR:-/etc/xdg/autostart}/polkit-kde-authentication-agent-1.desktop"
|
|
# src and dst are the same file in production — the condition to rewrite
|
|
# is "the file still contains OnlyShowIn", not "dst lacks it".
|
|
if [[ -f "$src" ]] && grep -q "^OnlyShowIn=" "$src" 2>/dev/null; then
|
|
info "Making polkit agent session-agnostic (stripping OnlyShowIn=KDE)..."
|
|
sudo mkdir -p "$(dirname "$dst")"
|
|
grep -v '^OnlyShowIn=' "$src" | sudo tee "$dst" >/dev/null
|
|
fi
|
|
}
|