Files
FWS-DeskManger/src/desktop-catalog.cpp
T
BlackAngelTV e47fd92f47 feat(launch): start desktops without the login screen
The greeter only starts the session its own selector points at, so an
installed environment with no open session could not be reached from
the tool. Starting one needs a one-shot autologin drop-in, a display
manager restart and a guaranteed cleanup, all as root: keep that in a
small pkexec helper so the CLI and the GTK window stay unprivileged.
2026-11-13 16:27:41 +01:00

109 lines
3.3 KiB
C++

#include "desktop-catalog.h"
#include "process.h"
#include "session-catalog.h"
#include <algorithm>
#include <cctype>
namespace fws {
namespace {
std::string lower(std::string value) {
std::transform(value.begin(), value.end(), value.begin(),
[](unsigned char character) { return static_cast<char>(std::tolower(character)); });
return value;
}
bool pacmanKnows(const std::vector<std::string>& arguments) {
const CommandResult result = runCommand(arguments);
return result.started && result.exitCode == 0;
}
bool targetInstalled(const std::string& target) {
// A target is either a package (pacman -Q) or a group (pacman -Qg).
if (pacmanKnows({"pacman", "-Q", target})) {
return true;
}
return pacmanKnows({"pacman", "-Qg", target});
}
} // namespace
const std::vector<DesktopProfile>& supportedDesktops() {
static const std::vector<DesktopProfile> desktops = {
{"xfce", "XFCE", {"xfce4"}, {"xfce", "xfce4"}, {"xfce", "xfce4-session"}},
{"gnome", "GNOME", {"gnome"}, {"gnome"}, {"gnome", "gnome-xorg"}},
// Plasma 6 renamed its session files; the Wayland entry comes first.
{"plasma",
"KDE Plasma",
{"plasma-meta"},
{"kde", "plasma"},
{"plasma", "plasmawayland", "plasmax11", "plasmadesktop"}},
{"hyprland", "Hyprland", {"hyprland"}, {"hyprland"}, {"hyprland"}},
{"i3", "i3", {"i3"}, {"i3"}, {"i3"}},
};
return desktops;
}
const DesktopProfile* findDesktopProfile(const std::string& name) {
const std::string wanted = lower(name);
if (wanted.empty()) {
return nullptr;
}
for (const DesktopProfile& profile : supportedDesktops()) {
if (lower(profile.id) == wanted || lower(profile.name) == wanted ||
lower(profile.name).rfind(wanted, 0) == 0) {
return &profile;
}
}
return nullptr;
}
bool isDesktopInstalled(const DesktopProfile& profile) {
return std::all_of(profile.packages.begin(), profile.packages.end(), targetInstalled);
}
bool findActiveSession(const DesktopProfile& profile, std::string& sessionId) {
// Prefer the session that owns the seat: a stale or closing session of the
// same desktop would activate a VT that has nothing left to draw.
std::string fallback;
for (const SessionInfo& session : listGraphicalSessions()) {
if (session.state == "closing" || session.state == "closing-failed") {
continue;
}
const std::string desktop = lower(session.desktop);
bool matches = false;
for (const std::string& name : profile.sessionNames) {
if (desktop == lower(name)) {
matches = true;
break;
}
}
if (!matches) {
continue;
}
if (session.active) {
sessionId = session.id;
return true;
}
if (fallback.empty()) {
fallback = session.id;
}
}
if (fallback.empty()) {
return false;
}
sessionId = fallback;
return true;
}
std::vector<std::string> installArguments(const DesktopProfile& profile) {
std::vector<std::string> arguments = {"pkexec", "pacman", "-S", "--needed", "--noconfirm"};
arguments.insert(arguments.end(), profile.packages.begin(), profile.packages.end());
return arguments;
}
} // namespace fws