2024-08-30 14:53:25 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
|
|
|
|
|
* 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/inputcapture.h>
|
|
|
|
|
#include <libportal/portal.h>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
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 PortalInputCapture
|
|
|
|
|
{
|
2024-08-30 14:53:25 +00:00
|
|
|
public:
|
|
|
|
|
PortalInputCapture(EiScreen *screen, IEventQueue *events);
|
|
|
|
|
~PortalInputCapture();
|
|
|
|
|
void enable();
|
|
|
|
|
void disable();
|
|
|
|
|
void release();
|
|
|
|
|
void release(double x, double y);
|
2024-10-17 18:04:35 +00:00
|
|
|
bool is_active() const
|
|
|
|
|
{
|
|
|
|
|
return is_active_;
|
|
|
|
|
}
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void glib_thread(void *);
|
|
|
|
|
gboolean timeout_handler();
|
|
|
|
|
gboolean init_input_capture_session();
|
|
|
|
|
void cb_init_input_capture_session(GObject *object, GAsyncResult *res);
|
|
|
|
|
void cb_set_pointer_barriers(GObject *object, GAsyncResult *res);
|
|
|
|
|
void cb_session_closed(XdpSession *session);
|
|
|
|
|
void cb_disabled(XdpInputCaptureSession *session);
|
2024-10-17 18:04:35 +00:00
|
|
|
void cb_activated(XdpInputCaptureSession *session, std::uint32_t activation_id, GVariant *options);
|
|
|
|
|
void cb_deactivated(XdpInputCaptureSession *session, std::uint32_t activation_id, GVariant *options);
|
2024-08-30 14:53:25 +00:00
|
|
|
void cb_zones_changed(XdpInputCaptureSession *session, GVariant *options);
|
|
|
|
|
|
|
|
|
|
/// g_signal_connect callback wrapper
|
2024-10-17 18:04:35 +00:00
|
|
|
static void cb_session_closed_cb(XdpSession *session, gpointer data)
|
|
|
|
|
{
|
2024-08-30 14:53:25 +00:00
|
|
|
reinterpret_cast<PortalInputCapture *>(data)->cb_session_closed(session);
|
|
|
|
|
}
|
2024-10-17 18:04:35 +00:00
|
|
|
static void cb_disabled_cb(XdpInputCaptureSession *session, gpointer data)
|
|
|
|
|
{
|
2024-08-30 14:53:25 +00:00
|
|
|
reinterpret_cast<PortalInputCapture *>(data)->cb_disabled(session);
|
|
|
|
|
}
|
2024-10-17 18:04:35 +00:00
|
|
|
static void
|
|
|
|
|
cb_activated_cb(XdpInputCaptureSession *session, std::uint32_t activation_id, GVariant *options, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
reinterpret_cast<PortalInputCapture *>(data)->cb_activated(session, activation_id, options);
|
2024-08-30 14:53:25 +00:00
|
|
|
}
|
2024-10-17 18:04:35 +00:00
|
|
|
static void
|
|
|
|
|
cb_deactivated_cb(XdpInputCaptureSession *session, std::uint32_t activation_id, GVariant *options, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
reinterpret_cast<PortalInputCapture *>(data)->cb_deactivated(session, activation_id, options);
|
2024-08-30 14:53:25 +00:00
|
|
|
}
|
2024-10-17 18:04:35 +00:00
|
|
|
static void cb_zones_changed_cb(XdpInputCaptureSession *session, GVariant *options, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
reinterpret_cast<PortalInputCapture *>(data)->cb_zones_changed(session, options);
|
2024-08-30 14:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int fake_eis_fd();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
EiScreen *screen_ = nullptr;
|
|
|
|
|
IEventQueue *events_ = nullptr;
|
|
|
|
|
|
|
|
|
|
Thread *glib_thread_;
|
|
|
|
|
GMainLoop *glib_main_loop_ = nullptr;
|
|
|
|
|
|
|
|
|
|
XdpPortal *portal_ = nullptr;
|
|
|
|
|
XdpInputCaptureSession *session_ = nullptr;
|
|
|
|
|
|
|
|
|
|
std::vector<guint> signals_;
|
|
|
|
|
|
|
|
|
|
bool enabled_ = false;
|
|
|
|
|
bool is_active_ = false;
|
|
|
|
|
std::uint32_t activation_id_ = 0;
|
|
|
|
|
|
|
|
|
|
std::vector<XdpInputCapturePointerBarrier *> barriers_;
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
} // namespace deskflow
|