2002-08-02 23:57:46 +04:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
#ifndef CSERVER_H
|
|
|
|
#define CSERVER_H
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
#include "CConfig.h"
|
|
|
|
#include "CClipboard.h"
|
2004-02-14 17:04:36 +03:00
|
|
|
#include "ClipboardTypes.h"
|
|
|
|
#include "KeyTypes.h"
|
|
|
|
#include "MouseTypes.h"
|
|
|
|
#include "CEvent.h"
|
2003-02-23 22:29:08 +03:00
|
|
|
#include "CStopwatch.h"
|
2002-06-01 23:26:11 +04:00
|
|
|
#include "stdmap.h"
|
2004-02-14 17:04:36 +03:00
|
|
|
#include "stdset.h"
|
2003-03-13 01:34:07 +03:00
|
|
|
#include "stdvector.h"
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
class CEventQueueTimer;
|
2002-07-10 01:22:31 +04:00
|
|
|
class CPrimaryClient;
|
|
|
|
class IClient;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Synergy server
|
|
|
|
/*!
|
|
|
|
This class implements the top-level server algorithms for synergy.
|
|
|
|
*/
|
2004-02-14 17:04:36 +03:00
|
|
|
class CServer {
|
2002-04-29 18:40:01 +04:00
|
|
|
public:
|
2002-07-30 18:59:36 +04:00
|
|
|
/*!
|
2004-02-14 17:04:36 +03:00
|
|
|
Start the server with the configuration \p config and the primary
|
|
|
|
client (local screen) \p primaryClient. The client retains
|
|
|
|
ownership of \p primaryClient.
|
2002-07-30 18:59:36 +04:00
|
|
|
*/
|
2004-02-14 17:04:36 +03:00
|
|
|
CServer(const CConfig& config, CPrimaryClient* primaryClient);
|
2001-10-06 18:13:28 +04:00
|
|
|
~CServer();
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! @name manipulators
|
|
|
|
//@{
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Set configuration
|
|
|
|
/*!
|
|
|
|
Change the server's configuration. Returns true iff the new
|
|
|
|
configuration was accepted (it must include the server's name).
|
|
|
|
This will disconnect any clients no longer in the configuration.
|
|
|
|
*/
|
2002-05-31 22:09:43 +04:00
|
|
|
bool setConfig(const CConfig&);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
//! Add a client
|
2002-07-30 22:31:00 +04:00
|
|
|
/*!
|
2004-02-14 17:04:36 +03:00
|
|
|
Adds \p client to the server. The client is adopted and will be
|
|
|
|
destroyed when the client disconnects or is disconnected.
|
2002-07-30 22:31:00 +04:00
|
|
|
*/
|
2004-02-14 17:04:36 +03:00
|
|
|
void adoptClient(IClient* client);
|
2002-07-30 22:31:00 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
//! Disconnect clients
|
2002-07-30 22:31:00 +04:00
|
|
|
/*!
|
2004-02-14 17:04:36 +03:00
|
|
|
Disconnect clients. This tells them to disconnect but does not wait
|
|
|
|
for them to actually do so. The server sends the disconnected event
|
|
|
|
when they're all disconnected (or immediately if none are connected).
|
|
|
|
The caller can also just destroy this object to force the disconnection.
|
2002-07-30 22:31:00 +04:00
|
|
|
*/
|
2004-02-14 17:04:36 +03:00
|
|
|
void disconnect();
|
2003-03-13 01:34:07 +03:00
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//@}
|
|
|
|
//! @name accessors
|
|
|
|
//@{
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2003-03-13 01:34:07 +03:00
|
|
|
//! Get number of connected clients
|
|
|
|
/*!
|
|
|
|
Returns the number of connected clients, including the server itself.
|
|
|
|
*/
|
|
|
|
UInt32 getNumClients() const;
|
|
|
|
|
|
|
|
//! Get the list of connected clients
|
|
|
|
/*!
|
|
|
|
Set the \c list to the names of the currently connected clients.
|
|
|
|
*/
|
|
|
|
void getClients(std::vector<CString>& list) const;
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
//! Get error event type
|
2003-03-13 01:34:07 +03:00
|
|
|
/*!
|
2004-02-14 17:04:36 +03:00
|
|
|
Returns the error event type. This is sent when the server fails
|
|
|
|
for some reason.
|
2003-03-13 01:34:07 +03:00
|
|
|
*/
|
2004-02-14 17:04:36 +03:00
|
|
|
static CEvent::Type getErrorEvent();
|
2003-03-13 01:34:07 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
//! Get disconnected event type
|
|
|
|
/*!
|
|
|
|
Returns the disconnected event type. This is sent when all the
|
|
|
|
clients have disconnected.
|
|
|
|
*/
|
|
|
|
static CEvent::Type getDisconnectedEvent();
|
2002-07-30 18:59:36 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
//@}
|
2002-07-11 01:22:28 +04:00
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
protected:
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Handle special keys
|
|
|
|
/*!
|
|
|
|
Handles keys with special meaning.
|
|
|
|
*/
|
2001-10-06 18:13:28 +04:00
|
|
|
bool onCommandKey(KeyID, KeyModifierMask, bool down);
|
|
|
|
|
2002-04-29 18:40:01 +04:00
|
|
|
private:
|
2004-02-14 17:04:36 +03:00
|
|
|
// get canonical name of client
|
|
|
|
CString getName(const IClient*) const;
|
2003-03-13 01:34:07 +03:00
|
|
|
|
2002-07-11 17:13:37 +04:00
|
|
|
// get the sides of the primary screen that have neighbors
|
|
|
|
UInt32 getActivePrimarySides() const;
|
|
|
|
|
2002-06-01 14:52:02 +04:00
|
|
|
// returns true iff mouse should be locked to the current screen
|
2004-03-26 23:59:26 +03:00
|
|
|
// according to this object only, ignoring what the primary client
|
|
|
|
// says.
|
|
|
|
bool isLockedToScreenServer() const;
|
|
|
|
|
|
|
|
// returns true iff mouse should be locked to the current screen
|
|
|
|
// according to this object or the primary client.
|
2004-02-14 17:04:36 +03:00
|
|
|
bool isLockedToScreen() const;
|
|
|
|
|
|
|
|
// returns the jump zone of the client
|
|
|
|
SInt32 getJumpZoneSize(IClient*) const;
|
2002-06-01 14:52:02 +04:00
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
// change the active screen
|
2002-07-10 01:22:31 +04:00
|
|
|
void switchScreen(IClient*,
|
2002-06-24 03:24:22 +04:00
|
|
|
SInt32 x, SInt32 y, bool forScreenSaver);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// lookup neighboring screen
|
2002-07-15 19:01:36 +04:00
|
|
|
IClient* getNeighbor(IClient*, EDirection) const;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// lookup neighboring screen. given a position relative to the
|
|
|
|
// source screen, find the screen we should move onto and where.
|
|
|
|
// if the position is sufficiently far from the source then we
|
2002-06-19 21:03:29 +04:00
|
|
|
// cross multiple screens. if there is no suitable screen then
|
|
|
|
// return NULL and x,y are not modified.
|
2002-07-15 19:01:36 +04:00
|
|
|
IClient* getNeighbor(IClient*, EDirection,
|
2002-06-11 02:06:45 +04:00
|
|
|
SInt32& x, SInt32& y) const;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2003-02-23 22:29:08 +03:00
|
|
|
// test if a switch is permitted. this includes testing user
|
|
|
|
// options like switch delay and tracking any state required to
|
|
|
|
// implement them. returns true iff a switch is permitted.
|
|
|
|
bool isSwitchOkay(IClient* dst, EDirection,
|
|
|
|
SInt32 x, SInt32 y);
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// update switch state due to a mouse move at \p x, \p y that
|
|
|
|
// doesn't switch screens.
|
|
|
|
void noSwitch(SInt32 x, SInt32 y);
|
2003-02-23 22:29:08 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// stop switch timers
|
|
|
|
void stopSwitch();
|
2003-02-23 00:53:25 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// start two tap switch timer
|
|
|
|
void startSwitchTwoTap();
|
2002-12-23 16:55:21 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// arm the two tap switch timer if \p x, \p y is outside the tap zone
|
|
|
|
void armSwitchTwoTap(SInt32 x, SInt32 y);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// stop the two tap switch timer
|
|
|
|
void stopSwitchTwoTap();
|
2002-04-29 17:31:44 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// returns true iff the two tap switch timer is started
|
|
|
|
bool isSwitchTwoTapStarted() const;
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// returns true iff should switch because of two tap
|
|
|
|
bool shouldSwitchTwoTap() const;
|
2002-06-21 19:18:01 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// start delay switch timer
|
|
|
|
void startSwitchWait(SInt32 x, SInt32 y);
|
2002-06-21 19:18:01 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// stop delay switch timer
|
|
|
|
void stopSwitchWait();
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// returns true iff the delay switch timer is started
|
|
|
|
bool isSwitchWaitStarted() const;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-05-01 19:18:59 +04:00
|
|
|
// stop relative mouse moves
|
|
|
|
void stopRelativeMoves();
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// send screen options to \c client
|
|
|
|
void sendOptions(IClient* client) const;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// process options from configuration
|
|
|
|
void processOptions();
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
void handleShapeChanged(const CEvent&, void*);
|
|
|
|
void handleClipboardGrabbed(const CEvent&, void*);
|
|
|
|
void handleClipboardChanged(const CEvent&, void*);
|
|
|
|
void handleKeyDownEvent(const CEvent&, void*);
|
|
|
|
void handleKeyUpEvent(const CEvent&, void*);
|
|
|
|
void handleKeyRepeatEvent(const CEvent&, void*);
|
|
|
|
void handleButtonDownEvent(const CEvent&, void*);
|
|
|
|
void handleButtonUpEvent(const CEvent&, void*);
|
|
|
|
void handleMotionPrimaryEvent(const CEvent&, void*);
|
|
|
|
void handleMotionSecondaryEvent(const CEvent&, void*);
|
|
|
|
void handleWheelEvent(const CEvent&, void*);
|
|
|
|
void handleScreensaverActivatedEvent(const CEvent&, void*);
|
|
|
|
void handleScreensaverDeactivatedEvent(const CEvent&, void*);
|
|
|
|
void handleSwitchWaitTimeout(const CEvent&, void*);
|
|
|
|
void handleClientDisconnected(const CEvent&, void*);
|
|
|
|
void handleClientCloseTimeout(const CEvent&, void*);
|
|
|
|
|
|
|
|
// event processing
|
|
|
|
void onClipboardChanged(IClient* sender,
|
|
|
|
ClipboardID id, UInt32 seqNum);
|
|
|
|
void onScreensaver(bool activated);
|
|
|
|
void onKeyDown(KeyID, KeyModifierMask, KeyButton);
|
|
|
|
void onKeyUp(KeyID, KeyModifierMask, KeyButton);
|
|
|
|
void onKeyRepeat(KeyID, KeyModifierMask, SInt32, KeyButton);
|
|
|
|
void onMouseDown(ButtonID);
|
|
|
|
void onMouseUp(ButtonID);
|
|
|
|
bool onMouseMovePrimary(SInt32 x, SInt32 y);
|
|
|
|
void onMouseMoveSecondary(SInt32 dx, SInt32 dy);
|
|
|
|
void onMouseWheel(SInt32 delta);
|
|
|
|
|
|
|
|
// add client to list and attach event handlers for client
|
|
|
|
bool addClient(IClient*);
|
|
|
|
|
|
|
|
// remove client from list and detach event handlers for client
|
|
|
|
bool removeClient(IClient*);
|
|
|
|
|
|
|
|
// close a client
|
|
|
|
void closeClient(IClient*, const char* msg);
|
|
|
|
|
|
|
|
// close clients not in \p config
|
|
|
|
void closeClients(const CConfig& config);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// close all clients whether they've completed the handshake or not,
|
|
|
|
// except the primary client
|
|
|
|
void closeAllClients();
|
|
|
|
|
|
|
|
// remove clients from internal state
|
|
|
|
void removeActiveClient(IClient*);
|
|
|
|
void removeOldClient(IClient*);
|
2002-10-18 01:37:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// force the cursor off of \p client
|
|
|
|
void forceLeaveClient(IClient* client);
|
|
|
|
|
|
|
|
private:
|
2002-04-29 17:31:44 +04:00
|
|
|
class CClipboardInfo {
|
2002-04-27 18:19:53 +04:00
|
|
|
public:
|
2002-04-29 17:31:44 +04:00
|
|
|
CClipboardInfo();
|
2002-04-27 18:19:53 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
CClipboard m_clipboard;
|
|
|
|
CString m_clipboardData;
|
|
|
|
CString m_clipboardOwner;
|
|
|
|
UInt32 m_clipboardSeqNum;
|
|
|
|
};
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// the primary screen client
|
|
|
|
CPrimaryClient* m_primaryClient;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// all clients (including the primary client) indexed by name
|
2002-07-10 01:22:31 +04:00
|
|
|
typedef std::map<CString, IClient*> CClientList;
|
2004-02-14 17:04:36 +03:00
|
|
|
typedef std::set<IClient*> CClientSet;
|
2002-07-10 01:22:31 +04:00
|
|
|
CClientList m_clients;
|
2004-02-14 17:04:36 +03:00
|
|
|
CClientSet m_clientSet;
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// all old connections that we're waiting to hangup
|
|
|
|
typedef std::map<IClient*, CEventQueueTimer*> COldClients;
|
|
|
|
COldClients m_oldClients;
|
2002-07-10 01:22:31 +04:00
|
|
|
|
|
|
|
// the client with focus
|
|
|
|
IClient* m_active;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-04-29 17:31:44 +04:00
|
|
|
// the sequence number of enter messages
|
|
|
|
UInt32 m_seqNum;
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// current mouse position (in absolute screen coordinates) on
|
|
|
|
// whichever screen is active
|
2001-10-06 18:13:28 +04:00
|
|
|
SInt32 m_x, m_y;
|
|
|
|
|
2004-04-06 01:10:06 +04:00
|
|
|
// last mouse deltas. this is needed to smooth out double tap
|
|
|
|
// on win32 which reports bogus mouse motion at the edge of
|
|
|
|
// the screen when using low level hooks, synthesizing motion
|
|
|
|
// in the opposite direction the mouse actually moved.
|
|
|
|
SInt32 m_xDelta, m_yDelta;
|
|
|
|
SInt32 m_xDelta2, m_yDelta2;
|
|
|
|
|
2002-06-22 23:20:21 +04:00
|
|
|
// current configuration
|
2002-05-31 18:43:23 +04:00
|
|
|
CConfig m_config;
|
2001-11-25 21:32:41 +03:00
|
|
|
|
2002-06-22 23:20:21 +04:00
|
|
|
// clipboard cache
|
2002-04-29 17:31:44 +04:00
|
|
|
CClipboardInfo m_clipboards[kClipboardEnd];
|
2002-05-30 20:13:16 +04:00
|
|
|
|
2002-06-22 23:20:21 +04:00
|
|
|
// state saved when screen saver activates
|
2002-07-10 01:22:31 +04:00
|
|
|
IClient* m_activeSaver;
|
2002-06-22 23:20:21 +04:00
|
|
|
SInt32 m_xSaver, m_ySaver;
|
|
|
|
|
2003-02-23 22:29:08 +03:00
|
|
|
// common state for screen switch tests. all tests are always
|
|
|
|
// trying to reach the same screen in the same direction.
|
|
|
|
EDirection m_switchDir;
|
|
|
|
IClient* m_switchScreen;
|
|
|
|
|
|
|
|
// state for delayed screen switching
|
2003-02-23 00:53:25 +03:00
|
|
|
double m_switchWaitDelay;
|
2004-02-14 17:04:36 +03:00
|
|
|
CEventQueueTimer* m_switchWaitTimer;
|
2003-02-23 00:53:25 +03:00
|
|
|
SInt32 m_switchWaitX, m_switchWaitY;
|
2003-02-23 22:29:08 +03:00
|
|
|
|
|
|
|
// state for double-tap screen switching
|
|
|
|
double m_switchTwoTapDelay;
|
|
|
|
CStopwatch m_switchTwoTapTimer;
|
|
|
|
bool m_switchTwoTapEngaged;
|
|
|
|
bool m_switchTwoTapArmed;
|
2003-05-21 23:38:11 +04:00
|
|
|
SInt32 m_switchTwoTapZone;
|
2003-03-13 01:34:07 +03:00
|
|
|
|
2004-05-01 19:18:59 +04:00
|
|
|
// relative mouse move option
|
|
|
|
bool m_relativeMoves;
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
static CEvent::Type s_errorEvent;
|
|
|
|
static CEvent::Type s_disconnectedEvent;
|
2001-10-06 18:13:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|