Deskflow 1.24.0.365
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
12
13#include <libei.h>
14#include <map>
15#include <mutex>
16#include <vector>
17
18struct ei;
19struct ei_event;
20struct ei_seat;
21struct ei_device;
22
23namespace deskflow {
24
25class EiClipboard;
26class EiKeyState;
29
32{
33public:
34 EiScreen(bool isPrimary, IEventQueue *events, bool usePortal, bool invertScrolling = false);
35 ~EiScreen() override;
36
37 // IScreen overrides
38 void *getEventTarget() const final;
39 bool getClipboard(ClipboardID id, IClipboard *) const override;
40 void getShape(std::int32_t &x, std::int32_t &y, std::int32_t &width, std::int32_t &height) const override;
41 void getCursorPos(std::int32_t &x, std::int32_t &y) const override;
42
43 // IPrimaryScreen overrides
44 void reconfigure(std::uint32_t activeSides) override;
45 std::uint32_t activeSides() override;
46 void warpCursor(std::int32_t x, std::int32_t y) override;
47 std::uint32_t registerHotKey(KeyID key, KeyModifierMask mask) override;
48 void unregisterHotKey(std::uint32_t id) override;
49 void fakeInputBegin() override;
50 void fakeInputEnd() override;
51 std::int32_t getJumpZoneSize() const override;
52 bool isAnyMouseButtonDown(std::uint32_t &buttonID) const override;
53 void getCursorCenter(std::int32_t &x, std::int32_t &y) const override;
54
55 // ISecondaryScreen overrides
56 void fakeMouseButton(ButtonID id, bool press) override;
57 void fakeMouseMove(std::int32_t x, std::int32_t y) override;
58 void fakeMouseRelativeMove(std::int32_t dx, std::int32_t dy) const override;
59 void fakeMouseWheel(std::int32_t xDelta, std::int32_t yDelta) const override;
60 void fakeKey(std::uint32_t keycode, bool isDown) const;
61
62 // IPlatformScreen overrides
63 void enable() override;
64 void disable() override;
65 void enter() override;
66 bool canLeave() override;
67 void leave() override;
68 bool setClipboard(ClipboardID, const IClipboard *) override;
69 void checkClipboards() override;
70 void openScreensaver(bool notify) override;
71 void closeScreensaver() override;
72 void screensaver(bool activate) override;
73 void resetOptions() override;
74 void setOptions(const OptionsList &options) override;
75 void setSequenceNumber(std::uint32_t) override;
76 bool isPrimary() const override;
77
78protected:
79 // IPlatformScreen overrides
80 void handleSystemEvent(const Event &event) override;
81 void updateButtons() override;
82 IKeyState *getKeyState() const override;
83 std::string getSecureInputApp() const override;
84
85 void updateShape();
86 void addDevice(ei_device *device);
87 void removeDevice(ei_device *device);
88
89private:
90 void initEi();
91 void cleanupEi();
92 void sendEvent(EventTypes type, void *data);
93 ButtonID mapButtonFromEvdev(ei_event *event) const;
94 void onKeyEvent(ei_event *event);
95 void onButtonEvent(ei_event *event);
96 void sendWheelEvents(ei_device *device, const int threshold, double dx, double dy, bool is_discrete);
97 void onPointerScrollEvent(ei_event *event);
98 void onPointerScrollDiscreteEvent(ei_event *event);
99 void onMotionEvent(ei_event *event);
100 void onAbsMotionEvent(const ei_event *) const;
101 bool onHotkey(KeyID key, bool isPressed, KeyModifierMask mask);
102 void eiLogEvent(ei_log_priority priority, const char *message) const;
103
104 void handleConnectedToEisEvent(const Event &event);
105 void handlePortalSessionClosed();
106
107 static void handleEiLogEvent(ei *ei, const ei_log_priority priority, const char *message, ei_log_context *)
108 {
109 auto screen = static_cast<EiScreen *>(ei_get_user_data(ei));
110 screen->eiLogEvent(priority, message);
111 }
112
113private:
114 // true if screen is being used as a primary screen, false otherwise
115 bool m_isPrimary = false;
116 IEventQueue *m_events = nullptr;
117
118 // keyboard stuff
119 EiKeyState *m_keyState = nullptr;
120
121 std::vector<ei_device *> m_eiDevices;
122
123 ei *m_ei = nullptr;
124 ei_seat *m_eiSeat = nullptr;
125 ei_device *m_eiPointer = nullptr;
126 ei_device *m_eiKeyboard = nullptr;
127 ei_device *m_eiAbs = nullptr;
128
129 std::uint32_t m_sequenceNumber = 0;
130
131 std::uint32_t m_activeSides = 0;
132 std::uint32_t m_x = 0;
133 std::uint32_t m_y = 0;
134 std::uint32_t m_w = 0;
135 std::uint32_t m_h = 0;
136
137 // true if mouse has entered the screen
138 bool m_isOnScreen;
139
140 // server: last pointer position
141 // client: position sent before enter()
142 std::int32_t m_cursorX = 0;
143 std::int32_t m_cursorY = 0;
144
145 double m_bufferDX = 0;
146 double m_bufferDY = 0;
147
148 mutable std::mutex m_mutex;
149
150 PortalRemoteDesktop *m_portalRemoteDesktop = nullptr;
151 PortalInputCapture *m_portalInputCapture = nullptr;
152
153 struct HotKeyItem
154 {
155 public:
156 HotKeyItem(std::uint32_t mask, std::uint32_t id);
157 auto operator<=>(const HotKeyItem &other) const
158 {
159 return mask <=> other.mask;
160 }
161
162 public:
163 std::uint32_t mask = 0;
164 std::uint32_t id = 0; // for registering the hotkey
165 };
166
167 class HotKeySet
168 {
169 public:
170 explicit HotKeySet(KeyID keyid);
171 KeyID keyid() const
172 {
173 return m_id;
174 }
175 bool removeById(std::uint32_t id);
176 void addItem(HotKeyItem item);
177 std::uint32_t findByMask(std::uint32_t mask) const;
178
179 private:
180 KeyID m_id = 0;
181 std::vector<HotKeyItem> m_set;
182 };
183
184 using HotKeyMap = std::map<KeyID, HotKeySet>;
185
186 HotKeyMap m_hotkeys;
187 [[no_unique_address]] XDGPowerManager m_powerManager;
188};
189
190} // 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
int key
Definition KeySequence.cpp:15
uint32_t KeyID
Key ID.
Definition KeyTypes.h:21
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:25
int x
Definition ServerConfig.cpp:24
Event.
Definition Event.h:29
Clipboard interface.
Definition IClipboard.h:19
Event queue interface.
Definition IEventQueue.h:29
IKeyState(const IEventQueue *events)
Definition IKeyState.cpp:17
PlatformScreen(IEventQueue *events, bool invertScrollDirection)
Definition PlatformScreen.cpp:12
Definition XDGPowerManager.h:13
A key state for Ei.
Definition EiKeyState.h:23
void leave() override
Leave screen.
Definition EiScreen.cpp:365
~EiScreen() override
Definition EiScreen.cpp:79
void checkClipboards() override
Check clipboard owner.
Definition EiScreen.cpp:387
void unregisterHotKey(std::uint32_t id) override
Definition EiScreen.cpp:216
void enter() override
Enter screen.
Definition EiScreen.cpp:339
void setOptions(const OptionsList &options) override
Notify of options changes.
Definition EiScreen.cpp:413
bool isAnyMouseButtonDown(std::uint32_t &buttonID) const override
Definition EiScreen.cpp:241
std::int32_t getJumpZoneSize() const override
Get jump zone size.
Definition EiScreen.cpp:236
void warpCursor(std::int32_t x, std::int32_t y) override
Definition EiScreen.cpp:193
void * getEventTarget() const final
Get event target.
Definition EiScreen.cpp:157
std::uint32_t activeSides() override
activeSides
Definition EiScreen.cpp:188
void openScreensaver(bool notify) override
Open screen saver.
Definition EiScreen.cpp:392
IKeyState * getKeyState() const override
Get the key state.
Definition EiScreen.cpp:853
void addDevice(ei_device *device)
Definition EiScreen.cpp:452
void getCursorPos(std::int32_t &x, std::int32_t &y) const override
Definition EiScreen.cpp:175
void fakeInputBegin() override
Prepare to synthesize input on primary screen.
Definition EiScreen.cpp:226
void fakeMouseWheel(std::int32_t xDelta, std::int32_t yDelta) const override
Definition EiScreen.cpp:303
std::uint32_t registerHotKey(KeyID key, KeyModifierMask mask) override
Register a system hotkey.
Definition EiScreen.cpp:199
void resetOptions() override
Notify of options changes.
Definition EiScreen.cpp:407
void closeScreensaver() override
Close screen saver.
Definition EiScreen.cpp:397
void updateButtons() override
Update mouse buttons.
Definition EiScreen.cpp:847
void reconfigure(std::uint32_t activeSides) override
Definition EiScreen.cpp:181
void fakeInputEnd() override
Done synthesizing input on primary screen.
Definition EiScreen.cpp:231
bool getClipboard(ClipboardID id, IClipboard *) const override
Get clipboard.
Definition EiScreen.cpp:162
void setSequenceNumber(std::uint32_t) override
Definition EiScreen.cpp:418
void getShape(std::int32_t &x, std::int32_t &y, std::int32_t &width, std::int32_t &height) const override
Definition EiScreen.cpp:167
void screensaver(bool activate) override
Activate/deactivate screen saver.
Definition EiScreen.cpp:402
void handleSystemEvent(const Event &event) override
Handle system event.
Definition EiScreen.cpp:728
bool canLeave() override
Leave screen.
Definition EiScreen.cpp:360
void enable() override
Enable screen.
Definition EiScreen.cpp:328
void fakeMouseRelativeMove(std::int32_t dx, std::int32_t dy) const override
Definition EiScreen.cpp:294
void removeDevice(ei_device *device)
Definition EiScreen.cpp:499
void fakeMouseButton(ButtonID id, bool press) override
Fake mouse press/release.
Definition EiScreen.cpp:252
std::string getSecureInputApp() const override
Determine the name of the app causing a secure input state.
Definition EiScreen.cpp:858
void updateShape()
Definition EiScreen.cpp:428
bool isPrimary() const override
Test if is primary screen.
Definition EiScreen.cpp:423
void getCursorCenter(std::int32_t &x, std::int32_t &y) const override
Definition EiScreen.cpp:246
bool setClipboard(ClipboardID, const IClipboard *) override
Set clipboard.
Definition EiScreen.cpp:382
void fakeMouseMove(std::int32_t x, std::int32_t y) override
Definition EiScreen.cpp:278
void fakeKey(std::uint32_t keycode, bool isDown) const
Definition EiScreen.cpp:317
EiScreen(bool isPrimary, IEventQueue *events, bool usePortal, bool invertScrolling=false)
Definition EiScreen.cpp:37
void disable() override
Disable screen.
Definition EiScreen.cpp:333
Definition PortalInputCapture.h:21
Definition PortalRemoteDesktop.h:19
Definition EventTypes.h:11
EventTypes
Definition EventTypes.h:13