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-21 21:22:14 +00:00
|
|
|
CThread::getCurrentThread().setPriority(-14);
|
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();
|
|
|
|
|
2003-07-05 17:05:12 +00:00
|
|
|
// create and prepare our window. pretend we're active so
|
|
|
|
// we don't try to show our window until later.
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
assert(m_active == false);
|
|
|
|
m_active = true;
|
|
|
|
}
|
2002-07-13 22:00:38 +00:00
|
|
|
createWindow();
|
2003-07-05 17:05:12 +00:00
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
m_active = false;
|
|
|
|
}
|
2002-07-13 22:00:38 +00:00
|
|
|
|
|
|
|
// 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
|
2003-07-26 13:41:41 +00:00
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
updateKeys();
|
|
|
|
}
|
2003-03-12 22:34:07 +00:00
|
|
|
|
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
|
|
|
|
2003-07-26 13:41:41 +00:00
|
|
|
sync();
|
2002-07-13 22:00:38 +00:00
|
|
|
|
|
|
|
// now active
|
|
|
|
m_active = true;
|
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPreEnter();
|
|
|
|
|
|
|
|
// update our keyboard state to reflect the local state
|
|
|
|
updateKeys();
|
|
|
|
|
2003-07-26 13:41:41 +00:00
|
|
|
// toggle modifiers that don't match the desired state and
|
|
|
|
// remember previous toggle key state.
|
|
|
|
m_toggleKeys = m_mask;
|
2002-07-13 22:00:38 +00:00
|
|
|
setToggleState(mask);
|
|
|
|
|
|
|
|
// warp to requested location
|
2003-07-26 13:41:41 +00:00
|
|
|
fakeMouseMove(x, y);
|
2002-07-13 22:00:38 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2003-07-26 13:41:41 +00:00
|
|
|
sync();
|
2002-07-13 22:00:38 +00:00
|
|
|
|
|
|
|
// subclass hook
|
|
|
|
onPreLeave();
|
|
|
|
|
2002-12-15 22:14:49 +00:00
|
|
|
// restore toggle key state
|
|
|
|
setToggleState(m_toggleKeys);
|
|
|
|
|
2003-07-26 13:41:41 +00:00
|
|
|
// hide mouse
|
2003-05-03 13:50:06 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-26 13:41:41 +00:00
|
|
|
CSecondaryScreen::SysKeyID
|
|
|
|
CSecondaryScreen::getUnhanded(SysKeyID) const
|
|
|
|
{
|
|
|
|
// no key represents both left and right sides of any key
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSecondaryScreen::SysKeyID
|
|
|
|
CSecondaryScreen::getOtherHanded(SysKeyID) const
|
|
|
|
{
|
|
|
|
// no key represents both left and right sides of any key
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CSecondaryScreen::synthesizeCtrlAltDel(EKeyAction)
|
|
|
|
{
|
|
|
|
// pass keys through unchanged
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::sync() const
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::flush()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::doKeystrokes(const Keystrokes& keys, SInt32 count)
|
|
|
|
{
|
|
|
|
// do nothing if no keys or no repeats
|
|
|
|
if (count < 1 || keys.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate key events
|
|
|
|
LOG((CLOG_DEBUG2 "keystrokes:"));
|
|
|
|
for (Keystrokes::const_iterator k = keys.begin(); k != keys.end(); ) {
|
|
|
|
if (k->m_repeat) {
|
|
|
|
// repeat from here up to but not including the next key
|
|
|
|
// with m_repeat == false count times.
|
|
|
|
Keystrokes::const_iterator start = k;
|
|
|
|
for (; count > 0; --count) {
|
|
|
|
// send repeating events
|
|
|
|
for (k = start; k != keys.end() && k->m_repeat; ++k) {
|
|
|
|
LOG((CLOG_DEBUG2 " %d %s repeat", k->m_sysKeyID, k->m_press ? "down" : "up"));
|
|
|
|
fakeKeyEvent(k->m_sysKeyID, k->m_press);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// note -- k is now on the first non-repeat key after the
|
|
|
|
// repeat keys, exactly where we'd like to continue from.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// send event
|
|
|
|
LOG((CLOG_DEBUG2 " %d %s", k->m_sysKeyID, k->m_press ? "down" : "up"));
|
|
|
|
fakeKeyEvent(k->m_sysKeyID, k->m_press);
|
|
|
|
|
|
|
|
// next key
|
|
|
|
++k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::keyDown(KeyID key,
|
|
|
|
KeyModifierMask mask, KeyButton button)
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
sync();
|
|
|
|
|
|
|
|
// check for ctrl+alt+del emulation
|
|
|
|
if (key == kKeyDelete &&
|
|
|
|
(mask & (KeyModifierControl | KeyModifierAlt)) ==
|
|
|
|
(KeyModifierControl | KeyModifierAlt)) {
|
|
|
|
LOG((CLOG_DEBUG "emulating ctrl+alt+del press"));
|
|
|
|
if (synthesizeCtrlAltDel(kPress)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the sequence of keys to simulate key press and the final
|
|
|
|
// modifier state.
|
|
|
|
Keystrokes keys;
|
|
|
|
SysKeyID sysKeyID;
|
|
|
|
m_mask = mapKey(keys, sysKeyID, key, m_mask, mask, kPress);
|
|
|
|
if (keys.empty()) {
|
|
|
|
// do nothing if there are no associated keys (i.e. lookup failed)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sysKeyID &= 0xffu;
|
|
|
|
|
|
|
|
// generate key events
|
|
|
|
doKeystrokes(keys, 1);
|
|
|
|
|
|
|
|
// do not record button down if button or system key is 0 (invalid)
|
|
|
|
if (button != 0 && sysKeyID != 0) {
|
|
|
|
// note that key is now down
|
|
|
|
SysKeyID unhandedSysKeyID = getUnhanded(sysKeyID);
|
|
|
|
m_serverKeyMap[button] = sysKeyID;
|
|
|
|
m_keys[sysKeyID] |= kDown;
|
|
|
|
m_fakeKeys[sysKeyID] |= kDown;
|
|
|
|
if (unhandedSysKeyID != 0) {
|
|
|
|
m_keys[unhandedSysKeyID] |= kDown;
|
|
|
|
m_fakeKeys[unhandedSysKeyID] |= kDown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::keyRepeat(KeyID key,
|
|
|
|
KeyModifierMask mask, SInt32 count, KeyButton button)
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
sync();
|
|
|
|
|
|
|
|
// if we haven't seen this button go down then ignore it
|
|
|
|
ServerKeyMap::iterator index = m_serverKeyMap.find(button);
|
|
|
|
if (index == m_serverKeyMap.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the sequence of keys to simulate key repeat and the final
|
|
|
|
// modifier state.
|
|
|
|
Keystrokes keys;
|
|
|
|
SysKeyID sysKeyID;
|
|
|
|
m_mask = mapKey(keys, sysKeyID, key, m_mask, mask, kRepeat);
|
|
|
|
if (keys.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sysKeyID &= 0xffu;
|
|
|
|
|
|
|
|
// if this key shouldn't auto-repeat then ignore
|
|
|
|
if (!isAutoRepeating(sysKeyID)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the keycode for the auto-repeat is not the same as for the
|
|
|
|
// initial press then mark the initial key as released and the new
|
|
|
|
// key as pressed. this can happen when we auto-repeat after a
|
|
|
|
// dead key. for example, a dead accent followed by 'a' will
|
|
|
|
// generate an 'a with accent' followed by a repeating 'a'. the
|
|
|
|
// keycodes for the two keysyms might be different.
|
|
|
|
if (sysKeyID != index->second) {
|
|
|
|
// replace key up with previous key id but leave key down
|
|
|
|
// alone so it uses the new keycode and store that keycode
|
|
|
|
// in the server key map.
|
|
|
|
for (Keystrokes::iterator index2 = keys.begin();
|
|
|
|
index2 != keys.end(); ++index2) {
|
|
|
|
if ((index2->m_sysKeyID & 0xffu) == sysKeyID) {
|
|
|
|
index2->m_sysKeyID = index->second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// note that old key is now up
|
|
|
|
m_keys[index->second] &= ~kDown;
|
|
|
|
m_fakeKeys[index->second] &= ~kDown;
|
|
|
|
|
|
|
|
// map server key to new key
|
|
|
|
index->second = sysKeyID;
|
|
|
|
|
|
|
|
// note that new key is now down
|
|
|
|
m_keys[index->second] |= kDown;
|
|
|
|
m_fakeKeys[index->second] |= kDown;
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate key events
|
|
|
|
doKeystrokes(keys, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::keyUp(KeyID key, KeyModifierMask mask, KeyButton button)
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
sync();
|
|
|
|
|
|
|
|
// if we haven't seen this button go down then ignore it
|
|
|
|
ServerKeyMap::iterator index = m_serverKeyMap.find(button);
|
|
|
|
if (index == m_serverKeyMap.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SysKeyID sysKeyID = index->second;
|
|
|
|
|
|
|
|
// check for ctrl+alt+del emulation
|
|
|
|
if (key == kKeyDelete &&
|
|
|
|
(mask & (KeyModifierControl | KeyModifierAlt)) ==
|
|
|
|
(KeyModifierControl | KeyModifierAlt)) {
|
|
|
|
LOG((CLOG_DEBUG "emulating ctrl+alt+del release"));
|
|
|
|
if (synthesizeCtrlAltDel(kRelease)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the sequence of keys to simulate key release
|
|
|
|
Keystrokes keys;
|
|
|
|
Keystroke keystroke;
|
|
|
|
keystroke.m_sysKeyID = sysKeyID;
|
|
|
|
keystroke.m_press = false;
|
|
|
|
keystroke.m_repeat = false;
|
|
|
|
keys.push_back(keystroke);
|
|
|
|
|
|
|
|
// generate key events
|
|
|
|
doKeystrokes(keys, 1);
|
|
|
|
|
|
|
|
// note that key is now up
|
|
|
|
SysKeyID unhandedSysKeyID = getUnhanded(sysKeyID);
|
|
|
|
m_serverKeyMap.erase(index);
|
|
|
|
m_keys[sysKeyID] &= ~kDown;
|
|
|
|
m_fakeKeys[sysKeyID] &= ~kDown;
|
|
|
|
if (unhandedSysKeyID != 0) {
|
|
|
|
SysKeyID otherHandedSysKeyID = getOtherHanded(sysKeyID);
|
|
|
|
if ((m_keys[otherHandedSysKeyID] & kDown) == 0) {
|
|
|
|
m_keys[unhandedSysKeyID] &= ~kDown;
|
|
|
|
m_fakeKeys[unhandedSysKeyID] &= ~kDown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the new modifier state
|
|
|
|
mask = getModifierKeyMask(sysKeyID);
|
|
|
|
if (mask != 0) {
|
|
|
|
// key is a modifier key
|
|
|
|
if ((mask & (KeyModifierCapsLock |
|
|
|
|
KeyModifierNumLock |
|
|
|
|
KeyModifierScrollLock)) != 0) {
|
|
|
|
// modifier is a toggle
|
|
|
|
m_mask ^= mask;
|
|
|
|
}
|
|
|
|
else if (!isModifierActive(sysKeyID)) {
|
|
|
|
// all keys for this modifier are released
|
|
|
|
m_mask &= ~mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::mouseDown(ButtonID button)
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
sync();
|
|
|
|
fakeMouseButton(button, true);
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::mouseUp(ButtonID button)
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
sync();
|
|
|
|
fakeMouseButton(button, false);
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::mouseMove(SInt32 x, SInt32 y)
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
sync();
|
|
|
|
fakeMouseMove(x, y);
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::mouseWheel(SInt32 delta)
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
sync();
|
|
|
|
fakeMouseWheel(delta);
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::setToggleState(KeyModifierMask mask)
|
|
|
|
{
|
|
|
|
// toggle modifiers that don't match the desired state
|
|
|
|
KeyModifierMask different = (m_mask ^ mask);
|
|
|
|
if ((different & KeyModifierCapsLock) != 0) {
|
|
|
|
toggleKey(kKeyCapsLock, KeyModifierCapsLock);
|
|
|
|
}
|
|
|
|
if ((different & KeyModifierNumLock) != 0) {
|
|
|
|
toggleKey(kKeyNumLock, KeyModifierNumLock);
|
|
|
|
}
|
|
|
|
if ((different & KeyModifierScrollLock) != 0) {
|
|
|
|
toggleKey(kKeyScrollLock, KeyModifierScrollLock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-03 14:38:36 +00:00
|
|
|
void
|
|
|
|
CSecondaryScreen::resetOptions()
|
|
|
|
{
|
|
|
|
// set screen saver synchronization flag and see if we need to
|
2003-07-26 13:41:41 +00:00
|
|
|
// update the screen saver synchronization. reset other options.
|
2003-05-03 14:38:36 +00:00
|
|
|
bool screenSaverSyncOn;
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
2003-07-26 13:41:41 +00:00
|
|
|
screenSaverSyncOn = (!m_screenSaverSync && m_remoteReady);
|
|
|
|
m_screenSaverSync = true;
|
|
|
|
m_numLockHalfDuplex = false;
|
|
|
|
m_capsLockHalfDuplex = false;
|
2003-05-03 14:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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"));
|
|
|
|
}
|
2003-07-26 13:41:41 +00:00
|
|
|
else if (options[i] == kOptionHalfDuplexCapsLock) {
|
|
|
|
m_capsLockHalfDuplex = (options[i + 1] != 0);
|
|
|
|
LOG((CLOG_DEBUG1 "half-duplex caps-lock %s", m_capsLockHalfDuplex ? "on" : "off"));
|
|
|
|
}
|
|
|
|
else if (options[i] == kOptionHalfDuplexNumLock) {
|
|
|
|
m_numLockHalfDuplex = (options[i + 1] != 0);
|
|
|
|
LOG((CLOG_DEBUG1 "half-duplex num-lock %s", m_numLockHalfDuplex ? "on" : "off"));
|
|
|
|
}
|
2003-05-03 14:38:36 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2003-07-26 13:41:41 +00:00
|
|
|
SInt32
|
|
|
|
CSecondaryScreen::getJumpZoneSize() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-13 22:00:38 +00:00
|
|
|
void
|
|
|
|
CSecondaryScreen::getShape(SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
|
|
|
|
{
|
2003-07-26 13:41:41 +00:00
|
|
|
sync();
|
2002-07-13 22:00:38 +00:00
|
|
|
getScreen()->getShape(x, y, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::getCursorPos(SInt32& x, SInt32& y) const
|
|
|
|
{
|
2003-07-26 13:41:41 +00:00
|
|
|
sync();
|
2002-07-13 22:00:38 +00:00
|
|
|
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
|
|
|
|
}
|
2003-07-26 13:41:41 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::updateKeys()
|
|
|
|
{
|
|
|
|
sync();
|
|
|
|
|
|
|
|
// clear key state
|
|
|
|
memset(m_keys, 0, sizeof(m_keys));
|
|
|
|
memset(m_fakeKeys, 0, sizeof(m_fakeKeys));
|
|
|
|
|
|
|
|
// let subclass set m_keys
|
|
|
|
updateKeys(m_keys);
|
|
|
|
|
|
|
|
// get m_mask from subclass
|
|
|
|
m_mask = getModifiers();
|
|
|
|
LOG((CLOG_DEBUG2 "modifiers on update: 0x%04x", m_mask));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::releaseKeys()
|
|
|
|
{
|
|
|
|
CLock lock(&m_mutex);
|
|
|
|
sync();
|
|
|
|
|
|
|
|
// release keys that we've synthesized a press for and only those
|
|
|
|
// keys. we don't want to synthesize a release on a key the user
|
|
|
|
// is still physically pressing.
|
|
|
|
for (UInt32 i = 1; i < 256; ++i) {
|
|
|
|
if ((m_fakeKeys[i] & kDown) != 0) {
|
|
|
|
fakeKeyEvent(i, false);
|
|
|
|
m_keys[i] &= ~kDown;
|
|
|
|
m_fakeKeys[i] &= ~kDown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSecondaryScreen::toggleKey(KeyID keyID, KeyModifierMask mask)
|
|
|
|
{
|
|
|
|
// get the system key ID for this toggle key ID
|
|
|
|
SysKeyID sysKeyID = getToggleSysKey(keyID);
|
|
|
|
if (sysKeyID == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// toggle the key
|
|
|
|
if (isKeyHalfDuplex(keyID)) {
|
|
|
|
// "half-duplex" toggle
|
|
|
|
fakeKeyEvent(sysKeyID, (m_mask & mask) == 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// normal toggle
|
|
|
|
fakeKeyEvent(sysKeyID, true);
|
|
|
|
fakeKeyEvent(sysKeyID, false);
|
|
|
|
}
|
|
|
|
flush();
|
|
|
|
|
|
|
|
// toggle shadow state
|
|
|
|
m_mask ^= mask;
|
|
|
|
sysKeyID &= 0xffu;
|
|
|
|
m_keys[sysKeyID] ^= kToggled;
|
|
|
|
m_fakeKeys[sysKeyID] ^= kToggled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CSecondaryScreen::isKeyDown(SysKeyID sysKeyID) const
|
|
|
|
{
|
|
|
|
sysKeyID &= 0xffu;
|
|
|
|
return (sysKeyID != 0 && ((m_keys[sysKeyID] & kDown) != 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CSecondaryScreen::isKeyToggled(SysKeyID sysKeyID) const
|
|
|
|
{
|
|
|
|
sysKeyID &= 0xffu;
|
|
|
|
return (sysKeyID != 0 && ((m_keys[sysKeyID] & kToggled) != 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CSecondaryScreen::isKeyHalfDuplex(KeyID keyID) const
|
|
|
|
{
|
|
|
|
return ((keyID == kKeyCapsLock && m_capsLockHalfDuplex) ||
|
|
|
|
(keyID == kKeyNumLock && m_numLockHalfDuplex));
|
|
|
|
}
|