Deskflow 1.22.0.197
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
EiScreen.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2024 Symless Ltd.
4 * SPDX-FileCopyrightText: (C) 2022 Red Hat, Inc.
5 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
6 */
7
8#pragma once
9
10#include "deskflow/KeyMap.h"
12
13#include <libei.h>
14#include <memory>
15#include <mutex>
16#include <set>
17#include <vector>
18
19struct ei;
20struct ei_event;
21struct ei_seat;
22struct ei_device;
23
24namespace deskflow {
25
26class EiClipboard;
27class EiKeyState;
30
33{
34public:
35 EiScreen(bool isPrimary, IEventQueue *events, bool usePortal);
36 ~EiScreen() override;
37
38 // IScreen overrides
39 void *getEventTarget() const final;
40 bool getClipboard(ClipboardID id, IClipboard *) const override;
41 void getShape(std::int32_t &x, std::int32_t &y, std::int32_t &width, std::int32_t &height) const override;
42 void getCursorPos(std::int32_t &x, std::int32_t &y) const override;
43
44 // IPrimaryScreen overrides
45 void reconfigure(std::uint32_t activeSides) override;
46 std::uint32_t activeSides() override;
47 void warpCursor(std::int32_t x, std::int32_t y) override;
48 std::uint32_t registerHotKey(KeyID key, KeyModifierMask mask) override;
49 void unregisterHotKey(std::uint32_t id) override;
50 void fakeInputBegin() override;
51 void fakeInputEnd() override;
52 std::int32_t getJumpZoneSize() const override;
53 bool isAnyMouseButtonDown(std::uint32_t &buttonID) const override;
54 void getCursorCenter(std::int32_t &x, std::int32_t &y) const override;
55
56 // ISecondaryScreen overrides
57 void fakeMouseButton(ButtonID id, bool press) override;
58 void fakeMouseMove(std::int32_t x, std::int32_t y) override;
59 void fakeMouseRelativeMove(std::int32_t dx, std::int32_t dy) const override;
60 void fakeMouseWheel(std::int32_t xDelta, std::int32_t yDelta) const override;
61 void fakeKey(std::uint32_t keycode, bool is_down) const;
62
63 // IPlatformScreen overrides
64 void enable() override;
65 void disable() override;
66 void enter() override;
67 bool canLeave() override;
68 void leave() override;
69 bool setClipboard(ClipboardID, const IClipboard *) override;
70 void checkClipboards() override;
71 void openScreensaver(bool notify) override;
72 void closeScreensaver() override;
73 void screensaver(bool activate) override;
74 void resetOptions() override;
75 void setOptions(const OptionsList &options) override;
76 void setSequenceNumber(std::uint32_t) override;
77 bool isPrimary() const override;
78
79protected:
80 // IPlatformScreen overrides
81 void handleSystemEvent(const Event &event) override;
82 void updateButtons() override;
83 IKeyState *getKeyState() const override;
84 std::string getSecureInputApp() const override;
85
86 void updateShape();
87 void addDevice(ei_device *device);
88 void removeDevice(ei_device *device);
89
90private:
91 void initEi();
92 void cleanupEi();
93 void sendEvent(EventTypes type, void *data);
94 ButtonID mapButtonFromEvdev(ei_event *event) const;
95 void onKeyEvent(ei_event *event);
96 void onButtonEvent(ei_event *event);
97 void sendWheelEvents(ei_device *device, const int threshold, double dx, double dy, bool is_discrete);
98 void onPointerScrollEvent(ei_event *event);
99 void onPointerScrollDiscreteEvent(ei_event *event);
100 void onMotionEvent(ei_event *event);
101 void onAbsMotionEvent(const ei_event *) const;
102 bool onHotkey(KeyID key, bool is_press, KeyModifierMask mask);
103 void eiLogEvent(ei_log_priority priority, const char *message) const;
104
105 void handleConnectedToEisEvent(const Event &event);
106 void handlePortalSessionClosed();
107
108 static void handleEiLogEvent(ei *ei, const ei_log_priority priority, const char *message, ei_log_context *)
109 {
110 auto screen = static_cast<EiScreen *>(ei_get_user_data(ei));
111 screen->eiLogEvent(priority, message);
112 }
113
114private:
115 // true if screen is being used as a primary screen, false otherwise
116 bool m_isPrimary = false;
117 IEventQueue *m_events = nullptr;
118
119 // keyboard stuff
120 EiKeyState *m_keyState = nullptr;
121
122 std::vector<ei_device *> m_eiDevices;
123
124 ei *m_ei = nullptr;
125 ei_seat *m_eiSeat = nullptr;
126 ei_device *m_eiPointer = nullptr;
127 ei_device *m_eiKeyboard = nullptr;
128 ei_device *m_eiAbs = nullptr;
129
130 std::uint32_t m_sequenceNumber = 0;
131
132 std::uint32_t m_activeSides = 0;
133 std::uint32_t m_x = 0;
134 std::uint32_t m_y = 0;
135 std::uint32_t m_w = 0;
136 std::uint32_t m_h = 0;
137
138 // true if mouse has entered the screen
139 bool m_isOnScreen;
140
141 // server: last pointer position
142 // client: position sent before enter()
143 std::int32_t m_cursorX = 0;
144 std::int32_t m_cursorY = 0;
145
146 double m_bufferDX = 0;
147 double m_bufferDY = 0;
148
149 mutable std::mutex m_mutex;
150
151 PortalRemoteDesktop *m_portalRemoteDesktop = nullptr;
152 PortalInputCapture *m_portalInputCapture = nullptr;
153
154 struct HotKeyItem
155 {
156 public:
157 HotKeyItem(std::uint32_t mask, std::uint32_t id);
158 bool operator<(const HotKeyItem &other) const
159 {
160 return mask < other.mask;
161 };
162
163 public:
164 std::uint32_t mask = 0;
165 std::uint32_t id = 0; // for registering the hotkey
166 };
167
168 class HotKeySet
169 {
170 public:
171 explicit HotKeySet(KeyID keyid);
172 KeyID keyid() const
173 {
174 return m_id;
175 };
176 bool removeById(std::uint32_t id);
177 void addItem(HotKeyItem item);
178 std::uint32_t findByMask(std::uint32_t mask) const;
179
180 private:
181 KeyID m_id = 0;
182 std::vector<HotKeyItem> m_set;
183 };
184
185 using HotKeyMap = std::map<KeyID, HotKeySet>;
186
187 HotKeyMap m_hotkeys;
188};
189
190} // namespace deskflow
static int void FAR * data
Definition ArchNetworkWinsock.cpp:34
static int type
Definition ArchNetworkWinsock.cpp:44
uint8_t ClipboardID
Clipboard ID.
Definition ClipboardTypes.h:16
int key
Definition KeySequence.cpp:15
uint32_t KeyID
Key ID.
Definition KeyTypes.h:22
uint32_t KeyModifierMask
Modifier key mask.
Definition KeyTypes.h:45
uint8_t ButtonID
Mouse button ID.
Definition MouseTypes.h:16
std::vector< uint32_t > OptionsList
Definition OptionTypes.h:27
int y
Definition ServerConfig.cpp:27
int x
Definition ServerConfig.cpp:26
Event.
Definition Event.h:27
Clipboard interface.
Definition IClipboard.h:20
Event queue interface.
Definition IEventQueue.h:32
IKeyState(const IEventQueue *events)
Definition IKeyState.cpp:18
PlatformScreen(IEventQueue *events, deskflow::ClientScrollDirection scrollDirection=deskflow::ClientScrollDirection::Normal)
Definition PlatformScreen.cpp:12
A key state for Ei.
Definition EiKeyState.h:21
void leave() override
Leave screen.
Definition EiScreen.cpp:361
~EiScreen() override
Definition EiScreen.cpp:78
void checkClipboards() override
Check clipboard owner.
Definition EiScreen.cpp:383
void unregisterHotKey(std::uint32_t id) override
Definition EiScreen.cpp:214
void enter() override
Enter screen.
Definition EiScreen.cpp:335
void setOptions(const OptionsList &options) override
Notify of options changes.
Definition EiScreen.cpp:409
bool isAnyMouseButtonDown(std::uint32_t &buttonID) const override
Definition EiScreen.cpp:239
std::int32_t getJumpZoneSize() const override
Get jump zone size.
Definition EiScreen.cpp:234
void warpCursor(std::int32_t x, std::int32_t y) override
Definition EiScreen.cpp:191
void * getEventTarget() const final
Get event target.
Definition EiScreen.cpp:156
std::uint32_t activeSides() override
activeSides
Definition EiScreen.cpp:186
void openScreensaver(bool notify) override
Open screen saver.
Definition EiScreen.cpp:388
IKeyState * getKeyState() const override
Get the key state.
Definition EiScreen.cpp:849
void addDevice(ei_device *device)
Definition EiScreen.cpp:448
void getCursorPos(std::int32_t &x, std::int32_t &y) const override
Definition EiScreen.cpp:174
void fakeInputBegin() override
Prepare to synthesize input on primary screen.
Definition EiScreen.cpp:224
void fakeMouseWheel(std::int32_t xDelta, std::int32_t yDelta) const override
Definition EiScreen.cpp:301
std::uint32_t registerHotKey(KeyID key, KeyModifierMask mask) override
Register a system hotkey.
Definition EiScreen.cpp:197
void resetOptions() override
Notify of options changes.
Definition EiScreen.cpp:403
EiScreen(bool isPrimary, IEventQueue *events, bool usePortal)
Definition EiScreen.cpp:41
void closeScreensaver() override
Close screen saver.
Definition EiScreen.cpp:393
void updateButtons() override
Update mouse buttons.
Definition EiScreen.cpp:843
void reconfigure(std::uint32_t activeSides) override
Definition EiScreen.cpp:180
void fakeInputEnd() override
Done synthesizing input on primary screen.
Definition EiScreen.cpp:229
bool getClipboard(ClipboardID id, IClipboard *) const override
Get clipboard.
Definition EiScreen.cpp:161
void setSequenceNumber(std::uint32_t) override
Definition EiScreen.cpp:414
void getShape(std::int32_t &x, std::int32_t &y, std::int32_t &width, std::int32_t &height) const override
Definition EiScreen.cpp:166
void screensaver(bool activate) override
Activate/deactivate screen saver.
Definition EiScreen.cpp:398
void handleSystemEvent(const Event &event) override
Handle system event.
Definition EiScreen.cpp:724
bool canLeave() override
Leave screen.
Definition EiScreen.cpp:356
void enable() override
Enable screen.
Definition EiScreen.cpp:324
void fakeMouseRelativeMove(std::int32_t dx, std::int32_t dy) const override
Definition EiScreen.cpp:292
void removeDevice(ei_device *device)
Definition EiScreen.cpp:495
void fakeMouseButton(ButtonID id, bool press) override
Fake mouse press/release.
Definition EiScreen.cpp:250
std::string getSecureInputApp() const override
Determine the name of the app causing a secure input state.
Definition EiScreen.cpp:854
void updateShape()
Definition EiScreen.cpp:424
bool isPrimary() const override
Test if is primary screen.
Definition EiScreen.cpp:419
void getCursorCenter(std::int32_t &x, std::int32_t &y) const override
Definition EiScreen.cpp:244
bool setClipboard(ClipboardID, const IClipboard *) override
Set clipboard.
Definition EiScreen.cpp:378
void fakeKey(std::uint32_t keycode, bool is_down) const
Definition EiScreen.cpp:313
void fakeMouseMove(std::int32_t x, std::int32_t y) override
Definition EiScreen.cpp:276
void disable() override
Disable screen.
Definition EiScreen.cpp:329
Definition PortalInputCapture.h:22
Definition PortalRemoteDesktop.h:21
Definition EventTypes.h:11
EventTypes
Definition EventTypes.h:13