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.
|
|
|
|
*/
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
#include "CPrimaryScreen.h"
|
|
|
|
#include "IScreen.h"
|
|
|
|
#include "IScreenReceiver.h"
|
|
|
|
#include "ProtocolTypes.h"
|
2002-07-16 20:52:26 +04:00
|
|
|
#include "CLock.h"
|
2002-07-14 02:00:38 +04:00
|
|
|
#include "CThread.h"
|
|
|
|
#include "CLog.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// CPrimaryScreen
|
|
|
|
//
|
|
|
|
|
|
|
|
CPrimaryScreen::CPrimaryScreen(IScreenReceiver* receiver) :
|
|
|
|
m_receiver(receiver),
|
|
|
|
m_active(false)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
CPrimaryScreen::~CPrimaryScreen()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-30 19:17:44 +04:00
|
|
|
CPrimaryScreen::mainLoop()
|
2002-07-14 02:00:38 +04:00
|
|
|
{
|
|
|
|
// change our priority
|
2003-05-03 16:37:03 +04:00
|
|
|
CThread::getCurrentThread().setPriority(-13);
|
2002-07-14 02:00:38 +04:00
|
|
|
|
|
|
|
// run event loop
|
|
|
|
try {
|
2002-10-16 01:29:44 +04:00
|
|
|
LOG((CLOG_DEBUG "entering event loop"));
|
2002-07-30 19:17:44 +04:00
|
|
|
onPreMainLoop();
|
2002-07-14 02:00:38 +04:00
|
|
|
getScreen()->mainLoop();
|
2002-07-30 19:17:44 +04:00
|
|
|
onPostMainLoop();
|
2002-10-16 01:29:44 +04:00
|
|
|
LOG((CLOG_DEBUG "exiting event loop"));
|
2002-07-14 02:00:38 +04:00
|
|
|
}
|
|
|
|
catch (...) {
|
2002-07-30 19:17:44 +04:00
|
|
|
onPostMainLoop();
|
2002-10-16 01:29:44 +04:00
|
|
|
LOG((CLOG_DEBUG "exiting event loop"));
|
2002-07-14 02:00:38 +04:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-30 19:17:44 +04:00
|
|
|
CPrimaryScreen::exitMainLoop()
|
2002-07-14 02:00:38 +04:00
|
|
|
{
|
|
|
|
getScreen()->exitMainLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::open()
|
|
|
|
{
|
|
|
|
CClientInfo info;
|
|
|
|
try {
|
|
|
|
// subclass hook
|
|
|
|
onPreOpen();
|
|
|
|
|
|
|
|
// open the screen
|
|
|
|
getScreen()->open();
|
|
|
|
|
|
|
|
// create and prepare our window
|
|
|
|
createWindow();
|
|
|
|
|
|
|
|
// collect screen info
|
|
|
|
getScreen()->getShape(info.m_x, info.m_y, info.m_w, info.m_h);
|
|
|
|
getScreen()->getCursorPos(info.m_mx, info.m_my);
|
|
|
|
info.m_zoneSize = getJumpZoneSize();
|
|
|
|
|
|
|
|
// update keyboard state
|
|
|
|
updateKeys();
|
|
|
|
|
|
|
|
// get notified of screen saver activation/deactivation
|
2002-07-15 19:01:36 +04:00
|
|
|
getScreen()->openScreensaver(true);
|
2002-07-14 02:00:38 +04:00
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPostOpen();
|
2002-12-23 16:55:21 +03:00
|
|
|
|
|
|
|
// reset options
|
|
|
|
resetOptions();
|
2002-07-14 02:00:38 +04:00
|
|
|
}
|
|
|
|
catch (...) {
|
|
|
|
close();
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
// enter the screen
|
2002-07-16 20:52:26 +04:00
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
enterNoWarp();
|
|
|
|
}
|
2002-07-14 02:00:38 +04:00
|
|
|
|
|
|
|
// send screen info
|
|
|
|
m_receiver->onInfoChanged(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::close()
|
|
|
|
{
|
|
|
|
onPreClose();
|
2002-07-15 19:01:36 +04:00
|
|
|
getScreen()->closeScreensaver();
|
2002-07-14 02:00:38 +04:00
|
|
|
destroyWindow();
|
|
|
|
getScreen()->close();
|
|
|
|
onPostClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::enter(SInt32 x, SInt32 y, bool forScreensaver)
|
|
|
|
{
|
2002-10-16 01:29:44 +04:00
|
|
|
LOG((CLOG_INFO "entering primary at %d,%d%s", x, y, forScreensaver ? " for screen saver" : ""));
|
2002-07-16 20:52:26 +04:00
|
|
|
CLock lock(&m_mutex);
|
2002-07-14 02:00:38 +04:00
|
|
|
assert(m_active == true);
|
|
|
|
|
|
|
|
if (!forScreensaver) {
|
|
|
|
warpCursor(x, y);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
onEnterScreensaver();
|
|
|
|
}
|
2002-07-19 21:39:45 +04:00
|
|
|
enterNoWarp();
|
2002-07-14 02:00:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::enterNoWarp()
|
|
|
|
{
|
2002-07-16 20:52:26 +04:00
|
|
|
// note -- must be locked on entry
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
// not active anymore
|
|
|
|
m_active = false;
|
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPreEnter();
|
|
|
|
|
|
|
|
// restore active window and hide our window
|
|
|
|
hideWindow();
|
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPostEnter();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CPrimaryScreen::leave()
|
|
|
|
{
|
2002-10-16 01:29:44 +04:00
|
|
|
LOG((CLOG_INFO "leaving primary"));
|
2002-07-16 20:52:26 +04:00
|
|
|
CLock lock(&m_mutex);
|
2002-07-14 02:00:38 +04:00
|
|
|
assert(m_active == false);
|
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPreLeave();
|
|
|
|
|
|
|
|
// show our window
|
|
|
|
if (!showWindow()) {
|
|
|
|
onPostLeave(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get keyboard state as we leave
|
|
|
|
updateKeys();
|
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPostLeave(true);
|
|
|
|
|
2002-07-17 21:27:41 +04:00
|
|
|
// warp mouse to center
|
|
|
|
warpCursorToCenter();
|
|
|
|
|
2002-07-14 02:00:38 +04:00
|
|
|
// local client now active
|
|
|
|
m_active = true;
|
|
|
|
|
|
|
|
// make sure our idea of clipboard ownership is correct
|
|
|
|
getScreen()->checkClipboards();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::setClipboard(ClipboardID id,
|
|
|
|
const IClipboard* clipboard)
|
|
|
|
{
|
|
|
|
getScreen()->setClipboard(id, clipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::grabClipboard(ClipboardID id)
|
|
|
|
{
|
|
|
|
getScreen()->setClipboard(id, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CPrimaryScreen::isActive() const
|
|
|
|
{
|
2002-07-16 20:52:26 +04:00
|
|
|
CLock lock(&m_mutex);
|
2002-07-14 02:00:38 +04:00
|
|
|
return m_active;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::getClipboard(ClipboardID id,
|
|
|
|
IClipboard* clipboard) const
|
|
|
|
{
|
|
|
|
getScreen()->getClipboard(id, clipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-30 19:17:44 +04:00
|
|
|
CPrimaryScreen::onPreMainLoop()
|
2002-07-14 02:00:38 +04:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-30 19:17:44 +04:00
|
|
|
CPrimaryScreen::onPostMainLoop()
|
2002-07-14 02:00:38 +04:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::onPreOpen()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::onPostOpen()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::onPreClose()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::onPostClose()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::onPreEnter()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::onPostEnter()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::onEnterScreensaver()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::onPreLeave()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimaryScreen::onPostLeave(bool)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|