Deskflow 1.26.0.314
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, 2026 Synergy App Ltd
4 * SPDX-FileCopyrightText: (C) 2022, 2026 Red Hat, Inc.
5 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
6 */
7
8#pragma once
9
10#include "deskflow/IScreen.h"
13
14#include <climits>
15#include <libei.h>
16#include <map>
17#include <mutex>
18#include <vector>
19
20struct ei;
21struct ei_event;
22struct ei_seat;
23struct ei_device;
24
25namespace deskflow {
26
27class EiKeyState;
30class EiClipboard;
31
33
36{
37public:
38 EiScreen(bool isPrimary, IEventQueue *events, bool usePortal);
39 ~EiScreen() override;
40
41 // IScreen overrides
42 void *getEventTarget() const final;
43 bool getClipboard(ClipboardID id, IClipboard *) const override;
44 void getShape(std::int32_t &x, std::int32_t &y, std::int32_t &width, std::int32_t &height) const override;
45 void getCursorPos(std::int32_t &x, std::int32_t &y) const override;
46
47 // IPrimaryScreen overrides
48 void reconfigure(std::uint32_t activeSides) override;
49 std::uint32_t activeSides() override;
50 void warpCursor(std::int32_t x, std::int32_t y) override;
51 std::uint32_t registerHotKey(KeyID key, KeyModifierMask mask) override;
52 void unregisterHotKey(std::uint32_t id) override;
53 void fakeInputBegin() override;
54 void fakeInputEnd() override;
55 std::int32_t getJumpZoneSize() const override;
56 bool isAnyMouseButtonDown(std::uint32_t &buttonID) const override;
57 void getCursorCenter(std::int32_t &x, std::int32_t &y) const override;
58
59 // ISecondaryScreen overrides
60 void fakeMouseButton(ButtonID id, bool press) override;
61 void fakeMouseMove(std::int32_t x, std::int32_t y) override;
62 void fakeMouseRelativeMove(std::int32_t dx, std::int32_t dy) const override;
63 void fakeMouseWheel(ScrollDelta delta) const override;
64 void fakeKey(std::uint32_t keycode, bool isDown) const;
65
66 // IPlatformScreen overrides
67 void enable() override;
68 void disable() override;
69 void enter() override;
70 bool canLeave() override;
71 void leave() override;
72 bool setClipboard(ClipboardID, const IClipboard *) override;
73 void checkClipboards() override;
74 void openScreensaver(bool notify) override;
75 void closeScreensaver() override;
76 void screensaver(bool activate) override;
77 void resetOptions() override;
78 void setOptions(const OptionsList &options) override;
79 void setSequenceNumber(std::uint32_t) override;
80 bool isPrimary() const override;
81
82 // Send clipboard event (needed by PortalInputCapture)
84
85 // Local clipboard cache (used by PortalRemoteDesktop to land selection reads)
87 {
88 return m_clipboard;
89 }
90
91 // Maximum clipboard size in KB, configured by the server
92 size_t maximumClipboardSize() const
93 {
94 return m_maximumClipboardSize;
95 }
96
97protected:
98 // IPlatformScreen overrides
99 void handleSystemEvent(const Event &event) override;
100 void updateButtons() override;
101 IKeyState *getKeyState() const override;
102 std::string getSecureInputApp() const override;
103
104 void updateShape();
105 void addDevice(ei_device *device);
106 void removeDevice(ei_device *device);
107
108private:
109 void initEi();
110 void cleanupEi();
111 void sendEvent(EventTypes type, void *data);
112 ButtonID mapButtonFromEvdev(ei_event *event) const;
113 void onKeyEvent(ei_event *event);
114 void onButtonEvent(ei_event *event);
115 void sendWheelEvents(ei_device *device, const int threshold, double dx, double dy, bool is_discrete);
116 void onPointerScrollEvent(ei_event *event);
117 void onPointerScrollDiscreteEvent(ei_event *event);
118 void onMotionEvent(ei_event *event);
119 void onAbsMotionEvent(const ei_event *) const;
120 bool onHotkey(KeyID key, bool isPressed, KeyModifierMask mask);
121 void eiLogEvent(ei_log_priority priority, const char *message) const;
122
123 void handleConnectedToEisEvent(const Event &event);
124 void handlePortalSessionClosed();
125
126 static void handleEiLogEvent(ei *ei, const ei_log_priority priority, const char *message, ei_log_context *)
127 {
128 auto screen = static_cast<EiScreen *>(ei_get_user_data(ei));
129 screen->eiLogEvent(priority, message);
130 }
131
132private:
133 // true if screen is being used as a primary screen, false otherwise
134 bool m_isPrimary = false;
135 IEventQueue *m_events = nullptr;
136
137 // keyboard stuff
138 EiKeyState *m_keyState = nullptr;
139
140 KeyID m_lastPressed = kKeyNone;
141
142 // clipboard stuff
143 EiClipboard *m_clipboard = nullptr;
144 size_t m_maximumClipboardSize = INT_MAX;
145
146 std::vector<ei_device *> m_eiDevices;
147
148 ei *m_ei = nullptr;
149 ei_seat *m_eiSeat = nullptr;
150 ei_device *m_eiPointer = nullptr;
151 ei_device *m_eiKeyboard = nullptr;
152 ei_device *m_eiAbs = nullptr;
153
154 std::uint32_t m_sequenceNumber = 0;
155
156 std::uint32_t m_activeSides = 0;
157 std::uint32_t m_x = 0;
158 std::uint32_t m_y = 0;
159 std::uint32_t m_w = 0;
160 std::uint32_t m_h = 0;
161
162 // true if mouse has entered the screen
163 bool m_isOnScreen;
164
165 // server: last pointer position
166 // client: position sent before enter()
167 std::int32_t m_cursorX = 0;
168 std::int32_t m_cursorY = 0;
169
170 double m_bufferDX = 0;
171 double m_bufferDY = 0;
172
173 mutable std::mutex m_mutex;
174
175 PortalRemoteDesktop *m_portalRemoteDesktop = nullptr;
176 PortalInputCapture *m_portalInputCapture = nullptr;
177
178 struct HotKeyItem
179 {
180 public:
181 HotKeyItem(std::uint32_t mask, std::uint32_t id);
182 auto operator<=>(const HotKeyItem &other) const
183 {
184 return mask <=> other.mask;
185 }
186
187 public:
188 std::uint32_t mask = 0;
189 std::uint32_t id = 0; // for registering the hotkey
190 };
191
192 class HotKeySet
193 {
194 public:
195 explicit HotKeySet(KeyID keyid);
196 KeyID keyid() const
197 {
198 return m_id;
199 }
200 bool removeById(std::uint32_t id);
201 void addItem(HotKeyItem item);
202 std::uint32_t findByMask(std::uint32_t mask) const;
203
204 private:
205 KeyID m_id = 0;
206 std::vector<HotKeyItem> m_set;
207 };
208
209 using HotKeyMap = std::map<KeyID, HotKeySet>;
210
211 HotKeyMap m_hotkeys;
212 [[no_unique_address]] XDGPowerManager m_powerManager;
213};
214
215} // namespace deskflow
static int void FAR * data
Definition ArchNetworkWinsock.cpp:35
static int type
Definition ArchNetworkWinsock.cpp:45
uint8_t ClipboardID
Clipboard ID.
Definition ClipboardTypes.h:16
Coordinate ScrollDelta
Definition Coordinate.h:21
int key
Definition KeySequence.cpp:15
uint32_t KeyID
Key ID.
Definition KeyTypes.h:21
static const KeyID kKeyNone
Definition KeyTypes.h:105
uint32_t KeyModifierMask
Modifier key mask.
Definition KeyTypes.h:44
uint8_t ButtonID
Mouse button ID.
Definition MouseTypes.h:16
std::vector< uint32_t > OptionsList
Definition OptionTypes.h:26
int y
Definition ServerConfig.cpp:24
int x
Definition ServerConfig.cpp:23
Event.
Definition Event.h:43
Clipboard interface.
Definition IClipboard.h:19
Event queue interface.
Definition IEventQueue.h:29
Key state interface.
Definition IKeyState.h:23
PlatformScreen(IEventQueue *events)
Definition PlatformScreen.cpp:13
EI/Portal clipboard implementation.
Definition EiClipboard.h:21
A key state for Ei.
Definition EiKeyState.h:23
Implementation of IPlatformScreen for X11.
Definition EiScreen.h:36
void leave() override
Leave screen.
Definition EiScreen.cpp:390
~EiScreen() override
Definition EiScreen.cpp:86
void checkClipboards() override
Check clipboard owner.
Definition EiScreen.cpp:436
void unregisterHotKey(std::uint32_t id) override
Definition EiScreen.cpp:239
void enter() override
Enter screen.
Definition EiScreen.cpp:364
size_t maximumClipboardSize() const
Definition EiScreen.h:92
void setOptions(const OptionsList &options) override
Notify of options changes.
Definition EiScreen.cpp:464
bool isAnyMouseButtonDown(std::uint32_t &buttonID) const override
Definition EiScreen.cpp:264
std::int32_t getJumpZoneSize() const override
Get jump zone size.
Definition EiScreen.cpp:259
void warpCursor(std::int32_t x, std::int32_t y) override
Definition EiScreen.cpp:216
void sendClipboardEvent(EventTypes type, ClipboardID id) const
Definition EiScreen.cpp:580
void * getEventTarget() const final
Get event target.
Definition EiScreen.cpp:166
std::uint32_t activeSides() override
activeSides
Definition EiScreen.cpp:211
void openScreensaver(bool notify) override
Open screen saver.
Definition EiScreen.cpp:443
IKeyState * getKeyState() const override
Get the key state.
Definition EiScreen.cpp:934
void addDevice(ei_device *device)
Definition EiScreen.cpp:506
void fakeMouseWheel(ScrollDelta delta) const override
Synthesize a mouse wheel event of amount This Implmentation for this method should call applyScrollMo...
Definition EiScreen.cpp:326
void getCursorPos(std::int32_t &x, std::int32_t &y) const override
Definition EiScreen.cpp:198
void fakeInputBegin() override
Prepare to synthesize input on primary screen.
Definition EiScreen.cpp:249
std::uint32_t registerHotKey(KeyID key, KeyModifierMask mask) override
Register a system hotkey.
Definition EiScreen.cpp:222
void resetOptions() override
Notify of options changes.
Definition EiScreen.cpp:458
EiScreen(bool isPrimary, IEventQueue *events, bool usePortal)
Definition EiScreen.cpp:40
void closeScreensaver() override
Close screen saver.
Definition EiScreen.cpp:448
void updateButtons() override
Update mouse buttons.
Definition EiScreen.cpp:928
void reconfigure(std::uint32_t activeSides) override
Definition EiScreen.cpp:204
void fakeInputEnd() override
Done synthesizing input on primary screen.
Definition EiScreen.cpp:254
bool getClipboard(ClipboardID id, IClipboard *) const override
Get clipboard.
Definition EiScreen.cpp:171
void setSequenceNumber(std::uint32_t) override
Definition EiScreen.cpp:594
void getShape(std::int32_t &x, std::int32_t &y, std::int32_t &width, std::int32_t &height) const override
Definition EiScreen.cpp:190
void screensaver(bool activate) override
Activate/deactivate screen saver.
Definition EiScreen.cpp:453
void handleSystemEvent(const Event &event) override
Handle system event.
Definition EiScreen.cpp:809
bool canLeave() override
Leave screen.
Definition EiScreen.cpp:385
void enable() override
Enable screen.
Definition EiScreen.cpp:350
void fakeMouseRelativeMove(std::int32_t dx, std::int32_t dy) const override
Definition EiScreen.cpp:317
void removeDevice(ei_device *device)
Definition EiScreen.cpp:553
void fakeMouseButton(ButtonID id, bool press) override
Fake mouse press/release.
Definition EiScreen.cpp:275
std::string getSecureInputApp() const override
Determine the name of the app causing a secure input state.
Definition EiScreen.cpp:939
void updateShape()
Definition EiScreen.cpp:482
bool isPrimary() const override
Test if is primary screen.
Definition EiScreen.cpp:477
void getCursorCenter(std::int32_t &x, std::int32_t &y) const override
Definition EiScreen.cpp:269
bool setClipboard(ClipboardID, const IClipboard *) override
Set clipboard.
Definition EiScreen.cpp:407
EiClipboard * getClipboardCache() const
Definition EiScreen.h:86
void fakeMouseMove(std::int32_t x, std::int32_t y) override
Definition EiScreen.cpp:301
void fakeKey(std::uint32_t keycode, bool isDown) const
Definition EiScreen.cpp:339
void disable() override
Disable screen.
Definition EiScreen.cpp:357
Definition PortalInputCapture.h:30
Definition PortalRemoteDesktop.h:21
Definition DaemonApp.h:18
EventTypes
Definition EventTypes.h:13
IScreen::ClipboardInfo ClipboardInfo
Definition EiScreen.h:32
Definition IScreen.h:24