deskflow/src/lib/synergy/Screen.cpp

532 lines
10 KiB
C++
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* synergy -- mouse and keyboard sharing utility
2016-09-07 14:24:00 +00:00
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2003 Chris Schoeneman
2012-06-10 16:50:54 +00:00
*
* 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 LICENSE that should have accompanied this file.
2012-06-10 16:50:54 +00:00
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "synergy/Screen.h"
#include "synergy/IPlatformScreen.h"
#include "synergy/protocol_types.h"
#include "base/Log.h"
#include "base/IEventQueue.h"
#include "server/ClientProxy.h"
#include "base/TMethodEventJob.h"
2012-06-10 16:50:54 +00:00
namespace synergy {
2012-06-10 16:50:54 +00:00
//
2014-11-11 13:51:47 +00:00
// Screen
2012-06-10 16:50:54 +00:00
//
2014-11-11 13:51:47 +00:00
Screen::Screen(IPlatformScreen* platformScreen, IEventQueue* events) :
m_screen(platformScreen),
m_isPrimary(platformScreen->isPrimary()),
m_enabled(false),
m_entered(m_isPrimary),
m_fakeInput(false),
m_events(events),
m_mock(false),
m_enableDragDrop(false)
2012-06-10 16:50:54 +00:00
{
assert(m_screen != NULL);
2012-06-10 16:50:54 +00:00
// reset options
resetOptions();
2012-06-10 16:50:54 +00:00
LOG((CLOG_DEBUG "opened display"));
2012-06-10 16:50:54 +00:00
}
2014-11-11 13:51:47 +00:00
Screen::~Screen()
2012-06-10 16:50:54 +00:00
{
if (m_mock) {
return;
}
if (m_enabled) {
disable();
}
assert(!m_enabled);
assert(m_entered == m_isPrimary);
delete m_screen;
LOG((CLOG_DEBUG "closed display"));
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::enable()
2012-06-10 16:50:54 +00:00
{
assert(!m_enabled);
2012-06-10 16:50:54 +00:00
m_screen->updateKeyMap();
m_screen->updateKeyState();
m_screen->enable();
if (m_isPrimary) {
enablePrimary();
}
else {
enableSecondary();
}
2012-06-10 16:50:54 +00:00
// note activation
m_enabled = true;
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::disable()
2012-06-10 16:50:54 +00:00
{
assert(m_enabled);
2012-06-10 16:50:54 +00:00
if (!m_isPrimary && m_entered) {
leave();
}
else if (m_isPrimary && !m_entered) {
enter(0);
}
m_screen->disable();
if (m_isPrimary) {
disablePrimary();
}
else {
disableSecondary();
}
2012-06-10 16:50:54 +00:00
// note deactivation
m_enabled = false;
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::enter(KeyModifierMask toggleMask)
2012-06-10 16:50:54 +00:00
{
assert(m_entered == false);
LOG((CLOG_INFO "entering screen"));
2012-06-10 16:50:54 +00:00
// now on screen
m_entered = true;
2012-06-10 16:50:54 +00:00
m_screen->enter();
if (m_isPrimary) {
enterPrimary();
}
else {
enterSecondary(toggleMask);
}
2012-06-10 16:50:54 +00:00
}
bool
2014-11-11 13:51:47 +00:00
Screen::leave()
2012-06-10 16:50:54 +00:00
{
assert(m_entered == true);
LOG((CLOG_INFO "leaving screen"));
2012-06-10 16:50:54 +00:00
if (!m_screen->leave()) {
return false;
}
if (m_isPrimary) {
leavePrimary();
}
else {
leaveSecondary();
}
2012-06-10 16:50:54 +00:00
// make sure our idea of clipboard ownership is correct
m_screen->checkClipboards();
2012-06-10 16:50:54 +00:00
// now not on screen
m_entered = false;
2012-06-10 16:50:54 +00:00
return true;
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::reconfigure(UInt32 activeSides)
2012-06-10 16:50:54 +00:00
{
assert(m_isPrimary);
m_screen->reconfigure(activeSides);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::warpCursor(SInt32 x, SInt32 y)
2012-06-10 16:50:54 +00:00
{
assert(m_isPrimary);
m_screen->warpCursor(x, y);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::setClipboard(ClipboardID id, const IClipboard* clipboard)
2012-06-10 16:50:54 +00:00
{
m_screen->setClipboard(id, clipboard);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::grabClipboard(ClipboardID id)
2012-06-10 16:50:54 +00:00
{
m_screen->setClipboard(id, NULL);
2012-06-10 16:50:54 +00:00
}
void
Screen::screensaver(bool) const
2012-06-10 16:50:54 +00:00
{
// do nothing
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::keyDown(KeyID id, KeyModifierMask mask, KeyButton button)
2012-06-10 16:50:54 +00:00
{
// check for ctrl+alt+del emulation
if (id == kKeyDelete &&
(mask & (KeyModifierControl | KeyModifierAlt)) ==
(KeyModifierControl | KeyModifierAlt)) {
LOG((CLOG_DEBUG "emulating ctrl+alt+del press"));
if (m_screen->fakeCtrlAltDel()) {
return;
}
}
m_screen->fakeKeyDown(id, mask, button);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::keyRepeat(KeyID id,
KeyModifierMask mask, SInt32 count, KeyButton button)
2012-06-10 16:50:54 +00:00
{
assert(!m_isPrimary);
m_screen->fakeKeyRepeat(id, mask, count, button);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::keyUp(KeyID, KeyModifierMask, KeyButton button)
2012-06-10 16:50:54 +00:00
{
m_screen->fakeKeyUp(button);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::mouseDown(ButtonID button)
2012-06-10 16:50:54 +00:00
{
m_screen->fakeMouseButton(button, true);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::mouseUp(ButtonID button)
2012-06-10 16:50:54 +00:00
{
m_screen->fakeMouseButton(button, false);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::mouseMove(SInt32 x, SInt32 y)
2012-06-10 16:50:54 +00:00
{
assert(!m_isPrimary);
m_screen->fakeMouseMove(x, y);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::mouseRelativeMove(SInt32 dx, SInt32 dy)
2012-06-10 16:50:54 +00:00
{
assert(!m_isPrimary);
m_screen->fakeMouseRelativeMove(dx, dy);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::mouseWheel(SInt32 xDelta, SInt32 yDelta)
2012-06-10 16:50:54 +00:00
{
assert(!m_isPrimary);
m_screen->fakeMouseWheel(xDelta, yDelta);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::resetOptions()
2012-06-10 16:50:54 +00:00
{
// reset options
m_halfDuplex = 0;
2012-06-10 16:50:54 +00:00
// let screen handle its own options
m_screen->resetOptions();
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::setOptions(const OptionsList& options)
2012-06-10 16:50:54 +00:00
{
// update options
for (UInt32 i = 0, n = (UInt32)options.size(); i < n; i += 2) {
if (options[i] == kOptionHalfDuplexCapsLock) {
if (options[i + 1] != 0) {
m_halfDuplex |= KeyModifierCapsLock;
}
else {
m_halfDuplex &= ~KeyModifierCapsLock;
}
LOG((CLOG_DEBUG1 "half-duplex caps-lock %s", ((m_halfDuplex & KeyModifierCapsLock) != 0) ? "on" : "off"));
}
else if (options[i] == kOptionHalfDuplexNumLock) {
if (options[i + 1] != 0) {
m_halfDuplex |= KeyModifierNumLock;
}
else {
m_halfDuplex &= ~KeyModifierNumLock;
}
LOG((CLOG_DEBUG1 "half-duplex num-lock %s", ((m_halfDuplex & KeyModifierNumLock) != 0) ? "on" : "off"));
}
else if (options[i] == kOptionHalfDuplexScrollLock) {
if (options[i + 1] != 0) {
m_halfDuplex |= KeyModifierScrollLock;
}
else {
m_halfDuplex &= ~KeyModifierScrollLock;
}
LOG((CLOG_DEBUG1 "half-duplex scroll-lock %s", ((m_halfDuplex & KeyModifierScrollLock) != 0) ? "on" : "off"));
}
}
// update half-duplex options
m_screen->setHalfDuplexMask(m_halfDuplex);
// let screen handle its own options
m_screen->setOptions(options);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::setSequenceNumber(UInt32 seqNum)
2012-06-10 16:50:54 +00:00
{
m_screen->setSequenceNumber(seqNum);
2012-06-10 16:50:54 +00:00
}
UInt32
2014-11-11 13:51:47 +00:00
Screen::registerHotKey(KeyID key, KeyModifierMask mask)
2012-06-10 16:50:54 +00:00
{
return m_screen->registerHotKey(key, mask);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::unregisterHotKey(UInt32 id)
2012-06-10 16:50:54 +00:00
{
m_screen->unregisterHotKey(id);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::fakeInputBegin()
2012-06-10 16:50:54 +00:00
{
assert(!m_fakeInput);
2012-06-10 16:50:54 +00:00
m_fakeInput = true;
m_screen->fakeInputBegin();
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::fakeInputEnd()
2012-06-10 16:50:54 +00:00
{
assert(m_fakeInput);
2012-06-10 16:50:54 +00:00
m_fakeInput = false;
m_screen->fakeInputEnd();
2012-06-10 16:50:54 +00:00
}
bool
2014-11-11 13:51:47 +00:00
Screen::isOnScreen() const
2012-06-10 16:50:54 +00:00
{
return m_entered;
2012-06-10 16:50:54 +00:00
}
bool
2014-11-11 13:51:47 +00:00
Screen::isLockedToScreen() const
2012-06-10 16:50:54 +00:00
{
// check for pressed mouse buttons
// HACK: commented out as it breaks new drag drop feature
UInt32 buttonID = 0;
if (m_screen->isAnyMouseButtonDown(buttonID)) {
if (buttonID != kButtonLeft) {
LOG((CLOG_DEBUG "locked by mouse buttonID: %d", buttonID));
}
if (m_enableDragDrop) {
return (buttonID == kButtonLeft) ? false : true;
}
else {
return true;
}
}
2012-06-10 16:50:54 +00:00
// not locked
return false;
2012-06-10 16:50:54 +00:00
}
SInt32
2014-11-11 13:51:47 +00:00
Screen::getJumpZoneSize() const
2012-06-10 16:50:54 +00:00
{
if (!m_isPrimary) {
return 0;
}
else {
return m_screen->getJumpZoneSize();
}
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::getCursorCenter(SInt32& x, SInt32& y) const
2012-06-10 16:50:54 +00:00
{
m_screen->getCursorCenter(x, y);
2012-06-10 16:50:54 +00:00
}
KeyModifierMask
2014-11-11 13:51:47 +00:00
Screen::getActiveModifiers() const
2012-06-10 16:50:54 +00:00
{
return m_screen->getActiveModifiers();
2012-06-10 16:50:54 +00:00
}
KeyModifierMask
2014-11-11 13:51:47 +00:00
Screen::pollActiveModifiers() const
2012-06-10 16:50:54 +00:00
{
return m_screen->pollActiveModifiers();
2012-06-10 16:50:54 +00:00
}
bool
2014-11-11 13:51:47 +00:00
Screen::isDraggingStarted() const
{
return m_screen->isDraggingStarted();
}
bool
2014-11-11 13:51:47 +00:00
Screen::isFakeDraggingStarted() const
{
return m_screen->isFakeDraggingStarted();
}
void
2014-11-11 13:51:47 +00:00
Screen::setDraggingStarted(bool started)
{
m_screen->setDraggingStarted(started);
}
void
2014-11-11 13:51:47 +00:00
Screen::startDraggingFiles(DragFileList& fileList)
{
m_screen->fakeDraggingFiles(fileList);
}
void
2014-11-11 13:51:47 +00:00
Screen::setEnableDragDrop(bool enabled)
{
m_enableDragDrop = enabled;
}
2014-11-11 13:51:47 +00:00
String&
Screen::getDraggingFilename() const
{
return m_screen->getDraggingFilename();
}
void
2014-11-11 13:51:47 +00:00
Screen::clearDraggingFilename()
{
m_screen->clearDraggingFilename();
}
2014-11-11 13:51:47 +00:00
const String&
Screen::getDropTarget() const
{
return m_screen->getDropTarget();
}
2012-06-10 16:50:54 +00:00
void*
2014-11-11 13:51:47 +00:00
Screen::getEventTarget() const
2012-06-10 16:50:54 +00:00
{
return m_screen;
2012-06-10 16:50:54 +00:00
}
bool
2014-11-11 13:51:47 +00:00
Screen::getClipboard(ClipboardID id, IClipboard* clipboard) const
2012-06-10 16:50:54 +00:00
{
return m_screen->getClipboard(id, clipboard);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::getShape(SInt32& x, SInt32& y, SInt32& w, SInt32& h) const
2012-06-10 16:50:54 +00:00
{
m_screen->getShape(x, y, w, h);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::getCursorPos(SInt32& x, SInt32& y) const
2012-06-10 16:50:54 +00:00
{
m_screen->getCursorPos(x, y);
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::enablePrimary()
2012-06-10 16:50:54 +00:00
{
// get notified of screen saver activation/deactivation
m_screen->openScreensaver(true);
2012-06-10 16:50:54 +00:00
// claim screen changed size
m_events->addEvent(Event(m_events->forIScreen().shapeChanged(), getEventTarget()));
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::enableSecondary()
2012-06-10 16:50:54 +00:00
{
// assume primary has all clipboards
for (ClipboardID id = 0; id < kClipboardEnd; ++id) {
grabClipboard(id);
}
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::disablePrimary()
2012-06-10 16:50:54 +00:00
{
// done with screen saver
m_screen->closeScreensaver();
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::disableSecondary()
2012-06-10 16:50:54 +00:00
{
// done with screen saver
m_screen->closeScreensaver();
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::enterPrimary()
2012-06-10 16:50:54 +00:00
{
// do nothing
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::enterSecondary(KeyModifierMask)
2012-06-10 16:50:54 +00:00
{
// do nothing
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::leavePrimary()
2012-06-10 16:50:54 +00:00
{
// we don't track keys while on the primary screen so update our
// idea of them now. this is particularly to update the state of
// the toggle modifiers.
m_screen->updateKeyState();
2012-06-10 16:50:54 +00:00
}
void
2014-11-11 13:51:47 +00:00
Screen::leaveSecondary()
2012-06-10 16:50:54 +00:00
{
// release any keys we think are still down
m_screen->fakeAllKeysUp();
2012-06-10 16:50:54 +00:00
}
SYNERGY-1032 - Use native notifications for secure input on MacOS (#7041) * SYNERGY-1017 - Try usnig NSUserNotification * SYNERGY-1032 - Use UNUserNotificationCenter instead of deprecated notifications * SYNERGY-1032 - Update app delegate and add log after notification access * SYNERGY-1032 - Try using deprecated notification * SYNERGY-1032 - Add notifications to the platform dependant code * SYNERGY-1032 - Check for development builds before asking permission for notifications * SYNERGY-1032 - Remove old notification and secure input detection * SYNERGY-1032 - Add permission request to the main app * SYNERGY-1032 - Only show notifications on server * SYNERGY-1032 - Request and show notification from main app * SYNERGY-1032 - Remove logging from OSX helpers * SYNERGY-1032 - Add UN notification for testing * SYNERGY-1032 - Show notification once * SYNERGY-1032 - Try replicating old flow * SYNERGY-1032 - Reuse notification center * SYNERGY-1032 - Send notification after granting permission * SYNERGY-1032 - Update app delegate * SYNERGY-1032 - Remove deprecated property * SYNERGY-1032 - Add output for debugging * SYNERGY-1032 - Try updating delegate * SYNERGY-1032 - Print current bundle name * SYNERGY-1032 - Add AppDelegate to the server * SYNERGY-1032 - Move notification creation to synergy app * SYNERGY-1032 - Update notification text * SYNERGY-1032 - Fix QString conversion for notification * SYNERGY-1032 - Move notification creation outside the handler * SYNERGY-1032 - Remove debug notification, show notification with no delay * SYNERGY-1032 - Show notification inside the completion handler * SYNERGY-1032 - Remove timed notification trigger * SYNERGY-1032 - Request permissions on synergy start * SYNERGY-1032 - Remove unused includes * SYNERGY-1032 - Update changelog * SYNERGY-1032 - Add empty notification implementations for Windows and Linux * SYNERGY-1032 - Removed temporary debug messages * SYNERGY-1032 - Resolve code smell
2021-06-29 10:20:56 +00:00
void
Screen::createNotification(const String& title, const String& content) const
{
m_screen->createNotification(title, content);
}
}