2002-08-02 19:57:46 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2002-07-13 22:00:38 +00:00
|
|
|
#include "CSecondaryScreen.h"
|
|
|
|
#include "IScreen.h"
|
|
|
|
#include "CLock.h"
|
|
|
|
#include "CThread.h"
|
|
|
|
#include "CLog.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// CSecondaryScreen
|
|
|
|
//
|
|
|
|
|
2002-12-15 22:14:49 +00:00
|
|
|
CSecondaryScreen::CSecondaryScreen() :
|
2003-05-03 14:38:36 +00:00
|
|
|
m_remoteReady(false),
|
2002-12-15 22:14:49 +00:00
|
|
|
m_active(false),
|
2003-05-03 14:38:36 +00:00
|
|
|
m_toggleKeys(0),
|
|
|
|
m_screenSaverSync(true)
|
2002-07-13 22:00:38 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
CSecondaryScreen::~CSecondaryScreen()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-30 15:17:44 +00:00
|
|
|
CSecondaryScreen::mainLoop()
|
2002-07-13 22:00:38 +00:00
|
|
|
{
|
|
|
|
// change our priority
|
2003-05-03 12:37:03 +00:00
|
|
|
CThread::getCurrentThread().setPriority(-13);
|
2002-07-13 22:00:38 +00:00
|
|
|
|
|
|
|
// run event loop
|
|
|
|
try {
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "entering event loop"));
|
2002-07-30 15:17:44 +00:00
|
|
|
onPreMainLoop();
|
2002-07-13 22:00:38 +00:00
|
|
|
getScreen()->mainLoop();
|
2002-07-30 15:17:44 +00:00
|
|
|
onPostMainLoop();
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "exiting event loop"));
|
2002-07-13 22:00:38 +00:00
|
|
|
}
|
|
|
|
catch (...) {
|
2002-07-30 15:17:44 +00:00
|
|
|
onPostMainLoop();
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_DEBUG "exiting event loop"));
|
2002-07-13 22:00:38 +00:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-30 15:17:44 +00:00
|
|
|
CSecondaryScreen::exitMainLoop()
|
2002-07-13 22:00:38 +00:00
|
|
|
{
|
|
|
|
getScreen()->exitMainLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::open()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
// subclass hook
|
|
|
|
onPreOpen();
|
|
|
|
|
|
|
|
// open the screen
|
|
|
|
getScreen()->open();
|
|
|
|
|
|
|
|
// create and prepare our window
|
|
|
|
createWindow();
|
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPostOpen();
|
2002-12-23 13:55:21 +00:00
|
|
|
|
|
|
|
// reset options
|
|
|
|
resetOptions();
|
2002-07-13 22:00:38 +00:00
|
|
|
}
|
|
|
|
catch (...) {
|
|
|
|
close();
|
|
|
|
throw;
|
|
|
|
}
|
2003-03-12 22:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::close()
|
|
|
|
{
|
|
|
|
onPreClose();
|
|
|
|
destroyWindow();
|
|
|
|
getScreen()->close();
|
|
|
|
onPostClose();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::remoteControl()
|
|
|
|
{
|
|
|
|
// assume primary has all clipboards
|
|
|
|
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
|
|
|
|
grabClipboard(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// update keyboard state
|
|
|
|
updateKeys();
|
|
|
|
|
2003-05-03 14:38:36 +00:00
|
|
|
// now remote ready. fake being active for call to leave().
|
|
|
|
bool screenSaverSync;
|
2002-07-16 16:52:26 +00:00
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
2003-05-03 14:38:36 +00:00
|
|
|
m_remoteReady = true;
|
|
|
|
m_active = true;
|
|
|
|
|
|
|
|
// copy screen saver synchronization state
|
|
|
|
screenSaverSync = m_screenSaverSync;
|
|
|
|
}
|
|
|
|
|
|
|
|
// disable the screen saver if synchronization is enabled
|
|
|
|
if (screenSaverSync) {
|
|
|
|
getScreen()->openScreensaver(false);
|
2002-07-16 16:52:26 +00:00
|
|
|
}
|
2003-05-03 14:38:36 +00:00
|
|
|
|
|
|
|
// hide the cursor
|
2002-07-13 22:00:38 +00:00
|
|
|
leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-03-12 22:34:07 +00:00
|
|
|
CSecondaryScreen::localControl()
|
2002-07-13 22:00:38 +00:00
|
|
|
{
|
2002-07-15 15:01:36 +00:00
|
|
|
getScreen()->closeScreensaver();
|
2003-05-03 14:38:36 +00:00
|
|
|
|
|
|
|
// not remote ready anymore
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
m_remoteReady = false;
|
2002-07-13 22:00:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::enter(SInt32 x, SInt32 y, KeyModifierMask mask)
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
assert(m_active == false);
|
|
|
|
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_INFO "entering screen at %d,%d mask=%04x", x, y, mask));
|
2002-07-13 22:00:38 +00:00
|
|
|
|
|
|
|
getScreen()->syncDesktop();
|
|
|
|
|
|
|
|
// now active
|
|
|
|
m_active = true;
|
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPreEnter();
|
|
|
|
|
|
|
|
// update our keyboard state to reflect the local state
|
|
|
|
updateKeys();
|
|
|
|
|
2002-12-15 22:14:49 +00:00
|
|
|
// remember toggle key state
|
|
|
|
m_toggleKeys = getToggleState();
|
|
|
|
|
2002-07-13 22:00:38 +00:00
|
|
|
// toggle modifiers that don't match the desired state
|
|
|
|
setToggleState(mask);
|
|
|
|
|
|
|
|
// warp to requested location
|
|
|
|
warpCursor(x, y);
|
|
|
|
|
|
|
|
// show mouse
|
|
|
|
hideWindow();
|
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPostEnter();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::leave()
|
|
|
|
{
|
2002-10-15 21:29:44 +00:00
|
|
|
LOG((CLOG_INFO "leaving screen"));
|
2002-07-13 22:00:38 +00:00
|
|
|
CLock lock(&m_mutex);
|
|
|
|
assert(m_active == true);
|
|
|
|
|
|
|
|
getScreen()->syncDesktop();
|
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPreLeave();
|
|
|
|
|
2002-12-15 22:14:49 +00:00
|
|
|
// restore toggle key state
|
|
|
|
setToggleState(m_toggleKeys);
|
|
|
|
|
2003-05-03 13:50:06 +00:00
|
|
|
// warp and hide mouse
|
|
|
|
SInt32 x, y;
|
|
|
|
getScreen()->getCursorCenter(x, y);
|
|
|
|
showWindow(x, y);
|
2002-07-13 22:00:38 +00:00
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPostLeave();
|
|
|
|
|
|
|
|
// not active anymore
|
|
|
|
m_active = false;
|
|
|
|
|
|
|
|
// make sure our idea of clipboard ownership is correct
|
|
|
|
getScreen()->checkClipboards();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::setClipboard(ClipboardID id,
|
|
|
|
const IClipboard* clipboard)
|
|
|
|
{
|
|
|
|
getScreen()->setClipboard(id, clipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::grabClipboard(ClipboardID id)
|
|
|
|
{
|
|
|
|
getScreen()->setClipboard(id, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::screensaver(bool activate)
|
|
|
|
{
|
2003-05-03 14:38:36 +00:00
|
|
|
// get screen saver synchronization flag
|
|
|
|
bool screenSaverSync;
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
screenSaverSync = m_screenSaverSync;
|
|
|
|
}
|
|
|
|
|
|
|
|
// activate/deactivation screen saver iff synchronization enabled
|
|
|
|
if (screenSaverSync) {
|
|
|
|
getScreen()->screensaver(activate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::resetOptions()
|
|
|
|
{
|
|
|
|
// set screen saver synchronization flag and see if we need to
|
|
|
|
// update the screen saver synchronization.
|
|
|
|
bool screenSaverSyncOn;
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
screenSaverSyncOn = (!m_screenSaverSync && m_remoteReady);
|
|
|
|
m_screenSaverSync = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update screen saver synchronization
|
|
|
|
if (screenSaverSyncOn) {
|
|
|
|
getScreen()->openScreensaver(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::setOptions(const COptionsList& options)
|
|
|
|
{
|
|
|
|
// update options
|
|
|
|
bool updateScreenSaverSync = false;
|
|
|
|
bool oldScreenSaverSync;
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
oldScreenSaverSync = m_screenSaverSync;
|
|
|
|
for (UInt32 i = 0, n = options.size(); i < n; i += 2) {
|
|
|
|
if (options[i] == kOptionScreenSaverSync) {
|
|
|
|
updateScreenSaverSync = true;
|
|
|
|
m_screenSaverSync = (options[i + 1] != 0);
|
|
|
|
LOG((CLOG_DEBUG1 "screen saver synchronization %s", m_screenSaverSync ? "on" : "off"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!m_remoteReady || oldScreenSaverSync == m_screenSaverSync) {
|
|
|
|
updateScreenSaverSync = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update screen saver synchronization
|
|
|
|
if (updateScreenSaverSync) {
|
|
|
|
if (oldScreenSaverSync) {
|
|
|
|
getScreen()->closeScreensaver();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
getScreen()->openScreensaver(false);
|
|
|
|
}
|
|
|
|
}
|
2002-07-13 22:00:38 +00:00
|
|
|
}
|
|
|
|
|
2002-07-16 16:52:26 +00:00
|
|
|
bool
|
|
|
|
CSecondaryScreen::isActive() const
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
return m_active;
|
|
|
|
}
|
|
|
|
|
2002-07-13 22:00:38 +00:00
|
|
|
void
|
|
|
|
CSecondaryScreen::getClipboard(ClipboardID id,
|
|
|
|
IClipboard* clipboard) const
|
|
|
|
{
|
|
|
|
getScreen()->getClipboard(id, clipboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::getShape(SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
|
|
|
|
{
|
|
|
|
getScreen()->syncDesktop();
|
|
|
|
getScreen()->getShape(x, y, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::getCursorPos(SInt32& x, SInt32& y) const
|
|
|
|
{
|
|
|
|
getScreen()->syncDesktop();
|
|
|
|
getScreen()->getCursorPos(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-30 15:17:44 +00:00
|
|
|
CSecondaryScreen::onPreMainLoop()
|
2002-07-13 22:00:38 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-30 15:17:44 +00:00
|
|
|
CSecondaryScreen::onPostMainLoop()
|
2002-07-13 22:00:38 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::onPreOpen()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::onPostOpen()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::onPreClose()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::onPostClose()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::onPreEnter()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::onPostEnter()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::onPreLeave()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::onPostLeave()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|