読者です 読者をやめる 読者になる 読者になる

Let's write β

趣味で書いたこととか、RustとLispが好き

Synergyのソースを読んだNo.2

前回grepした結果をのせておきます。

lib/synergy/IPlatformScreen.h:	EVENTQUEUE->adoptHandler(CEvent::kSystem,
cmd/synergyc/synergyc.cpp:	EVENTQUEUE->adoptHandler(IScreen::getErrorEvent(),
cmd/synergyc/synergyc.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, timer,
cmd/synergyc/synergyc.cpp:	EVENTQUEUE->adoptHandler(CClient::getConnectedEvent(),
cmd/synergyc/synergyc.cpp:	EVENTQUEUE->adoptHandler(CClient::getConnectionFailedEvent(),
cmd/synergyc/synergyc.cpp:	EVENTQUEUE->adoptHandler(CClient::getDisconnectedEvent(),
cmd/synergys/synergys.cpp:	EVENTQUEUE->adoptHandler(CClientListener::getConnectedEvent(), listen,
cmd/synergys/synergys.cpp:	EVENTQUEUE->adoptHandler(IScreen::getErrorEvent(),
cmd/synergys/synergys.cpp:	EVENTQUEUE->adoptHandler(IScreen::getSuspendEvent(),
cmd/synergys/synergys.cpp:	EVENTQUEUE->adoptHandler(IScreen::getResumeEvent(),
cmd/synergys/synergys.cpp:	EVENTQUEUE->adoptHandler(CServer::getDisconnectedEvent(), server,
cmd/synergys/synergys.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, timer,
cmd/synergys/synergys.cpp:	EVENTQUEUE->adoptHandler(CServer::getDisconnectedEvent(), server,
cmd/synergys/synergys.cpp:		EVENTQUEUE->adoptHandler(CEvent::kTimer, s_timer,
cmd/synergys/synergys.cpp:		EVENTQUEUE->adoptHandler(CEvent::kTimer, s_timer,
cmd/synergys/synergys.cpp:	EVENTQUEUE->adoptHandler(getReloadConfigEvent(),
cmd/synergys/synergys.cpp:	EVENTQUEUE->adoptHandler(getForceReconnectEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(IScreen::getSuspendEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(IScreen::getResumeEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(IDataSocket::getConnectedEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(IDataSocket::getConnectionFailedEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(ISocket::getDisconnectedEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(IStream::getInputReadyEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(IStream::getOutputErrorEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(IStream::getInputShutdownEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(IStream::getOutputShutdownEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(IScreen::getShapeChangedEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(IScreen::getClipboardGrabbedEvent(),
lib/client/CClient.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, m_timer,
lib/client/CServerProxy.cpp:	EVENTQUEUE->adoptHandler(IStream::getInputReadyEvent(),
lib/client/CServerProxy.cpp:		EVENTQUEUE->adoptHandler(CEvent::kTimer, m_keepAliveAlarmTimer,
lib/io/CStreamFilter.cpp:	EVENTQUEUE->adoptHandler(CEvent::kUnknown, m_stream->getEventTarget(),
lib/platform/CMSWindowsDesks.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, m_timer,
lib/platform/CMSWindowsKeyState.cpp:		EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,
lib/platform/CMSWindowsScreen.cpp:	EVENTQUEUE->adoptHandler(CEvent::kSystem, IEventQueue::getSystemTarget(),
lib/platform/CMSWindowsScreen.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, m_fixTimer,
lib/platform/COSXScreen.cpp:		EVENTQUEUE->adoptHandler(COSXScreen::getConfirmSleepEvent(),
lib/platform/COSXScreen.cpp:	EVENTQUEUE->adoptHandler(CEvent::kSystem, IEventQueue::getSystemTarget(),
lib/platform/COSXScreen.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, m_clipboardTimer,
lib/platform/COSXScreen.cpp:		EVENTQUEUE->adoptHandler(CEvent::kTimer, m_dragTimer,
lib/platform/CXWindowsScreen.cpp:	EVENTQUEUE->adoptHandler(CEvent::kSystem, IEventQueue::getSystemTarget(),
lib/platform/CXWindowsScreenSaver.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, this,
lib/server/CClientListener.cpp:	EVENTQUEUE->adoptHandler(IListenSocket::getConnectingEvent(), m_listen,
lib/server/CClientListener.cpp:	EVENTQUEUE->adoptHandler(CClientProxyUnknown::getSuccessEvent(), client,
lib/server/CClientListener.cpp:	EVENTQUEUE->adoptHandler(CClientProxyUnknown::getFailureEvent(), client,
lib/server/CClientListener.cpp:		EVENTQUEUE->adoptHandler(CClientProxy::getDisconnectedEvent(), client,
lib/server/CClientProxy1_0.cpp:	EVENTQUEUE->adoptHandler(IStream::getInputReadyEvent(),
lib/server/CClientProxy1_0.cpp:	EVENTQUEUE->adoptHandler(IStream::getOutputErrorEvent(),
lib/server/CClientProxy1_0.cpp:	EVENTQUEUE->adoptHandler(IStream::getInputShutdownEvent(),
lib/server/CClientProxy1_0.cpp:	EVENTQUEUE->adoptHandler(IStream::getOutputShutdownEvent(),
lib/server/CClientProxy1_0.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, this,
lib/server/CClientProxy1_3.cpp:		EVENTQUEUE->adoptHandler(CEvent::kTimer, m_keepAliveTimer,
lib/server/CClientProxyUnknown.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, this,
lib/server/CClientProxyUnknown.cpp:	EVENTQUEUE->adoptHandler(IStream::getInputReadyEvent(),
lib/server/CClientProxyUnknown.cpp:	EVENTQUEUE->adoptHandler(IStream::getOutputErrorEvent(),
lib/server/CClientProxyUnknown.cpp:	EVENTQUEUE->adoptHandler(IStream::getInputShutdownEvent(),
lib/server/CClientProxyUnknown.cpp:	EVENTQUEUE->adoptHandler(IStream::getOutputShutdownEvent(),
lib/server/CClientProxyUnknown.cpp:	EVENTQUEUE->adoptHandler(CClientProxy::getReadyEvent(),
lib/server/CClientProxyUnknown.cpp:	EVENTQUEUE->adoptHandler(CClientProxy::getDisconnectedEvent(),
lib/server/CInputFilter.cpp:		EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyDownEvent(),
lib/server/CInputFilter.cpp:		EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyUpEvent(),
lib/server/CInputFilter.cpp:		EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyRepeatEvent(),
lib/server/CInputFilter.cpp:		EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonDownEvent(),
lib/server/CInputFilter.cpp:		EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonUpEvent(),
lib/server/CInputFilter.cpp:		EVENTQUEUE->adoptHandler(IPlatformScreen::getHotKeyDownEvent(),
lib/server/CInputFilter.cpp:		EVENTQUEUE->adoptHandler(IPlatformScreen::getHotKeyUpEvent(),
lib/server/CInputFilter.cpp:		EVENTQUEUE->adoptHandler(CServer::getConnectedEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, this,
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyDownEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyUpEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyRepeatEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonDownEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getButtonUpEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getMotionOnPrimaryEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getMotionOnSecondaryEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getWheelEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getScreensaverActivatedEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getScreensaverDeactivatedEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(getSwitchToScreenEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(getSwitchInDirectionEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(getLockCursorToScreenEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getFakeInputBeginEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IPlatformScreen::getFakeInputEndEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(CClientProxy::getDisconnectedEvent(), client,
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IScreen::getShapeChangedEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(IScreen::getClipboardGrabbedEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(CClientProxy::getClipboardChangedEvent(),
lib/server/CServer.cpp:	EVENTQUEUE->adoptHandler(CEvent::kTimer, timer,

ものすごい量です。しかし、今回知りたいKeyとかMouseとかはCInputFilter.cppとかCServer.cppに有るようですね。そこらへんを確認しましょう。



まずgetKeyDownEvent()です。
CServer.cpp

EVENTQUEUE->adoptHandler(IPlatformScreen::getKeyDownEvent(),
                                                        m_inputFilter,
                                                        new TMethodEventJob<CServer>(this,
                                                                &CServer::handleKeyDownEvent));

対応するのはhandleKeyDownEventのようです。

CServer::handleKeyDownEvent(const CEvent& event, void*)
{
        IPlatformScreen::CKeyInfo* info =
                reinterpret_cast<IPlatformScreen::CKeyInfo*>(event.getData());
        onKeyDown(info->m_key, info->m_mask, info->m_button, info->m_screens);
}

みると、onKeyDownというのを呼び出していますね。

CServer::onKeyDown(KeyID id, KeyModifierMask mask, KeyButton button,
                                const char* screens)
{
        LOG((CLOG_DEBUG1 "onKeyDown id=%d mask=0x%04x button=0x%04x", id, mask, button));
        assert(m_active != NULL);

        // relay
        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);
                        }
                }
        }
}

中ではkeyDownを呼び出しています。
このkeyDownはクライアントにkeyDownを実行するように通信しています。



具体的なソースには触れていませんが、MouseのClickやMoveも同様です。serverの所に居るならば、そのままですが、client上にカーソルが有る場合はそちらにイベントの実行を通知しています。

僕が働いているAzit.incでは一緒に働けるエンジニアを募集しています!
採用情報 — 株式会社アジット|Azit Inc.