feat(gui): manage desktop environments from a gtk window
Offer a single window to install and switch between XFCE, GNOME, Plasma, Hyprland and i3. Installation goes through pkexec and pacman, switching uses logind sessions, so neither action requires a reboot.
This commit is contained in:
4 files changed
+487
-12
No files matched your search
@@ -0,0 +1,67 @@
|
||||
#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"}},
|
||||
{"gnome", "GNOME", {"gnome"}, {"gnome"}},
|
||||
{"plasma", "KDE Plasma", {"plasma-meta"}, {"kde", "plasma"}},
|
||||
{"hyprland", "Hyprland", {"hyprland"}, {"hyprland"}},
|
||||
{"i3", "i3", {"i3"}, {"i3"}},
|
||||
};
|
||||
return desktops;
|
||||
}
|
||||
|
||||
bool isDesktopInstalled(const DesktopProfile& profile) {
|
||||
return std::all_of(profile.packages.begin(), profile.packages.end(), targetInstalled);
|
||||
}
|
||||
|
||||
bool findActiveSession(const DesktopProfile& profile, std::string& sessionId) {
|
||||
for (const SessionInfo& session : listGraphicalSessions()) {
|
||||
const std::string desktop = lower(session.desktop);
|
||||
for (const std::string& name : profile.sessionNames) {
|
||||
if (desktop == lower(name)) {
|
||||
sessionId = session.id;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
Reference in new issue
Block a user