Fixed screensaver detection on XP.

This commit is contained in:
crs 2004-11-06 16:13:52 +00:00
parent 01dc8fa337
commit 57fddf4cdc
6 changed files with 73 additions and 5 deletions

View File

@ -62,6 +62,31 @@ CArchMiscWindows::isWindows95Family()
return result; return result;
} }
bool
CArchMiscWindows::isWindowsModern()
{
static bool init = false;
static bool result = false;
if (!init) {
OSVERSIONINFO version;
version.dwOSVersionInfoSize = sizeof(version);
if (GetVersionEx(&version) == 0) {
// cannot determine OS; assume not modern
result = false;
}
else {
result = ((version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
version.dwMajorVersion == 4 &&
version.dwMinorVersion > 0) ||
(version.dwPlatformId == VER_PLATFORM_WIN32_NT &&
version.dwMajorVersion > 4));
}
init = true;
}
return result;
}
int int
CArchMiscWindows::runDaemon(RunFunc runFunc) CArchMiscWindows::runDaemon(RunFunc runFunc)
{ {

View File

@ -49,6 +49,13 @@ public:
*/ */
static bool isWindows95Family(); static bool isWindows95Family();
//! Test if windows 95, et al.
/*!
Returns true iff the platform is win98 or win2k or higher (i.e.
not windows 95 or windows NT).
*/
static bool isWindowsModern();
//! Run the daemon //! Run the daemon
/*! /*!
Delegates to CArchDaemonWindows. Delegates to CArchDaemonWindows.

View File

@ -33,6 +33,9 @@
#if !defined(SPI_SETMOUSESPEED) #if !defined(SPI_SETMOUSESPEED)
#define SPI_SETMOUSESPEED 113 #define SPI_SETMOUSESPEED 113
#endif #endif
#if !defined(SPI_GETSCREENSAVERRUNNING)
#define SPI_GETSCREENSAVERRUNNING 114
#endif
// X button stuff // X button stuff
#if !defined(WM_XBUTTONDOWN) #if !defined(WM_XBUTTONDOWN)
@ -84,6 +87,7 @@ CMSWindowsDesks::CMSWindowsDesks(
const IScreenSaver* screensaver, IJob* updateKeys) : const IScreenSaver* screensaver, IJob* updateKeys) :
m_isPrimary(isPrimary), m_isPrimary(isPrimary),
m_is95Family(CArchMiscWindows::isWindows95Family()), m_is95Family(CArchMiscWindows::isWindows95Family()),
m_isModernFamily(CArchMiscWindows::isWindowsModern()),
m_isOnScreen(m_isPrimary), m_isOnScreen(m_isPrimary),
m_x(0), m_y(0), m_x(0), m_y(0),
m_w(0), m_h(0), m_w(0), m_h(0),
@ -622,8 +626,22 @@ CMSWindowsDesks::deskLeave(CDesk* desk, HKL keyLayout)
strcmp(className, "ConsoleWindowClass") == 0) { strcmp(className, "ConsoleWindowClass") == 0) {
EnableWindow(desk->m_window, TRUE); EnableWindow(desk->m_window, TRUE);
SetActiveWindow(desk->m_window); SetActiveWindow(desk->m_window);
// force our window to the foreground. we can't
// simply call SetForegroundWindow() because that
// will only alert the user that the window wants
// to be the foreground as of windows 98/2000. we
// have to attach to the thread of the current
// foreground window then call it on our window
// and finally detach the threads.
DWORD thisThread =
GetWindowThreadProcessId(desk->m_window, NULL);
DWORD thatThread =
GetWindowThreadProcessId(foreground, NULL);
AttachThreadInput(thatThread, thisThread, TRUE);
SetForegroundWindow(desk->m_window);
AttachThreadInput(thatThread, thisThread, FALSE);
} }
LOG((CLOG_DEBUG1 "active window class: %s", className));
} }
} }
@ -901,6 +919,14 @@ void
CMSWindowsDesks::handleCheckDesk(const CEvent&, void*) CMSWindowsDesks::handleCheckDesk(const CEvent&, void*)
{ {
checkDesk(); checkDesk();
// also check if screen saver is running if on a modern OS and
// this is the primary screen.
if (m_isPrimary && m_isModernFamily) {
BOOL running;
SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &running, FALSE);
PostThreadMessage(m_threadID, SYNERGY_MSG_SCREEN_SAVER, running, 0);
}
} }
HDESK HDESK

View File

@ -214,6 +214,9 @@ private:
// true if windows 95/98/me // true if windows 95/98/me
bool m_is95Family; bool m_is95Family;
// true if windows 98/2k or higher (i.e. not 95/nt)
bool m_isModernFamily;
// true if mouse has entered the screen // true if mouse has entered the screen
bool m_isOnScreen; bool m_isOnScreen;

View File

@ -94,6 +94,7 @@ CMSWindowsScreen::CMSWindowsScreen(bool isPrimary,
m_fixTimer(NULL), m_fixTimer(NULL),
m_screensaver(NULL), m_screensaver(NULL),
m_screensaverNotify(false), m_screensaverNotify(false),
m_screensaverActive(false),
m_window(NULL), m_window(NULL),
m_nextClipboardWindow(NULL), m_nextClipboardWindow(NULL),
m_ownClipboard(false), m_ownClipboard(false),
@ -1133,7 +1134,9 @@ CMSWindowsScreen::onScreensaver(bool activated)
} }
if (activated) { if (activated) {
if (m_screensaver->checkStarted(SYNERGY_MSG_SCREEN_SAVER, FALSE, 0)) { if (!m_screensaverActive &&
m_screensaver->checkStarted(SYNERGY_MSG_SCREEN_SAVER, FALSE, 0)) {
m_screensaverActive = true;
sendEvent(getScreensaverActivatedEvent()); sendEvent(getScreensaverActivatedEvent());
// enable display power down // enable display power down
@ -1141,11 +1144,14 @@ CMSWindowsScreen::onScreensaver(bool activated)
} }
} }
else { else {
if (m_screensaverActive) {
m_screensaverActive = false;
sendEvent(getScreensaverDeactivatedEvent()); sendEvent(getScreensaverDeactivatedEvent());
// disable display power down // disable display power down
CArchMiscWindows::addBusyState(CArchMiscWindows::kDISPLAY); CArchMiscWindows::addBusyState(CArchMiscWindows::kDISPLAY);
} }
}
return true; return true;
} }

View File

@ -238,6 +238,7 @@ private:
// screen saver stuff // screen saver stuff
CMSWindowsScreenSaver* m_screensaver; CMSWindowsScreenSaver* m_screensaver;
bool m_screensaverNotify; bool m_screensaverNotify;
bool m_screensaverActive;
// clipboard stuff. our window is used mainly as a clipboard // clipboard stuff. our window is used mainly as a clipboard
// owner and as a link in the clipboard viewer chain. // owner and as a link in the clipboard viewer chain.