From 4d19941428870d399e14d3a0faadc6f814f19831 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 2 Dec 2015 15:02:19 -0800 Subject: [PATCH] Revert "Revert to old behavior of checkDesk(), add workaround to broken EnumClipboardFormats() in the case where the server is started while the screen saver is active." This reverts commit 38209e5079d1695ddd561f8045647e077fccff91. --- src/lib/platform/MSWindowsClipboard.cpp | 19 +-------- src/lib/platform/MSWindowsDesks.cpp | 54 ++++++++++++------------- 2 files changed, 29 insertions(+), 44 deletions(-) diff --git a/src/lib/platform/MSWindowsClipboard.cpp b/src/lib/platform/MSWindowsClipboard.cpp index 07831a51..bb7c87cb 100644 --- a/src/lib/platform/MSWindowsClipboard.cpp +++ b/src/lib/platform/MSWindowsClipboard.cpp @@ -180,24 +180,9 @@ MSWindowsClipboard::get(EFormat format) const win32Format = EnumClipboardFormats(win32Format); } - // if no converter then EnumClipboardFormats() is broken: try just - // GetClipboardData() directly (Issue $5041) + // if no converter then we don't recognize any formats if (converter == NULL) { - LOG((CLOG_INFO "Broken EnumClipboardFormats, falling back to using GetClipboardData")); - - for (ConverterList::const_iterator index = m_converters.begin(); - index != m_converters.end(); ++index) { - converter = *index; - if (converter->getFormat() == format) { - LOG((CLOG_DEBUG "using converter 0x%x%s for %d\n", - converter->getWin32Format(), - l_name(converter->getWin32Format()).c_str(), - format)); - HANDLE win32Data = GetClipboardData(converter->getWin32Format()); - if (win32Data != NULL) - return converter->toIClipboard(win32Data); - } - } + LOG((CLOG_WARN "No converter for format %d", format)); return String(); } diff --git a/src/lib/platform/MSWindowsDesks.cpp b/src/lib/platform/MSWindowsDesks.cpp index e0a140ff..6408b560 100644 --- a/src/lib/platform/MSWindowsDesks.cpp +++ b/src/lib/platform/MSWindowsDesks.cpp @@ -851,30 +851,24 @@ MSWindowsDesks::checkDesk() desk = index->second; } - if (name == m_activeDeskName) { - return; - } - - if (m_activeDesk != NULL) { - LOG((CLOG_DEBUG "switched desk \"%s\"->\"%s\"", - m_activeDeskName.c_str(), name.c_str())); - } - - // if we are told to shut down on desk switch, and this is not the - // first switch, then shut down. - if (m_stopOnDeskSwitch && m_activeDesk != NULL) { - LOG((CLOG_DEBUG "shutting down because of desk switch \"%s\"->\"%s\"", - m_activeDeskName.c_str(), name.c_str())); - m_events->addEvent(Event(Event::kQuit)); - return; - } - // if active desktop changed then tell the old and new desk threads // about the change. don't switch desktops when the screensaver is // active becaue we'd most likely switch to the screensaver desktop // which would have the side effect of forcing the screensaver to // stop. - if (!m_screensaver->isActive()) { + if (name != m_activeDeskName && !m_screensaver->isActive()) { + // if we are told to shut down on desk switch, and this is not the + // first switch, then shut down. + // Issue #5041 workaround - prevent synergys from shutting down when + // screen saver activates - if it is restarted while the screen saver + // is active, the clipboard no longer works. + if (m_stopOnDeskSwitch && m_activeDesk != NULL) { + LOG((CLOG_DEBUG "shutting down because of desk switch \"%s\"->\"%s\"", + m_activeDeskName.c_str(), name.c_str())); + m_events->addEvent(Event(Event::kQuit)); + return; + } + // show cursor on previous desk bool wasOnScreen = m_isOnScreen; if (!wasOnScreen) { @@ -885,6 +879,10 @@ MSWindowsDesks::checkDesk() // from an inaccessible desktop so when we switch from an // inaccessible desktop to an accessible one we have to // update the keyboard state. + if (m_activeDesk != NULL) { + LOG((CLOG_DEBUG "switched desk \"%s\"->\"%s\"", + m_activeDeskName.c_str(), name.c_str())); + } bool syncKeys = false; bool isAccessible = isDeskAccessible(desk); if (isDeskAccessible(m_activeDesk) != isAccessible) { @@ -912,17 +910,19 @@ MSWindowsDesks::checkDesk() updateKeys(); } } - else { + else if (name != m_activeDeskName) { + if (m_activeDesk != NULL) { + LOG((CLOG_DEBUG "switched desk \"%s\"->\"%s\"", + m_activeDeskName.c_str(), name.c_str())); + } + // screen saver is active (see check above) PostThreadMessage(m_threadID, SYNERGY_MSG_SCREEN_SAVER, TRUE, 0); - // FIXME? Because m_activeDesk isn't updated if screen saver is active, - // SYNERGY_MSG_SCREEN_SAVER will be sent on every call to checkDesk() - // until isActive() returns false, since name will not match - // m_activeDeskName until the latter is updated. - // For now, preserve old (broken?) behavior. - //m_activeDesk = desk; - //m_activeDeskName = name; + // Prevent this from retriggering over and over if screen saver stays + // active: + m_activeDesk = desk; + m_activeDeskName = name; } }