(Maybe) fixed a problem detecting when win32 screen saver started.

This commit is contained in:
crs 2004-06-12 20:48:04 +00:00
parent a80ddb4a78
commit ccb45bc2bc
4 changed files with 25 additions and 3 deletions

View File

@ -115,6 +115,8 @@ CMSWindowsDesks::~CMSWindowsDesks()
void void
CMSWindowsDesks::enable() CMSWindowsDesks::enable()
{ {
m_threadID = GetCurrentThreadId();
// set the active desk and (re)install the hooks // set the active desk and (re)install the hooks
checkDesk(); checkDesk();
@ -844,6 +846,10 @@ CMSWindowsDesks::checkDesk()
sendMessage(SYNERGY_MSG_LEAVE, (WPARAM)m_keyLayout, 0); 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 bool

View File

@ -233,6 +233,7 @@ private:
CEventQueueTimer* m_timer; CEventQueueTimer* m_timer;
// screen saver stuff // screen saver stuff
DWORD m_threadID;
const IScreenSaver* m_screensaver; const IScreenSaver* m_screensaver;
bool m_screensaverNotify; bool m_screensaverNotify;

View File

@ -43,7 +43,8 @@ CMSWindowsScreenSaver::CMSWindowsScreenSaver() :
m_wasSecureAnInt(false), m_wasSecureAnInt(false),
m_process(NULL), m_process(NULL),
m_watch(NULL), m_watch(NULL),
m_threadID(0) m_threadID(0),
m_active(false)
{ {
// detect OS // detect OS
m_is95Family = false; m_is95Family = false;
@ -76,6 +77,11 @@ CMSWindowsScreenSaver::~CMSWindowsScreenSaver()
bool bool
CMSWindowsScreenSaver::checkStarted(UINT msg, WPARAM wParam, LPARAM lParam) 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 // screen saver may have started. look for it and get
// the process. if we can't find it then assume it // the process. if we can't find it then assume it
// didn't really start. we wait a moment before // didn't really start. we wait a moment before
@ -322,7 +328,8 @@ CMSWindowsScreenSaver::watchDesktop()
// watch desktop in another thread // watch desktop in another thread
LOG((CLOG_DEBUG "watching screen saver desktop")); LOG((CLOG_DEBUG "watching screen saver desktop"));
m_watch = new CThread(new TMethodJob<CMSWindowsScreenSaver>(this, m_active = true;
m_watch = new CThread(new TMethodJob<CMSWindowsScreenSaver>(this,
&CMSWindowsScreenSaver::watchDesktopThread)); &CMSWindowsScreenSaver::watchDesktopThread));
} }
@ -336,6 +343,7 @@ CMSWindowsScreenSaver::watchProcess(HANDLE process)
if (process != NULL) { if (process != NULL) {
LOG((CLOG_DEBUG "watching screen saver process")); LOG((CLOG_DEBUG "watching screen saver process"));
m_process = process; m_process = process;
m_active = true;
m_watch = new CThread(new TMethodJob<CMSWindowsScreenSaver>(this, m_watch = new CThread(new TMethodJob<CMSWindowsScreenSaver>(this,
&CMSWindowsScreenSaver::watchProcessThread)); &CMSWindowsScreenSaver::watchProcessThread));
} }
@ -349,7 +357,8 @@ CMSWindowsScreenSaver::unwatchProcess()
m_watch->cancel(); m_watch->cancel();
m_watch->wait(); m_watch->wait();
delete m_watch; delete m_watch;
m_watch = NULL; m_watch = NULL;
m_active = false;
} }
if (m_process != NULL) { if (m_process != NULL) {
CloseHandle(m_process); CloseHandle(m_process);
@ -394,6 +403,7 @@ CMSWindowsScreenSaver::watchDesktopThread(void*)
} }
// send screen saver deactivation message // send screen saver deactivation message
m_active = false;
PostThreadMessage(m_threadID, m_msg, m_wParam, m_lParam); PostThreadMessage(m_threadID, m_msg, m_wParam, m_lParam);
return; return;
} }
@ -409,6 +419,7 @@ CMSWindowsScreenSaver::watchProcessThread(void*)
LOG((CLOG_DEBUG "screen saver died")); LOG((CLOG_DEBUG "screen saver died"));
// send screen saver deactivation message // send screen saver deactivation message
m_active = false;
PostThreadMessage(m_threadID, m_msg, m_wParam, m_lParam); PostThreadMessage(m_threadID, m_msg, m_wParam, m_lParam);
return; return;
} }

View File

@ -83,6 +83,10 @@ private:
UINT m_msg; UINT m_msg;
WPARAM m_wParam; WPARAM m_wParam;
LPARAM m_lParam; LPARAM m_lParam;
// checkActive state. true if the screen saver is being watched
// for deactivation (and is therefore active).
bool m_active;
}; };
#endif #endif