Deskflow 1.26.0.134
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 "common/Enums.h"
15#include "deskflow/IClipboard.h"
16#include "net/NetworkAddress.h"
17
18#include <climits>
19
20class Event;
21class EventQueueTimer;
22namespace deskflow {
23class Screen;
24}
25class ServerProxy;
26class IDataSocket;
27class ISocketFactory;
28namespace deskflow {
29class IStream;
30}
31class IEventQueue;
32class Thread;
33class TCPSocket;
34
36
39class Client : public IClient
40{
41public:
43 {
44 public:
45 explicit FailInfo(const char *what) : m_what(what)
46 {
47 // do nothing
48 }
49 bool m_retry = false;
50 std::string m_what;
51 };
52
53public:
59 Client(
60 IEventQueue *events, const std::string &name, const NetworkAddress &address, ISocketFactory *socketFactory,
61 deskflow::Screen *screen
62 );
63 Client(Client const &) = delete;
64 Client(Client &&) = delete;
65 ~Client() override;
66
67 Client &operator=(Client const &) = delete;
68 Client &operator=(Client &&) = delete;
69
71
72
74
78 void connect(size_t addressIndex = 0);
79 void setServerAddress(const NetworkAddress &address);
80
82
85 void disconnect(const char *msg);
86
88
92 void refuseConnection(deskflow::core::ConnectionRefusal reason, const char *msg);
93
95
98 virtual void handshakeComplete();
99
101
103
105
108 bool isConnected() const;
109
111
115 bool isConnecting() const;
116
118
123
126 {
127 return m_resolvedAddressesCount;
128 }
129
131
132 // IScreen overrides
133 void *getEventTarget() const final;
134 bool getClipboard(ClipboardID id, IClipboard *) const override;
135 void getShape(int32_t &x, int32_t &y, int32_t &width, int32_t &height) const override;
136 void getCursorPos(int32_t &x, int32_t &y) const override;
137
138 // IClient overrides
139 void enter(int32_t xAbs, int32_t yAbs, uint32_t seqNum, KeyModifierMask mask, bool forScreensaver) override;
140 bool leave() override;
141 void setClipboard(ClipboardID, const IClipboard *) override;
142 void grabClipboard(ClipboardID) override;
143 void setClipboardDirty(ClipboardID, bool) override;
144 void keyDown(KeyID, KeyModifierMask, KeyButton, const std::string &) override;
145 void keyRepeat(KeyID, KeyModifierMask, int32_t count, KeyButton, const std::string &lang) override;
146 void keyUp(KeyID, KeyModifierMask, KeyButton) override;
147 void mouseDown(ButtonID) override;
148 void mouseUp(ButtonID) override;
149 void mouseMove(int32_t xAbs, int32_t yAbs) override;
150 void mouseRelativeMove(int32_t xRel, int32_t yRel) override;
151 void mouseWheel(int32_t xDelta, int32_t yDelta) override;
152 void screensaver(bool activate) override;
153 void resetOptions() override;
154 void setOptions(const OptionsList &options) override;
155 std::string getName() const override;
156
157private:
158 void sendClipboard(ClipboardID);
159 void sendEvent(deskflow::EventTypes);
160 void sendConnectionFailedEvent(const char *msg);
161 void setupConnecting();
162 void setupConnection();
163 void setupScreen();
164 void setupTimer();
165 void cleanup();
166 void cleanupConnecting();
167 void cleanupConnection();
168 void cleanupScreen();
169 void cleanupTimer();
170 void cleanupStream();
171 void handleConnected();
172 void handleConnectionFailed(const Event &event);
173 void handleConnectTimeout();
174 void handleOutputError();
175 void handleDisconnected();
176 void handleShapeChanged();
177 void handleClipboardGrabbed(const Event &event);
178 void handleHello();
179 void handleSuspend();
180 void handleResume();
181 void sendClipboardThread(void *);
182 void bindNetworkInterface(IDataSocket *socket) const;
183
184private:
185 std::string m_name;
186 NetworkAddress m_serverAddress;
187 ISocketFactory *m_socketFactory = nullptr;
188 deskflow::Screen *m_screen = nullptr;
189 deskflow::IStream *m_stream = nullptr;
190 EventQueueTimer *m_timer = nullptr;
191 ServerProxy *m_server = nullptr;
192 bool m_ready = false;
193 bool m_active = false;
194 bool m_suspended = false;
195 bool m_connectOnResume = false;
196 bool m_ownClipboard[kClipboardEnd];
197 bool m_sentClipboard[kClipboardEnd];
198 IClipboard::Time m_timeClipboard[kClipboardEnd];
199 std::string m_dataClipboard[kClipboardEnd];
200 IEventQueue *m_events = nullptr;
201 bool m_useSecureNetwork = false;
202 bool m_enableClipboard = true;
203 size_t m_maximumClipboardSize = INT_MAX;
204 size_t m_resolvedAddressesCount = 0;
205};
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:24
int x
Definition ServerConfig.cpp:23
std::string m_what
Definition Client.h:50
bool m_retry
Definition Client.h:49
FailInfo(const char *what)
Definition Client.h:45
void refuseConnection(deskflow::core::ConnectionRefusal reason, const char *msg)
Refuse connection.
Definition Client.cpp:138
void enter(int32_t xAbs, int32_t yAbs, uint32_t seqNum, KeyModifierMask mask, bool forScreensaver) override
Enter screen.
Definition Client.cpp:195
void resetOptions() override
Notify of options changes.
Definition Client.cpp:284
void grabClipboard(ClipboardID) override
Grab clipboard.
Definition Client.cpp:227
void keyUp(KeyID, KeyModifierMask, KeyButton) override
Notify of key release.
Definition Client.cpp:249
void mouseRelativeMove(int32_t xRel, int32_t yRel) override
Notify of mouse motion.
Definition Client.cpp:269
virtual void handshakeComplete()
Notify of handshake complete.
Definition Client.cpp:153
Client(Client &&)=delete
Client(IEventQueue *events, const std::string &name, const NetworkAddress &address, ISocketFactory *socketFactory, deskflow::Screen *screen)
Definition Client.cpp:39
std::string getName() const override
Get client name.
Definition Client.cpp:317
void keyRepeat(KeyID, KeyModifierMask, int32_t count, KeyButton, const std::string &lang) override
Notify of key repeat.
Definition Client.cpp:244
void screensaver(bool activate) override
Notify of screen saver change.
Definition Client.cpp:279
void setOptions(const OptionsList &options) override
Notify of options changes.
Definition Client.cpp:289
void connect(size_t addressIndex=0)
Connect to server.
Definition Client.cpp:75
void disconnect(const char *msg)
Disconnect.
Definition Client.cpp:127
bool getClipboard(ClipboardID id, IClipboard *) const override
Get clipboard.
Definition Client.cpp:180
Client(Client const &)=delete
void mouseWheel(int32_t xDelta, int32_t yDelta) override
Notify of mouse wheel motion.
Definition Client.cpp:274
NetworkAddress getServerAddress() const
Get address of server.
Definition Client.cpp:170
void mouseMove(int32_t xAbs, int32_t yAbs) override
Notify of mouse motion.
Definition Client.cpp:264
void keyDown(KeyID, KeyModifierMask, KeyButton, const std::string &) override
Notify of key press.
Definition Client.cpp:239
void mouseUp(ButtonID) override
Notify of mouse release.
Definition Client.cpp:259
void setClipboardDirty(ClipboardID, bool) override
Mark clipboard dirty.
Definition Client.cpp:234
void mouseDown(ButtonID) override
Notify of mouse press.
Definition Client.cpp:254
bool isConnecting() const
Test if connecting.
Definition Client.cpp:165
bool isConnected() const
Test if connected.
Definition Client.cpp:160
void setClipboard(ClipboardID, const IClipboard *) override
Set clipboard.
Definition Client.cpp:220
void getShape(int32_t &x, int32_t &y, int32_t &width, int32_t &height) const override
Get screen shape.
Definition Client.cpp:185
void * getEventTarget() const final
Get event target.
Definition Client.cpp:175
size_t getLastResolvedAddressesCount() const
Return last resolved adresses count.
Definition Client.h:125
Client & operator=(Client &&)=delete
bool leave() override
Leave screen.
Definition Client.cpp:202
void getCursorPos(int32_t &x, int32_t &y) const override
Get cursor position.
Definition Client.cpp:190
~Client() override
Definition Client.cpp:58
Client & operator=(Client const &)=delete
void setServerAddress(const NetworkAddress &address)
Definition Client.cpp:70
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
ConnectionRefusal
Definition Enums.h:48
Definition DaemonApp.h:20
Definition Config.h:28