From ccb45bc2bc904e7c3fcdf0fc4d5e6c4aca989e73 Mon Sep 17 00:00:00 2001 From: crs Date: Sat, 12 Jun 2004 20:48:04 +0000 Subject: [PATCH] (Maybe) fixed a problem detecting when win32 screen saver started. --- lib/platform/CMSWindowsDesks.cpp | 6 ++++++ lib/platform/CMSWindowsDesks.h | 1 + lib/platform/CMSWindowsScreenSaver.cpp | 17 ++++++++++++++--- lib/platform/CMSWindowsScreenSaver.h | 4 ++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/platform/CMSWindowsDesks.cpp b/lib/platform/CMSWindowsDesks.cpp index b6319bc7..8c71b4b5 100644 --- a/lib/platform/CMSWindowsDesks.cpp +++ b/lib/platform/CMSWindowsDesks.cpp @@ -115,6 +115,8 @@ CMSWindowsDesks::~CMSWindowsDesks() void CMSWindowsDesks::enable() { + m_threadID = GetCurrentThreadId(); + // set the active desk and (re)install the hooks checkDesk(); @@ -844,6 +846,10 @@ CMSWindowsDesks::checkDesk() sendMessage(SYNERGY_MSG_LEAVE, (WPARAM)m_keyLayout, 0); } } + else if (name != m_activeDeskName) { + // screen saver might have started + PostThreadMessage(m_threadID, SYNERGY_MSG_SCREEN_SAVER, TRUE, 0); + } } bool diff --git a/lib/platform/CMSWindowsDesks.h b/lib/platform/CMSWindowsDesks.h index 9b966416..df209eca 100644 --- a/lib/platform/CMSWindowsDesks.h +++ b/lib/platform/CMSWindowsDesks.h @@ -233,6 +233,7 @@ private: CEventQueueTimer* m_timer; // screen saver stuff + DWORD m_threadID; const IScreenSaver* m_screensaver; bool m_screensaverNotify; diff --git a/lib/platform/CMSWindowsScreenSaver.cpp b/lib/platform/CMSWindowsScreenSaver.cpp index b9101c9f..b3ab2779 100644 --- a/lib/platform/CMSWindowsScreenSaver.cpp +++ b/lib/platform/CMSWindowsScreenSaver.cpp @@ -43,7 +43,8 @@ CMSWindowsScreenSaver::CMSWindowsScreenSaver() : m_wasSecureAnInt(false), m_process(NULL), m_watch(NULL), - m_threadID(0) + m_threadID(0), + m_active(false) { // detect OS m_is95Family = false; @@ -76,6 +77,11 @@ CMSWindowsScreenSaver::~CMSWindowsScreenSaver() bool CMSWindowsScreenSaver::checkStarted(UINT msg, WPARAM wParam, LPARAM lParam) { + // if already started then say it didn't just start + if (m_active) { + return false; + } + // screen saver may have started. look for it and get // the process. if we can't find it then assume it // didn't really start. we wait a moment before @@ -322,7 +328,8 @@ CMSWindowsScreenSaver::watchDesktop() // watch desktop in another thread LOG((CLOG_DEBUG "watching screen saver desktop")); - m_watch = new CThread(new TMethodJob(this, + m_active = true; + m_watch = new CThread(new TMethodJob(this, &CMSWindowsScreenSaver::watchDesktopThread)); } @@ -336,6 +343,7 @@ CMSWindowsScreenSaver::watchProcess(HANDLE process) if (process != NULL) { LOG((CLOG_DEBUG "watching screen saver process")); m_process = process; + m_active = true; m_watch = new CThread(new TMethodJob(this, &CMSWindowsScreenSaver::watchProcessThread)); } @@ -349,7 +357,8 @@ CMSWindowsScreenSaver::unwatchProcess() m_watch->cancel(); m_watch->wait(); delete m_watch; - m_watch = NULL; + m_watch = NULL; + m_active = false; } if (m_process != NULL) { CloseHandle(m_process); @@ -394,6 +403,7 @@ CMSWindowsScreenSaver::watchDesktopThread(void*) } // send screen saver deactivation message + m_active = false; PostThreadMessage(m_threadID, m_msg, m_wParam, m_lParam); return; } @@ -409,6 +419,7 @@ CMSWindowsScreenSaver::watchProcessThread(void*) LOG((CLOG_DEBUG "screen saver died")); // send screen saver deactivation message + m_active = false; PostThreadMessage(m_threadID, m_msg, m_wParam, m_lParam); return; } diff --git a/lib/platform/CMSWindowsScreenSaver.h b/lib/platform/CMSWindowsScreenSaver.h index 7cc7cdc9..bb43c703 100644 --- a/lib/platform/CMSWindowsScreenSaver.h +++ b/lib/platform/CMSWindowsScreenSaver.h @@ -83,6 +83,10 @@ private: UINT m_msg; WPARAM m_wParam; LPARAM m_lParam; + + // checkActive state. true if the screen saver is being watched + // for deactivation (and is therefore active). + bool m_active; }; #endif