more refactoring.

This commit is contained in:
crs 2002-07-10 21:22:28 +00:00
parent 710e1bdd47
commit 3468f3d503
16 changed files with 176 additions and 276 deletions

View File

@ -28,7 +28,6 @@ CClient::CClient(const CString& clientName) :
m_server(NULL), m_server(NULL),
m_camp(false), m_camp(false),
m_active(false), m_active(false),
m_seqNum(0),
m_rejected(true) m_rejected(true)
{ {
// do nothing // do nothing
@ -66,18 +65,29 @@ CClient::wasRejected() const
} }
void void
CClient::onClipboardChanged(ClipboardID id) CClient::onInfoChanged(const CClientInfo& info)
{
log((CLOG_DEBUG "resolution changed"));
CLock lock(&m_mutex);
if (m_server != NULL) {
m_server->onInfoChanged(info);
}
}
bool
CClient::onGrabClipboard(ClipboardID id)
{ {
CLock lock(&m_mutex); CLock lock(&m_mutex);
if (m_server == NULL) { if (m_server == NULL) {
// m_server can be NULL if the screen calls this method // m_server can be NULL if the screen calls this method
// before we've gotten around to connecting to the server. // before we've gotten around to connecting to the server.
// we simply ignore the clipboard change in that case. // we simply ignore the clipboard change in that case.
return; return false;
} }
// grab ownership // grab ownership
m_server->onGrabClipboard(m_name, id, m_seqNum); m_server->onGrabClipboard(id);
// we now own the clipboard and it has not been sent to the server // we now own the clipboard and it has not been sent to the server
m_ownClipboard[id] = true; m_ownClipboard[id] = true;
@ -88,21 +98,14 @@ CClient::onClipboardChanged(ClipboardID id)
if (!m_active) { if (!m_active) {
sendClipboard(id); sendClipboard(id);
} }
return true;
} }
void void
CClient::onResolutionChanged() CClient::onClipboardChanged(ClipboardID, const CString&)
{ {
log((CLOG_DEBUG "resolution changed")); // ignore -- we'll check the clipboard when we leave
CLock lock(&m_mutex);
if (m_server != NULL) {
CClientInfo info;
m_screen->getShape(info.m_x, info.m_y, info.m_w, info.m_h);
m_screen->getMousePos(info.m_mx, info.m_my);
info.m_zoneSize = m_screen->getJumpZoneSize();
m_server->onInfoChanged("", info);
}
} }
bool bool
@ -194,7 +197,6 @@ CClient::enter(SInt32 xAbs, SInt32 yAbs,
{ {
CLock lock(&m_mutex); CLock lock(&m_mutex);
m_active = true; m_active = true;
m_seqNum = seqNum;
} }
m_screen->enter(xAbs, yAbs, mask); m_screen->enter(xAbs, yAbs, mask);
@ -337,9 +339,6 @@ CClient::openSecondaryScreen()
// not active // not active
m_active = false; m_active = false;
// reset last sequence number
m_seqNum = 0;
// reset clipboard state // reset clipboard state
for (ClipboardID id = 0; id < kClipboardEnd; ++id) { for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
m_ownClipboard[id] = false; m_ownClipboard[id] = false;
@ -349,12 +348,12 @@ CClient::openSecondaryScreen()
// open screen // open screen
log((CLOG_DEBUG1 "creating secondary screen")); log((CLOG_DEBUG1 "creating secondary screen"));
#if WINDOWS_LIKE #if WINDOWS_LIKE
m_screen = new CMSWindowsSecondaryScreen; m_screen = new CMSWindowsSecondaryScreen(this);
#elif UNIX_LIKE #elif UNIX_LIKE
m_screen = new CXWindowsSecondaryScreen; m_screen = new CXWindowsSecondaryScreen(this);
#endif #endif
log((CLOG_DEBUG1 "opening secondary screen")); log((CLOG_DEBUG1 "opening secondary screen"));
m_screen->open(this); m_screen->open();
} }
void void
@ -406,7 +405,7 @@ CClient::sendClipboard(ClipboardID id)
// save and send data if different // save and send data if different
if (data != m_dataClipboard[id]) { if (data != m_dataClipboard[id]) {
m_dataClipboard[id] = data; m_dataClipboard[id] = data;
m_server->onClipboardChanged(id, m_seqNum, data); m_server->onClipboardChanged(id, data);
} }
} }
} }

View File

