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
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
#include "deskflow/KeyMap.h"
|
|
|
|
|
#include "deskflow/PlatformScreen.h"
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
#include <libei.h>
|
2025-06-20 02:20:36 +00:00
|
|
|
#include <memory>
|
2024-08-30 14:53:25 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
struct ei;
|
|
|
|
|
struct ei_event;
|
|
|
|
|
struct ei_seat;
|
|
|
|
|
struct ei_device;
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
namespace deskflow {
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
class EiClipboard;
|
|
|
|
|
class EiKeyState;
|
|
|
|
|
class PortalRemoteDesktop;
|
|
|
|
|
class PortalInputCapture;
|
|
|
|
|
|
|
|
|
|
//! Implementation of IPlatformScreen for X11
|
2024-10-17 18:04:35 +00:00
|
|
|
class EiScreen : public PlatformScreen
|
|
|
|
|
{
|
2024-08-30 14:53:25 +00:00
|
|
|
public:
|
2025-08-26 07:43:41 +00:00
|
|
|
EiScreen(
|
|
|
|
|
bool isPrimary, IEventQueue *events, bool usePortal,
|
|
|
|
|
deskflow::ClientScrollDirection scrollDirection = deskflow::ClientScrollDirection::Normal
|
|
|
|
|
);
|
2025-04-28 01:27:48 +00:00
|
|
|
~EiScreen() override;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
// IScreen overrides
|
2025-05-23 17:48:39 +00:00
|
|
|
void *getEventTarget() const final;
|
2024-08-30 14:53:25 +00:00
|
|
|
bool getClipboard(ClipboardID id, IClipboard *) const override;
|
2024-10-17 18:04:35 +00:00
|
|
|
void getShape(std::int32_t &x, std::int32_t &y, std::int32_t &width, std::int32_t &height) const override;
|
2024-08-30 14:53:25 +00:00
|
|
|
void getCursorPos(std::int32_t &x, std::int32_t &y) const override;
|
|
|
|
|
|
|
|
|
|
// IPrimaryScreen overrides
|
|
|
|
|
void reconfigure(std::uint32_t activeSides) override;
|
2025-07-13 14:26:11 +00:00
|
|
|
std::uint32_t activeSides() override;
|
2024-08-30 14:53:25 +00:00
|
|
|
void warpCursor(std::int32_t x, std::int32_t y) override;
|
|
|
|
|
std::uint32_t registerHotKey(KeyID key, KeyModifierMask mask) override;
|
|
|
|
|
void unregisterHotKey(std::uint32_t id) override;
|
|
|
|
|
void fakeInputBegin() override;
|
|
|
|
|
void fakeInputEnd() override;
|
|
|
|
|
std::int32_t getJumpZoneSize() const override;
|
|
|
|
|
bool isAnyMouseButtonDown(std::uint32_t &buttonID) const override;
|
|
|
|
|
void getCursorCenter(std::int32_t &x, std::int32_t &y) const override;
|
|
|
|
|
|
|
|
|
|
// ISecondaryScreen overrides
|
|
|
|
|
void fakeMouseButton(ButtonID id, bool press) override;
|
|
|
|
|
void fakeMouseMove(std::int32_t x, std::int32_t y) override;
|
|
|
|
|
void fakeMouseRelativeMove(std::int32_t dx, std::int32_t dy) const override;
|
|
|
|
|
void fakeMouseWheel(std::int32_t xDelta, std::int32_t yDelta) const override;
|
2025-08-06 23:36:53 +00:00
|
|
|
void fakeKey(std::uint32_t keycode, bool isDown) const;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
// IPlatformScreen overrides
|
|
|
|
|
void enable() override;
|
|
|
|
|
void disable() override;
|
|
|
|
|
void enter() override;
|
2024-09-17 03:19:52 +00:00
|
|
|
bool canLeave() override;
|
|
|
|
|
void leave() override;
|
2024-08-30 14:53:25 +00:00
|
|
|
bool setClipboard(ClipboardID, const IClipboard *) override;
|
|
|
|
|
void checkClipboards() override;
|
|
|
|
|
void openScreensaver(bool notify) override;
|
|
|
|
|
void closeScreensaver() override;
|
|
|
|
|
void screensaver(bool activate) override;
|
|
|
|
|
void resetOptions() override;
|
|
|
|
|
void setOptions(const OptionsList &options) override;
|
|
|
|
|
void setSequenceNumber(std::uint32_t) override;
|
|
|
|
|
bool isPrimary() const override;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
// IPlatformScreen overrides
|
2025-06-18 04:17:54 +00:00
|
|
|
void handleSystemEvent(const Event &event) override;
|
2024-08-30 14:53:25 +00:00
|
|
|
void updateButtons() override;
|
|
|
|
|
IKeyState *getKeyState() const override;
|
2025-01-06 00:55:07 +00:00
|
|
|
std::string getSecureInputApp() const override;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-06-20 00:53:37 +00:00
|
|
|
void updateShape();
|
|
|
|
|
void addDevice(ei_device *device);
|
|
|
|
|
void removeDevice(ei_device *device);
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
private:
|
2025-06-20 00:53:37 +00:00
|
|
|
void initEi();
|
|
|
|
|
void cleanupEi();
|
2025-05-02 01:50:53 +00:00
|
|
|
void sendEvent(EventTypes type, void *data);
|
2025-06-20 00:53:37 +00:00
|
|
|
ButtonID mapButtonFromEvdev(ei_event *event) const;
|
|
|
|
|
void onKeyEvent(ei_event *event);
|
|
|
|
|
void onButtonEvent(ei_event *event);
|
|
|
|
|
void sendWheelEvents(ei_device *device, const int threshold, double dx, double dy, bool is_discrete);
|
|
|
|
|
void onPointerScrollEvent(ei_event *event);
|
|
|
|
|
void onPointerScrollDiscreteEvent(ei_event *event);
|
|
|
|
|
void onMotionEvent(ei_event *event);
|
2025-06-20 02:20:36 +00:00
|
|
|
void onAbsMotionEvent(const ei_event *) const;
|
2025-08-06 23:36:53 +00:00
|
|
|
bool onHotkey(KeyID key, bool isPressed, KeyModifierMask mask);
|
2025-06-20 00:53:37 +00:00
|
|
|
void eiLogEvent(ei_log_priority priority, const char *message) const;
|
|
|
|
|
|
|
|
|
|
void handleConnectedToEisEvent(const Event &event);
|
|
|
|
|
void handlePortalSessionClosed();
|
|
|
|
|
|
2025-06-20 02:20:36 +00:00
|
|
|
static void handleEiLogEvent(ei *ei, const ei_log_priority priority, const char *message, ei_log_context *)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-05-23 18:32:42 +00:00
|
|
|
auto screen = static_cast<EiScreen *>(ei_get_user_data(ei));
|
2025-06-20 00:53:37 +00:00
|
|
|
screen->eiLogEvent(priority, message);
|
2024-08-30 14:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// true if screen is being used as a primary screen, false otherwise
|
2025-06-20 00:53:37 +00:00
|
|
|
bool m_isPrimary = false;
|
|
|
|
|
IEventQueue *m_events = nullptr;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
// keyboard stuff
|
2025-06-20 00:53:37 +00:00
|
|
|
EiKeyState *m_keyState = nullptr;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-06-20 00:53:37 +00:00
|
|
|
std::vector<ei_device *> m_eiDevices;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-06-20 00:53:37 +00:00
|
|
|
ei *m_ei = nullptr;
|
|
|
|
|
ei_seat *m_eiSeat = nullptr;
|
|
|
|
|
ei_device *m_eiPointer = nullptr;
|
|
|
|
|
ei_device *m_eiKeyboard = nullptr;
|
|
|
|
|
ei_device *m_eiAbs = nullptr;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-06-20 00:53:37 +00:00
|
|
|
std::uint32_t m_sequenceNumber = 0;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-07-13 14:26:11 +00:00
|
|
|
std::uint32_t m_activeSides = 0;
|
2025-06-20 00:53:37 +00:00
|
|
|
std::uint32_t m_x = 0;
|
|
|
|
|
std::uint32_t m_y = 0;
|
|
|
|
|
std::uint32_t m_w = 0;
|
|
|
|
|
std::uint32_t m_h = 0;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
// true if mouse has entered the screen
|
2025-06-20 00:53:37 +00:00
|
|
|
bool m_isOnScreen;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
// server: last pointer position
|
|
|
|
|
// client: position sent before enter()
|
2025-06-20 00:53:37 +00:00
|
|
|
std::int32_t m_cursorX = 0;
|
|
|
|
|
std::int32_t m_cursorY = 0;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-06-20 00:53:37 +00:00
|
|
|
double m_bufferDX = 0;
|
|
|
|
|
double m_bufferDY = 0;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-06-20 00:53:37 +00:00
|
|
|
mutable std::mutex m_mutex;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2025-06-20 00:53:37 +00:00
|
|
|
PortalRemoteDesktop *m_portalRemoteDesktop = nullptr;
|
|
|
|
|
PortalInputCapture *m_portalInputCapture = nullptr;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
struct HotKeyItem
|
|
|
|
|
{
|
2024-08-30 14:53:25 +00:00
|
|
|
public:
|
|
|
|
|
HotKeyItem(std::uint32_t mask, std::uint32_t id);
|
2024-10-17 18:04:35 +00:00
|
|
|
bool operator<(const HotKeyItem &other) const
|
|
|
|
|
{
|
2025-06-20 00:53:37 +00:00
|
|
|
return mask < other.mask;
|
2024-08-30 14:53:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
2025-06-20 00:53:37 +00:00
|
|
|
std::uint32_t mask = 0;
|
|
|
|
|
std::uint32_t id = 0; // for registering the hotkey
|
2024-08-30 14:53:25 +00:00
|
|
|
};
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
class HotKeySet
|
|
|
|
|
{
|
2024-08-30 14:53:25 +00:00
|
|
|
public:
|
2025-05-21 01:09:55 +00:00
|
|
|
explicit HotKeySet(KeyID keyid);
|
2024-10-17 18:04:35 +00:00
|
|
|
KeyID keyid() const
|
|
|
|
|
{
|
2025-06-20 00:53:37 +00:00
|
|
|
return m_id;
|
2024-10-17 18:04:35 +00:00
|
|
|
};
|
2025-06-20 00:53:37 +00:00
|
|
|
bool removeById(std::uint32_t id);
|
|
|
|
|
void addItem(HotKeyItem item);
|
|
|
|
|
std::uint32_t findByMask(std::uint32_t mask) const;
|
2024-08-30 14:53:25 +00:00
|
|
|
|
|
|
|
|
private:
|
2025-06-20 00:53:37 +00:00
|
|
|
KeyID m_id = 0;
|
|
|
|
|
std::vector<HotKeyItem> m_set;
|
2024-08-30 14:53:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using HotKeyMap = std::map<KeyID, HotKeySet>;
|
|
|
|
|
|
2025-06-20 00:53:37 +00:00
|
|
|
HotKeyMap m_hotkeys;
|
2024-08-30 14:53:25 +00:00
|
|
|
};
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
} // namespace deskflow
|