Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
HostDirectory.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include "phosphorconfig_export.h"
7
8#include <QDateTime>
9#include <QList>
10#include <QString>
11#include <QStringList>
12
13#include <optional>
14
15QT_BEGIN_NAMESPACE
16class QJsonObject;
17QT_END_NAMESPACE
18
19namespace PhosphorConfig {
20
32struct PHOSPHORCONFIG_EXPORT HostDescriptor
33{
36 QString id;
38 QString name;
42 QString busName;
44 QString backend;
48 QString configPath;
52 QStringList desktops;
53
57 [[nodiscard]] static std::optional<HostDescriptor> parse(const QJsonObject& json, QString* error);
58
64 [[nodiscard]] QString resolvedConfigPath() const;
65};
66
69struct PHOSPHORCONFIG_EXPORT HostRecord
70{
71 QString host;
72 QString configPath;
73 qint64 pid = 0;
74 QDateTime written;
75};
76
78struct PHOSPHORCONFIG_EXPORT HostResolution
79{
83 std::optional<HostDescriptor> host;
88 QString configPath;
93 QList<HostDescriptor> candidates;
107 bool running = false;
108};
109
116class PHOSPHORCONFIG_EXPORT HostDirectory
117{
118public:
123 explicit HostDirectory(QString api);
124
132 [[nodiscard]] QList<HostDescriptor> descriptors() const;
133
137 [[nodiscard]] QString recordPath() const;
142 [[nodiscard]] std::optional<HostRecord> record() const;
149 [[nodiscard]] bool writeRecord(const QString& hostId, const QString& configPath, qint64 pid) const;
150
186 [[nodiscard]] static HostResolution resolve(const QList<HostDescriptor>& descriptors,
187 const std::optional<HostRecord>& record, qint64 busOwnerPid,
188 const QStringList& currentDesktops);
189
191 [[nodiscard]] static QStringList currentDesktops();
192
193private:
194 QString m_api;
195};
196
197} // namespace PhosphorConfig
bool writeRecord(const QString &hostId, const QString &configPath, qint64 pid) const
Record host hostId, keeping its settings in configPath, as this user's host of the API.
std::optional< HostRecord > record() const
The record, or nullopt when there is none.
HostDirectory(QString api)
api names the API, placement for the placement API.
static QStringList currentDesktops()
XDG_CURRENT_DESKTOP, split on :.
static HostResolution resolve(const QList< HostDescriptor > &descriptors, const std::optional< HostRecord > &record, qint64 busOwnerPid, const QStringList &currentDesktops)
Choose a host.
QList< HostDescriptor > descriptors() const
Every valid descriptor in the phosphor-works/<api>-hosts/ directories of the XDG data dirs,...
QString recordPath() const
$XDG_STATE_HOME/phosphor-works/<api>-host.json.
Definition HostDirectory.h:19
One host of a settings API, as the static descriptor its package installs in <datadir>/phosphor-works...
Definition HostDirectory.h:33
QStringList desktops
XDG_CURRENT_DESKTOP entries the host serves, compared ignoring case.
Definition HostDirectory.h:52
QString busName
The bus name the host owns while it runs.
Definition HostDirectory.h:42
QString backend
The PhosphorConfig backend the file uses. Only json is known.
Definition HostDirectory.h:44
QString id
Matches [a-z0-9][a-z0-9-]*.
Definition HostDirectory.h:36
QString resolvedConfigPath() const
configPath with its leading variable expanded for this user.
QString name
A product name, shown untranslated where a user chooses between hosts.
Definition HostDirectory.h:38
static std::optional< HostDescriptor > parse(const QJsonObject &json, QString *error)
Parse json.
QString configPath
The file: $XDG_CONFIG_HOME, $XDG_DATA_HOME, $XDG_STATE_HOME or $HOME, then / and a path with no empty...
Definition HostDirectory.h:48
What the last host of an API to start wrote about itself, or the choice a user made between several h...
Definition HostDirectory.h:70
QString configPath
Definition HostDirectory.h:72
QString host
Definition HostDirectory.h:71
QDateTime written
Definition HostDirectory.h:74
qint64 pid
Definition HostDirectory.h:73
Which host's settings file a module edits, from HostDirectory::resolve().
Definition HostDirectory.h:79
std::optional< HostDescriptor > host
The host, or nullopt when none could be chosen: no record chose one and the session's desktops match ...
Definition HostDirectory.h:83
QList< HostDescriptor > candidates
Several descriptors match this session and nothing chose between them: ask the user,...
Definition HostDirectory.h:93
QString configPath
The file to edit.
Definition HostDirectory.h:88
bool running
Some process owns the API's bus name.
Definition HostDirectory.h:107