@ -1,6 +1,7 @@
#ifndef CCLIENT_H #ifndef CCLIENT_H
#define CCLIENT_H #define CCLIENT_H
#include "IScreenReceiver.h"
#include "IClient.h" #include "IClient.h"
#include "IClipboard.h" #include "IClipboard.h"
#include "CNetworkAddress.h" #include "CNetworkAddress.h"
@ -10,9 +11,9 @@ class CServerProxy;
class CThread; class CThread;
class IDataSocket; class IDataSocket;
class ISecondaryScreen; class ISecondaryScreen;
class IServer; class IScreenReceiver;
class CClient : public IClient { class CClient : public IScreenReceiver, public IClient {
public: public:
CClient(const CString& clientName); CClient(const CString& clientName);
~CClient(); ~CClient();
@ -32,31 +33,21 @@ public:
// after a successful open(). // after a successful open().
void quit(); void quit();
// handle events on client's screen
// FIXME -- this should mimic methods on IServer
// FIXME -- maybe create a IScreenReceiver with these methods and
// have CPrimaryClient and CClient inherit from them. IServer
// still needs similar methods with extra parameters, though. so
// CServerProxy
// CPrimaryClient
// CClient
// need IScreenReceiver. these classes effective receive notifications
// from screens. note that there's another class of notifications that
// only the server needs (key, mouyse, screensaver). so maybe we have
// IPrimaryScreenReceiver and ISecondaryScreenReceiver (the latter is
// derived with no extra methods from IScreenReceiver).
void onClipboardChanged(ClipboardID);
void onResolutionChanged();
// accessors // accessors
// returns true if the server rejected us // returns true if the server rejected us
bool wasRejected() const; bool wasRejected() const;
// IScreenReceiver overrides
virtual void onInfoChanged(const CClientInfo&);
virtual bool onGrabClipboard(ClipboardID);
virtual void onClipboardChanged(ClipboardID, const CString&);
// IClient overrides // IClient overrides
virtual bool open(); virtual bool open();
virtual void run(); virtual void run();
virtual void close(); virtual void close();
// FIXME -- can we avoid passing everything here?
virtual void enter(SInt32 xAbs, SInt32 yAbs, virtual void enter(SInt32 xAbs, SInt32 yAbs,
UInt32 seqNum, KeyModifierMask mask, UInt32 seqNum, KeyModifierMask mask,
bool screenSaver); bool screenSaver);
@ -97,11 +88,10 @@ private:
CMutex m_mutex; CMutex m_mutex;
CString m_name; CString m_name;
ISecondaryScreen* m_screen; ISecondaryScreen* m_screen;
IServer* m_server; IScreenReceiver* m_server;
CNetworkAddress m_serverAddress; CNetworkAddress m_serverAddress;
bool m_camp; bool m_camp;
bool m_active; bool m_active;
UInt32 m_seqNum;
bool m_rejected; bool m_rejected;
bool m_ownClipboard[kClipboardEnd]; bool m_ownClipboard[kClipboardEnd];
IClipboard::Time m_timeClipboard[kClipboardEnd]; IClipboard::Time m_timeClipboard[kClipboardEnd];

View File

@ -18,7 +18,8 @@ CServerProxy::CServerProxy(IClient* client,
IInputStream* input, IOutputStream* output) : IInputStream* input, IOutputStream* output) :
m_client(client), m_client(client),
m_input(input), m_input(input),
m_output(output) m_output(output),
m_seqNum(0)
{ {
assert(m_client != NULL); assert(m_client != NULL);
assert(m_input != NULL); assert(m_input != NULL);
@ -40,7 +41,10 @@ CServerProxy::run()
m_compressMouse = false; m_compressMouse = false;
// not ignoring mouse motions // not ignoring mouse motions
m_ignoreMouse = false; m_ignoreMouse = false;
// reset sequence number
m_seqNum = 0;
// handle messages from server // handle messages from server
CStopwatch heartbeat; CStopwatch heartbeat;
@ -218,13 +222,7 @@ CServerProxy::getOutputStream() const
} }
void void
CServerProxy::onError() CServerProxy::onInfoChanged(const CClientInfo& info)
{
// ignore
}
void
CServerProxy::onInfoChanged(const CString&, const CClientInfo& info)
{ {
// ignore mouse motion until we receive acknowledgment of our info // ignore mouse motion until we receive acknowledgment of our info
// change message. // change message.
@ -236,74 +234,19 @@ CServerProxy::onInfoChanged(const CString&, const CClientInfo& info)
} }
bool bool
CServerProxy::onGrabClipboard(const CString&, ClipboardID id, UInt32 seqNum) CServerProxy::onGrabClipboard(ClipboardID id)
{ {
log((CLOG_DEBUG1 "sending clipboard %d changed", id)); log((CLOG_DEBUG1 "sending clipboard %d changed", id));
CLock lock(&m_mutex); CLock lock(&m_mutex);
CProtocolUtil::writef(getOutputStream(), kMsgCClipboard, id, seqNum); CProtocolUtil::writef(getOutputStream(), kMsgCClipboard, id, m_seqNum);
} }
void void
CServerProxy::onClipboardChanged(ClipboardID id, CServerProxy::onClipboardChanged(ClipboardID id, const CString& data)
UInt32 seqNum, const CString& data)
{ {
log((CLOG_DEBUG1 "sending clipboard %d seqnum=%d, size=%d", id, seqNum, data.size()));
CLock lock(&m_mutex); CLock lock(&m_mutex);
CProtocolUtil::writef(getOutputStream(), kMsgDClipboard, id, seqNum, &data); log((CLOG_DEBUG1 "sending clipboard %d seqnum=%d, size=%d", id, m_seqNum, data.size()));
} CProtocolUtil::writef(getOutputStream(), kMsgDClipboard, id, m_seqNum, &data);
void
CServerProxy::onKeyDown(KeyID, KeyModifierMask)
{
// ignore
}
void
CServerProxy::onKeyUp(KeyID, KeyModifierMask)
{
// ignore
}
void
CServerProxy::onKeyRepeat(KeyID, KeyModifierMask, SInt32)
{
// ignore
}
void
CServerProxy::onMouseDown(ButtonID)
{
// ignore
}
void
CServerProxy::onMouseUp(ButtonID)
{
// ignore
}
bool
CServerProxy::onMouseMovePrimary(SInt32, SInt32)
{
return false;
}
void
CServerProxy::onMouseMoveSecondary(SInt32, SInt32)
{
// ignore
}
void
CServerProxy::onMouseWheel(SInt32)
{
// ignore
}
void
CServerProxy::onScreenSaver(bool)
{
// ignore
} }
void void
@ -353,6 +296,7 @@ CServerProxy::enter()
{ {
CLock lock(&m_mutex); CLock lock(&m_mutex);
m_compressMouse = false; m_compressMouse = false;
m_seqNum = seqNum;
} }
// forward // forward

View File

@ -1,14 +1,14 @@
#ifndef CSERVERPROXY_H #ifndef CSERVERPROXY_H
#define CSERVERPROXY_H #define CSERVERPROXY_H
#include "IServer.h" #include "IScreenReceiver.h"
#include "CMutex.h" #include "CMutex.h"
class IClient; class IClient;
class IInputStream; class IInputStream;
class IOutputStream; class IOutputStream;
class CServerProxy : public IServer { class CServerProxy : public IScreenReceiver {
public: public:
CServerProxy(IClient* client, CServerProxy(IClient* client,
IInputStream* adoptedInput, IInputStream* adoptedInput,
@ -33,23 +33,10 @@ public:
IInputStream* getInputStream() const; IInputStream* getInputStream() const;
IOutputStream* getOutputStream() const; IOutputStream* getOutputStream() const;
// IServer overrides // IScreenReceiver overrides
virtual void onError(); virtual void onInfoChanged(const CClientInfo&);
virtual void onInfoChanged(const CString& clientName, virtual bool onGrabClipboard(ClipboardID);
const CClientInfo&); virtual void onClipboardChanged(ClipboardID, const CString& data);
virtual bool onGrabClipboard(const CString& clientName,
ClipboardID, UInt32 seqNum);
virtual void onClipboardChanged(ClipboardID,
UInt32 seqNum, const CString& data);
virtual void onKeyDown(KeyID, KeyModifierMask);
virtual void onKeyUp(KeyID, KeyModifierMask);
virtual void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count);
virtual void onMouseDown(ButtonID);
virtual void onMouseUp(ButtonID);
virtual bool onMouseMovePrimary(SInt32 x, SInt32 y);
virtual void onMouseMoveSecondary(SInt32 dx, SInt32 dy);
virtual void onMouseWheel(SInt32 delta);
virtual void onScreenSaver(bool activated);
private: private:
// if compressing mouse motion then send the last motion now // if compressing mouse motion then send the last motion now
@ -80,6 +67,8 @@ private:
IInputStream* m_input; IInputStream* m_input;
IOutputStream* m_output; IOutputStream* m_output;
UInt32 m_seqNum;
bool m_compressMouse; bool m_compressMouse;
SInt32 m_xMouse, m_yMouse; SInt32 m_xMouse, m_yMouse;

View File

@ -24,8 +24,8 @@
// CXWindowsSecondaryScreen // CXWindowsSecondaryScreen
// //
CXWindowsSecondaryScreen::CXWindowsSecondaryScreen() : CXWindowsSecondaryScreen::CXWindowsSecondaryScreen(IScreenReceiver* receiver) :
m_client(NULL), m_receiver(receiver),
m_window(None) m_window(None)
{ {
// do nothing // do nothing
@ -82,13 +82,9 @@ CXWindowsSecondaryScreen::stop()
} }
void void
CXWindowsSecondaryScreen::open(CClient* client) CXWindowsSecondaryScreen::open()
{ {
assert(m_client == NULL); assert(m_receiver != NULL);
assert(client != NULL);
// set the client
m_client = client;
// open the display // open the display
openDisplay(); openDisplay();
@ -128,8 +124,6 @@ CXWindowsSecondaryScreen::open(CClient* client)
void void
CXWindowsSecondaryScreen::close() CXWindowsSecondaryScreen::close()
{ {
assert(m_client != NULL);
// release keys that are logically pressed // release keys that are logically pressed
releaseKeys(); releaseKeys();
@ -138,9 +132,6 @@ CXWindowsSecondaryScreen::close()
// close the display // close the display
closeDisplay(); closeDisplay();
// done with client
m_client = NULL;
} }
void void
@ -396,7 +387,7 @@ void
CXWindowsSecondaryScreen::onLostClipboard(ClipboardID id) CXWindowsSecondaryScreen::onLostClipboard(ClipboardID id)
{ {
// tell client that the clipboard was grabbed locally // tell client that the clipboard was grabbed locally
m_client->onClipboardChanged(id); m_receiver->onGrabClipboard(id);
} }
void void

View File

@ -6,16 +6,18 @@
#include "stdmap.h" #include "stdmap.h"
#include "stdvector.h" #include "stdvector.h"
class IScreenReceiver;
class CXWindowsSecondaryScreen : public CXWindowsScreen, class CXWindowsSecondaryScreen : public CXWindowsScreen,
public ISecondaryScreen { public ISecondaryScreen {
public: public:
CXWindowsSecondaryScreen(); CXWindowsSecondaryScreen(IScreenReceiver*);
virtual ~CXWindowsSecondaryScreen(); virtual ~CXWindowsSecondaryScreen();
// ISecondaryScreen overrides // ISecondaryScreen overrides
virtual void run(); virtual void run();
virtual void stop(); virtual void stop();
virtual void open(CClient*); virtual void open();
virtual void close(); virtual void close();
virtual void enter(SInt32 xAbsolute, SInt32 yAbsolute, virtual void enter(SInt32 xAbsolute, SInt32 yAbsolute,
KeyModifierMask mask); KeyModifierMask mask);
@ -81,7 +83,7 @@ private:
static bool isToggleKeysym(KeySym); static bool isToggleKeysym(KeySym);
private: private:
CClient* m_client; IScreenReceiver* m_receiver;
Window m_window; Window m_window;
// note toggle keys that toggles on up/down (false) or on // note toggle keys that toggles on up/down (false) or on

View File

@ -6,7 +6,6 @@
#include "KeyTypes.h" #include "KeyTypes.h"
#include "MouseTypes.h" #include "MouseTypes.h"
class CClient;
class IClipboard; class IClipboard;
class ISecondaryScreen : public IInterface { class ISecondaryScreen : public IInterface {
@ -23,9 +22,9 @@ public:
virtual void stop() = 0; virtual void stop() = 0;
// initialize the screen, hide the cursor, and disable the screen // initialize the screen, hide the cursor, and disable the screen
// saver. start reporting certain events to the client (clipboard // saver. start reporting events to the IScreenReceiver (which is
// stolen and screen size changed). // set through some other interface).
virtual void open(CClient*) = 0; virtual void open() = 0;
// close the screen. should restore the screen saver. it should // close the screen. should restore the screen saver. it should
// also simulate key up events for any keys that have simulate key // also simulate key up events for any keys that have simulate key

View File

@ -25,9 +25,9 @@ CPrimaryClient::CPrimaryClient(IServer* server, const CString& name) :
// create screen // create screen
log((CLOG_DEBUG1 "creating primary screen")); log((CLOG_DEBUG1 "creating primary screen"));
#if WINDOWS_LIKE #if WINDOWS_LIKE
m_screen = new CMSWindowsPrimaryScreen(this); m_screen = new CMSWindowsPrimaryScreen(this, m_server);
#elif UNIX_LIKE #elif UNIX_LIKE
m_screen = new CXWindowsPrimaryScreen(this); m_screen = new CXWindowsPrimaryScreen(this, m_server);
#endif #endif
} }
@ -69,20 +69,14 @@ CPrimaryClient::getToggleMask() const
} }
void void
CPrimaryClient::onError() CPrimaryClient::onInfoChanged(const CClientInfo& info)
{
m_server->onError();
}
void
CPrimaryClient::onInfoChanged(const CString&, const CClientInfo& info)
{ {
m_info = info; m_info = info;
m_server->onInfoChanged(getName(), m_info); m_server->onInfoChanged(getName(), m_info);
} }
bool bool
CPrimaryClient::onGrabClipboard(const CString&, ClipboardID id, UInt32) CPrimaryClient::onGrabClipboard(ClipboardID id)
{ {
bool result = m_server->onGrabClipboard(getName(), id, m_seqNum); bool result = m_server->onGrabClipboard(getName(), id, m_seqNum);
m_clipboardOwner[id] = result; m_clipboardOwner[id] = result;
@ -90,65 +84,11 @@ CPrimaryClient::onGrabClipboard(const CString&, ClipboardID id, UInt32)
} }
void void
CPrimaryClient::onClipboardChanged(ClipboardID id, UInt32, const CString& data) CPrimaryClient::onClipboardChanged(ClipboardID id, const CString& data)
{ {
m_server->onClipboardChanged(id, m_seqNum, data); m_server->onClipboardChanged(id, m_seqNum, data);
} }
void
CPrimaryClient::onKeyDown(KeyID id, KeyModifierMask mask)
{
m_server->onKeyDown(id, mask);
}
void
CPrimaryClient::onKeyUp(KeyID id, KeyModifierMask mask)
{
m_server->onKeyUp(id, mask);
}
void
CPrimaryClient::onKeyRepeat(KeyID id, KeyModifierMask mask, SInt32 count)
{
m_server->onKeyRepeat(id, mask, count);
}
void
CPrimaryClient::onMouseDown(ButtonID id)
{
m_server->onMouseDown(id);
}
void
CPrimaryClient::onMouseUp(ButtonID id)
{
m_server->onMouseUp(id);
}
bool
CPrimaryClient::onMouseMovePrimary(SInt32 x, SInt32 y)
{
return m_server->onMouseMovePrimary(x, y);
}
void
CPrimaryClient::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
{
m_server->onMouseMoveSecondary(dx, dy);
}
void
CPrimaryClient::onMouseWheel(SInt32 delta)
{
m_server->onMouseWheel(delta);
}
void
CPrimaryClient::onScreenSaver(bool activated)
{
m_server->onScreenSaver(activated);
}
bool bool
CPrimaryClient::open() CPrimaryClient::open()
{ {

View File

@ -1,15 +1,15 @@
#ifndef CPRIMARYCLIENT_H #ifndef CPRIMARYCLIENT_H
#define CPRIMARYCLIENT_H #define CPRIMARYCLIENT_H
#include "IServer.h"
#include "IClient.h" #include "IClient.h"
#include "IScreenReceiver.h"
#include "ProtocolTypes.h" #include "ProtocolTypes.h"
class IClipboard; class IClipboard;
class IPrimaryScreen; class IPrimaryScreen;
class IServer; class IServer;
class CPrimaryClient : public IServer, public IClient { class CPrimaryClient : public IScreenReceiver, public IClient {
public: public:
CPrimaryClient(IServer*, const CString& name); CPrimaryClient(IServer*, const CString& name);
~CPrimaryClient(); ~CPrimaryClient();
@ -33,23 +33,10 @@ public:
// returns the state of the toggle keys on the primary screen // returns the state of the toggle keys on the primary screen
KeyModifierMask getToggleMask() const; KeyModifierMask getToggleMask() const;
// IServer overrides // IScreenReceiver overrides
// onInfoChanged() ignores the client name. virtual void onInfoChanged(const CClientInfo&);
// onGrabClipboard() ignores the client name and sequence number. virtual bool onGrabClipboard(ClipboardID);
// onClipboardChanged() ignores the sequence number. virtual void onClipboardChanged(ClipboardID, const CString&);
virtual void onError();
virtual void onInfoChanged(const CString&, const CClientInfo&);
virtual bool onGrabClipboard(const CString&, ClipboardID, UInt32);
virtual void onClipboardChanged(ClipboardID, UInt32, const CString&);
virtual void onKeyDown(KeyID, KeyModifierMask);
virtual void onKeyUp(KeyID, KeyModifierMask);
virtual void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count);
virtual void onMouseDown(ButtonID);
virtual void onMouseUp(ButtonID);
virtual bool onMouseMovePrimary(SInt32 x, SInt32 y);
virtual void onMouseMoveSecondary(SInt32 dx, SInt32 dy);
virtual void onMouseWheel(SInt32 delta);
virtual void onScreenSaver(bool activated);
// IClient overrides // IClient overrides
virtual bool open(); virtual bool open();

View File

@ -53,11 +53,8 @@ public:
// get the sides of the primary screen that have neighbors // get the sides of the primary screen that have neighbors
UInt32 getActivePrimarySides() const; UInt32 getActivePrimarySides() const;
// IServer overrides // IPrimaryScreenReceiver overrides
virtual void onError(); virtual void onError();
virtual void onInfoChanged(const CString&, const CClientInfo&);
virtual bool onGrabClipboard(const CString&, ClipboardID, UInt32);
virtual void onClipboardChanged(ClipboardID, UInt32, const CString&);
virtual void onKeyDown(KeyID, KeyModifierMask); virtual void onKeyDown(KeyID, KeyModifierMask);
virtual void onKeyUp(KeyID, KeyModifierMask); virtual void onKeyUp(KeyID, KeyModifierMask);
virtual void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count); virtual void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count);
@ -68,6 +65,11 @@ public:
virtual void onMouseWheel(SInt32 delta); virtual void onMouseWheel(SInt32 delta);
virtual void onScreenSaver(bool activated); virtual void onScreenSaver(bool activated);
// IServer overrides
virtual void onInfoChanged(const CString&, const CClientInfo&);
virtual bool onGrabClipboard(const CString&, ClipboardID, UInt32);
virtual void onClipboardChanged(ClipboardID, UInt32, const CString&);
protected: protected:
bool onCommandKey(KeyID, KeyModifierMask, bool down); bool onCommandKey(KeyID, KeyModifierMask, bool down);

View File

@ -1,9 +1,10 @@
#include "CXWindowsPrimaryScreen.h" #include "CXWindowsPrimaryScreen.h"
#include "IScreenReceiver.h"
#include "IPrimaryScreenReceiver.h"
#include "CXWindowsClipboard.h" #include "CXWindowsClipboard.h"
#include "CXWindowsScreenSaver.h" #include "CXWindowsScreenSaver.h"
#include "CXWindowsUtil.h" #include "CXWindowsUtil.h"
#include "CClipboard.h" #include "CClipboard.h"
#include "IServer.h"
#include "ProtocolTypes.h" #include "ProtocolTypes.h"
#include "CThread.h" #include "CThread.h"
#include "CLog.h" #include "CLog.h"
@ -21,8 +22,11 @@
// CXWindowsPrimaryScreen // CXWindowsPrimaryScreen
// //
CXWindowsPrimaryScreen::CXWindowsPrimaryScreen(IServer* server) : CXWindowsPrimaryScreen::CXWindowsPrimaryScreen(
m_server(server), IScreenReceiver* receiver,
IPrimaryScreenReceiver* primaryReceiver) :
m_receiver(receiver),
m_primaryReceiver(primaryReceiver),
m_active(false), m_active(false),
m_window(None) m_window(None)
{ {
@ -67,7 +71,7 @@ CXWindowsPrimaryScreen::run()
if (xevent.xclient.message_type == m_atomScreenSaver || if (xevent.xclient.message_type == m_atomScreenSaver ||
xevent.xclient.format == 32) { xevent.xclient.format == 32) {
// screen saver activation/deactivation event // screen saver activation/deactivation event
m_server->onScreenSaver(xevent.xclient.data.l[0] != 0); m_primaryReceiver->onScreenSaver(xevent.xclient.data.l[0] != 0);
} }
break; break;
@ -77,12 +81,12 @@ CXWindowsPrimaryScreen::run()
const KeyModifierMask mask = mapModifier(xevent.xkey.state); const KeyModifierMask mask = mapModifier(xevent.xkey.state);
const KeyID key = mapKey(&xevent.xkey); const KeyID key = mapKey(&xevent.xkey);
if (key != kKeyNone) { if (key != kKeyNone) {
m_server->onKeyDown(key, mask); m_primaryReceiver->onKeyDown(key, mask);
if (key == XK_Caps_Lock && m_capsLockHalfDuplex) { if (key == XK_Caps_Lock && m_capsLockHalfDuplex) {
m_server->onKeyUp(key, mask | KeyModifierCapsLock); m_primaryReceiver->onKeyUp(key, mask | KeyModifierCapsLock);
} }
else if (key == XK_Num_Lock && m_numLockHalfDuplex) { else if (key == XK_Num_Lock && m_numLockHalfDuplex) {
m_server->onKeyUp(key, mask | KeyModifierNumLock); m_primaryReceiver->onKeyUp(key, mask | KeyModifierNumLock);
} }
} }
} }
@ -112,12 +116,12 @@ CXWindowsPrimaryScreen::run()
// no press event follows so it's a plain release // no press event follows so it's a plain release
log((CLOG_DEBUG1 "event: KeyRelease code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state)); log((CLOG_DEBUG1 "event: KeyRelease code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
if (key == XK_Caps_Lock && m_capsLockHalfDuplex) { if (key == XK_Caps_Lock && m_capsLockHalfDuplex) {
m_server->onKeyDown(key, mask); m_primaryReceiver->onKeyDown(key, mask);
} }
else if (key == XK_Num_Lock && m_numLockHalfDuplex) { else if (key == XK_Num_Lock && m_numLockHalfDuplex) {
m_server->onKeyDown(key, mask); m_primaryReceiver->onKeyDown(key, mask);
} }
m_server->onKeyUp(key, mask); m_primaryReceiver->onKeyUp(key, mask);
} }
else { else {
// found a press event following so it's a repeat. // found a press event following so it's a repeat.
@ -125,7 +129,7 @@ CXWindowsPrimaryScreen::run()
// repeats but we'll just send a repeat of 1. // repeats but we'll just send a repeat of 1.
// note that we discard the press event. // note that we discard the press event.
log((CLOG_DEBUG1 "event: repeat code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state)); log((CLOG_DEBUG1 "event: repeat code=%d, state=0x%04x", xevent.xkey.keycode, xevent.xkey.state));
m_server->onKeyRepeat(key, mask, 1); m_primaryReceiver->onKeyRepeat(key, mask, 1);
} }
} }
} }
@ -136,7 +140,7 @@ CXWindowsPrimaryScreen::run()
log((CLOG_DEBUG1 "event: ButtonPress button=%d", xevent.xbutton.button)); log((CLOG_DEBUG1 "event: ButtonPress button=%d", xevent.xbutton.button));
const ButtonID button = mapButton(xevent.xbutton.button); const ButtonID button = mapButton(xevent.xbutton.button);
if (button != kButtonNone) { if (button != kButtonNone) {
m_server->onMouseDown(button); m_primaryReceiver->onMouseDown(button);
} }
} }
break; break;
@ -146,15 +150,15 @@ CXWindowsPrimaryScreen::run()
log((CLOG_DEBUG1 "event: ButtonRelease button=%d", xevent.xbutton.button)); log((CLOG_DEBUG1 "event: ButtonRelease button=%d", xevent.xbutton.button));
const ButtonID button = mapButton(xevent.xbutton.button); const ButtonID button = mapButton(xevent.xbutton.button);
if (button != kButtonNone) { if (button != kButtonNone) {
m_server->onMouseUp(button); m_primaryReceiver->onMouseUp(button);
} }
else if (xevent.xbutton.button == 4) { else if (xevent.xbutton.button == 4) {
// wheel forward (away from user) // wheel forward (away from user)
m_server->onMouseWheel(120); m_primaryReceiver->onMouseWheel(120);
} }
else if (xevent.xbutton.button == 5) { else if (xevent.xbutton.button == 5) {
// wheel backward (toward user) // wheel backward (toward user)
m_server->onMouseWheel(-120); m_primaryReceiver->onMouseWheel(-120);
} }
} }
break; break;
@ -185,7 +189,7 @@ CXWindowsPrimaryScreen::run()
} }
else if (!m_active) { else if (!m_active) {
// motion on primary screen // motion on primary screen
m_server->onMouseMovePrimary(m_x, m_y); m_primaryReceiver->onMouseMovePrimary(m_x, m_y);
} }
else { else {
// motion on secondary screen. warp mouse back to // motion on secondary screen. warp mouse back to
@ -216,7 +220,7 @@ CXWindowsPrimaryScreen::run()
// warping to the primary screen's enter position, // warping to the primary screen's enter position,
// effectively overriding it. // effectively overriding it.
if (x != 0 || y != 0) { if (x != 0 || y != 0) {
m_server->onMouseMoveSecondary(x, y); m_primaryReceiver->onMouseMoveSecondary(x, y);
} }
} }
} }
@ -287,7 +291,7 @@ CXWindowsPrimaryScreen::open()
info.m_zoneSize = 1; info.m_zoneSize = 1;
info.m_mx = m_x; info.m_mx = m_x;
info.m_my = m_y; info.m_my = m_y;
m_server->onInfoChanged("", info); m_receiver->onInfoChanged(info);
} }
void void
@ -498,12 +502,15 @@ CXWindowsPrimaryScreen::getToggleMask() const
// convert to KeyModifierMask // convert to KeyModifierMask
KeyModifierMask mask = 0; KeyModifierMask mask = 0;
if (state & m_numLockMask) if (state & m_numLockMask) {
mask |= KeyModifierNumLock; mask |= KeyModifierNumLock;
if (state & m_capsLockMask) }
if (state & m_capsLockMask) {
mask |= KeyModifierCapsLock; mask |= KeyModifierCapsLock;
if (state & m_scrollLockMask) }
if (state & m_scrollLockMask) {
mask |= KeyModifierScrollLock; mask |= KeyModifierScrollLock;
}
return mask; return mask;
} }
@ -595,14 +602,14 @@ void
CXWindowsPrimaryScreen::onUnexpectedClose() CXWindowsPrimaryScreen::onUnexpectedClose()
{ {
// tell server to shutdown // tell server to shutdown
m_server->onError(); m_primaryReceiver->onError();
} }
void void
CXWindowsPrimaryScreen::onLostClipboard(ClipboardID id) CXWindowsPrimaryScreen::onLostClipboard(ClipboardID id)
{ {
// tell server that the clipboard was grabbed locally // tell server that the clipboard was grabbed locally
m_server->onGrabClipboard("", id, 0); m_receiver->onGrabClipboard(id);
} }
void void

