Deskflow 1.26.0.0
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
Client.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
4 * SPDX-FileCopyrightText: (C) 2012 - 2016, 2026 Symless Ltd.
5 * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
6 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
7 */
8
9#pragma once
10
11#include "deskflow/IClient.h"
12
13#include "base/EventTypes.h"
14#include "deskflow/IClipboard.h"
15#include "net/NetworkAddress.h"
16
17#include <climits>
18
19class Event;
20class EventQueueTimer;
21namespace deskflow {
22class Screen;
23}
24class ServerProxy;
25class IDataSocket;
26class ISocketFactory;
27namespace deskflow {
28class IStream;
29}
30class IEventQueue;
31class Thread;
32class TCPSocket;
33
35
38class Client : public IClient
39{
40public:
42 {
43 public:
44 explicit FailInfo(const char *what) : m_what(what)
45 {
46 // do nothing
47 }
48 bool m_retry = false;
49 std::string m_what;
50 };
51
52public:
58 Client(
59 IEventQueue *events, const std::string &name, const NetworkAddress &address, ISocketFactory *socketFactory,
60 deskflow::Screen *screen
61 );
62 Client(Client const &) = delete;
63 Client(Client &&) = delete;
64 ~Client() override;
65
66 Client &operator=(Client const &) = delete;
67 Client &operator=(Client &&) = delete;
68
70
71
73
77 void connect(size_t addressIndex = 0);
78 void setServerAddress(const NetworkAddress &address);
79
81
84 void disconnect(const char *msg);
85
87
91 void refuseConnection(const char *msg);
92
94
97 virtual void handshakeComplete();
98
100
102
104
107 bool isConnected() const;
108
110
114 bool isConnecting() const;
115
117
122
125 {
126 return m_resolvedAddressesCount;
127 }
128
130
131 // IScreen overrides
132 void *getEventTarget() const final;
133 bool getClipboard(ClipboardID id, IClipboard *) const override;
134 void getShape(int32_t &x, int32_t &y, int32_t &width, int32_t &height) const override;
135 void getCursorPos(int32_t &x, int32_t &y) const override;
136
137 // IClient overrides
138 void enter(int32_t xAbs, int32_t yAbs, uint32_t seqNum, KeyModifierMask mask, bool forScreensaver) override;
139 bool leave() override;
140 void setClipboard(ClipboardID, const IClipboard *) override;
141 void grabClipboard(ClipboardID) override;
142 void setClipboardDirty(ClipboardID, bool) override;
143 void keyDown(KeyID, KeyModifierMask, KeyButton, const std::string &) override;
144 void keyRepeat(KeyID, KeyModifierMask, int32_t count, KeyButton, const std::string &lang) override;
145 void keyUp(KeyID, KeyModifierMask, KeyButton) override;
146 void mouseDown(ButtonID) override;
147 void mouseUp(ButtonID) override;
148 void mouseMove(int32_t xAbs, int32_t yAbs) override;
149 void mouseRelativeMove(int32_t xRel, int32_t yRel) override;
150 void mouseWheel(int32_t xDelta, int32_t yDelta) override;
151 void screensaver(bool activate) override;
152 void resetOptions() override;
153 void setOptions(const OptionsList &options) override;
154 std::string getName() const override;
155
156private:
157 void sendClipboard(ClipboardID);
158 void sendEvent(deskflow::EventTypes);
159 void sendConnectionFailedEvent(const char *msg);
160 void setupConnecting();
161 void setupConnection();
162 void setupScreen();
163 void setupTimer();
164 void cleanup();
165 void cleanupConnecting();
166 void cleanupConnection();
167 void cleanupScreen();
168 void cleanupTimer();
169 void cleanupStream();
170 void handleConnected();
171 void handleConnectionFailed(const Event &event);
172 void handleConnectTimeout();
173 void handleOutputError();
174 void handleDisconnected();
175 void handleShapeChanged();
176 void handleClipboardGrabbed(const Event &event);
177 void handleHello();
178 void handleSuspend();
179 void handleResume();
180 void sendClipboardThread(void *);
181 void bindNetworkInterface(IDataSocket *socket) const;
182
183private:
184 std::string m_name;
185 NetworkAddress m_serverAddress;
186 ISocketFactory *m_socketFactory = nullptr;
187 deskflow::Screen *m_screen = nullptr;
188 deskflow::IStream *m_stream = nullptr;
189 EventQueueTimer *m_timer = nullptr;
190 ServerProxy *m_server = nullptr;
191 bool m_ready = false;
192 bool m_active = false;
193 bool m_suspended = false;
194 bool m_connectOnResume = false;
195 bool m_ownClipboard[kClipboardEnd];
196 bool m_sentClipboard[kClipboardEnd];
197 IClipboard::Time m_timeClipboard[kClipboardEnd];
198 std::string m_dataClipboard[kClipboardEnd];
199 IEventQueue *m_events = nullptr;
200 bool m_useSecureNetwork = false;
201 bool m_enableClipboard = true;
202 size_t m_maximumClipboardSize = INT_MAX;
203 size_t m_resolvedAddressesCount = 0;
204};
static const struct sockaddr FAR * name
Definition ArchNetworkWinsock.cpp:28
static const ClipboardID kClipboardEnd
Definition ClipboardTypes.h:30
uint8_t ClipboardID
Clipboard ID.
Definition ClipboardTypes.h:16
EventTypes
Definition EventTypes.h:13
uint32_t KeyID
Key ID.
Definition KeyTypes.h:21
uint16_t KeyButton
Key Code.
Definition KeyTypes.h:34
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
std::string m_what
Definition Client.h:49
bool m_retry
Definition Client.h:48
FailInfo(const char *what)
Definition Client.h:44
void enter(int32_t xAbs, int32_t yAbs, uint32_t seqNum, KeyModifierMask mask, bool forScreensaver) override
Enter screen.
Definition Client.cpp:188
void resetOptions() override
Notify of options changes.
Definition Client.cpp:277
void grabClipboard(ClipboardID) override
Grab clipboard.
Definition Client.cpp:220
void keyUp(KeyID, KeyModifierMask, KeyButton) override
Notify of key release.
Definition Client.cpp:242
void mouseRelativeMove(int32_t xRel, int32_t yRel) override
Notify of mouse motion.
Definition Client.cpp:262
virtual void handshakeComplete()
Notify of handshake complete.
Definition Client.cpp:146
Client(Client &&)=delete
Client(IEventQueue *events, const std::string &name, const NetworkAddress &address, ISocketFactory *socketFactory, deskflow::Screen *screen)
Definition Client.cpp:36
void refuseConnection(const char *msg)
Refuse connection.
Definition Client.cpp:134
std::string getName() const override
Get client name.
Definition Client.cpp:310
void keyRepeat(KeyID, KeyModifierMask, int32_t count, KeyButton, const std::string &lang) override
Notify of key repeat.
Definition Client.cpp:237
void screensaver(bool activate) override
Notify of screen saver change.
Definition Client.cpp:272
void setOptions(const OptionsList &options) override
Notify of options changes.
Definition Client.cpp:282
void connect(size_t addressIndex=0)
Connect to server.
Definition Client.cpp:72
void disconnect(const char *msg)
Disconnect.
Definition Client.cpp:123
bool getClipboard(ClipboardID id, IClipboard *) const override
Get clipboard.
Definition Client.cpp:173
Client(Client const &)=delete
void mouseWheel(int32_t xDelta, int32_t yDelta) override
Notify of mouse wheel motion.
Definition Client.cpp:267
NetworkAddress getServerAddress() const
Get address of server.
Definition Client.cpp:163
void mouseMove(int32_t xAbs, int32_t yAbs) override
Notify of mouse motion.
Definition Client.cpp:257
void keyDown(KeyID, KeyModifierMask, KeyButton, const std::string &) override
Notify of key press.
Definition Client.cpp:232
void mouseUp(ButtonID) override
Notify of mouse release.
Definition Client.cpp:252
void setClipboardDirty(ClipboardID, bool) override
Mark clipboard dirty.
Definition Client.cpp:227
void mouseDown(ButtonID) override
Notify of mouse press.
Definition Client.cpp:247
bool isConnecting() const
Test if connecting.
Definition Client.cpp:158
bool isConnected() const
Test if connected.
Definition Client.cpp:153
void setClipboard(ClipboardID, const IClipboard *) override
Set clipboard.
Definition Client.cpp:213
void getShape(int32_t &x, int32_t &y, int32_t &width, int32_t &height) const override
Get screen shape.
Definition Client.cpp:178
void * getEventTarget() const final
Get event target.
Definition Client.cpp:168
size_t getLastResolvedAddressesCount() const
Return last resolved adresses count.
Definition Client.h:124
Client & operator=(Client &&)=delete
bool leave() override
Leave screen.
Definition Client.cpp:195
void getCursorPos(int32_t &x, int32_t &y) const override
Get cursor position.
Definition Client.cpp:183
~Client() override
Definition Client.cpp:55
Client & operator=(Client const &)=delete
void setServerAddress(const NetworkAddress &address)
Definition Client.cpp:67
Definition EventQueueTimer.h:12
Event.
Definition Event.h:29
Client interface.
Definition IClient.h:24
Clipboard interface.
Definition IClipboard.h:19
Data stream socket interface.
Definition IDataSocket.h:21
Event queue interface.
Definition IEventQueue.h:29
Socket factory.
Definition ISocketFactory.h:23
Network address type.
Definition NetworkAddress.h:17
Definition Screen.h:26
Proxy for server.
Definition ServerProxy.h:30
TCP data socket.
Definition TCPSocket.h:28
Thread handle.
Definition Thread.h:33
Bidirectional stream interface.
Definition IStream.h:22
Platform independent screen.
Definition Screen.h:30
Definition DaemonApp.h:20
Definition Config.h:28