2002-08-02 19:57:46 +00: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.
|
|
|
|
*/
|
|
|
|
|
2002-07-09 21:22:31 +00:00
|
|
|
#include "CClientProxy1_0.h"
|
|
|
|
#include "CProtocolUtil.h"
|
|
|
|
#include "XSynergy.h"
|
2004-02-01 21:09:22 +00:00
|
|
|
#include "IStream.h"
|
2002-07-09 21:22:31 +00:00
|
|
|
#include "CLog.h"
|
2004-02-01 21:09:22 +00:00
|
|
|
#include "IEventQueue.h"
|
|
|
|
#include "TMethodEventJob.h"
|
2002-07-09 21:22:31 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
//
|
|
|
|
// CClientProxy1_0
|
|
|
|
//
|
|
|
|
|
2004-02-14 14:04:36 +00:00
|
|
|
CClientProxy1_0::CClientProxy1_0(const CString& name, IStream* stream) :
|
|
|
|
CClientProxy(name, stream),
|
2004-02-01 21:09:22 +00:00
|
|
|
m_heartbeatAlarm(kHeartRate * kHeartBeatsUntilDeath),
|
2004-02-14 14:04:36 +00:00
|
|
|
m_heartbeatTimer(NULL),
|
|
|
|
m_parser(&CClientProxy1_0::parseHandshakeMessage)
|
2002-07-09 21:22:31 +00:00
|
|
|
{
|
2004-02-01 21:09:22 +00:00
|
|
|
// install event handlers
|
|
|
|
EVENTQUEUE->adoptHandler(IStream::getInputReadyEvent(),
|
|
|
|
stream->getEventTarget(),
|
|
|
|
new TMethodEventJob<CClientProxy1_0>(this,
|
|
|
|
&CClientProxy1_0::handleData, NULL));
|
|
|
|
EVENTQUEUE->adoptHandler(IStream::getOutputErrorEvent(),
|
|
|
|
stream->getEventTarget(),
|
|
|
|
new TMethodEventJob<CClientProxy1_0>(this,
|
|
|
|
&CClientProxy1_0::handleWriteError, NULL));
|
|
|
|
EVENTQUEUE->adoptHandler(IStream::getInputShutdownEvent(),
|
|
|
|
stream->getEventTarget(),
|
|
|
|
new TMethodEventJob<CClientProxy1_0>(this,
|
|
|
|
&CClientProxy1_0::handleDisconnect, NULL));
|
|
|
|
EVENTQUEUE->adoptHandler(IStream::getOutputShutdownEvent(),
|
|
|
|
stream->getEventTarget(),
|
|
|
|
new TMethodEventJob<CClientProxy1_0>(this,
|
|
|
|
&CClientProxy1_0::handleWriteError, NULL));
|
|
|
|
EVENTQUEUE->adoptHandler(CEvent::kTimer, this,
|
|
|
|
new TMethodEventJob<CClientProxy1_0>(this,
|
|
|
|
&CClientProxy1_0::handleFlatline, NULL));
|
|
|
|
|
2004-02-14 14:04:36 +00:00
|
|
|
LOG((CLOG_DEBUG1 "querying client \"%s\" info", getName().c_str()));
|
|
|
|
CProtocolUtil::writef(getStream(), kMsgQInfo);
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CClientProxy1_0::~CClientProxy1_0()
|
|
|
|
{
|
2004-02-01 21:09:22 +00:00
|
|
|
removeHandlers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::disconnect()
|
|
|
|
{
|
|
|
|
removeHandlers();
|
|
|
|
getStream()->close();
|
2004-02-14 14:04:36 +00:00
|
|
|
EVENTQUEUE->addEvent(CEvent(getDisconnectedEvent(), getEventTarget()));
|
2004-02-01 21:09:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::removeHandlers()
|
|
|
|
{
|
|
|
|
// uninstall event handlers
|
|
|
|
EVENTQUEUE->removeHandler(IStream::getInputReadyEvent(),
|
|
|
|
getStream()->getEventTarget());
|
|
|
|
EVENTQUEUE->removeHandler(IStream::getOutputErrorEvent(),
|
|
|
|
getStream()->getEventTarget());
|
|
|
|
EVENTQUEUE->removeHandler(IStream::getInputShutdownEvent(),
|
|
|
|
getStream()->getEventTarget());
|
|
|
|
EVENTQUEUE->removeHandler(IStream::getOutputShutdownEvent(),
|
|
|
|
getStream()->getEventTarget());
|
|
|
|
EVENTQUEUE->removeHandler(CEvent::kTimer, this);
|
|
|
|
|
|
|
|
// remove timer
|
|
|
|
removeHeartbeatTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::addHeartbeatTimer()
|
|
|
|
{
|
|
|
|
if (m_heartbeatAlarm > 0.0) {
|
|
|
|
m_heartbeatTimer = EVENTQUEUE->newOneShotTimer(m_heartbeatAlarm, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::removeHeartbeatTimer()
|
|
|
|
{
|
|
|
|
if (m_heartbeatTimer != NULL) {
|
|
|
|
EVENTQUEUE->deleteTimer(m_heartbeatTimer);
|
|
|
|
m_heartbeatTimer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::handleData(const CEvent&, void*)
|
|
|
|
{
|
|
|
|
// handle messages until there are no more. first read message code.
|
|
|
|
UInt8 code[4];
|
|
|
|
UInt32 n = getStream()->read(code, 4);
|
|
|
|
while (n != 0) {
|
|
|
|
// verify we got an entire code
|
|
|
|
if (n != 4) {
|
|
|
|
LOG((CLOG_ERR "incomplete message from \"%s\": %d bytes", getName().c_str(), n));
|
|
|
|
disconnect();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse message
|
|
|
|
LOG((CLOG_DEBUG2 "msg from \"%s\": %c%c%c%c", getName().c_str(), code[0], code[1], code[2], code[3]));
|
2004-02-14 14:04:36 +00:00
|
|
|
if (!(this->*m_parser)(code)) {
|
2004-02-01 21:09:22 +00:00
|
|
|
LOG((CLOG_ERR "invalid message from client \"%s\"", getName().c_str()));
|
|
|
|
disconnect();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// next message
|
|
|
|
n = getStream()->read(code, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// restart heartbeat timer
|
|
|
|
removeHeartbeatTimer();
|
|
|
|
addHeartbeatTimer();
|
|
|
|
}
|
|
|
|
|
2004-02-14 14:04:36 +00:00
|
|
|
bool
|
|
|
|
CClientProxy1_0::parseHandshakeMessage(const UInt8* code)
|
|
|
|
{
|
|
|
|
if (memcmp(code, kMsgCNoop, 4) == 0) {
|
|
|
|
// discard no-ops
|
|
|
|
LOG((CLOG_DEBUG2 "no-op from", getName().c_str()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (memcmp(code, kMsgDInfo, 4) == 0) {
|
|
|
|
// future messages get parsed by parseMessage
|
|
|
|
m_parser = &CClientProxy1_0::parseMessage;
|
|
|
|
if (recvInfo()) {
|
|
|
|
EVENTQUEUE->addEvent(CEvent(getReadyEvent(), getEventTarget()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-02-01 21:09:22 +00:00
|
|
|
bool
|
|
|
|
CClientProxy1_0::parseMessage(const UInt8* code)
|
|
|
|
{
|
|
|
|
if (memcmp(code, kMsgDInfo, 4) == 0) {
|
2004-02-14 14:04:36 +00:00
|
|
|
if (recvInfo()) {
|
|
|
|
EVENTQUEUE->addEvent(
|
|
|
|
CEvent(getShapeChangedEvent(), getEventTarget()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2004-02-01 21:09:22 +00:00
|
|
|
}
|
|
|
|
else if (memcmp(code, kMsgCNoop, 4) == 0) {
|
|
|
|
// discard no-ops
|
|
|
|
LOG((CLOG_DEBUG2 "no-op from", getName().c_str()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (memcmp(code, kMsgCClipboard, 4) == 0) {
|
|
|
|
return recvGrabClipboard();
|
|
|
|
}
|
|
|
|
else if (memcmp(code, kMsgDClipboard, 4) == 0) {
|
|
|
|
return recvClipboard();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::handleDisconnect(const CEvent&, void*)
|
|
|
|
{
|
2004-02-14 14:04:36 +00:00
|
|
|
LOG((CLOG_NOTE "client \"%s\" has disconnected", getName().c_str()));
|
2004-02-01 21:09:22 +00:00
|
|
|
disconnect();
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
2004-02-01 21:09:22 +00:00
|
|
|
void
|
|
|
|
CClientProxy1_0::handleWriteError(const CEvent&, void*)
|
|
|
|
{
|
2004-02-14 14:04:36 +00:00
|
|
|
LOG((CLOG_WARN "error writing to client \"%s\"", getName().c_str()));
|
2004-02-01 21:09:22 +00:00
|
|
|
disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::handleFlatline(const CEvent&, void*)
|
|
|
|
{
|
|
|
|
// didn't get a heartbeat fast enough. assume client is dead.
|
|
|
|
LOG((CLOG_NOTE "client \"%s\" is dead", getName().c_str()));
|
|
|
|
disconnect();
|
|
|
|
}
|
|
|
|
|
2004-02-14 14:04:36 +00:00
|
|
|
bool
|
|
|
|
CClientProxy1_0::getClipboard(ClipboardID id, IClipboard* clipboard) const
|
2002-07-09 21:22:31 +00:00
|
|
|
{
|
2004-02-14 14:04:36 +00:00
|
|
|
CClipboard::copy(clipboard, &m_clipboard[id].m_clipboard);
|
|
|
|
return true;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-14 14:04:36 +00:00
|
|
|
CClientProxy1_0::getShape(SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
|
2002-07-09 21:22:31 +00:00
|
|
|
{
|
2004-02-14 14:04:36 +00:00
|
|
|
x = m_info.m_x;
|
|
|
|
y = m_info.m_y;
|
|
|
|
w = m_info.m_w;
|
|
|
|
h = m_info.m_h;
|
|
|
|
}
|
2002-07-09 21:22:31 +00:00
|
|
|
|
2004-02-14 14:04:36 +00:00
|
|
|
void
|
|
|
|
CClientProxy1_0::getCursorPos(SInt32& x, SInt32& y) const
|
|
|
|
{
|
|
|
|
assert(0 && "shouldn't be called");
|
|
|
|
x = m_info.m_mx;
|
|
|
|
y = m_info.m_my;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::enter(SInt32 xAbs, SInt32 yAbs,
|
|
|
|
UInt32 seqNum, KeyModifierMask mask, bool)
|
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "send enter to \"%s\", %d,%d %d %04x", getName().c_str(), xAbs, yAbs, seqNum, mask));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgCEnter,
|
2002-07-09 21:22:31 +00:00
|
|
|
xAbs, yAbs, seqNum, mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CClientProxy1_0::leave()
|
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "send leave to \"%s\"", getName().c_str()));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgCLeave);
|
2002-07-09 21:22:31 +00:00
|
|
|
|
|
|
|
// we can never prevent the user from leaving
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::setClipboard(ClipboardID id, const CString& data)
|
|
|
|
{
|
|
|
|
// ignore if this clipboard is already clean
|
2004-02-14 14:04:36 +00:00
|
|
|
if (m_clipboard[id].m_dirty) {
|
2002-07-09 21:22:31 +00:00
|
|
|
// this clipboard is now clean
|
2004-02-14 14:04:36 +00:00
|
|
|
m_clipboard[id].m_dirty = false;
|
2002-07-09 21:22:31 +00:00
|
|
|
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "send clipboard %d to \"%s\" size=%d", id, getName().c_str(), data.size()));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgDClipboard, id, 0, &data);
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::grabClipboard(ClipboardID id)
|
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "send grab clipboard %d to \"%s\"", id, getName().c_str()));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgCClipboard, id, 0);
|
2002-07-09 21:22:31 +00:00
|
|
|
|
|
|
|
// this clipboard is now dirty
|
2004-02-14 14:04:36 +00:00
|
|
|
m_clipboard[id].m_dirty = true;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::setClipboardDirty(ClipboardID id, bool dirty)
|
|
|
|
{
|
2004-02-14 14:04:36 +00:00
|
|
|
m_clipboard[id].m_dirty = dirty;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-04-27 17:01:14 +00:00
|
|
|
CClientProxy1_0::keyDown(KeyID key, KeyModifierMask mask, KeyButton)
|
2002-07-09 21:22:31 +00:00
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "send key down to \"%s\" id=%d, mask=0x%04x", getName().c_str(), key, mask));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgDKeyDown1_0, key, mask);
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-04-27 17:01:14 +00:00
|
|
|
CClientProxy1_0::keyRepeat(KeyID key, KeyModifierMask mask,
|
|
|
|
SInt32 count, KeyButton)
|
2002-07-09 21:22:31 +00:00
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "send key repeat to \"%s\" id=%d, mask=0x%04x, count=%d", getName().c_str(), key, mask, count));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgDKeyRepeat1_0, key, mask, count);
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-04-27 17:01:14 +00:00
|
|
|
CClientProxy1_0::keyUp(KeyID key, KeyModifierMask mask, KeyButton)
|
2002-07-09 21:22:31 +00:00
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "send key up to \"%s\" id=%d, mask=0x%04x", getName().c_str(), key, mask));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgDKeyUp1_0, key, mask);
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::mouseDown(ButtonID button)
|
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "send mouse down to \"%s\" id=%d", getName().c_str(), button));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgDMouseDown, button);
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::mouseUp(ButtonID button)
|
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "send mouse up to \"%s\" id=%d", getName().c_str(), button));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgDMouseUp, button);
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::mouseMove(SInt32 xAbs, SInt32 yAbs)
|
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG2 "send mouse move to \"%s\" %d,%d", getName().c_str(), xAbs, yAbs));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgDMouseMove, xAbs, yAbs);
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::mouseWheel(SInt32 delta)
|
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG2 "send mouse wheel to \"%s\" %+d", getName().c_str(), delta));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgDMouseWheel, delta);
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-13 22:00:38 +00:00
|
|
|
CClientProxy1_0::screensaver(bool on)
|
2002-07-09 21:22:31 +00:00
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "send screen saver to \"%s\" on=%d", getName().c_str(), on ? 1 : 0));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgCScreenSaver, on ? 1 : 0);
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
2002-12-23 13:55:21 +00:00
|
|
|
void
|
|
|
|
CClientProxy1_0::resetOptions()
|
|
|
|
{
|
|
|
|
LOG((CLOG_DEBUG1 "send reset options to \"%s\"", getName().c_str()));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgCResetOptions);
|
2003-02-22 16:20:23 +00:00
|
|
|
|
|
|
|
// reset heart rate and death
|
2004-02-01 21:09:22 +00:00
|
|
|
m_heartbeatAlarm = kHeartRate * kHeartBeatsUntilDeath;
|
|
|
|
removeHeartbeatTimer();
|
|
|
|
addHeartbeatTimer();
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CClientProxy1_0::setOptions(const COptionsList& options)
|
|
|
|
{
|
|
|
|
LOG((CLOG_DEBUG1 "send set options to \"%s\" size=%d", getName().c_str(), options.size()));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgDSetOptions, &options);
|
2003-02-22 16:20:23 +00:00
|
|
|
|
|
|
|
// check options
|
|
|
|
for (UInt32 i = 0, n = options.size(); i < n; i += 2) {
|
|
|
|
if (options[i] == kOptionHeartbeat) {
|
2004-02-01 21:09:22 +00:00
|
|
|
double rate = 1.0e-3 * static_cast<double>(options[i + 1]);
|
|
|
|
if (rate <= 0.0) {
|
|
|
|
rate = -1.0;
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
2004-02-01 21:09:22 +00:00
|
|
|
m_heartbeatAlarm = rate * kHeartBeatsUntilDeath;
|
|
|
|
removeHeartbeatTimer();
|
|
|
|
addHeartbeatTimer();
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
|
2004-02-01 21:09:22 +00:00
|
|
|
bool
|
2004-02-14 14:04:36 +00:00
|
|
|
CClientProxy1_0::recvInfo()
|
2002-07-09 21:22:31 +00:00
|
|
|
{
|
2004-02-14 14:04:36 +00:00
|
|
|
// parse the message
|
|
|
|
SInt16 x, y, w, h, zoneSize, mx, my;
|
|
|
|
if (!CProtocolUtil::readf(getStream(), kMsgDInfo + 4,
|
|
|
|
&x, &y, &w, &h, &zoneSize, &mx, &my)) {
|
|
|
|
return false;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
2004-02-14 14:04:36 +00:00
|
|
|
LOG((CLOG_DEBUG "received client \"%s\" info shape=%d,%d %dx%d, zone=%d, pos=%d,%d", getName().c_str(), x, y, w, h, zoneSize, mx, my));
|
2002-07-09 21:22:31 +00:00
|
|
|
|
2004-02-14 14:04:36 +00:00
|
|
|
// validate
|
|
|
|
if (w <= 0 || h <= 0 || zoneSize < 0) {
|
|
|
|
return false;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
2004-02-14 14:04:36 +00:00
|
|
|
if (mx < x || my < y || mx >= x + w || my >= y + h) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// save
|
|
|
|
m_info.m_x = x;
|
|
|
|
m_info.m_y = y;
|
|
|
|
m_info.m_w = w;
|
|
|
|
m_info.m_h = h;
|
|
|
|
m_info.m_zoneSize = zoneSize;
|
|
|
|
m_info.m_mx = mx;
|
|
|
|
m_info.m_my = my;
|
2002-07-09 21:22:31 +00:00
|
|
|
|
|
|
|
// acknowledge receipt
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG1 "send info ack to \"%s\"", getName().c_str()));
|
2004-02-01 21:09:22 +00:00
|
|
|
CProtocolUtil::writef(getStream(), kMsgCInfoAck);
|
|
|
|
return true;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
2004-02-01 21:09:22 +00:00
|
|
|
bool
|
2002-07-09 21:22:31 +00:00
|
|
|
CClientProxy1_0::recvClipboard()
|
|
|
|
{
|
|
|
|
// parse message
|
|
|
|
ClipboardID id;
|
|
|
|
UInt32 seqNum;
|
|
|
|
CString data;
|
2004-02-01 21:09:22 +00:00
|
|
|
if (!CProtocolUtil::readf(getStream(),
|
|
|
|
kMsgDClipboard + 4, &id, &seqNum, &data)) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "received client \"%s\" clipboard %d seqnum=%d, size=%d", getName().c_str(), id, seqNum, data.size()));
|
2002-07-09 21:22:31 +00:00
|
|
|
|
|
|
|
// validate
|
|
|
|
if (id >= kClipboardEnd) {
|
2004-02-01 21:09:22 +00:00
|
|
|
return false;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
2004-02-14 14:04:36 +00:00
|
|
|
// save clipboard
|
|
|
|
m_clipboard[id].m_clipboard.unmarshall(data, 0);
|
|
|
|
m_clipboard[id].m_sequenceNumber = seqNum;
|
|
|
|
|
|
|
|
// notify
|
|
|
|
CClipboardInfo* info = new CClipboardInfo;
|
|
|
|
info->m_id = id;
|
|
|
|
info->m_sequenceNumber = seqNum;
|
|
|
|
EVENTQUEUE->addEvent(CEvent(getClipboardChangedEvent(),
|
|
|
|
getEventTarget(), info));
|
|
|
|
|
2004-02-01 21:09:22 +00:00
|
|
|
return true;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
2004-02-01 21:09:22 +00:00
|
|
|
bool
|
2002-07-09 21:22:31 +00:00
|
|
|
CClientProxy1_0::recvGrabClipboard()
|
|
|
|
{
|
|
|
|
// parse message
|
|
|
|
ClipboardID id;
|
|
|
|
UInt32 seqNum;
|
2004-02-01 21:09:22 +00:00
|
|
|
if (!CProtocolUtil::readf(getStream(), kMsgCClipboard + 4, &id, &seqNum)) {
|
|
|
|
return false;
|
|
|
|
}
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "received client \"%s\" grabbed clipboard %d seqnum=%d", getName().c_str(), id, seqNum));
|
2002-07-09 21:22:31 +00:00
|
|
|
|
|
|
|
// validate
|
|
|
|
if (id >= kClipboardEnd) {
|
2004-02-01 21:09:22 +00:00
|
|
|
return false;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
|
2004-02-14 14:04:36 +00:00
|
|
|
// notify
|
|
|
|
CClipboardInfo* info = new CClipboardInfo;
|
|
|
|
info->m_id = id;
|
|
|
|
info->m_sequenceNumber = seqNum;
|
|
|
|
EVENTQUEUE->addEvent(CEvent(getClipboardGrabbedEvent(),
|
|
|
|
getEventTarget(), info));
|
|
|
|
|
2004-02-01 21:09:22 +00:00
|
|
|
return true;
|
2002-07-09 21:22:31 +00:00
|
|
|
}
|
2004-02-14 14:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CClientProxy1_0::CClientClipboard
|
|
|
|
//
|
|
|
|
|
|
|
|
CClientProxy1_0::CClientClipboard::CClientClipboard() :
|
|
|
|
m_clipboard(),
|
|
|
|
m_sequenceNumber(0),
|
|
|
|
m_dirty(true)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|