View File

@ -5,11 +5,12 @@
#include "IPrimaryScreen.h" #include "IPrimaryScreen.h"
#include "MouseTypes.h" #include "MouseTypes.h"
class IServer; class IScreenReceiver;
class IPrimaryScreenReceiver;
class CXWindowsPrimaryScreen : public CXWindowsScreen, public IPrimaryScreen { class CXWindowsPrimaryScreen : public CXWindowsScreen, public IPrimaryScreen {
public: public:
CXWindowsPrimaryScreen(IServer*); CXWindowsPrimaryScreen(IScreenReceiver*, IPrimaryScreenReceiver*);
virtual ~CXWindowsPrimaryScreen(); virtual ~CXWindowsPrimaryScreen();
// IPrimaryScreen overrides // IPrimaryScreen overrides
@ -60,7 +61,9 @@ private:
static Bool findKeyEvent(Display*, XEvent* xevent, XPointer arg); static Bool findKeyEvent(Display*, XEvent* xevent, XPointer arg);
private: private:
IServer* m_server; IScreenReceiver* m_receiver;
IPrimaryScreenReceiver* m_primaryReceiver;
bool m_active; bool m_active;
Window m_window; Window m_window;

View File

@ -0,0 +1,28 @@
#ifndef IPRIMARYSCREENRECEIVER_H
#define IPRIMARYSCREENRECEIVER_H
#include "IInterface.h"
#include "KeyTypes.h"
#include "MouseTypes.h"
class IPrimaryScreenReceiver : public IInterface {
public:
// notify of serious error. this implies that the server should
// shutdown.
virtual void onError() = 0;
// call to notify of events. onMouseMovePrimary() returns
// true iff the mouse enters a jump zone and jumps.
virtual void onKeyDown(KeyID, KeyModifierMask) = 0;
virtual void onKeyUp(KeyID, KeyModifierMask) = 0;
virtual void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count) = 0;
virtual void onMouseDown(ButtonID) = 0;
virtual void onMouseUp(ButtonID) = 0;
virtual bool onMouseMovePrimary(SInt32 x, SInt32 y) = 0;
virtual void onMouseMoveSecondary(SInt32 dx, SInt32 dy) = 0;
virtual void onMouseWheel(SInt32 delta) = 0;
virtual void onScreenSaver(bool activated) = 0;
};
#endif

23
synergy/IScreenReceiver.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef ISCREENRECEIVER_H
#define ISCREENRECEIVER_H
#include "IInterface.h"
#include "ClipboardTypes.h"
#include "ProtocolTypes.h"
#include "CString.h"
class IScreenReceiver : public IInterface {
public:
// notify of client info change
virtual void onInfoChanged(const CClientInfo&) = 0;
// notify of clipboard grab. returns true if the grab was honored,
// false otherwise.
virtual bool onGrabClipboard(ClipboardID) = 0;
// notify of new clipboard data
virtual void onClipboardChanged(ClipboardID,
const CString& data) = 0;
};
#endif

View File

@ -1,22 +1,16 @@
#ifndef ISERVER_H #ifndef ISERVER_H
#define ISERVER_H #define ISERVER_H
#include "IInterface.h" #include "IPrimaryScreenReceiver.h"
#include "ClipboardTypes.h" #include "ClipboardTypes.h"
#include "KeyTypes.h"
#include "MouseTypes.h"
#include "CString.h" #include "CString.h"
class CClientInfo; class CClientInfo;
class IServer : public IInterface { class IServer : public IPrimaryScreenReceiver {
public: public:
// manipulators // manipulators
// notify of serious error. this implies that the server should
// shutdown.
virtual void onError() = 0;
// notify of client info change // notify of client info change
virtual void onInfoChanged(const CString& clientName, virtual void onInfoChanged(const CString& clientName,
const CClientInfo&) = 0; const CClientInfo&) = 0;
@ -30,8 +24,8 @@ public:
virtual void onClipboardChanged(ClipboardID, virtual void onClipboardChanged(ClipboardID,
UInt32 seqNum, const CString& data) = 0; UInt32 seqNum, const CString& data) = 0;
// call to notify of events. onMouseMovePrimary() returns // IPrimaryScreenReceiver overrides
// true iff the mouse enters a jump zone and jumps. virtual void onError() = 0;
virtual void onKeyDown(KeyID, KeyModifierMask) = 0; virtual void onKeyDown(KeyID, KeyModifierMask) = 0;
virtual void onKeyUp(KeyID, KeyModifierMask) = 0; virtual void onKeyUp(KeyID, KeyModifierMask) = 0;
virtual void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count) = 0; virtual void onKeyRepeat(KeyID, KeyModifierMask, SInt32 count) = 0;

View File

@ -19,6 +19,8 @@ libsynergy_a_SOURCES = \
ClipboardTypes.h \ ClipboardTypes.h \
IClient.h \ IClient.h \
IClipboard.h \ IClipboard.h \
IPrimaryScreenReceiver.h\
IScreenReceiver.h \
IScreenSaver.h \ IScreenSaver.h \
IServer.h \ IServer.h \
ISocketFactory.h \ ISocketFactory.h \