From ed439ec33c6bc23a5f0e82d50514e28e7a27ef6e Mon Sep 17 00:00:00 2001 From: crs Date: Sat, 3 May 2003 14:38:36 +0000 Subject: [PATCH] Added global configuration option to disable screen saver synchronization. --- lib/platform/CMSWindowsSecondaryScreen.cpp | 6 +- lib/platform/CXWindowsSecondaryScreen.cpp | 2 + lib/server/CConfig.cpp | 9 ++- lib/synergy/CSecondaryScreen.cpp | 93 ++++++++++++++++++++-- lib/synergy/CSecondaryScreen.h | 16 +++- lib/synergy/OptionTypes.h | 1 + 6 files changed, 112 insertions(+), 15 deletions(-) diff --git a/lib/platform/CMSWindowsSecondaryScreen.cpp b/lib/platform/CMSWindowsSecondaryScreen.cpp index f4be6dea..35fd8c74 100644 --- a/lib/platform/CMSWindowsSecondaryScreen.cpp +++ b/lib/platform/CMSWindowsSecondaryScreen.cpp @@ -300,13 +300,13 @@ CMSWindowsSecondaryScreen::mouseWheel(SInt32 delta) void CMSWindowsSecondaryScreen::resetOptions() { - // no options + CSecondaryScreen::resetOptions(); } void -CMSWindowsSecondaryScreen::setOptions(const COptionsList& /*options*/) +CMSWindowsSecondaryScreen::setOptions(const COptionsList& options) { - // no options + CSecondaryScreen::setOptions(options); } IScreen* diff --git a/lib/platform/CXWindowsSecondaryScreen.cpp b/lib/platform/CXWindowsSecondaryScreen.cpp index 9eb93af8..5f9c89ca 100644 --- a/lib/platform/CXWindowsSecondaryScreen.cpp +++ b/lib/platform/CXWindowsSecondaryScreen.cpp @@ -287,6 +287,7 @@ CXWindowsSecondaryScreen::resetOptions() { m_numLockHalfDuplex = false; m_capsLockHalfDuplex = false; + CSecondaryScreen::resetOptions(); } void @@ -302,6 +303,7 @@ CXWindowsSecondaryScreen::setOptions(const COptionsList& options) LOG((CLOG_DEBUG1 "half-duplex num-lock %s", m_numLockHalfDuplex ? "on" : "off")); } } + CSecondaryScreen::setOptions(options); } IScreen* diff --git a/lib/server/CConfig.cpp b/lib/server/CConfig.cpp index f75193a2..3a66103b 100644 --- a/lib/server/CConfig.cpp +++ b/lib/server/CConfig.cpp @@ -640,6 +640,9 @@ CConfig::getOptionName(OptionID id) if (id == kOptionScreenSwitchTwoTap) { return "switchDoubleTap"; } + if (id == kOptionScreenSaverSync) { + return "screenSaverSync"; + } return NULL; } @@ -647,7 +650,8 @@ CString CConfig::getOptionValue(OptionID id, OptionValue value) { if (id == kOptionHalfDuplexCapsLock || - id == kOptionHalfDuplexNumLock) { + id == kOptionHalfDuplexNumLock || + id == kOptionScreenSaverSync) { return (value != 0) ? "true" : "false"; } if (id == kOptionModifierMapForShift || @@ -791,6 +795,9 @@ CConfig::readSectionOptions(std::istream& s) else if (name == "switchDoubleTap") { addOption("", kOptionScreenSwitchTwoTap, parseInt(value)); } + else if (name == "screenSaverSync") { + addOption("", kOptionScreenSaverSync, parseBoolean(value)); + } else { throw XConfigRead("unknown argument"); } diff --git a/lib/synergy/CSecondaryScreen.cpp b/lib/synergy/CSecondaryScreen.cpp index 24a9146f..941e468a 100644 --- a/lib/synergy/CSecondaryScreen.cpp +++ b/lib/synergy/CSecondaryScreen.cpp @@ -23,8 +23,10 @@ // CSecondaryScreen::CSecondaryScreen() : + m_remoteReady(false), m_active(false), - m_toggleKeys(0) + m_toggleKeys(0), + m_screenSaverSync(true) { // do nothing } @@ -106,14 +108,23 @@ CSecondaryScreen::remoteControl() // update keyboard state updateKeys(); - // disable the screen saver - getScreen()->openScreensaver(false); - - // hide the cursor + // now remote ready. fake being active for call to leave(). + bool screenSaverSync; { CLock lock(&m_mutex); - m_active = true; + 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); + } + + // hide the cursor leave(); } @@ -121,6 +132,10 @@ void CSecondaryScreen::localControl() { getScreen()->closeScreensaver(); + + // not remote ready anymore + CLock lock(&m_mutex); + m_remoteReady = false; } void @@ -204,7 +219,71 @@ CSecondaryScreen::grabClipboard(ClipboardID id) void CSecondaryScreen::screensaver(bool activate) { - getScreen()->screensaver(activate); + // get screen saver synchronization flag + bool screenSaverSync; + { + CLock lock(&m_mutex); + screenSaverSync = m_screenSaverSync; + } + + // activate/deactivation screen saver iff synchronization enabled + if (screenSaverSync) { +LOG((CLOG_INFO "screensaver(%s)", activate ? "on" : "off")); + getScreen()->screensaver(activate); + } +else { +LOG((CLOG_INFO "screensaver(%s) ignored", activate ? "on" : "off")); +} +} + +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); + } + } } bool diff --git a/lib/synergy/CSecondaryScreen.h b/lib/synergy/CSecondaryScreen.h index e4dd8a9f..f1790a83 100644 --- a/lib/synergy/CSecondaryScreen.h +++ b/lib/synergy/CSecondaryScreen.h @@ -177,16 +177,18 @@ public: //! Notify of options changes /*! - Reset all options to their default values. + Reset all options to their default values. Overrides should call + the superclass's method. */ - virtual void resetOptions() = 0; + virtual void resetOptions(); //! Notify of options changes /*! Set options to given values. Ignore unknown options and don't - modify our options that aren't given in \c options. + modify our options that aren't given in \c options. Overrides + should call the superclass's method. */ - virtual void setOptions(const COptionsList& options) = 0; + virtual void setOptions(const COptionsList& options); //@} //! @name accessors @@ -372,11 +374,17 @@ protected: private: CMutex m_mutex; + // true if ready for remote control + bool m_remoteReady; + // m_active is true if this screen has been entered bool m_active; // the toggle key state when this screen was last entered KeyModifierMask m_toggleKeys; + + // true if screen saver should be synchronized to server + bool m_screenSaverSync; }; #endif diff --git a/lib/synergy/OptionTypes.h b/lib/synergy/OptionTypes.h index 84a09f5c..d94cac37 100644 --- a/lib/synergy/OptionTypes.h +++ b/lib/synergy/OptionTypes.h @@ -53,6 +53,7 @@ static const OptionID kOptionModifierMapForSuper = OPTION_CODE("MMFR"); static const OptionID kOptionHeartbeat = OPTION_CODE("HART"); static const OptionID kOptionScreenSwitchDelay = OPTION_CODE("SSWT"); static const OptionID kOptionScreenSwitchTwoTap = OPTION_CODE("SSTT"); +static const OptionID kOptionScreenSaverSync = OPTION_CODE("SSVR"); //@} #undef OPTION_CODE