From dc8653845644d332327056068db4b847f53e5eb7 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Sun, 10 Aug 2025 21:30:40 -0400 Subject: [PATCH] feat: Set app id on wayland this is required for restore tokens to work correctly --- src/apps/deskflow-gui/deskflow-gui.cpp | 8 +++++ src/lib/deskflow/App.cpp | 7 +++++ src/lib/platform/CMakeLists.txt | 1 + src/lib/platform/XDGPortalRegistry.h | 41 ++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 src/lib/platform/XDGPortalRegistry.h diff --git a/src/apps/deskflow-gui/deskflow-gui.cpp b/src/apps/deskflow-gui/deskflow-gui.cpp index e40157d96..0aff866cf 100644 --- a/src/apps/deskflow-gui/deskflow-gui.cpp +++ b/src/apps/deskflow-gui/deskflow-gui.cpp @@ -32,6 +32,10 @@ #include #endif +#if defined(WINAPI_XWINDOWS) or defined(WINAPI_LIBEI) +#include "platform/XDGPortalRegistry.h" +#endif + using namespace deskflow::gui; #if defined(Q_OS_MAC) @@ -47,6 +51,10 @@ int main(int argc, char *argv[]) QLoggingCategory::setFilterRules(QStringLiteral("*.debug=true\nqt.*=false")); #endif +#if defined(WINAPI_XWINDOWS) or defined(WINAPI_LIBEI) + deskflow::platform::setAppId(); +#endif + QCoreApplication::setApplicationName(kAppName); QCoreApplication::setOrganizationName(kAppName); QCoreApplication::setApplicationVersion(kVersion); diff --git a/src/lib/deskflow/App.cpp b/src/lib/deskflow/App.cpp index ad33d7d9d..c32e81a8f 100644 --- a/src/lib/deskflow/App.cpp +++ b/src/lib/deskflow/App.cpp @@ -33,6 +33,10 @@ #include #endif +#if defined(WINAPI_XWINDOWS) or defined(WINAPI_LIBEI) +#include "platform/XDGPortalRegistry.h" +#endif + #include using namespace deskflow; @@ -51,6 +55,9 @@ App::App(IEventQueue *events, deskflow::ArgsBase *args) { assert(s_instance == nullptr); s_instance = this; +#if defined(WINAPI_XWINDOWS) or defined(WINAPI_LIBEI) + deskflow::platform::setAppId(); +#endif } App::~App() diff --git a/src/lib/platform/CMakeLists.txt b/src/lib/platform/CMakeLists.txt index 7dee5c783..39cf1e4fa 100644 --- a/src/lib/platform/CMakeLists.txt +++ b/src/lib/platform/CMakeLists.txt @@ -96,6 +96,7 @@ elseif(APPLE) ) elseif(UNIX) set(PLATFORM_SOURCES + XDGPortalRegistry.h XDGPowerManager.cpp XDGPowerManager.h XWindowsClipboard.cpp diff --git a/src/lib/platform/XDGPortalRegistry.h b/src/lib/platform/XDGPortalRegistry.h new file mode 100644 index 000000000..abb996855 --- /dev/null +++ b/src/lib/platform/XDGPortalRegistry.h @@ -0,0 +1,41 @@ +/* + * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello + * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception + */ + +#pragma once + +#include +#include +#include + +#include "platform/Wayland.h" + +namespace deskflow::platform { + +/** + * @brief setAppId Set the app id for the xdg portal registry + * All Applications should do this before attempting any other portal calls + * If the app is runing from inside a sandbox (i.e flatpak or a snap) this call does nothing + */ +inline void setAppId() +{ + // Sandboxed applications are unable to use this portal + if (isSandboxed()) { + return; + } + auto i = new QDBusInterface( + "org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop", "org.freedesktop.host.portal.Registry", + QDBusConnection::sessionBus(), nullptr + ); + + if (!i->property("version").toInt()) { + qDebug() << "portal registry not found"; + return; + } + + std::ignore = i->call("Register", "org.deskflow.deskflow", QVariantMap{}); +} + +} // namespace deskflow::platform