2024-08-30 14:53:25 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2026-06-08 20:37:23 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2024 Synergy App Ltd
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2022 Red Hat, Inc.
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2024-08-30 14:53:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "mt/Thread.h"
|
|
|
|
|
#include "platform/EiScreen.h"
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <libportal/portal.h>
|
|
|
|
|
|
2026-05-19 19:01:38 +00:00
|
|
|
#include <QByteArray>
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
namespace deskflow {
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
class PortalRemoteDesktop
|
|
|
|
|
{
|
2024-08-30 14:53:25 +00:00
|
|
|
public:
|
|
|
|
|
PortalRemoteDesktop(EiScreen *screen, IEventQueue *events);
|
|
|
|
|
~PortalRemoteDesktop();
|
|
|
|
|
|
2026-05-19 19:01:38 +00:00
|
|
|
void claimClipboard();
|
|
|
|
|
|
2024-08-30 14:53:25 +00:00
|
|
|
private:
|
2025-05-23 20:52:46 +00:00
|
|
|
void glibThread(const void *);
|
2025-06-19 23:42:18 +00:00
|
|
|
gboolean timeoutHandler() const;
|
|
|
|
|
gboolean initSession();
|
|
|
|
|
void handleInitSession(GObject *object, GAsyncResult *res);
|
|
|
|
|
void handleSessionStarted(GObject *object, GAsyncResult *res);
|
|
|
|
|
void handleSessionClosed(XdpSession *session);
|
2026-05-19 19:01:38 +00:00
|
|
|
void handleSelectionTransfer(XdpSession *session, const char *mimeType, uint32_t serial);
|
|
|
|
|
void handleSelectionOwnerChanged(XdpSession *session, char **mimeTypes, gboolean isOwner);
|
2024-08-30 14:53:25 +00:00
|
|
|
void reconnect(unsigned int timeout = 1000);
|
|
|
|
|
|
2025-06-19 23:42:18 +00:00
|
|
|
static void handleSessionClosedCallback(XdpSession *session, gpointer data)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-06-19 23:42:18 +00:00
|
|
|
static_cast<PortalRemoteDesktop *>(data)->handleSessionClosed(session);
|
2024-08-30 14:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
2026-05-19 19:01:38 +00:00
|
|
|
static void selectionTransferCallback(XdpSession *session, const char *mimeType, uint32_t serial, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
static_cast<PortalRemoteDesktop *>(data)->handleSelectionTransfer(session, mimeType, serial);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void selectionOwnerChangedCallback(XdpSession *session, char **mimeTypes, gboolean isOwner, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
static_cast<PortalRemoteDesktop *>(data)->handleSelectionOwnerChanged(session, mimeTypes, isOwner);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 14:53:25 +00:00
|
|
|
private:
|
2025-06-19 23:42:18 +00:00
|
|
|
EiScreen *m_screen;
|
|
|
|
|
IEventQueue *m_events;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-06-19 23:42:18 +00:00
|
|
|
Thread *m_glibThread;
|
|
|
|
|
GMainLoop *m_glibMainLoop = nullptr;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-06-19 23:42:18 +00:00
|
|
|
XdpPortal *m_portal = nullptr;
|
|
|
|
|
XdpSession *m_session = nullptr;
|
|
|
|
|
char *m_sessionRestoreToken = nullptr;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-06-19 23:42:18 +00:00
|
|
|
guint m_sessionSignalId = 0;
|
2026-05-19 19:01:38 +00:00
|
|
|
guint m_selectionTransferSignalId = 0;
|
|
|
|
|
guint m_selectionOwnerChangedSignalId = 0;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
/// The number of successful sessions we've had already
|
2025-06-19 23:42:18 +00:00
|
|
|
guint m_sessionIteration = 0;
|
2024-08-30 14:53:25 +00:00
|
|
|
};
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
} // namespace deskflow
|