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
|
|
|
#include "CServer.h"
|
2004-02-14 17:04:36 +03:00
|
|
|
#include "CClientProxy.h"
|
|
|
|
#include "CClientProxyUnknown.h"
|
2002-07-30 22:31:00 +04:00
|
|
|
#include "CPrimaryClient.h"
|
2004-02-14 17:04:36 +03:00
|
|
|
#include "IPlatformScreen.h"
|
2002-12-23 16:55:21 +03:00
|
|
|
#include "OptionTypes.h"
|
2001-10-06 18:13:28 +04:00
|
|
|
#include "ProtocolTypes.h"
|
2002-06-11 02:06:45 +04:00
|
|
|
#include "XScreen.h"
|
|
|
|
#include "XSynergy.h"
|
2002-06-17 16:02:26 +04:00
|
|
|
#include "IDataSocket.h"
|
2004-02-14 17:04:36 +03:00
|
|
|
#include "IListenSocket.h"
|
2002-06-11 02:06:45 +04:00
|
|
|
#include "XSocket.h"
|
2004-02-14 17:04:36 +03:00
|
|
|
#include "IEventQueue.h"
|
2002-06-11 02:06:45 +04:00
|
|
|
#include "CLog.h"
|
2004-02-14 17:04:36 +03:00
|
|
|
#include "TMethodEventJob.h"
|
2003-01-05 01:01:32 +03:00
|
|
|
#include "CArch.h"
|
2007-06-17 15:19:18 +04:00
|
|
|
#include <string.h>
|
2001-11-19 03:33:36 +03:00
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
//
|
|
|
|
// CServer
|
|
|
|
//
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
CEvent::Type CServer::s_errorEvent = CEvent::kUnknown;
|
|
|
|
CEvent::Type CServer::s_connectedEvent = CEvent::kUnknown;
|
|
|
|
CEvent::Type CServer::s_disconnectedEvent = CEvent::kUnknown;
|
|
|
|
CEvent::Type CServer::s_switchToScreen = CEvent::kUnknown;
|
|
|
|
CEvent::Type CServer::s_switchInDirection = CEvent::kUnknown;
|
|
|
|
CEvent::Type CServer::s_lockCursorToScreen = CEvent::kUnknown;
|
2004-02-14 17:04:36 +03:00
|
|
|
|
|
|
|
CServer::CServer(const CConfig& config, CPrimaryClient* primaryClient) :
|
|
|
|
m_primaryClient(primaryClient),
|
2004-02-28 15:19:49 +03:00
|
|
|
m_active(primaryClient),
|
2002-06-11 02:06:45 +04:00
|
|
|
m_seqNum(0),
|
2004-04-06 01:10:06 +04:00
|
|
|
m_xDelta(0),
|
|
|
|
m_yDelta(0),
|
|
|
|
m_xDelta2(0),
|
|
|
|
m_yDelta2(0),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_config(),
|
|
|
|
m_inputFilter(m_config.getInputFilter()),
|
2002-06-26 20:31:48 +04:00
|
|
|
m_activeSaver(NULL),
|
2003-02-23 22:29:08 +03:00
|
|
|
m_switchDir(kNoDirection),
|
|
|
|
m_switchScreen(NULL),
|
2003-02-23 00:53:25 +03:00
|
|
|
m_switchWaitDelay(0.0),
|
2004-02-14 17:04:36 +03:00
|
|
|
m_switchWaitTimer(NULL),
|
2003-02-23 22:29:08 +03:00
|
|
|
m_switchTwoTapDelay(0.0),
|
|
|
|
m_switchTwoTapEngaged(false),
|
2003-03-13 01:34:07 +03:00
|
|
|
m_switchTwoTapArmed(false),
|
2004-05-01 19:18:59 +04:00
|
|
|
m_switchTwoTapZone(3),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_relativeMoves(false),
|
|
|
|
m_lockedToScreen(false)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
// must have a primary client and it must have a canonical name
|
|
|
|
assert(m_primaryClient != NULL);
|
2007-06-17 15:19:18 +04:00
|
|
|
assert(config.isScreen(primaryClient->getName()));
|
2002-10-16 02:01:41 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
CString primaryName = getName(primaryClient);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// clear clipboards
|
|
|
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
|
|
|
CClipboardInfo& clipboard = m_clipboards[id];
|
|
|
|
clipboard.m_clipboardOwner = primaryName;
|
|
|
|
clipboard.m_clipboardSeqNum = m_seqNum;
|
|
|
|
if (clipboard.m_clipboard.open(0)) {
|
|
|
|
clipboard.m_clipboard.empty();
|
|
|
|
clipboard.m_clipboard.close();
|
|
|
|
}
|
|
|
|
clipboard.m_clipboardData = clipboard.m_clipboard.marshall();
|
2002-06-02 22:49:35 +04:00
|
|
|
}
|
2003-03-13 01:34:07 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// install event handlers
|
|
|
|
EVENTQUEUE->adoptHandler(CEvent::kTimer, this,
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleSwitchWaitTimeout));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyDownEvent(),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter,
|
2004-02-14 17:04:36 +03:00
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleKeyDownEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyUpEvent(),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter,
|
2004-02-14 17:04:36 +03:00
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleKeyUpEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyRepeatEvent(),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter,
|
2004-02-14 17:04:36 +03:00
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleKeyRepeatEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonDownEvent(),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter,
|
2004-02-14 17:04:36 +03:00
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleButtonDownEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonUpEvent(),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter,
|
2004-02-14 17:04:36 +03:00
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleButtonUpEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getMotionOnPrimaryEvent(),
|
|
|
|
m_primaryClient->getEventTarget(),
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleMotionPrimaryEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getMotionOnSecondaryEvent(),
|
|
|
|
m_primaryClient->getEventTarget(),
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleMotionSecondaryEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getWheelEvent(),
|
|
|
|
m_primaryClient->getEventTarget(),
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleWheelEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getScreensaverActivatedEvent(),
|
|
|
|
m_primaryClient->getEventTarget(),
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleScreensaverActivatedEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getScreensaverDeactivatedEvent(),
|
|
|
|
m_primaryClient->getEventTarget(),
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleScreensaverDeactivatedEvent));
|
2007-06-17 15:19:18 +04:00
|
|
|
EVENTQUEUE->adoptHandler(getSwitchToScreenEvent(),
|
|
|
|
m_inputFilter,
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleSwitchToScreenEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(getSwitchInDirectionEvent(),
|
|
|
|
m_inputFilter,
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleSwitchInDirectionEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(getLockCursorToScreenEvent(),
|
|
|
|
m_inputFilter,
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleLockCursorToScreenEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getFakeInputBeginEvent(),
|
|
|
|
m_inputFilter,
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleFakeInputBeginEvent));
|
|
|
|
EVENTQUEUE->adoptHandler(IPlatformScreen::getFakeInputEndEvent(),
|
|
|
|
m_inputFilter,
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleFakeInputEndEvent));
|
2001-10-14 18:37:41 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// add connection
|
|
|
|
addClient(m_primaryClient);
|
2002-10-18 01:37:31 +04:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// set initial configuration
|
|
|
|
setConfig(config);
|
2002-06-03 17:45:30 +04:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// enable primary client
|
2004-02-14 17:04:36 +03:00
|
|
|
m_primaryClient->enable();
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter->setPrimaryClient(m_primaryClient);
|
2002-10-18 01:37:31 +04:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
CServer::~CServer()
|
2002-07-14 02:00:38 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
// remove event handlers and timers
|
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyDownEvent(),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter);
|
2004-02-14 17:04:36 +03:00
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyUpEvent(),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter);
|
2004-02-14 17:04:36 +03:00
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getKeyRepeatEvent(),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter);
|
2004-02-14 17:04:36 +03:00
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getButtonDownEvent(),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter);
|
2004-02-14 17:04:36 +03:00
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getButtonUpEvent(),
|
2007-06-17 15:19:18 +04:00
|
|
|
m_inputFilter);
|
2004-02-14 17:04:36 +03:00
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getMotionOnPrimaryEvent(),
|
|
|
|
m_primaryClient->getEventTarget());
|
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getMotionOnSecondaryEvent(),
|
|
|
|
m_primaryClient->getEventTarget());
|
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getWheelEvent(),
|
|
|
|
m_primaryClient->getEventTarget());
|
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getScreensaverActivatedEvent(),
|
|
|
|
m_primaryClient->getEventTarget());
|
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getScreensaverDeactivatedEvent(),
|
|
|
|
m_primaryClient->getEventTarget());
|
2007-06-17 15:19:18 +04:00
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getFakeInputBeginEvent(),
|
|
|
|
m_inputFilter);
|
|
|
|
EVENTQUEUE->removeHandler(IPlatformScreen::getFakeInputEndEvent(),
|
|
|
|
m_inputFilter);
|
2004-02-14 17:04:36 +03:00
|
|
|
EVENTQUEUE->removeHandler(CEvent::kTimer, this);
|
|
|
|
stopSwitch();
|
|
|
|
|
|
|
|
// force immediate disconnection of secondary clients
|
|
|
|
disconnect();
|
|
|
|
for (COldClients::iterator index = m_oldClients.begin();
|
|
|
|
index != m_oldClients.begin(); ++index) {
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* client = index->first;
|
2004-02-14 17:04:36 +03:00
|
|
|
EVENTQUEUE->deleteTimer(index->second);
|
|
|
|
EVENTQUEUE->removeHandler(CEvent::kTimer, client);
|
|
|
|
EVENTQUEUE->removeHandler(CClientProxy::getDisconnectedEvent(), client);
|
|
|
|
delete client;
|
|
|
|
}
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// remove input filter
|
|
|
|
m_inputFilter->setPrimaryClient(NULL);
|
|
|
|
|
|
|
|
// disable and disconnect primary client
|
|
|
|
m_primaryClient->disable();
|
2004-02-14 17:04:36 +03:00
|
|
|
removeClient(m_primaryClient);
|
2002-07-14 02:00:38 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
bool
|
2002-06-17 17:31:21 +04:00
|
|
|
CServer::setConfig(const CConfig& config)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2002-07-10 01:22:31 +04:00
|
|
|
// refuse configuration if it doesn't include the primary screen
|
2004-02-28 15:19:49 +03:00
|
|
|
if (!config.isScreen(m_primaryClient->getName())) {
|
2004-02-14 17:04:36 +03:00
|
|
|
return false;
|
2002-06-09 03:24:40 +04:00
|
|
|
}
|
2002-06-01 14:52:02 +04:00
|
|
|
|
2002-07-10 01:22:31 +04:00
|
|
|
// close clients that are connected but being dropped from the
|
|
|
|
// configuration.
|
|
|
|
closeClients(config);
|
2002-06-21 19:18:01 +04:00
|
|
|
|
2002-06-09 03:24:40 +04:00
|
|
|
// cut over
|
|
|
|
m_config = config;
|
2004-02-14 17:04:36 +03:00
|
|
|
processOptions();
|
2003-02-22 19:20:23 +03:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// add ScrollLock as a hotkey to lock to the screen. this was a
|
|
|
|
// built-in feature in earlier releases and is now supported via
|
|
|
|
// the user configurable hotkey mechanism. if the user has already
|
|
|
|
// registered ScrollLock for something else then that will win but
|
|
|
|
// we will unfortunately generate a warning. if the user has
|
|
|
|
// configured a CLockCursorToScreenAction then we don't add
|
|
|
|
// ScrollLock as a hotkey.
|
|
|
|
if (!m_config.hasLockToScreenAction()) {
|
|
|
|
IPlatformScreen::CKeyInfo* key =
|
|
|
|
IPlatformScreen::CKeyInfo::alloc(kKeyScrollLock, 0, 0, 0);
|
|
|
|
CInputFilter::CRule rule(new CInputFilter::CKeystrokeCondition(key));
|
|
|
|
rule.adoptAction(new CInputFilter::CLockCursorToScreenAction, true);
|
|
|
|
m_inputFilter->addFilterRule(rule);
|
|
|
|
}
|
|
|
|
|
2002-06-09 03:24:40 +04:00
|
|
|
// tell primary screen about reconfiguration
|
2004-02-28 15:19:49 +03:00
|
|
|
m_primaryClient->reconfigure(getActivePrimarySides());
|
2002-06-09 03:24:40 +04:00
|
|
|
|
2003-02-22 19:20:23 +03:00
|
|
|
// tell all (connected) clients about current options
|
|
|
|
for (CClientList::const_iterator index = m_clients.begin();
|
|
|
|
index != m_clients.end(); ++index) {
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* client = index->second;
|
2003-02-22 19:20:23 +03:00
|
|
|
sendOptions(client);
|
|
|
|
}
|
2002-12-23 16:55:21 +03:00
|
|
|
|
2002-05-31 22:09:43 +04:00
|
|
|
return true;
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-07-30 22:31:00 +04:00
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::adoptClient(CBaseClientProxy* client)
|
2002-07-30 22:31:00 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
assert(client != NULL);
|
2002-07-30 22:31:00 +04:00
|
|
|
|
2004-02-15 20:32:11 +03:00
|
|
|
// watch for client disconnection
|
|
|
|
EVENTQUEUE->adoptHandler(CClientProxy::getDisconnectedEvent(), client,
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleClientDisconnected, client));
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// name must be in our configuration
|
|
|
|
if (!m_config.isScreen(client->getName())) {
|
|
|
|
LOG((CLOG_WARN "a client with name \"%s\" is not in the map", client->getName().c_str()));
|
|
|
|
closeClient(client, kMsgEUnknown);
|
|
|
|
return;
|
|
|
|
}
|
2002-07-30 22:31:00 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// add client to client list
|
|
|
|
if (!addClient(client)) {
|
|
|
|
// can only have one screen with a given name at any given time
|
|
|
|
LOG((CLOG_WARN "a client with name \"%s\" is already connected", getName(client).c_str()));
|
|
|
|
closeClient(client, kMsgEBusy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOG((CLOG_NOTE "client \"%s\" has connected", getName(client).c_str()));
|
2002-07-30 22:31:00 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// send configuration options to client
|
|
|
|
sendOptions(client);
|
|
|
|
|
|
|
|
// activate screen saver on new client if active on the primary screen
|
|
|
|
if (m_activeSaver != NULL) {
|
|
|
|
client->screensaver(true);
|
|
|
|
}
|
2007-06-17 15:19:18 +04:00
|
|
|
|
|
|
|
// send notification
|
|
|
|
CServer::CScreenConnectedInfo* info =
|
|
|
|
CServer::CScreenConnectedInfo::alloc(getName(client));
|
|
|
|
EVENTQUEUE->addEvent(CEvent(CServer::getConnectedEvent(),
|
|
|
|
m_primaryClient->getEventTarget(), info));
|
2003-03-13 01:34:07 +03:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
void
|
|
|
|
CServer::disconnect()
|
2002-05-30 20:13:16 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
// close all secondary clients
|
|
|
|
if (m_clients.size() > 1 || !m_oldClients.empty()) {
|
|
|
|
CConfig emptyConfig;
|
|
|
|
closeClients(emptyConfig);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
EVENTQUEUE->addEvent(CEvent(getDisconnectedEvent(), this));
|
|
|
|
}
|
2002-05-30 20:13:16 +04:00
|
|
|
}
|
|
|
|
|
2003-03-13 01:34:07 +03:00
|
|
|
UInt32
|
|
|
|
CServer::getNumClients() const
|
|
|
|
{
|
|
|
|
return m_clients.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::getClients(std::vector<CString>& list) const
|
|
|
|
{
|
|
|
|
list.clear();
|
|
|
|
for (CClientList::const_iterator index = m_clients.begin();
|
|
|
|
index != m_clients.end(); ++index) {
|
|
|
|
list.push_back(index->first);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
CEvent::Type
|
|
|
|
CServer::getErrorEvent()
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
return CEvent::registerTypeOnce(s_errorEvent,
|
|
|
|
"CServer::error");
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
CEvent::Type
|
|
|
|
CServer::getConnectedEvent()
|
|
|
|
{
|
|
|
|
return CEvent::registerTypeOnce(s_connectedEvent,
|
|
|
|
"CServer::connected");
|
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
CEvent::Type
|
|
|
|
CServer::getDisconnectedEvent()
|
2004-02-02 00:09:22 +03:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
return CEvent::registerTypeOnce(s_disconnectedEvent,
|
|
|
|
"CServer::disconnected");
|
2004-02-02 00:09:22 +03:00
|
|
|
}
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
CEvent::Type
|
|
|
|
CServer::getSwitchToScreenEvent()
|
2003-03-13 01:34:07 +03:00
|
|
|
{
|
2007-06-17 15:19:18 +04:00
|
|
|
return CEvent::registerTypeOnce(s_switchToScreen,
|
|
|
|
"CServer::switchToScreen");
|
|
|
|
}
|
|
|
|
|
|
|
|
CEvent::Type
|
|
|
|
CServer::getSwitchInDirectionEvent()
|
|
|
|
{
|
|
|
|
return CEvent::registerTypeOnce(s_switchInDirection,
|
|
|
|
"CServer::switchInDirection");
|
|
|
|
}
|
|
|
|
|
|
|
|
CEvent::Type
|
|
|
|
CServer::getLockCursorToScreenEvent()
|
|
|
|
{
|
|
|
|
return CEvent::registerTypeOnce(s_lockCursorToScreen,
|
|
|
|
"CServer::lockCursorToScreen");
|
2003-03-13 01:34:07 +03:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
CString
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::getName(const CBaseClientProxy* client) const
|
2003-03-13 01:34:07 +03:00
|
|
|
{
|
2004-02-15 20:32:11 +03:00
|
|
|
CString name = m_config.getCanonicalName(client->getName());
|
|
|
|
if (name.empty()) {
|
|
|
|
name = client->getName();
|
|
|
|
}
|
|
|
|
return name;
|
2003-03-13 01:34:07 +03:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
UInt32
|
|
|
|
CServer::getActivePrimarySides() const
|
2001-11-19 03:33:36 +03:00
|
|
|
{
|
|
|
|
UInt32 sides = 0;
|
2004-03-26 23:59:26 +03:00
|
|
|
if (!isLockedToScreenServer()) {
|
2007-06-17 15:19:18 +04:00
|
|
|
if (hasAnyNeighbor(m_primaryClient, kLeft)) {
|
2004-03-06 19:20:08 +03:00
|
|
|
sides |= kLeftMask;
|
|
|
|
}
|
2007-06-17 15:19:18 +04:00
|
|
|
if (hasAnyNeighbor(m_primaryClient, kRight)) {
|
2004-03-06 19:20:08 +03:00
|
|
|
sides |= kRightMask;
|
|
|
|
}
|
2007-06-17 15:19:18 +04:00
|
|
|
if (hasAnyNeighbor(m_primaryClient, kTop)) {
|
2004-03-06 19:20:08 +03:00
|
|
|
sides |= kTopMask;
|
|
|
|
}
|
2007-06-17 15:19:18 +04:00
|
|
|
if (hasAnyNeighbor(m_primaryClient, kBottom)) {
|
2004-03-06 19:20:08 +03:00
|
|
|
sides |= kBottomMask;
|
|
|
|
}
|
2002-05-31 22:09:43 +04:00
|
|
|
}
|
2001-11-19 03:33:36 +03:00
|
|
|
return sides;
|
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
bool
|
2004-03-26 23:59:26 +03:00
|
|
|
CServer::isLockedToScreenServer() const
|
2002-07-16 20:52:26 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
// locked if scroll-lock is toggled on
|
2007-06-17 15:19:18 +04:00
|
|
|
return m_lockedToScreen;
|
2004-03-26 23:59:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CServer::isLockedToScreen() const
|
|
|
|
{
|
|
|
|
// locked if we say we're locked
|
|
|
|
if (isLockedToScreenServer()) {
|
2007-06-17 15:19:18 +04:00
|
|
|
LOG((CLOG_DEBUG "locked to screen"));
|
2004-03-26 23:59:26 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// locked if primary says we're locked
|
|
|
|
if (m_primaryClient->isLockedToScreen()) {
|
|
|
|
return true;
|
|
|
|
}
|
2002-07-16 20:52:26 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// not locked
|
|
|
|
return false;
|
2002-07-16 20:52:26 +04:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
SInt32
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::getJumpZoneSize(CBaseClientProxy* client) const
|
2002-06-01 14:52:02 +04:00
|
|
|
{
|
2002-07-10 01:22:31 +04:00
|
|
|
if (client == m_primaryClient) {
|
2004-02-14 17:04:36 +03:00
|
|
|
return m_primaryClient->getJumpZoneSize();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
2002-05-24 21:54:28 +04:00
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::switchScreen(CBaseClientProxy* dst,
|
|
|
|
SInt32 x, SInt32 y, bool forScreensaver)
|
2001-11-25 21:32:41 +03:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
assert(dst != NULL);
|
|
|
|
#ifndef NDEBUG
|
|
|
|
{
|
|
|
|
SInt32 dx, dy, dw, dh;
|
|
|
|
dst->getShape(dx, dy, dw, dh);
|
|
|
|
assert(x >= dx && y >= dy && x < dx + dw && y < dy + dh);
|
2001-11-25 21:32:41 +03:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
#endif
|
|
|
|
assert(m_active != NULL);
|
2001-11-25 21:32:41 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_INFO "switch from \"%s\" to \"%s\" at %d,%d", getName(m_active).c_str(), getName(dst).c_str(), x, y));
|
2001-11-25 21:32:41 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// stop waiting to switch
|
|
|
|
stopSwitch();
|
2001-11-25 21:32:41 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// record new position
|
2004-04-06 01:10:06 +04:00
|
|
|
m_x = x;
|
|
|
|
m_y = y;
|
|
|
|
m_xDelta = 0;
|
|
|
|
m_yDelta = 0;
|
|
|
|
m_xDelta2 = 0;
|
|
|
|
m_yDelta2 = 0;
|
2001-11-25 21:32:41 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// wrapping means leaving the active screen and entering it again.
|
|
|
|
// since that's a waste of time we skip that and just warp the
|
|
|
|
// mouse.
|
|
|
|
if (m_active != dst) {
|
|
|
|
// leave active screen
|
|
|
|
if (!m_active->leave()) {
|
|
|
|
// cannot leave screen
|
|
|
|
LOG((CLOG_WARN "can't leave screen"));
|
|
|
|
return;
|
2001-11-25 21:32:41 +03:00
|
|
|
}
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// update the primary client's clipboards if we're leaving the
|
|
|
|
// primary screen.
|
|
|
|
if (m_active == m_primaryClient) {
|
|
|
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
|
|
|
CClipboardInfo& clipboard = m_clipboards[id];
|
|
|
|
if (clipboard.m_clipboardOwner == getName(m_primaryClient)) {
|
|
|
|
onClipboardChanged(m_primaryClient,
|
|
|
|
id, clipboard.m_clipboardSeqNum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-11-25 21:32:41 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// cut over
|
|
|
|
m_active = dst;
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// increment enter sequence number
|
|
|
|
++m_seqNum;
|
2001-11-25 21:32:41 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// enter new screen
|
|
|
|
m_active->enter(x, y, m_seqNum,
|
|
|
|
m_primaryClient->getToggleMask(),
|
|
|
|
forScreensaver);
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// send the clipboard data to new active screen
|
|
|
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
2004-02-15 20:32:11 +03:00
|
|
|
m_active->setClipboard(id, &m_clipboards[id].m_clipboard);
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
2001-11-25 21:32:41 +03:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
else {
|
|
|
|
m_active->mouseMove(x, y);
|
2002-04-29 17:31:44 +04:00
|
|
|
}
|
2001-11-25 21:32:41 +03:00
|
|
|
}
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
void
|
|
|
|
CServer::jumpToScreen(CBaseClientProxy* newScreen)
|
|
|
|
{
|
|
|
|
assert(newScreen != NULL);
|
|
|
|
|
|
|
|
// record the current cursor position on the active screen
|
|
|
|
m_active->setJumpCursorPos(m_x, m_y);
|
|
|
|
|
|
|
|
// get the last cursor position on the target screen
|
|
|
|
SInt32 x, y;
|
|
|
|
newScreen->getJumpCursorPos(x, y);
|
|
|
|
|
|
|
|
switchScreen(newScreen, x, y, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
CServer::mapToFraction(CBaseClientProxy* client,
|
|
|
|
EDirection dir, SInt32 x, SInt32 y) const
|
|
|
|
{
|
|
|
|
SInt32 sx, sy, sw, sh;
|
|
|
|
client->getShape(sx, sy, sw, sh);
|
|
|
|
switch (dir) {
|
|
|
|
case kLeft:
|
|
|
|
case kRight:
|
|
|
|
return static_cast<float>(y - sy + 0.5f) / static_cast<float>(sh);
|
|
|
|
|
|
|
|
case kTop:
|
|
|
|
case kBottom:
|
|
|
|
return static_cast<float>(x - sx + 0.5f) / static_cast<float>(sw);
|
|
|
|
|
|
|
|
case kNoDirection:
|
|
|
|
assert(0 && "bad direction");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::mapToPixel(CBaseClientProxy* client,
|
|
|
|
EDirection dir, float f, SInt32& x, SInt32& y) const
|
|
|
|
{
|
|
|
|
SInt32 sx, sy, sw, sh;
|
|
|
|
client->getShape(sx, sy, sw, sh);
|
|
|
|
switch (dir) {
|
|
|
|
case kLeft:
|
|
|
|
case kRight:
|
|
|
|
y = static_cast<SInt32>(f * sh) + sy;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kTop:
|
|
|
|
case kBottom:
|
|
|
|
x = static_cast<SInt32>(f * sw) + sx;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kNoDirection:
|
|
|
|
assert(0 && "bad direction");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CServer::hasAnyNeighbor(CBaseClientProxy* client, EDirection dir) const
|
|
|
|
{
|
|
|
|
assert(client != NULL);
|
|
|
|
|
|
|
|
return m_config.hasNeighbor(getName(client), dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
CBaseClientProxy*
|
|
|
|
CServer::getNeighbor(CBaseClientProxy* src,
|
|
|
|
EDirection dir, SInt32& x, SInt32& y) const
|
2002-07-14 02:00:38 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
// note -- must be locked on entry
|
2002-12-23 16:55:21 +03:00
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
assert(src != NULL);
|
|
|
|
|
2003-01-17 00:28:15 +03:00
|
|
|
// get source screen name
|
2004-02-14 17:04:36 +03:00
|
|
|
CString srcName = getName(src);
|
2001-10-06 18:13:28 +04:00
|
|
|
assert(!srcName.empty());
|
2002-10-16 01:29:44 +04:00
|
|
|
LOG((CLOG_DEBUG2 "find neighbor on %s of \"%s\"", CConfig::dirName(dir), srcName.c_str()));
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// convert position to fraction
|
|
|
|
float t = mapToFraction(src, dir, x, y);
|
2003-01-17 00:28:15 +03:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// search for the closest neighbor that exists in direction dir
|
|
|
|
float tTmp;
|
2003-01-17 00:28:15 +03:00
|
|
|
for (;;) {
|
2007-06-17 15:19:18 +04:00
|
|
|
CString dstName(m_config.getNeighbor(srcName, dir, t, &tTmp));
|
|
|
|
|
2003-01-17 00:28:15 +03:00
|
|
|
// if nothing in that direction then return NULL. if the
|
|
|
|
// destination is the source then we can make no more
|
|
|
|
// progress in this direction. since we haven't found a
|
|
|
|
// connected neighbor we return NULL.
|
2007-06-17 15:19:18 +04:00
|
|
|
if (dstName.empty()) {
|
2002-10-16 01:29:44 +04:00
|
|
|
LOG((CLOG_DEBUG2 "no neighbor on %s of \"%s\"", CConfig::dirName(dir), srcName.c_str()));
|
2001-10-06 18:13:28 +04:00
|
|
|
return NULL;
|
2001-10-14 18:37:41 +04:00
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-06-01 14:52:02 +04:00
|
|
|
// look up neighbor cell. if the screen is connected and
|
2003-01-17 00:28:15 +03:00
|
|
|
// ready then we can stop.
|
2002-07-10 01:22:31 +04:00
|
|
|
CClientList::const_iterator index = m_clients.find(dstName);
|
|
|
|
if (index != m_clients.end()) {
|
2007-06-17 15:19:18 +04:00
|
|
|
LOG((CLOG_DEBUG2 "\"%s\" is on %s of \"%s\" at %f", dstName.c_str(), CConfig::dirName(dir), srcName.c_str(), t));
|
|
|
|
mapToPixel(index->second, dir, tTmp, x, y);
|
2001-10-06 18:13:28 +04:00
|
|
|
return index->second;
|
|
|
|
}
|
|
|
|
|
2003-01-17 00:28:15 +03:00
|
|
|
// skip over unconnected screen
|
2002-10-16 01:29:44 +04:00
|
|
|
LOG((CLOG_DEBUG2 "ignored \"%s\" on %s of \"%s\"", dstName.c_str(), CConfig::dirName(dir), srcName.c_str()));
|
2001-10-06 18:13:28 +04:00
|
|
|
srcName = dstName;
|
2003-01-17 00:28:15 +03:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// use position on skipped screen
|
|
|
|
t = tTmp;
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy*
|
|
|
|
CServer::mapToNeighbor(CBaseClientProxy* src,
|
2002-07-15 19:01:36 +04:00
|
|
|
EDirection srcSide, SInt32& x, SInt32& y) const
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2002-12-23 16:55:21 +03:00
|
|
|
// note -- must be locked on entry
|
|
|
|
|
2001-10-06 18:13:28 +04:00
|
|
|
assert(src != NULL);
|
|
|
|
|
|
|
|
// get the first neighbor
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* dst = getNeighbor(src, srcSide, x, y);
|
2002-06-11 22:31:06 +04:00
|
|
|
if (dst == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// get the source screen's size
|
2002-07-10 01:22:31 +04:00
|
|
|
SInt32 dx, dy, dw, dh;
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* lastGoodScreen = src;
|
2002-07-10 01:22:31 +04:00
|
|
|
lastGoodScreen->getShape(dx, dy, dw, dh);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2002-06-19 21:03:29 +04:00
|
|
|
// find destination screen, adjusting x or y (but not both). the
|
|
|
|
// searches are done in a sort of canonical screen space where
|
|
|
|
// the upper-left corner is 0,0 for each screen. we adjust from
|
|
|
|
// actual to canonical position on entry to and from canonical to
|
|
|
|
// actual on exit from the search.
|
2001-10-06 18:13:28 +04:00
|
|
|
switch (srcSide) {
|
2002-07-15 19:01:36 +04:00
|
|
|
case kLeft:
|
2002-07-10 01:22:31 +04:00
|
|
|
x -= dx;
|
2003-01-17 00:28:15 +03:00
|
|
|
while (dst != NULL) {
|
2001-10-06 18:13:28 +04:00
|
|
|
lastGoodScreen = dst;
|
2002-07-10 01:22:31 +04:00
|
|
|
lastGoodScreen->getShape(dx, dy, dw, dh);
|
|
|
|
x += dw;
|
2001-10-06 18:13:28 +04:00
|
|
|
if (x >= 0) {
|
|
|
|
break;
|
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_DEBUG2 "skipping over screen %s", getName(dst).c_str()));
|
2007-06-17 15:19:18 +04:00
|
|
|
dst = getNeighbor(lastGoodScreen, srcSide, x, y);
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
2002-06-19 21:03:29 +04:00
|
|
|
assert(lastGoodScreen != NULL);
|
2002-07-10 01:22:31 +04:00
|
|
|
x += dx;
|
2001-10-06 18:13:28 +04:00
|
|
|
break;
|
|
|
|
|
2002-07-15 19:01:36 +04:00
|
|
|
case kRight:
|
2002-07-10 01:22:31 +04:00
|
|
|
x -= dx;
|
2001-10-06 18:13:28 +04:00
|
|
|
while (dst != NULL) {
|
2002-07-10 01:22:31 +04:00
|
|
|
x -= dw;
|
2001-10-06 18:13:28 +04:00
|
|
|
lastGoodScreen = dst;
|
2002-07-10 01:22:31 +04:00
|
|
|
lastGoodScreen->getShape(dx, dy, dw, dh);
|
|
|
|
if (x < dw) {
|
2001-10-06 18:13:28 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_DEBUG2 "skipping over screen %s", getName(dst).c_str()));
|
2007-06-17 15:19:18 +04:00
|
|
|
dst = getNeighbor(lastGoodScreen, srcSide, x, y);
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
2002-06-19 21:03:29 +04:00
|
|
|
assert(lastGoodScreen != NULL);
|
2002-07-10 01:22:31 +04:00
|
|
|
x += dx;
|
2001-10-06 18:13:28 +04:00
|
|
|
break;
|
|
|
|
|
2002-07-15 19:01:36 +04:00
|
|
|
case kTop:
|
2002-07-10 01:22:31 +04:00
|
|
|
y -= dy;
|
2001-10-06 18:13:28 +04:00
|
|
|
while (dst != NULL) {
|
|
|
|
lastGoodScreen = dst;
|
2002-07-10 01:22:31 +04:00
|
|
|
lastGoodScreen->getShape(dx, dy, dw, dh);
|
|
|
|
y += dh;
|
2001-10-06 18:13:28 +04:00
|
|
|
if (y >= 0) {
|
|
|
|
break;
|
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_DEBUG2 "skipping over screen %s", getName(dst).c_str()));
|
2007-06-17 15:19:18 +04:00
|
|
|
dst = getNeighbor(lastGoodScreen, srcSide, x, y);
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
2002-06-19 21:03:29 +04:00
|
|
|
assert(lastGoodScreen != NULL);
|
2002-07-10 01:22:31 +04:00
|
|
|
y += dy;
|
2001-10-06 18:13:28 +04:00
|
|
|
break;
|
|
|
|
|
2002-07-15 19:01:36 +04:00
|
|
|
case kBottom:
|
2002-07-10 01:22:31 +04:00
|
|
|
y -= dy;
|
2001-10-06 18:13:28 +04:00
|
|
|
while (dst != NULL) {
|
2002-07-10 01:22:31 +04:00
|
|
|
y -= dh;
|
2001-10-06 18:13:28 +04:00
|
|
|
lastGoodScreen = dst;
|
2002-07-10 01:22:31 +04:00
|
|
|
lastGoodScreen->getShape(dx, dy, dw, dh);
|
2007-06-17 15:19:18 +04:00
|
|
|
if (y < dh) {
|
2001-10-06 18:13:28 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_DEBUG2 "skipping over screen %s", getName(dst).c_str()));
|
2007-06-17 15:19:18 +04:00
|
|
|
dst = getNeighbor(lastGoodScreen, srcSide, x, y);
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
2002-06-19 21:03:29 +04:00
|
|
|
assert(lastGoodScreen != NULL);
|
2002-07-10 01:22:31 +04:00
|
|
|
y += dy;
|
2001-10-06 18:13:28 +04:00
|
|
|
break;
|
2004-02-28 15:19:49 +03:00
|
|
|
|
|
|
|
case kNoDirection:
|
|
|
|
assert(0 && "bad direction");
|
|
|
|
return NULL;
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
2001-10-24 01:13:08 +04:00
|
|
|
|
2002-06-19 21:03:29 +04:00
|
|
|
// save destination screen
|
|
|
|
assert(lastGoodScreen != NULL);
|
|
|
|
dst = lastGoodScreen;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
|
|
|
// if entering primary screen then be sure to move in far enough
|
|
|
|
// to avoid the jump zone. if entering a side that doesn't have
|
|
|
|
// a neighbor (i.e. an asymmetrical side) then we don't need to
|
|
|
|
// move inwards because that side can't provoke a jump.
|
2007-06-17 15:19:18 +04:00
|
|
|
avoidJumpZone(dst, srcSide, x, y);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
return dst;
|
|
|
|
}
|
2004-02-28 15:19:49 +03:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
void
|
|
|
|
CServer::avoidJumpZone(CBaseClientProxy* dst,
|
|
|
|
EDirection dir, SInt32& x, SInt32& y) const
|
|
|
|
{
|
|
|
|
// we only need to avoid jump zones on the primary screen
|
|
|
|
if (dst != m_primaryClient) {
|
|
|
|
return;
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
const CString dstName(getName(dst));
|
|
|
|
SInt32 dx, dy, dw, dh;
|
|
|
|
dst->getShape(dx, dy, dw, dh);
|
|
|
|
float t = mapToFraction(dst, dir, x, y);
|
|
|
|
SInt32 z = getJumpZoneSize(dst);
|
|
|
|
|
|
|
|
// move in far enough to avoid the jump zone. if entering a side
|
|
|
|
// that doesn't have a neighbor (i.e. an asymmetrical side) then we
|
|
|
|
// don't need to move inwards because that side can't provoke a jump.
|
|
|
|
switch (dir) {
|
2002-07-15 19:01:36 +04:00
|
|
|
case kLeft:
|
2007-06-17 15:19:18 +04:00
|
|
|
if (!m_config.getNeighbor(dstName, kRight, t, NULL).empty() &&
|
|
|
|
x > dx + dw - 1 - z)
|
|
|
|
x = dx + dw - 1 - z;
|
|
|
|
break;
|
|
|
|
|
2002-07-15 19:01:36 +04:00
|
|
|
case kRight:
|
2007-06-17 15:19:18 +04:00
|
|
|
if (!m_config.getNeighbor(dstName, kLeft, t, NULL).empty() &&
|
|
|
|
x < dx + z)
|
|
|
|
x = dx + z;
|
2001-10-06 18:13:28 +04:00
|
|
|
break;
|
|
|
|
|
2002-07-15 19:01:36 +04:00
|
|
|
case kTop:
|
2007-06-17 15:19:18 +04:00
|
|
|
if (!m_config.getNeighbor(dstName, kBottom, t, NULL).empty() &&
|
|
|
|
y > dy + dh - 1 - z)
|
|
|
|
y = dy + dh - 1 - z;
|
|
|
|
break;
|
|
|
|
|
2002-07-15 19:01:36 +04:00
|
|
|
case kBottom:
|
2007-06-17 15:19:18 +04:00
|
|
|
if (!m_config.getNeighbor(dstName, kTop, t, NULL).empty() &&
|
|
|
|
y < dy + z)
|
|
|
|
y = dy + z;
|
2001-10-06 18:13:28 +04:00
|
|
|
break;
|
2004-02-28 15:19:49 +03:00
|
|
|
|
|
|
|
case kNoDirection:
|
|
|
|
assert(0 && "bad direction");
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-23 22:29:08 +03:00
|
|
|
bool
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::isSwitchOkay(CBaseClientProxy* newScreen,
|
|
|
|
EDirection dir, SInt32 x, SInt32 y,
|
|
|
|
SInt32 xActive, SInt32 yActive)
|
2003-02-23 22:29:08 +03:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_DEBUG1 "try to leave \"%s\" on %s", getName(m_active).c_str(), CConfig::dirName(dir)));
|
2003-02-23 22:29:08 +03:00
|
|
|
|
|
|
|
// is there a neighbor?
|
|
|
|
if (newScreen == NULL) {
|
|
|
|
// there's no neighbor. we don't want to switch and we don't
|
|
|
|
// want to try to switch later.
|
|
|
|
LOG((CLOG_DEBUG1 "no neighbor %s", CConfig::dirName(dir)));
|
2004-02-14 17:04:36 +03:00
|
|
|
stopSwitch();
|
2003-02-23 22:29:08 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// should we switch or not?
|
|
|
|
bool preventSwitch = false;
|
|
|
|
bool allowSwitch = false;
|
|
|
|
|
|
|
|
// note if the switch direction has changed. save the new
|
|
|
|
// direction and screen if so.
|
|
|
|
bool isNewDirection = (dir != m_switchDir);
|
|
|
|
if (isNewDirection || m_switchScreen == NULL) {
|
|
|
|
m_switchDir = dir;
|
|
|
|
m_switchScreen = newScreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
// is this a double tap and do we care?
|
|
|
|
if (!allowSwitch && m_switchTwoTapDelay > 0.0) {
|
2004-02-14 17:04:36 +03:00
|
|
|
if (isNewDirection ||
|
|
|
|
!isSwitchTwoTapStarted() || !shouldSwitchTwoTap()) {
|
|
|
|
// tapping a different or new edge or second tap not
|
|
|
|
// fast enough. prepare for second tap.
|
|
|
|
preventSwitch = true;
|
|
|
|
startSwitchTwoTap();
|
2003-02-23 22:29:08 +03:00
|
|
|
}
|
|
|
|
else {
|
2004-02-14 17:04:36 +03:00
|
|
|
// got second tap
|
|
|
|
allowSwitch = true;
|
2003-02-23 22:29:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if waiting before a switch then prepare to switch later
|
|
|
|
if (!allowSwitch && m_switchWaitDelay > 0.0) {
|
2004-02-14 17:04:36 +03:00
|
|
|
if (isNewDirection || !isSwitchWaitStarted()) {
|
|
|
|
startSwitchWait(x, y);
|
2003-02-23 22:29:08 +03:00
|
|
|
}
|
|
|
|
preventSwitch = true;
|
|
|
|
}
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// are we in a locked corner? first check if screen has the option set
|
|
|
|
// and, if not, check the global options.
|
|
|
|
const CConfig::CScreenOptions* options =
|
|
|
|
m_config.getOptions(getName(m_active));
|
|
|
|
if (options == NULL || options->count(kOptionScreenSwitchCorners) == 0) {
|
|
|
|
options = m_config.getOptions("");
|
|
|
|
}
|
|
|
|
if (options != NULL && options->count(kOptionScreenSwitchCorners) > 0) {
|
|
|
|
// get corner mask and size
|
|
|
|
CConfig::CScreenOptions::const_iterator i =
|
|
|
|
options->find(kOptionScreenSwitchCorners);
|
|
|
|
UInt32 corners = static_cast<UInt32>(i->second);
|
|
|
|
i = options->find(kOptionScreenSwitchCornerSize);
|
|
|
|
SInt32 size = 0;
|
|
|
|
if (i != options->end()) {
|
|
|
|
size = i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if we're in a locked corner
|
|
|
|
if ((getCorner(m_active, xActive, yActive, size) & corners) != 0) {
|
|
|
|
// yep, no switching
|
|
|
|
LOG((CLOG_DEBUG1 "locked in corner"));
|
|
|
|
preventSwitch = true;
|
|
|
|
stopSwitch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// ignore if mouse is locked to screen and don't try to switch later
|
|
|
|
if (!preventSwitch && isLockedToScreen()) {
|
2003-02-23 22:29:08 +03:00
|
|
|
LOG((CLOG_DEBUG1 "locked to screen"));
|
|
|
|
preventSwitch = true;
|
2004-02-14 17:04:36 +03:00
|
|
|
stopSwitch();
|
|
|
|
}
|
|
|
|
|
|
|
|
return !preventSwitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::noSwitch(SInt32 x, SInt32 y)
|
|
|
|
{
|
|
|
|
armSwitchTwoTap(x, y);
|
|
|
|
stopSwitchWait();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::stopSwitch()
|
|
|
|
{
|
|
|
|
if (m_switchScreen != NULL) {
|
|
|
|
m_switchScreen = NULL;
|
|
|
|
m_switchDir = kNoDirection;
|
|
|
|
stopSwitchTwoTap();
|
|
|
|
stopSwitchWait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::startSwitchTwoTap()
|
|
|
|
{
|
|
|
|
m_switchTwoTapEngaged = true;
|
|
|
|
m_switchTwoTapArmed = false;
|
|
|
|
m_switchTwoTapTimer.reset();
|
|
|
|
LOG((CLOG_DEBUG1 "waiting for second tap"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::armSwitchTwoTap(SInt32 x, SInt32 y)
|
|
|
|
{
|
|
|
|
if (m_switchTwoTapEngaged) {
|
|
|
|
if (m_switchTwoTapTimer.getTime() > m_switchTwoTapDelay) {
|
|
|
|
// second tap took too long. disengage.
|
|
|
|
stopSwitchTwoTap();
|
|
|
|
}
|
|
|
|
else if (!m_switchTwoTapArmed) {
|
|
|
|
// still time for a double tap. see if we left the tap
|
|
|
|
// zone and, if so, arm the two tap.
|
|
|
|
SInt32 ax, ay, aw, ah;
|
|
|
|
m_active->getShape(ax, ay, aw, ah);
|
|
|
|
SInt32 tapZone = m_primaryClient->getJumpZoneSize();
|
|
|
|
if (tapZone < m_switchTwoTapZone) {
|
|
|
|
tapZone = m_switchTwoTapZone;
|
|
|
|
}
|
|
|
|
if (x >= ax + tapZone && x < ax + aw - tapZone &&
|
|
|
|
y >= ay + tapZone && y < ay + ah - tapZone) {
|
2004-04-06 01:10:06 +04:00
|
|
|
// win32 can generate bogus mouse events that appear to
|
|
|
|
// move in the opposite direction that the mouse actually
|
|
|
|
// moved. try to ignore that crap here.
|
|
|
|
switch (m_switchDir) {
|
|
|
|
case kLeft:
|
|
|
|
m_switchTwoTapArmed = (m_xDelta > 0 && m_xDelta2 > 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kRight:
|
|
|
|
m_switchTwoTapArmed = (m_xDelta < 0 && m_xDelta2 < 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kTop:
|
|
|
|
m_switchTwoTapArmed = (m_yDelta > 0 && m_yDelta2 > 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kBottom:
|
|
|
|
m_switchTwoTapArmed = (m_yDelta < 0 && m_yDelta2 < 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::stopSwitchTwoTap()
|
|
|
|
{
|
|
|
|
m_switchTwoTapEngaged = false;
|
|
|
|
m_switchTwoTapArmed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CServer::isSwitchTwoTapStarted() const
|
|
|
|
{
|
|
|
|
return m_switchTwoTapEngaged;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CServer::shouldSwitchTwoTap() const
|
|
|
|
{
|
|
|
|
// this is the second tap if two-tap is armed and this tap
|
|
|
|
// came fast enough
|
|
|
|
return (m_switchTwoTapArmed &&
|
|
|
|
m_switchTwoTapTimer.getTime() <= m_switchTwoTapDelay);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::startSwitchWait(SInt32 x, SInt32 y)
|
|
|
|
{
|
|
|
|
stopSwitchWait();
|
|
|
|
m_switchWaitX = x;
|
|
|
|
m_switchWaitY = y;
|
|
|
|
m_switchWaitTimer = EVENTQUEUE->newOneShotTimer(m_switchWaitDelay, this);
|
|
|
|
LOG((CLOG_DEBUG1 "waiting to switch"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::stopSwitchWait()
|
|
|
|
{
|
|
|
|
if (m_switchWaitTimer != NULL) {
|
|
|
|
EVENTQUEUE->deleteTimer(m_switchWaitTimer);
|
|
|
|
m_switchWaitTimer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CServer::isSwitchWaitStarted() const
|
|
|
|
{
|
|
|
|
return (m_switchWaitTimer != NULL);
|
|
|
|
}
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
UInt32
|
|
|
|
CServer::getCorner(CBaseClientProxy* client,
|
|
|
|
SInt32 x, SInt32 y, SInt32 size) const
|
|
|
|
{
|
|
|
|
assert(client != NULL);
|
|
|
|
|
|
|
|
// get client screen shape
|
|
|
|
SInt32 ax, ay, aw, ah;
|
|
|
|
client->getShape(ax, ay, aw, ah);
|
|
|
|
|
|
|
|
// check for x,y on the left or right
|
|
|
|
SInt32 xSide;
|
|
|
|
if (x <= ax) {
|
|
|
|
xSide = -1;
|
|
|
|
}
|
|
|
|
else if (x >= ax + aw - 1) {
|
|
|
|
xSide = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xSide = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for x,y on the top or bottom
|
|
|
|
SInt32 ySide;
|
|
|
|
if (y <= ay) {
|
|
|
|
ySide = -1;
|
|
|
|
}
|
|
|
|
else if (y >= ay + ah - 1) {
|
|
|
|
ySide = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ySide = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if against the left or right then check if y is within size
|
|
|
|
if (xSide != 0) {
|
|
|
|
if (y < ay + size) {
|
|
|
|
return (xSide < 0) ? kTopLeftMask : kTopRightMask;
|
|
|
|
}
|
|
|
|
else if (y >= ay + ah - size) {
|
|
|
|
return (xSide < 0) ? kBottomLeftMask : kBottomRightMask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if against the left or right then check if y is within size
|
|
|
|
if (ySide != 0) {
|
|
|
|
if (x < ax + size) {
|
|
|
|
return (ySide < 0) ? kTopLeftMask : kBottomLeftMask;
|
|
|
|
}
|
|
|
|
else if (x >= ax + aw - size) {
|
|
|
|
return (ySide < 0) ? kTopRightMask : kBottomRightMask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return kNoCornerMask;
|
|
|
|
}
|
|
|
|
|
2004-05-01 19:18:59 +04:00
|
|
|
void
|
|
|
|
CServer::stopRelativeMoves()
|
|
|
|
{
|
|
|
|
if (m_relativeMoves && m_active != m_primaryClient) {
|
|
|
|
// warp to the center of the active client so we know where we are
|
|
|
|
SInt32 ax, ay, aw, ah;
|
|
|
|
m_active->getShape(ax, ay, aw, ah);
|
|
|
|
m_x = ax + (aw >> 1);
|
|
|
|
m_y = ay + (ah >> 1);
|
|
|
|
m_xDelta = 0;
|
|
|
|
m_yDelta = 0;
|
|
|
|
m_xDelta2 = 0;
|
|
|
|
m_yDelta2 = 0;
|
|
|
|
LOG((CLOG_DEBUG2 "synchronize move on %s by %d,%d", getName(m_active).c_str(), m_x, m_y));
|
|
|
|
m_active->mouseMove(m_x, m_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::sendOptions(CBaseClientProxy* client) const
|
2004-02-14 17:04:36 +03:00
|
|
|
{
|
|
|
|
COptionsList optionsList;
|
|
|
|
|
|
|
|
// look up options for client
|
|
|
|
const CConfig::CScreenOptions* options =
|
|
|
|
m_config.getOptions(getName(client));
|
|
|
|
if (options != NULL) {
|
|
|
|
// convert options to a more convenient form for sending
|
|
|
|
optionsList.reserve(2 * options->size());
|
|
|
|
for (CConfig::CScreenOptions::const_iterator index = options->begin();
|
|
|
|
index != options->end(); ++index) {
|
|
|
|
optionsList.push_back(index->first);
|
|
|
|
optionsList.push_back(static_cast<UInt32>(index->second));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// look up global options
|
|
|
|
options = m_config.getOptions("");
|
|
|
|
if (options != NULL) {
|
|
|
|
// convert options to a more convenient form for sending
|
|
|
|
optionsList.reserve(optionsList.size() + 2 * options->size());
|
|
|
|
for (CConfig::CScreenOptions::const_iterator index = options->begin();
|
|
|
|
index != options->end(); ++index) {
|
|
|
|
optionsList.push_back(index->first);
|
|
|
|
optionsList.push_back(static_cast<UInt32>(index->second));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// send the options
|
2007-06-17 15:19:18 +04:00
|
|
|
client->resetOptions();
|
2004-02-14 17:04:36 +03:00
|
|
|
client->setOptions(optionsList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::processOptions()
|
|
|
|
{
|
|
|
|
const CConfig::CScreenOptions* options = m_config.getOptions("");
|
|
|
|
if (options == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-01 19:18:59 +04:00
|
|
|
bool newRelativeMoves = m_relativeMoves;
|
2004-02-14 17:04:36 +03:00
|
|
|
for (CConfig::CScreenOptions::const_iterator index = options->begin();
|
|
|
|
index != options->end(); ++index) {
|
|
|
|
const OptionID id = index->first;
|
|
|
|
const OptionValue value = index->second;
|
|
|
|
if (id == kOptionScreenSwitchDelay) {
|
|
|
|
m_switchWaitDelay = 1.0e-3 * static_cast<double>(value);
|
|
|
|
if (m_switchWaitDelay < 0.0) {
|
|
|
|
m_switchWaitDelay = 0.0;
|
|
|
|
}
|
|
|
|
stopSwitchWait();
|
|
|
|
}
|
|
|
|
else if (id == kOptionScreenSwitchTwoTap) {
|
|
|
|
m_switchTwoTapDelay = 1.0e-3 * static_cast<double>(value);
|
|
|
|
if (m_switchTwoTapDelay < 0.0) {
|
|
|
|
m_switchTwoTapDelay = 0.0;
|
|
|
|
}
|
|
|
|
stopSwitchTwoTap();
|
|
|
|
}
|
2004-05-01 19:18:59 +04:00
|
|
|
else if (id == kOptionRelativeMouseMoves) {
|
|
|
|
newRelativeMoves = (value != 0);
|
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
2004-05-01 19:18:59 +04:00
|
|
|
|
|
|
|
if (m_relativeMoves && !newRelativeMoves) {
|
|
|
|
stopRelativeMoves();
|
|
|
|
}
|
|
|
|
m_relativeMoves = newRelativeMoves;
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleShapeChanged(const CEvent&, void* vclient)
|
|
|
|
{
|
|
|
|
// ignore events from unknown clients
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* client = reinterpret_cast<CBaseClientProxy*>(vclient);
|
2004-02-14 17:04:36 +03:00
|
|
|
if (m_clientSet.count(client) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
LOG((CLOG_INFO "screen \"%s\" shape changed", getName(client).c_str()));
|
|
|
|
|
|
|
|
// update jump coordinate
|
|
|
|
SInt32 x, y;
|
|
|
|
client->getCursorPos(x, y);
|
|
|
|
client->setJumpCursorPos(x, y);
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// update the mouse coordinates
|
|
|
|
if (client == m_active) {
|
2007-06-17 15:19:18 +04:00
|
|
|
m_x = x;
|
|
|
|
m_y = y;
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// handle resolution change to primary screen
|
|
|
|
if (client == m_primaryClient) {
|
|
|
|
if (client == m_active) {
|
|
|
|
onMouseMovePrimary(m_x, m_y);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
onMouseMoveSecondary(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleClipboardGrabbed(const CEvent& event, void* vclient)
|
|
|
|
{
|
|
|
|
// ignore events from unknown clients
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* grabber = reinterpret_cast<CBaseClientProxy*>(vclient);
|
2004-02-14 17:04:36 +03:00
|
|
|
if (m_clientSet.count(grabber) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const IScreen::CClipboardInfo* info =
|
|
|
|
reinterpret_cast<const IScreen::CClipboardInfo*>(event.getData());
|
|
|
|
|
|
|
|
// ignore grab if sequence number is old. always allow primary
|
|
|
|
// screen to grab.
|
|
|
|
CClipboardInfo& clipboard = m_clipboards[info->m_id];
|
|
|
|
if (grabber != m_primaryClient &&
|
|
|
|
info->m_sequenceNumber < clipboard.m_clipboardSeqNum) {
|
|
|
|
LOG((CLOG_INFO "ignored screen \"%s\" grab of clipboard %d", getName(grabber).c_str(), info->m_id));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mark screen as owning clipboard
|
|
|
|
LOG((CLOG_INFO "screen \"%s\" grabbed clipboard %d from \"%s\"", getName(grabber).c_str(), info->m_id, clipboard.m_clipboardOwner.c_str()));
|
|
|
|
clipboard.m_clipboardOwner = getName(grabber);
|
|
|
|
clipboard.m_clipboardSeqNum = info->m_sequenceNumber;
|
|
|
|
|
|
|
|
// clear the clipboard data (since it's not known at this point)
|
|
|
|
if (clipboard.m_clipboard.open(0)) {
|
|
|
|
clipboard.m_clipboard.empty();
|
|
|
|
clipboard.m_clipboard.close();
|
|
|
|
}
|
|
|
|
clipboard.m_clipboardData = clipboard.m_clipboard.marshall();
|
|
|
|
|
|
|
|
// tell all other screens to take ownership of clipboard. tell the
|
|
|
|
// grabber that it's clipboard isn't dirty.
|
|
|
|
for (CClientList::iterator index = m_clients.begin();
|
|
|
|
index != m_clients.end(); ++index) {
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* client = index->second;
|
2004-02-14 17:04:36 +03:00
|
|
|
if (client == grabber) {
|
|
|
|
client->setClipboardDirty(info->m_id, false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
client->grabClipboard(info->m_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleClipboardChanged(const CEvent& event, void* vclient)
|
|
|
|
{
|
|
|
|
// ignore events from unknown clients
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* sender = reinterpret_cast<CBaseClientProxy*>(vclient);
|
2004-02-14 17:04:36 +03:00
|
|
|
if (m_clientSet.count(sender) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const IScreen::CClipboardInfo* info =
|
|
|
|
reinterpret_cast<const IScreen::CClipboardInfo*>(event.getData());
|
|
|
|
onClipboardChanged(sender, info->m_id, info->m_sequenceNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleKeyDownEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
IPlatformScreen::CKeyInfo* info =
|
|
|
|
reinterpret_cast<IPlatformScreen::CKeyInfo*>(event.getData());
|
2007-06-17 15:19:18 +04:00
|
|
|
onKeyDown(info->m_key, info->m_mask, info->m_button, info->m_screens);
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleKeyUpEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
IPlatformScreen::CKeyInfo* info =
|
|
|
|
reinterpret_cast<IPlatformScreen::CKeyInfo*>(event.getData());
|
2007-06-17 15:19:18 +04:00
|
|
|
onKeyUp(info->m_key, info->m_mask, info->m_button, info->m_screens);
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleKeyRepeatEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
IPlatformScreen::CKeyInfo* info =
|
|
|
|
reinterpret_cast<IPlatformScreen::CKeyInfo*>(event.getData());
|
|
|
|
onKeyRepeat(info->m_key, info->m_mask, info->m_count, info->m_button);
|
|
|
|
}
|
2003-02-23 22:29:08 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
void
|
|
|
|
CServer::handleButtonDownEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
IPlatformScreen::CButtonInfo* info =
|
|
|
|
reinterpret_cast<IPlatformScreen::CButtonInfo*>(event.getData());
|
|
|
|
onMouseDown(info->m_button);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleButtonUpEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
IPlatformScreen::CButtonInfo* info =
|
|
|
|
reinterpret_cast<IPlatformScreen::CButtonInfo*>(event.getData());
|
|
|
|
onMouseUp(info->m_button);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleMotionPrimaryEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
IPlatformScreen::CMotionInfo* info =
|
|
|
|
reinterpret_cast<IPlatformScreen::CMotionInfo*>(event.getData());
|
|
|
|
onMouseMovePrimary(info->m_x, info->m_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleMotionSecondaryEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
IPlatformScreen::CMotionInfo* info =
|
|
|
|
reinterpret_cast<IPlatformScreen::CMotionInfo*>(event.getData());
|
|
|
|
onMouseMoveSecondary(info->m_x, info->m_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleWheelEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
IPlatformScreen::CWheelInfo* info =
|
|
|
|
reinterpret_cast<IPlatformScreen::CWheelInfo*>(event.getData());
|
2007-06-17 15:19:18 +04:00
|
|
|
onMouseWheel(info->m_xDelta, info->m_yDelta);
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-28 15:19:49 +03:00
|
|
|
CServer::handleScreensaverActivatedEvent(const CEvent&, void*)
|
2004-02-14 17:04:36 +03:00
|
|
|
{
|
|
|
|
onScreensaver(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-28 15:19:49 +03:00
|
|
|
CServer::handleScreensaverDeactivatedEvent(const CEvent&, void*)
|
2004-02-14 17:04:36 +03:00
|
|
|
{
|
|
|
|
onScreensaver(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleSwitchWaitTimeout(const CEvent&, void*)
|
|
|
|
{
|
|
|
|
// ignore if mouse is locked to screen
|
|
|
|
if (isLockedToScreen()) {
|
|
|
|
LOG((CLOG_DEBUG1 "locked to screen"));
|
|
|
|
stopSwitch();
|
|
|
|
return;
|
2003-02-23 22:29:08 +03:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// switch screen
|
|
|
|
switchScreen(m_switchScreen, m_switchWaitX, m_switchWaitY, false);
|
2003-02-23 22:29:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-14 17:04:36 +03:00
|
|
|
CServer::handleClientDisconnected(const CEvent&, void* vclient)
|
2003-02-23 22:29:08 +03:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
// client has disconnected. it might be an old client or an
|
|
|
|
// active client. we don't care so just handle it both ways.
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* client = reinterpret_cast<CBaseClientProxy*>(vclient);
|
2004-02-14 17:04:36 +03:00
|
|
|
removeActiveClient(client);
|
|
|
|
removeOldClient(client);
|
|
|
|
delete client;
|
2003-02-23 22:29:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-14 17:04:36 +03:00
|
|
|
CServer::handleClientCloseTimeout(const CEvent&, void* vclient)
|
2003-02-23 22:29:08 +03:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
// client took too long to disconnect. just dump it.
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* client = reinterpret_cast<CBaseClientProxy*>(vclient);
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_NOTE "forced disconnection of client \"%s\"", getName(client).c_str()));
|
|
|
|
removeOldClient(client);
|
|
|
|
delete client;
|
2003-02-23 22:29:08 +03:00
|
|
|
}
|
|
|
|
|
2002-07-10 01:22:31 +04:00
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::handleSwitchToScreenEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
CSwitchToScreenInfo* info =
|
|
|
|
reinterpret_cast<CSwitchToScreenInfo*>(event.getData());
|
|
|
|
|
|
|
|
CClientList::const_iterator index = m_clients.find(info->m_screen);
|
|
|
|
if (index == m_clients.end()) {
|
|
|
|
LOG((CLOG_DEBUG1 "screen \"%s\" not active", info->m_screen));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
jumpToScreen(index->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleSwitchInDirectionEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
CSwitchInDirectionInfo* info =
|
|
|
|
reinterpret_cast<CSwitchInDirectionInfo*>(event.getData());
|
|
|
|
|
|
|
|
// jump to screen in chosen direction from center of this screen
|
|
|
|
SInt32 x = m_x, y = m_y;
|
|
|
|
CBaseClientProxy* newScreen =
|
|
|
|
getNeighbor(m_active, info->m_direction, x, y);
|
|
|
|
if (newScreen == NULL) {
|
|
|
|
LOG((CLOG_DEBUG1 "no neighbor %s", CConfig::dirName(info->m_direction)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
jumpToScreen(newScreen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleLockCursorToScreenEvent(const CEvent& event, void*)
|
|
|
|
{
|
|
|
|
CLockCursorToScreenInfo* info = (CLockCursorToScreenInfo*)event.getData();
|
|
|
|
|
|
|
|
// choose new state
|
|
|
|
bool newState;
|
|
|
|
switch (info->m_state) {
|
|
|
|
case CLockCursorToScreenInfo::kOff:
|
|
|
|
newState = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case CLockCursorToScreenInfo::kOn:
|
|
|
|
newState = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLockCursorToScreenInfo::kToggle:
|
|
|
|
newState = !m_lockedToScreen;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enter new state
|
|
|
|
if (newState != m_lockedToScreen) {
|
|
|
|
m_lockedToScreen = newState;
|
|
|
|
LOG((CLOG_DEBUG "cursor %s current screen", m_lockedToScreen ? "locked to" : "unlocked from"));
|
|
|
|
|
|
|
|
m_primaryClient->reconfigure(getActivePrimarySides());
|
|
|
|
if (!isLockedToScreenServer()) {
|
|
|
|
stopRelativeMoves();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleFakeInputBeginEvent(const CEvent&, void*)
|
|
|
|
{
|
|
|
|
m_primaryClient->fakeInputBegin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::handleFakeInputEndEvent(const CEvent&, void*)
|
|
|
|
{
|
|
|
|
m_primaryClient->fakeInputEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CServer::onClipboardChanged(CBaseClientProxy* sender,
|
|
|
|
ClipboardID id, UInt32 seqNum)
|
2002-07-10 01:22:31 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
CClipboardInfo& clipboard = m_clipboards[id];
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// ignore update if sequence number is old
|
|
|
|
if (seqNum < clipboard.m_clipboardSeqNum) {
|
2007-06-17 15:19:18 +04:00
|
|
|
LOG((CLOG_INFO "ignored screen \"%s\" update of clipboard %d (missequenced)", getName(sender).c_str(), id));
|
2004-02-14 17:04:36 +03:00
|
|
|
return;
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// should be the expected client
|
|
|
|
assert(sender == m_clients.find(clipboard.m_clipboardOwner)->second);
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// get data
|
|
|
|
sender->getClipboard(id, &clipboard.m_clipboard);
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// ignore if data hasn't changed
|
|
|
|
CString data = clipboard.m_clipboard.marshall();
|
|
|
|
if (data == clipboard.m_clipboardData) {
|
|
|
|
LOG((CLOG_DEBUG "ignored screen \"%s\" update of clipboard %d (unchanged)", clipboard.m_clipboardOwner.c_str(), id));
|
|
|
|
return;
|
|
|
|
}
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// got new data
|
|
|
|
LOG((CLOG_INFO "screen \"%s\" updated clipboard %d", clipboard.m_clipboardOwner.c_str(), id));
|
|
|
|
clipboard.m_clipboardData = data;
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// tell all clients except the sender that the clipboard is dirty
|
|
|
|
for (CClientList::const_iterator index = m_clients.begin();
|
|
|
|
index != m_clients.end(); ++index) {
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* client = index->second;
|
2004-02-14 17:04:36 +03:00
|
|
|
client->setClipboardDirty(id, client != sender);
|
|
|
|
}
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// send the new clipboard to the active screen
|
2004-02-15 20:32:11 +03:00
|
|
|
m_active->setClipboard(id, &clipboard.m_clipboard);
|
2002-06-21 19:18:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-14 17:04:36 +03:00
|
|
|
CServer::onScreensaver(bool activated)
|
2002-06-21 19:18:01 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_DEBUG "onScreenSaver %s", activated ? "activated" : "deactivated"));
|
2002-06-21 19:18:01 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
if (activated) {
|
|
|
|
// save current screen and position
|
|
|
|
m_activeSaver = m_active;
|
|
|
|
m_xSaver = m_x;
|
|
|
|
m_ySaver = m_y;
|
2002-07-18 21:00:48 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// jump to primary screen
|
|
|
|
if (m_active != m_primaryClient) {
|
|
|
|
switchScreen(m_primaryClient, 0, 0, true);
|
|
|
|
}
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
else {
|
|
|
|
// jump back to previous screen and position. we must check
|
|
|
|
// that the position is still valid since the screen may have
|
|
|
|
// changed resolutions while the screen saver was running.
|
|
|
|
if (m_activeSaver != NULL && m_activeSaver != m_primaryClient) {
|
|
|
|
// check position
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* screen = m_activeSaver;
|
2004-02-14 17:04:36 +03:00
|
|
|
SInt32 x, y, w, h;
|
|
|
|
screen->getShape(x, y, w, h);
|
|
|
|
SInt32 zoneSize = getJumpZoneSize(screen);
|
|
|
|
if (m_xSaver < x + zoneSize) {
|
|
|
|
m_xSaver = x + zoneSize;
|
|
|
|
}
|
|
|
|
else if (m_xSaver >= x + w - zoneSize) {
|
|
|
|
m_xSaver = x + w - zoneSize - 1;
|
|
|
|
}
|
|
|
|
if (m_ySaver < y + zoneSize) {
|
|
|
|
m_ySaver = y + zoneSize;
|
|
|
|
}
|
|
|
|
else if (m_ySaver >= y + h - zoneSize) {
|
|
|
|
m_ySaver = y + h - zoneSize - 1;
|
|
|
|
}
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// jump
|
|
|
|
switchScreen(screen, m_xSaver, m_ySaver, false);
|
|
|
|
}
|
2002-06-21 19:18:01 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// reset state
|
|
|
|
m_activeSaver = NULL;
|
2002-06-21 19:18:01 +04:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// send message to all clients
|
|
|
|
for (CClientList::const_iterator index = m_clients.begin();
|
|
|
|
index != m_clients.end(); ++index) {
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* client = index->second;
|
2004-02-14 17:04:36 +03:00
|
|
|
client->screensaver(activated);
|
2002-06-21 19:18:01 +04:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::onKeyDown(KeyID id, KeyModifierMask mask, KeyButton button,
|
|
|
|
const char* screens)
|
2004-02-14 17:04:36 +03:00
|
|
|
{
|
|
|
|
LOG((CLOG_DEBUG1 "onKeyDown id=%d mask=0x%04x button=0x%04x", id, mask, button));
|
|
|
|
assert(m_active != NULL);
|
2002-06-21 19:18:01 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// relay
|
2007-06-17 15:19:18 +04:00
|
|
|
if (IKeyState::CKeyInfo::isDefault(screens)) {
|
|
|
|
m_active->keyDown(id, mask, button);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (CClientList::const_iterator index = m_clients.begin();
|
|
|
|
index != m_clients.end(); ++index) {
|
|
|
|
if (IKeyState::CKeyInfo::contains(screens, index->first)) {
|
|
|
|
index->second->keyDown(id, mask, button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-21 19:18:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::onKeyUp(KeyID id, KeyModifierMask mask, KeyButton button,
|
|
|
|
const char* screens)
|
2002-06-21 19:18:01 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_DEBUG1 "onKeyUp id=%d mask=0x%04x button=0x%04x", id, mask, button));
|
|
|
|
assert(m_active != NULL);
|
|
|
|
|
|
|
|
// relay
|
2007-06-17 15:19:18 +04:00
|
|
|
if (IKeyState::CKeyInfo::isDefault(screens)) {
|
|
|
|
m_active->keyUp(id, mask, button);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (CClientList::const_iterator index = m_clients.begin();
|
|
|
|
index != m_clients.end(); ++index) {
|
|
|
|
if (IKeyState::CKeyInfo::contains(screens, index->first)) {
|
|
|
|
index->second->keyUp(id, mask, button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-21 19:18:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-02-14 17:04:36 +03:00
|
|
|
CServer::onKeyRepeat(KeyID id, KeyModifierMask mask,
|
|
|
|
SInt32 count, KeyButton button)
|
|
|
|
{
|
|
|
|
LOG((CLOG_DEBUG1 "onKeyRepeat id=%d mask=0x%04x count=%d button=0x%04x", id, mask, count, button));
|
|
|
|
assert(m_active != NULL);
|
|
|
|
|
|
|
|
// relay
|
|
|
|
m_active->keyRepeat(id, mask, count, button);
|
2002-06-21 19:18:01 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2004-02-14 17:04:36 +03:00
|
|
|
CServer::onMouseDown(ButtonID id)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_DEBUG1 "onMouseDown id=%d", id));
|
|
|
|
assert(m_active != NULL);
|
2001-10-14 18:37:41 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// relay
|
|
|
|
m_active->mouseDown(id);
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
void
|
|
|
|
CServer::onMouseUp(ButtonID id)
|
|
|
|
{
|
|
|
|
LOG((CLOG_DEBUG1 "onMouseUp id=%d", id));
|
|
|
|
assert(m_active != NULL);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// relay
|
|
|
|
m_active->mouseUp(id);
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
bool
|
|
|
|
CServer::onMouseMovePrimary(SInt32 x, SInt32 y)
|
|
|
|
{
|
|
|
|
LOG((CLOG_DEBUG2 "onMouseMovePrimary %d,%d", x, y));
|
|
|
|
|
|
|
|
// mouse move on primary (server's) screen
|
2004-03-08 23:53:32 +03:00
|
|
|
if (m_active != m_primaryClient) {
|
|
|
|
// stale event -- we're actually on a secondary screen
|
|
|
|
return false;
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-04-06 01:10:06 +04:00
|
|
|
// save last delta
|
|
|
|
m_xDelta2 = m_xDelta;
|
|
|
|
m_yDelta2 = m_yDelta;
|
|
|
|
|
|
|
|
// save current delta
|
|
|
|
m_xDelta = x - m_x;
|
|
|
|
m_yDelta = y - m_y;
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// save position
|
2004-04-06 01:10:06 +04:00
|
|
|
m_x = x;
|
|
|
|
m_y = y;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// get screen shape
|
|
|
|
SInt32 ax, ay, aw, ah;
|
|
|
|
m_active->getShape(ax, ay, aw, ah);
|
|
|
|
SInt32 zoneSize = getJumpZoneSize(m_active);
|
2002-12-23 16:55:21 +03:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// clamp position to screen
|
|
|
|
SInt32 xc = x, yc = y;
|
|
|
|
if (xc < ax + zoneSize) {
|
|
|
|
xc = ax;
|
|
|
|
}
|
|
|
|
else if (xc >= ax + aw - zoneSize) {
|
|
|
|
xc = ax + aw - 1;
|
|
|
|
}
|
|
|
|
if (yc < ay + zoneSize) {
|
|
|
|
yc = ay;
|
|
|
|
}
|
|
|
|
else if (yc >= ay + ah - zoneSize) {
|
|
|
|
yc = ay + ah - 1;
|
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// see if we should change screens
|
|
|
|
EDirection dir;
|
|
|
|
if (x < ax + zoneSize) {
|
|
|
|
x -= zoneSize;
|
|
|
|
dir = kLeft;
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
else if (x >= ax + aw - zoneSize) {
|
|
|
|
x += zoneSize;
|
|
|
|
dir = kRight;
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
else if (y < ay + zoneSize) {
|
|
|
|
y -= zoneSize;
|
|
|
|
dir = kTop;
|
|
|
|
}
|
|
|
|
else if (y >= ay + ah - zoneSize) {
|
|
|
|
y += zoneSize;
|
|
|
|
dir = kBottom;
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
else {
|
|
|
|
// still on local screen
|
|
|
|
noSwitch(x, y);
|
|
|
|
return false;
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// get jump destination
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* newScreen = mapToNeighbor(m_active, dir, x, y);
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// should we switch or not?
|
2007-06-17 15:19:18 +04:00
|
|
|
if (isSwitchOkay(newScreen, dir, x, y, xc, yc)) {
|
2004-02-14 17:04:36 +03:00
|
|
|
// switch screen
|
|
|
|
switchScreen(newScreen, x, y, false);
|
|
|
|
return true;
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
else {
|
|
|
|
return false;
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
void
|
|
|
|
CServer::onMouseMoveSecondary(SInt32 dx, SInt32 dy)
|
2002-07-10 01:22:31 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
LOG((CLOG_DEBUG2 "onMouseMoveSecondary %+d,%+d", dx, dy));
|
|
|
|
|
|
|
|
// mouse move on secondary (client's) screen
|
|
|
|
assert(m_active != NULL);
|
|
|
|
if (m_active == m_primaryClient) {
|
2004-03-08 23:53:32 +03:00
|
|
|
// stale event -- we're actually on the primary screen
|
2004-02-14 17:04:36 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-05-01 19:18:59 +04:00
|
|
|
// if doing relative motion on secondary screens and we're locked
|
|
|
|
// to the screen (which activates relative moves) then send a
|
|
|
|
// relative mouse motion. when we're doing this we pretend as if
|
|
|
|
// the mouse isn't actually moving because we're expecting some
|
|
|
|
// program on the secondary screen to warp the mouse on us, so we
|
|
|
|
// have no idea where it really is.
|
|
|
|
if (m_relativeMoves && isLockedToScreenServer()) {
|
|
|
|
LOG((CLOG_DEBUG2 "relative move on %s by %d,%d", getName(m_active).c_str(), dx, dy));
|
|
|
|
m_active->mouseRelativeMove(dx, dy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// save old position
|
|
|
|
const SInt32 xOld = m_x;
|
|
|
|
const SInt32 yOld = m_y;
|
2002-05-23 18:56:03 +04:00
|
|
|
|
2004-04-06 01:10:06 +04:00
|
|
|
// save last delta
|
|
|
|
m_xDelta2 = m_xDelta;
|
|
|
|
m_yDelta2 = m_yDelta;
|
|
|
|
|
|
|
|
// save current delta
|
|
|
|
m_xDelta = dx;
|
|
|
|
m_yDelta = dy;
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// accumulate motion
|
2004-04-06 01:10:06 +04:00
|
|
|
m_x += dx;
|
|
|
|
m_y += dy;
|
2002-06-23 19:43:40 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// get screen shape
|
|
|
|
SInt32 ax, ay, aw, ah;
|
|
|
|
m_active->getShape(ax, ay, aw, ah);
|
2002-07-30 22:31:00 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// find direction of neighbor and get the neighbor
|
|
|
|
bool jump = true;
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* newScreen;
|
2004-02-14 17:04:36 +03:00
|
|
|
do {
|
2007-06-17 15:19:18 +04:00
|
|
|
// clamp position to screen
|
|
|
|
SInt32 xc = m_x, yc = m_y;
|
|
|
|
if (xc < ax) {
|
|
|
|
xc = ax;
|
|
|
|
}
|
|
|
|
else if (xc >= ax + aw) {
|
|
|
|
xc = ax + aw - 1;
|
|
|
|
}
|
|
|
|
if (yc < ay) {
|
|
|
|
yc = ay;
|
|
|
|
}
|
|
|
|
else if (yc >= ay + ah) {
|
|
|
|
yc = ay + ah - 1;
|
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
EDirection dir;
|
|
|
|
if (m_x < ax) {
|
|
|
|
dir = kLeft;
|
|
|
|
}
|
|
|
|
else if (m_x > ax + aw - 1) {
|
|
|
|
dir = kRight;
|
2002-05-23 18:56:03 +04:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
else if (m_y < ay) {
|
|
|
|
dir = kTop;
|
|
|
|
}
|
|
|
|
else if (m_y > ay + ah - 1) {
|
|
|
|
dir = kBottom;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// we haven't left the screen
|
|
|
|
newScreen = m_active;
|
|
|
|
jump = false;
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// if waiting and mouse is not on the border we're waiting
|
|
|
|
// on then stop waiting. also if it's not on the border
|
|
|
|
// then arm the double tap.
|
|
|
|
if (m_switchScreen != NULL) {
|
|
|
|
bool clearWait;
|
|
|
|
SInt32 zoneSize = m_primaryClient->getJumpZoneSize();
|
|
|
|
switch (m_switchDir) {
|
|
|
|
case kLeft:
|
|
|
|
clearWait = (m_x >= ax + zoneSize);
|
|
|
|
break;
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
case kRight:
|
|
|
|
clearWait = (m_x <= ax + aw - 1 - zoneSize);
|
|
|
|
break;
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
case kTop:
|
|
|
|
clearWait = (m_y >= ay + zoneSize);
|
|
|
|
break;
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
case kBottom:
|
|
|
|
clearWait = (m_y <= ay + ah - 1 + zoneSize);
|
|
|
|
break;
|
2003-04-27 21:01:14 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
default:
|
|
|
|
clearWait = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (clearWait) {
|
|
|
|
// still on local screen
|
|
|
|
noSwitch(m_x, m_y);
|
|
|
|
}
|
2003-04-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// skip rest of block
|
|
|
|
break;
|
2003-04-27 21:01:14 +04:00
|
|
|
}
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// try to switch screen. get the neighbor.
|
2007-06-17 15:19:18 +04:00
|
|
|
newScreen = mapToNeighbor(m_active, dir, m_x, m_y);
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// see if we should switch
|
2007-06-17 15:19:18 +04:00
|
|
|
if (!isSwitchOkay(newScreen, dir, m_x, m_y, xc, yc)) {
|
2004-02-14 17:04:36 +03:00
|
|
|
newScreen = m_active;
|
|
|
|
jump = false;
|
2003-01-12 19:08:45 +03:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
} while (false);
|
|
|
|
|
|
|
|
if (jump) {
|
|
|
|
// switch screens
|
|
|
|
switchScreen(newScreen, m_x, m_y, false);
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
else {
|
|
|
|
// same screen. clamp mouse to edge.
|
|
|
|
m_x = xOld + dx;
|
|
|
|
m_y = yOld + dy;
|
|
|
|
if (m_x < ax) {
|
|
|
|
m_x = ax;
|
|
|
|
LOG((CLOG_DEBUG2 "clamp to left of \"%s\"", getName(m_active).c_str()));
|
2003-01-12 19:08:45 +03:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
else if (m_x > ax + aw - 1) {
|
|
|
|
m_x = ax + aw - 1;
|
|
|
|
LOG((CLOG_DEBUG2 "clamp to right of \"%s\"", getName(m_active).c_str()));
|
2003-01-12 19:08:45 +03:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
if (m_y < ay) {
|
|
|
|
m_y = ay;
|
|
|
|
LOG((CLOG_DEBUG2 "clamp to top of \"%s\"", getName(m_active).c_str()));
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
else if (m_y > ay + ah - 1) {
|
|
|
|
m_y = ay + ah - 1;
|
|
|
|
LOG((CLOG_DEBUG2 "clamp to bottom of \"%s\"", getName(m_active).c_str()));
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// warp cursor if it moved.
|
|
|
|
if (m_x != xOld || m_y != yOld) {
|
|
|
|
LOG((CLOG_DEBUG2 "move on %s to %d,%d", getName(m_active).c_str(), m_x, m_y));
|
|
|
|
m_active->mouseMove(m_x, m_y);
|
|
|
|
}
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-12-23 16:55:21 +03:00
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::onMouseWheel(SInt32 xDelta, SInt32 yDelta)
|
2002-12-23 16:55:21 +03:00
|
|
|
{
|
2007-06-17 15:19:18 +04:00
|
|
|
LOG((CLOG_DEBUG1 "onMouseWheel %+d,%+d", xDelta, yDelta));
|
2004-02-14 17:04:36 +03:00
|
|
|
assert(m_active != NULL);
|
2002-12-23 16:55:21 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// relay
|
2007-06-17 15:19:18 +04:00
|
|
|
m_active->mouseWheel(xDelta, yDelta);
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
2003-02-22 19:20:23 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
bool
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::addClient(CBaseClientProxy* client)
|
2004-02-14 17:04:36 +03:00
|
|
|
{
|
|
|
|
CString name = getName(client);
|
|
|
|
if (m_clients.count(name) != 0) {
|
|
|
|
return false;
|
2003-02-22 19:20:23 +03:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// add event handlers
|
|
|
|
EVENTQUEUE->adoptHandler(IScreen::getShapeChangedEvent(),
|
|
|
|
client->getEventTarget(),
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleShapeChanged, client));
|
|
|
|
EVENTQUEUE->adoptHandler(IScreen::getClipboardGrabbedEvent(),
|
|
|
|
client->getEventTarget(),
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleClipboardGrabbed, client));
|
2004-02-29 20:28:51 +03:00
|
|
|
EVENTQUEUE->adoptHandler(CClientProxy::getClipboardChangedEvent(),
|
2004-02-14 17:04:36 +03:00
|
|
|
client->getEventTarget(),
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleClipboardChanged, client));
|
2002-12-23 16:55:21 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// add to list
|
|
|
|
m_clientSet.insert(client);
|
|
|
|
m_clients.insert(std::make_pair(name, client));
|
2004-02-28 15:19:49 +03:00
|
|
|
|
2007-06-17 15:19:18 +04:00
|
|
|
// initialize client data
|
|
|
|
SInt32 x, y;
|
|
|
|
client->getCursorPos(x, y);
|
|
|
|
client->setJumpCursorPos(x, y);
|
|
|
|
|
2004-02-28 15:19:49 +03:00
|
|
|
// tell primary client about the active sides
|
|
|
|
m_primaryClient->reconfigure(getActivePrimarySides());
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
return true;
|
2002-12-23 16:55:21 +03:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
bool
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::removeClient(CBaseClientProxy* client)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
// return false if not in list
|
2004-04-06 01:23:44 +04:00
|
|
|
CClientSet::iterator i = m_clientSet.find(client);
|
|
|
|
if (i == m_clientSet.end()) {
|
2004-02-14 17:04:36 +03:00
|
|
|
return false;
|
2002-07-10 01:22:31 +04:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// remove event handlers
|
|
|
|
EVENTQUEUE->removeHandler(IScreen::getShapeChangedEvent(),
|
|
|
|
client->getEventTarget());
|
|
|
|
EVENTQUEUE->removeHandler(IScreen::getClipboardGrabbedEvent(),
|
|
|
|
client->getEventTarget());
|
2004-02-29 20:28:51 +03:00
|
|
|
EVENTQUEUE->removeHandler(CClientProxy::getClipboardChangedEvent(),
|
2004-02-14 17:04:36 +03:00
|
|
|
client->getEventTarget());
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// remove from list
|
2004-04-06 01:23:44 +04:00
|
|
|
m_clients.erase(getName(client));
|
|
|
|
m_clientSet.erase(i);
|
2004-02-28 15:19:49 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
return true;
|
|
|
|
}
|
2002-07-10 01:22:31 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::closeClient(CBaseClientProxy* client, const char* msg)
|
2004-02-14 17:04:36 +03:00
|
|
|
{
|
|
|
|
assert(client != m_primaryClient);
|
|
|
|
assert(msg != NULL);
|
|
|
|
|
|
|
|
// send message to client. this message should cause the client
|
|
|
|
// to disconnect. we add this client to the closed client list
|
|
|
|
// and install a timer to remove the client if it doesn't respond
|
|
|
|
// quickly enough. we also remove the client from the active
|
|
|
|
// client list since we're not going to listen to it anymore.
|
|
|
|
// note that this method also works on clients that are not in
|
|
|
|
// the m_clients list. adoptClient() may call us with such a
|
|
|
|
// client.
|
|
|
|
LOG((CLOG_NOTE "disconnecting client \"%s\"", getName(client).c_str()));
|
|
|
|
|
|
|
|
// send message
|
|
|
|
// FIXME -- avoid type cast (kinda hard, though)
|
|
|
|
((CClientProxy*)client)->close(msg);
|
|
|
|
|
|
|
|
// install timer. wait timeout seconds for client to close.
|
|
|
|
double timeout = 5.0;
|
2004-02-28 15:19:49 +03:00
|
|
|
CEventQueueTimer* timer = EVENTQUEUE->newOneShotTimer(timeout, NULL);
|
2004-02-14 17:04:36 +03:00
|
|
|
EVENTQUEUE->adoptHandler(CEvent::kTimer, timer,
|
|
|
|
new TMethodEventJob<CServer>(this,
|
|
|
|
&CServer::handleClientCloseTimeout, client));
|
2002-07-11 17:13:37 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// move client to closing list
|
|
|
|
removeClient(client);
|
|
|
|
m_oldClients.insert(std::make_pair(client, timer));
|
2002-12-23 16:55:21 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// if this client is the active screen then we have to
|
|
|
|
// jump off of it
|
|
|
|
forceLeaveClient(client);
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2004-02-14 17:04:36 +03:00
|
|
|
CServer::closeClients(const CConfig& config)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
// collect the clients that are connected but are being dropped
|
|
|
|
// from the configuration (or who's canonical name is changing).
|
2007-06-17 15:19:18 +04:00
|
|
|
typedef std::set<CBaseClientProxy*> CRemovedClients;
|
2004-02-14 17:04:36 +03:00
|
|
|
CRemovedClients removed;
|
|
|
|
for (CClientList::iterator index = m_clients.begin();
|
|
|
|
index != m_clients.end(); ++index) {
|
|
|
|
if (!config.isCanonicalName(index->first)) {
|
|
|
|
removed.insert(index->second);
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// don't close the primary client
|
|
|
|
removed.erase(m_primaryClient);
|
|
|
|
|
|
|
|
// now close them. we collect the list then close in two steps
|
|
|
|
// because closeClient() modifies the collection we iterate over.
|
|
|
|
for (CRemovedClients::iterator index = removed.begin();
|
|
|
|
index != removed.end(); ++index) {
|
|
|
|
closeClient(*index, kMsgCClose);
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-07-10 01:22:31 +04:00
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::removeActiveClient(CBaseClientProxy* client)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2004-02-14 17:04:36 +03:00
|
|
|
if (removeClient(client)) {
|
|
|
|
forceLeaveClient(client);
|
|
|
|
EVENTQUEUE->removeHandler(CClientProxy::getDisconnectedEvent(), client);
|
|
|
|
if (m_clients.size() == 1 && m_oldClients.empty()) {
|
|
|
|
EVENTQUEUE->addEvent(CEvent(getDisconnectedEvent(), this));
|
2003-03-13 01:34:07 +03:00
|
|
|
}
|
2004-02-14 17:04:36 +03:00
|
|
|
}
|
|
|
|
}
|
2002-06-09 03:24:40 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::removeOldClient(CBaseClientProxy* client)
|
2004-02-14 17:04:36 +03:00
|
|
|
{
|
|
|
|
COldClients::iterator i = m_oldClients.find(client);
|
|
|
|
if (i != m_oldClients.end()) {
|
|
|
|
EVENTQUEUE->removeHandler(CClientProxy::getDisconnectedEvent(), client);
|
|
|
|
EVENTQUEUE->removeHandler(CEvent::kTimer, i->second);
|
|
|
|
EVENTQUEUE->deleteTimer(i->second);
|
|
|
|
m_oldClients.erase(i);
|
|
|
|
if (m_clients.size() == 1 && m_oldClients.empty()) {
|
|
|
|
EVENTQUEUE->addEvent(CEvent(getDisconnectedEvent(), this));
|
2003-03-13 01:34:07 +03:00
|
|
|
}
|
|
|
|
}
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
|
|
|
|
2002-06-11 02:06:45 +04:00
|
|
|
void
|
2007-06-17 15:19:18 +04:00
|
|
|
CServer::forceLeaveClient(CBaseClientProxy* client)
|
2001-10-06 18:13:28 +04:00
|
|
|
{
|
2007-06-17 15:19:18 +04:00
|
|
|
CBaseClientProxy* active =
|
|
|
|
(m_activeSaver != NULL) ? m_activeSaver : m_active;
|
2004-02-14 17:04:36 +03:00
|
|
|
if (active == client) {
|
|
|
|
// record new position (center of primary screen)
|
|
|
|
m_primaryClient->getCursorCenter(m_x, m_y);
|
2001-10-25 03:29:29 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// stop waiting to switch to this client
|
|
|
|
if (active == m_switchScreen) {
|
|
|
|
stopSwitch();
|
2003-03-13 01:34:07 +03:00
|
|
|
}
|
2002-06-22 23:20:21 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// don't notify active screen since it has probably already
|
|
|
|
// disconnected.
|
|
|
|
LOG((CLOG_INFO "jump from \"%s\" to \"%s\" at %d,%d", getName(active).c_str(), getName(m_primaryClient).c_str(), m_x, m_y));
|
2001-10-06 18:13:28 +04:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// cut over
|
|
|
|
m_active = m_primaryClient;
|
2003-03-13 01:34:07 +03:00
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// enter new screen (unless we already have because of the
|
|
|
|
// screen saver)
|
|
|
|
if (m_activeSaver == NULL) {
|
|
|
|
m_primaryClient->enter(m_x, m_y, m_seqNum,
|
|
|
|
m_primaryClient->getToggleMask(), false);
|
|
|
|
}
|
2003-03-13 01:34:07 +03:00
|
|
|
}
|
|
|
|
|
2004-02-14 17:04:36 +03:00
|
|
|
// if this screen had the cursor when the screen saver activated
|
|
|
|
// then we can't switch back to it when the screen saver
|
|
|
|
// deactivates.
|
|
|
|
if (m_activeSaver == client) {
|
|
|
|
m_activeSaver = NULL;
|
2003-03-13 01:34:07 +03:00
|
|
|
}
|
2004-02-28 15:19:49 +03:00
|
|
|
|
|
|
|
// tell primary client about the active sides
|
|
|
|
m_primaryClient->reconfigure(getActivePrimarySides());
|
2001-10-06 18:13:28 +04:00
|
|
|
}
|
2002-04-27 18:19:53 +04:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2002-04-29 17:31:44 +04:00
|
|
|
// CServer::CClipboardInfo
|
2002-04-27 18:19:53 +04:00
|
|
|
//
|
|
|
|
|
2002-04-29 17:31:44 +04:00
|
|
|
CServer::CClipboardInfo::CClipboardInfo() :
|
2002-06-11 02:06:45 +04:00
|
|
|
m_clipboard(),
|
|
|
|
m_clipboardData(),
|
|
|
|
m_clipboardOwner(),
|
2002-07-10 01:22:31 +04:00
|
|
|
m_clipboardSeqNum(0)
|
2002-04-27 18:19:53 +04:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
2007-06-17 15:19:18 +04:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CServer::CLockCursorToScreenInfo
|
|
|
|
//
|
|
|
|
|
|
|
|
CServer::CLockCursorToScreenInfo*
|
|
|
|
CServer::CLockCursorToScreenInfo::alloc(State state)
|
|
|
|
{
|
|
|
|
CLockCursorToScreenInfo* info =
|
|
|
|
(CLockCursorToScreenInfo*)malloc(sizeof(CLockCursorToScreenInfo));
|
|
|
|
info->m_state = state;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CServer::CSwitchToScreenInfo
|
|
|
|
//
|
|
|
|
|
|
|
|
CServer::CSwitchToScreenInfo*
|
|
|
|
CServer::CSwitchToScreenInfo::alloc(const CString& screen)
|
|
|
|
{
|
|
|
|
CSwitchToScreenInfo* info =
|
|
|
|
(CSwitchToScreenInfo*)malloc(sizeof(CSwitchToScreenInfo) +
|
|
|
|
screen.size());
|
|
|
|
strcpy(info->m_screen, screen.c_str());
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CServer::CSwitchInDirectionInfo
|
|
|
|
//
|
|
|
|
|
|
|
|
CServer::CSwitchInDirectionInfo*
|
|
|
|
CServer::CSwitchInDirectionInfo::alloc(EDirection direction)
|
|
|
|
{
|
|
|
|
CSwitchInDirectionInfo* info =
|
|
|
|
(CSwitchInDirectionInfo*)malloc(sizeof(CSwitchInDirectionInfo));
|
|
|
|
info->m_direction = direction;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CServer::CScreenConnectedInfo
|
|
|
|
//
|
|
|
|
|
|
|
|
CServer::CScreenConnectedInfo*
|
|
|
|
CServer::CScreenConnectedInfo::alloc(const CString& screen)
|
|
|
|
{
|
|
|
|
CScreenConnectedInfo* info =
|
|
|
|
(CScreenConnectedInfo*)malloc(sizeof(CScreenConnectedInfo) +
|
|
|
|
screen.size());
|
|
|
|
strcpy(info->m_screen, screen.c_str());
|
|
|
|
return info;
|
|
|
|
}
|