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