deskflow/src/lib/platform/PortalInputCapture.h
Chris Rizzitello ed1217e9cc
Use Deskflow Name (#7519)
* Use Deskflow Name

* Remove business-oriented options from issue templates

* Remove business-oriented workflow

* Bump version to 3.0.0 (to avoid confusion with previously used version numbers 1.x & 2.x)

* Update readme to reflect new project name and goals

* Found some more "synergy" to rename

* Rename `synlib` to `app`

* Rename `syntool` to `deskflow-legacy`

* Rename `synwinhk` to `dfwhook`

* Rename dirs from synergy to deskflow

* Rename more "Synergy" files

* Rename app bundle ID

* Fixed copyright typo

* Rename only title in serial key dialog (to be moved downstream later)

* Preserve original serial key window for moving downstream

* Restore dialogs ready for moving downstream

* Rename `QDeskflowApplication` to `DeskflowApplication` (the Q is confusing)

* Restore Volker's original project name

* Fixed mimetype

* Fixed weird grammar

* Fixed (more) weird grammar

* Broken link, restoring (but we should move all links out of source)

* Broken link, restoring (but we should move all links out of source)

* Add write permission to valgrind-analysis.yml

* Restore AUR conflicts

* Apply Clang format

* Update ChangeLog

* Back out version change

---------

Co-authored-by: Nick Bolton <nick@symless.com>
2024-09-17 20:00:25 +01:00

109 lines
3.4 KiB
C++

/*
* Deskflow -- mouse and keyboard sharing utility
* Copyright (C) 2022 Red Hat, Inc.
* Copyright (C) 2024 Symless Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "config.h"
#if HAVE_LIBPORTAL_INPUTCAPTURE
#include "mt/Thread.h"
#include "platform/EiScreen.h"
#include <glib.h>
#include <libportal/inputcapture.h>
#include <libportal/portal.h>
#include <memory>
namespace deskflow {
class PortalInputCapture {
public:
PortalInputCapture(EiScreen *screen, IEventQueue *events);
~PortalInputCapture();
void enable();
void disable();
void release();
void release(double x, double y);
bool is_active() const { return is_active_; }
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);
void cb_activated(
XdpInputCaptureSession *session, std::uint32_t activation_id,
GVariant *options);
void cb_deactivated(
XdpInputCaptureSession *session, std::uint32_t activation_id,
GVariant *options);
void cb_zones_changed(XdpInputCaptureSession *session, GVariant *options);
/// g_signal_connect callback wrapper
static void cb_session_closed_cb(XdpSession *session, gpointer data) {
reinterpret_cast<PortalInputCapture *>(data)->cb_session_closed(session);
}
static void cb_disabled_cb(XdpInputCaptureSession *session, gpointer data) {
reinterpret_cast<PortalInputCapture *>(data)->cb_disabled(session);
}
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);
}
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);
}
static void cb_zones_changed_cb(
XdpInputCaptureSession *session, GVariant *options, gpointer data) {
reinterpret_cast<PortalInputCapture *>(data)->cb_zones_changed(
session, options);
}
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_;
};
} // namespace deskflow
#endif // HAVE_LIBPORTAL_INPUTCAPTURE