1
0
mirror of https://github.com/KDE/krfb synced 2026-07-01 07:41:17 -07:00

wayland: Add support for the persistence feature of the remote desktop portal

Same idea as https://invent.kde.org/network/kdeconnect-kde/-/merge_requests/639, v2 of the remote desktop portal can accept and return a restore token that we can use to avoid constantly asking the user for permission every time Krfb is started.

Note that there's a bug in `xdg-desktop-portal-kde` that breaks persistence if it's restarted for whatever reason, for example when rebooting (see https://bugs.kde.org/show_bug.cgi?id=480235 and https://invent.kde.org/network/kdeconnect-kde/-/merge_requests/639#note_859651 for more details), so at the moment this only works when restarting Krfb in the same session.
This commit is contained in:
Prajna Sariputra
2024-06-01 12:27:07 +00:00
committed by Nicolas Fella
parent 24a3a261f8
commit f071ad4eba
3 changed files with 161 additions and 12 deletions

View File

@@ -57,6 +57,7 @@ target_link_libraries(krfb_framebuffer_pw
Qt::Gui
Qt::DBus
KF6::CoreAddons
KF6::ConfigCore
PkgConfig::PipeWire
Plasma::KWaylandClient
Wayland::Client

View File

@@ -22,6 +22,9 @@
#include <QDebug>
#include <QRandomGenerator>
#include <KConfigGroup>
#include <KSharedConfig>
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/registry.h>
@@ -185,8 +188,16 @@ void PWFrameBuffer::Private::handleSessionCreated(quint32 code, const QVariantMa
auto selectionOptions = QVariantMap {
// We have to specify it's an uint, otherwise xdg-desktop-portal will not forward it to backend implementation
{ QStringLiteral("types"), QVariant::fromValue<uint>(7) }, // request all (KeyBoard, Pointer, TouchScreen)
{ QStringLiteral("handle_token"), QStringLiteral("krfb%1").arg(QRandomGenerator::global()->generate()) }
{ QStringLiteral("handle_token"), QStringLiteral("krfb%1").arg(QRandomGenerator::global()->generate()) },
{ QStringLiteral("persist_mode"), QVariant::fromValue<uint>(2) }, // Persist permission until explicitly revoked by user
};
KConfigGroup stateConfig = KSharedConfig::openStateConfig()->group(QStringLiteral("XdgPortal"));
const QString restoreToken = stateConfig.readEntry(QStringLiteral("RestoreToken"), QString());
if (!restoreToken.isEmpty()) {
selectionOptions[QStringLiteral("restore_token")] = restoreToken;
}
auto selectorReply = dbusXdpRemoteDesktopService->SelectDevices(sessionPath, selectionOptions);
selectorReply.waitForFinished();
if (!selectorReply.isValid()) {
@@ -334,6 +345,10 @@ void PWFrameBuffer::Private::handleRemoteDesktopStarted(quint32 code, const QVar
isValid = false;
return;
}
// save restore token
KConfigGroup stateConfig = KSharedConfig::openStateConfig()->group(QStringLiteral("XdgPortal"));
stateConfig.writeEntry(QStringLiteral("RestoreToken"), results[QStringLiteral("restore_token")].toString());
}
void PWFrameBuffer::Private::handleFrame(const PipeWireFrame &frame)