mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-08 23:14:20 +08:00
Task #3961 - Remove Windows 95 support
This commit is contained in:
@@ -40,11 +40,6 @@ CMSWindowsClipboard::CMSWindowsClipboard(HWND window) :
|
||||
{
|
||||
// add converters, most desired first
|
||||
m_converters.push_back(new CMSWindowsClipboardUTF16Converter);
|
||||
if (CArchMiscWindows::isWindows95Family()) {
|
||||
// windows nt family converts to/from unicode automatically.
|
||||
// let it do so to avoid text encoding issues.
|
||||
m_converters.push_back(new CMSWindowsClipboardTextConverter);
|
||||
}
|
||||
m_converters.push_back(new CMSWindowsClipboardBitmapConverter);
|
||||
m_converters.push_back(new CMSWindowsClipboardHTMLConverter);
|
||||
}
|
||||
|
||||
@@ -98,8 +98,6 @@ CMSWindowsDesks::CMSWindowsDesks(
|
||||
IJob* updateKeys, bool stopOnDeskSwitch) :
|
||||
m_isPrimary(isPrimary),
|
||||
m_noHooks(noHooks),
|
||||
m_is95Family(CArchMiscWindows::isWindows95Family()),
|
||||
m_isModernFamily(CArchMiscWindows::isWindowsModern()),
|
||||
m_isOnScreen(m_isPrimary),
|
||||
m_x(0), m_y(0),
|
||||
m_w(0), m_h(0),
|
||||
@@ -253,26 +251,6 @@ CMSWindowsDesks::fakeKeyEvent(
|
||||
KeyButton button, UINT virtualKey,
|
||||
bool press, bool /*isAutoRepeat*/) const
|
||||
{
|
||||
// win 95 family doesn't understand handed modifier virtual keys
|
||||
if (m_is95Family) {
|
||||
switch (virtualKey) {
|
||||
case VK_LSHIFT:
|
||||
case VK_RSHIFT:
|
||||
virtualKey = VK_SHIFT;
|
||||
break;
|
||||
|
||||
case VK_LCONTROL:
|
||||
case VK_RCONTROL:
|
||||
virtualKey = VK_CONTROL;
|
||||
break;
|
||||
|
||||
case VK_LMENU:
|
||||
case VK_RMENU:
|
||||
virtualKey = VK_MENU;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// synthesize event
|
||||
DWORD flags = 0;
|
||||
if (((button & 0x100u) != 0)) {
|
||||
@@ -517,51 +495,15 @@ CMSWindowsDesks::secondaryDeskProc(
|
||||
void
|
||||
CMSWindowsDesks::deskMouseMove(SInt32 x, SInt32 y) const
|
||||
{
|
||||
// motion is simple (i.e. it's on the primary monitor) if there
|
||||
// is only one monitor. it's also simple if we're not on the
|
||||
// windows 95 family since those platforms don't have a broken
|
||||
// mouse_event() function (see the comment below).
|
||||
bool simple = (!m_multimon || !m_is95Family);
|
||||
if (!simple) {
|
||||
// also simple if motion is within the primary monitor
|
||||
simple = (x >= 0 && x < GetSystemMetrics(SM_CXSCREEN) &&
|
||||
y >= 0 && y < GetSystemMetrics(SM_CYSCREEN));
|
||||
}
|
||||
|
||||
// move the mouse directly to target position if motion is simple
|
||||
if (simple) {
|
||||
// when using absolute positioning with mouse_event(),
|
||||
// the normalized device coordinates range over only
|
||||
// the primary screen.
|
||||
SInt32 w = GetSystemMetrics(SM_CXSCREEN);
|
||||
SInt32 h = GetSystemMetrics(SM_CYSCREEN);
|
||||
mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE,
|
||||
(DWORD)((65535.0f * x) / (w - 1) + 0.5f),
|
||||
(DWORD)((65535.0f * y) / (h - 1) + 0.5f),
|
||||
0, 0);
|
||||
}
|
||||
|
||||
// windows 98 and Me are broken. you cannot set the absolute
|
||||
// position of the mouse except on the primary monitor but you
|
||||
// can do relative moves onto any monitor. this is, in microsoft's
|
||||
// words, "by design." apparently the designers of windows 2000
|
||||
// we're a little less lazy and did it right.
|
||||
//
|
||||
// microsoft recommends in Q193003 to absolute position the cursor
|
||||
// somewhere on the primary monitor then relative move to the
|
||||
// desired location. this doesn't work for us because when the
|
||||
// user drags a scrollbar, a window, etc. it causes the dragged
|
||||
// item to jump back and forth between the position on the primary
|
||||
// monitor and the desired position. while it always ends up in
|
||||
// the right place, the effect is disconcerting.
|
||||
//
|
||||
// instead we'll get the cursor's current position and do just a
|
||||
// relative move from there to the desired position.
|
||||
else {
|
||||
POINT pos;
|
||||
GetCursorPos(&pos);
|
||||
deskMouseRelativeMove(x - pos.x, y - pos.y);
|
||||
}
|
||||
// when using absolute positioning with mouse_event(),
|
||||
// the normalized device coordinates range over only
|
||||
// the primary screen.
|
||||
SInt32 w = GetSystemMetrics(SM_CXSCREEN);
|
||||
SInt32 h = GetSystemMetrics(SM_CYSCREEN);
|
||||
mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE,
|
||||
(DWORD)((65535.0f * x) / (w - 1) + 0.5f),
|
||||
(DWORD)((65535.0f * y) / (h - 1) + 0.5f),
|
||||
0, 0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -993,7 +935,7 @@ CMSWindowsDesks::handleCheckDesk(const CEvent&, void*)
|
||||
|
||||
// also check if screen saver is running if on a modern OS and
|
||||
// this is the primary screen.
|
||||
if (m_isPrimary && m_isModernFamily) {
|
||||
if (m_isPrimary) {
|
||||
BOOL running;
|
||||
SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &running, FALSE);
|
||||
PostThreadMessage(m_threadID, SYNERGY_MSG_SCREEN_SAVER, running, 0);
|
||||
@@ -1003,24 +945,15 @@ CMSWindowsDesks::handleCheckDesk(const CEvent&, void*)
|
||||
HDESK
|
||||
CMSWindowsDesks::openInputDesktop()
|
||||
{
|
||||
if (m_is95Family) {
|
||||
// there's only one desktop on windows 95 et al.
|
||||
return GetThreadDesktop(GetCurrentThreadId());
|
||||
}
|
||||
else {
|
||||
return OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, TRUE,
|
||||
DESKTOP_CREATEWINDOW |
|
||||
DESKTOP_HOOKCONTROL |
|
||||
GENERIC_WRITE);
|
||||
}
|
||||
return OpenInputDesktop(
|
||||
DF_ALLOWOTHERACCOUNTHOOK, TRUE,
|
||||
DESKTOP_CREATEWINDOW | DESKTOP_HOOKCONTROL | GENERIC_WRITE);
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsDesks::closeDesktop(HDESK desk)
|
||||
{
|
||||
// on 95/98/me we don't need to close the desktop returned by
|
||||
// openInputDesktop().
|
||||
if (desk != NULL && !m_is95Family) {
|
||||
if (desk != NULL) {
|
||||
CloseDesktop(desk);
|
||||
}
|
||||
}
|
||||
@@ -1031,9 +964,6 @@ CMSWindowsDesks::getDesktopName(HDESK desk)
|
||||
if (desk == NULL) {
|
||||
return CString();
|
||||
}
|
||||
else if (m_is95Family) {
|
||||
return "desktop";
|
||||
}
|
||||
else {
|
||||
DWORD size;
|
||||
GetUserObjectInformation(desk, UOI_NAME, NULL, 0, &size);
|
||||
|
||||
@@ -251,12 +251,6 @@ private:
|
||||
// true if hooks are not to be installed (useful for debugging)
|
||||
bool m_noHooks;
|
||||
|
||||
// true if windows 95/98/me
|
||||
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
|
||||
bool m_isOnScreen;
|
||||
|
||||
|
||||
@@ -579,7 +579,6 @@ static const CWin32Modifiers s_modifiers[] =
|
||||
CMSWindowsKeyState::CMSWindowsKeyState(
|
||||
CMSWindowsDesks* desks, void* eventTarget, IEventQueue* events) :
|
||||
CKeyState(events),
|
||||
m_is95Family(CArchMiscWindows::isWindows95Family()),
|
||||
m_eventTarget(eventTarget),
|
||||
m_desks(desks),
|
||||
m_keyLayout(GetKeyboardLayout(0)),
|
||||
@@ -596,7 +595,6 @@ CMSWindowsKeyState::CMSWindowsKeyState(
|
||||
CMSWindowsKeyState::CMSWindowsKeyState(
|
||||
CMSWindowsDesks* desks, void* eventTarget, IEventQueue* events, CKeyMap& keyMap) :
|
||||
CKeyState(events, keyMap),
|
||||
m_is95Family(CArchMiscWindows::isWindows95Family()),
|
||||
m_eventTarget(eventTarget),
|
||||
m_desks(desks),
|
||||
m_keyLayout(GetKeyboardLayout(0)),
|
||||
@@ -761,10 +759,7 @@ CMSWindowsKeyState::mapKeyToVirtualKey(KeyID key) const
|
||||
void
|
||||
CMSWindowsKeyState::onKey(KeyButton button, bool down, KeyModifierMask newState)
|
||||
{
|
||||
// handle win32 brokenness and forward to superclass
|
||||
fixKeys();
|
||||
CKeyState::onKey(button, down, newState);
|
||||
fixKeys();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -810,28 +805,22 @@ CMSWindowsKeyState::fakeKeyRepeat(KeyID id, KeyModifierMask mask,
|
||||
bool
|
||||
CMSWindowsKeyState::fakeCtrlAltDel()
|
||||
{
|
||||
if (!m_is95Family) {
|
||||
// to fake ctrl+alt+del on the NT family we broadcast a suitable
|
||||
// hotkey to all windows on the winlogon desktop. however, the
|
||||
// current thread must be on that desktop to do the broadcast
|
||||
// and we can't switch just any thread because some own windows
|
||||
// or hooks. so start a new thread to do the real work.
|
||||
HANDLE hEvtSendSas = OpenEvent( EVENT_MODIFY_STATE, FALSE, "Global\\SendSAS" );
|
||||
if ( hEvtSendSas ) {
|
||||
LOG((CLOG_DEBUG "found the SendSAS event - signaling my launcher to simulate ctrl+alt+del"));
|
||||
SetEvent( hEvtSendSas );
|
||||
CloseHandle( hEvtSendSas );
|
||||
}
|
||||
else {
|
||||
// to fake ctrl+alt+del on the NT family we broadcast a suitable
|
||||
// hotkey to all windows on the winlogon desktop. however, the
|
||||
// current thread must be on that desktop to do the broadcast
|
||||
// and we can't switch just any thread because some own windows
|
||||
// or hooks. so start a new thread to do the real work.
|
||||
HANDLE hEvtSendSas = OpenEvent( EVENT_MODIFY_STATE, FALSE, "Global\\SendSAS" );
|
||||
if ( hEvtSendSas ) {
|
||||
LOG((CLOG_DEBUG "found the SendSAS event - signaling my launcher to simulate ctrl+alt+del"));
|
||||
SetEvent( hEvtSendSas );
|
||||
CloseHandle( hEvtSendSas );
|
||||
}
|
||||
else {
|
||||
CThread cad(new CFunctionJob(&CMSWindowsKeyState::ctrlAltDelThread));
|
||||
cad.wait();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// simulate ctrl+alt+del
|
||||
fakeKeyDown(kKeyDelete, KeyModifierControl | KeyModifierAlt,
|
||||
virtualKeyToButton(VK_DELETE));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1006,11 +995,6 @@ CMSWindowsKeyState::getKeyMap(CKeyMap& keyMap)
|
||||
|
||||
case VK_LWIN:
|
||||
case VK_RWIN:
|
||||
// add extended key only for these on 95 family
|
||||
if (m_is95Family) {
|
||||
m_buttonToVK[i | 0x100u] = vk;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case VK_RETURN:
|
||||
@@ -1351,77 +1335,6 @@ CMSWindowsKeyState::setWindowGroup(SInt32 group)
|
||||
Sleep(100);
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsKeyState::fixKeys()
|
||||
{
|
||||
// fake key releases for the windows keys if we think they're
|
||||
// down but they're really up. we have to do this because if the
|
||||
// user presses and releases a windows key without pressing any
|
||||
// other key while it's down then the system will eat the key
|
||||
// release. if we don't detect that and synthesize the release
|
||||
// then the client won't take the usual windows key release action
|
||||
// (which on windows is to show the start menu).
|
||||
//
|
||||
// only check on the windows 95 family since the NT family reports
|
||||
// the key releases as usual.
|
||||
if (!m_is95Family) {
|
||||
return;
|
||||
}
|
||||
|
||||
KeyButton leftButton = virtualKeyToButton(VK_LWIN);
|
||||
KeyButton rightButton = virtualKeyToButton(VK_RWIN);
|
||||
bool leftDown = isKeyDown(leftButton);
|
||||
bool rightDown = isKeyDown(rightButton);
|
||||
bool fix = (leftDown || rightDown);
|
||||
if (fix) {
|
||||
// check if either button is not really down
|
||||
bool leftAsyncDown = ((GetAsyncKeyState(VK_LWIN) & 0x8000) != 0);
|
||||
bool rightAsyncDown = ((GetAsyncKeyState(VK_RWIN) & 0x8000) != 0);
|
||||
|
||||
if (leftAsyncDown != leftDown || rightAsyncDown != rightDown) {
|
||||
KeyModifierMask state = getActiveModifiers();
|
||||
if (!leftAsyncDown && !rightAsyncDown) {
|
||||
// no win keys are down so remove super modifier
|
||||
state &= ~KeyModifierSuper;
|
||||
}
|
||||
|
||||
// report up events
|
||||
if (leftDown && !leftAsyncDown) {
|
||||
LOG((CLOG_DEBUG1 "event: fake key release left windows key (0x%03x)", leftButton));
|
||||
CKeyState::onKey(leftButton, false, state);
|
||||
CKeyState::sendKeyEvent(m_eventTarget, false, false,
|
||||
kKeySuper_L, state, 1, leftButton);
|
||||
}
|
||||
if (rightDown && !rightAsyncDown) {
|
||||
LOG((CLOG_DEBUG1 "event: fake key release right windows key (0x%03x)", rightButton));
|
||||
CKeyState::onKey(rightButton, false, state);
|
||||
CKeyState::sendKeyEvent(m_eventTarget, false, false,
|
||||
kKeySuper_R, state, 1, rightButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fix && m_fixTimer == NULL) {
|
||||
// schedule check
|
||||
m_fixTimer = m_events->newTimer(0.1, NULL);
|
||||
m_events->adoptHandler(CEvent::kTimer, m_fixTimer,
|
||||
new TMethodEventJob<CMSWindowsKeyState>(
|
||||
this, &CMSWindowsKeyState::handleFixKeys));
|
||||
}
|
||||
else if (!fix && m_fixTimer != NULL) {
|
||||
// remove scheduled check
|
||||
m_events->removeHandler(CEvent::kTimer, m_fixTimer);
|
||||
m_events->deleteTimer(m_fixTimer);
|
||||
m_fixTimer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsKeyState::handleFixKeys(const CEvent&, void*)
|
||||
{
|
||||
fixKeys();
|
||||
}
|
||||
|
||||
KeyID
|
||||
CMSWindowsKeyState::getKeyID(UINT virtualKey, KeyButton button)
|
||||
{
|
||||
@@ -1436,21 +1349,12 @@ CMSWindowsKeyState::getIDForKey(CKeyMap::KeyItem& item,
|
||||
KeyButton button, UINT virtualKey,
|
||||
PBYTE keyState, HKL hkl) const
|
||||
{
|
||||
int n;
|
||||
KeyID id;
|
||||
if (m_is95Family) {
|
||||
// XXX -- how do we get characters not in Latin-1?
|
||||
WORD ascii;
|
||||
n = ToAsciiEx(virtualKey, button, keyState, &ascii, 0, hkl);
|
||||
id = static_cast<KeyID>(ascii & 0xffu);
|
||||
}
|
||||
else {
|
||||
WCHAR unicode[2];
|
||||
n = m_ToUnicodeEx(virtualKey, button, keyState,
|
||||
unicode, sizeof(unicode) / sizeof(unicode[0]),
|
||||
0, hkl);
|
||||
id = static_cast<KeyID>(unicode[0]);
|
||||
}
|
||||
WCHAR unicode[2];
|
||||
int n = m_ToUnicodeEx(
|
||||
virtualKey, button, keyState, unicode,
|
||||
sizeof(unicode) / sizeof(unicode[0]), 0, hkl);
|
||||
KeyID id = static_cast<KeyID>(unicode[0]);
|
||||
|
||||
switch (n) {
|
||||
case -1:
|
||||
return CKeyMap::getDeadKey(id);
|
||||
|
||||
@@ -167,9 +167,6 @@ private:
|
||||
bool getGroups(GroupList&) const;
|
||||
void setWindowGroup(SInt32 group);
|
||||
|
||||
void fixKeys();
|
||||
void handleFixKeys(const CEvent&, void*);
|
||||
|
||||
KeyID getIDForKey(CKeyMap::KeyItem& item,
|
||||
KeyButton button, UINT virtualKey,
|
||||
PBYTE keyState, HKL hkl) const;
|
||||
@@ -187,7 +184,6 @@ private:
|
||||
typedef std::map<HKL, SInt32> GroupMap;
|
||||
typedef std::map<KeyID, UINT> KeyToVKMap;
|
||||
|
||||
bool m_is95Family;
|
||||
void* m_eventTarget;
|
||||
CMSWindowsDesks* m_desks;
|
||||
HKL m_keyLayout;
|
||||
|
||||
@@ -97,7 +97,6 @@ CMSWindowsScreen::CMSWindowsScreen(
|
||||
CPlatformScreen(events),
|
||||
m_isPrimary(isPrimary),
|
||||
m_noHooks(noHooks),
|
||||
m_is95Family(CArchMiscWindows::isWindows95Family()),
|
||||
m_isOnScreen(m_isPrimary),
|
||||
m_class(0),
|
||||
m_x(0), m_y(0),
|
||||
@@ -1007,22 +1006,6 @@ CMSWindowsScreen::onEvent(HWND, UINT msg,
|
||||
WPARAM wParam, LPARAM lParam, LRESULT* result)
|
||||
{
|
||||
switch (msg) {
|
||||
case WM_QUERYENDSESSION:
|
||||
if (m_is95Family) {
|
||||
*result = TRUE;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_ENDSESSION:
|
||||
if (m_is95Family) {
|
||||
if (wParam == TRUE && lParam == 0) {
|
||||
m_events->addEvent(CEvent(CEvent::kQuit));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_DRAWCLIPBOARD:
|
||||
// first pass on the message
|
||||
if (m_nextClipboardWindow != NULL) {
|
||||
@@ -1183,37 +1166,6 @@ CMSWindowsScreen::onKey(WPARAM wParam, LPARAM lParam)
|
||||
KeyID key = m_keyState->mapKeyFromEvent(wParam, lParam, &mask);
|
||||
button = static_cast<KeyButton>((lParam & 0x01ff0000u) >> 16);
|
||||
if (key != kKeyNone) {
|
||||
// fix key up. if the key isn't down according to
|
||||
// our table then we never got the key press event
|
||||
// for it. if it's not a modifier key then we'll
|
||||
// synthesize the press first. only do this on
|
||||
// the windows 95 family, which eats certain special
|
||||
// keys like alt+tab, ctrl+esc, etc.
|
||||
if (m_is95Family && !wasDown && !down) {
|
||||
switch (virtKey) {
|
||||
case VK_SHIFT:
|
||||
case VK_LSHIFT:
|
||||
case VK_RSHIFT:
|
||||
case VK_CONTROL:
|
||||
case VK_LCONTROL:
|
||||
case VK_RCONTROL:
|
||||
case VK_MENU:
|
||||
case VK_LMENU:
|
||||
case VK_RMENU:
|
||||
case VK_LWIN:
|
||||
case VK_RWIN:
|
||||
case VK_CAPITAL:
|
||||
case VK_NUMLOCK:
|
||||
case VK_SCROLL:
|
||||
break;
|
||||
|
||||
default:
|
||||
m_keyState->sendKeyEvent(getEventTarget(),
|
||||
true, false, key, mask, 1, button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// do it
|
||||
m_keyState->sendKeyEvent(getEventTarget(),
|
||||
((lParam & 0x80000000u) == 0),
|
||||
@@ -1617,15 +1569,6 @@ CMSWindowsScreen::fixClipboardViewer()
|
||||
void
|
||||
CMSWindowsScreen::enableSpecialKeys(bool enable) const
|
||||
{
|
||||
// enable/disable ctrl+alt+del, alt+tab, etc on win95 family.
|
||||
// since the win95 family doesn't support low-level hooks, we
|
||||
// use this undocumented feature to suppress normal handling
|
||||
// of certain key combinations.
|
||||
if (m_is95Family) {
|
||||
DWORD dummy = 0;
|
||||
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,
|
||||
enable ? FALSE : TRUE, &dummy, 0);
|
||||
}
|
||||
}
|
||||
|
||||
ButtonID
|
||||
@@ -1865,7 +1808,7 @@ CMSWindowsScreen::getDraggingFilename()
|
||||
void
|
||||
CMSWindowsScreen::clearDraggingFilename()
|
||||
{
|
||||
LOG((CLOG_DEBUG "clearing stored dragging file name"));
|
||||
LOG((CLOG_DEBUG1 "clearing stored dragging file name"));
|
||||
m_shellEx.clearDraggingFilename();
|
||||
}
|
||||
|
||||
|
||||
@@ -237,9 +237,6 @@ private:
|
||||
// true if hooks are not to be installed (useful for debugging)
|
||||
bool m_noHooks;
|
||||
|
||||
// true if windows 95/98/me
|
||||
bool m_is95Family;
|
||||
|
||||
// true if mouse has entered the screen
|
||||
bool m_isOnScreen;
|
||||
|
||||
|
||||
@@ -52,25 +52,6 @@ CMSWindowsScreenSaver::CMSWindowsScreenSaver() :
|
||||
m_threadID(0),
|
||||
m_active(false)
|
||||
{
|
||||
// detect OS
|
||||
m_is95Family = false;
|
||||
m_is95 = false;
|
||||
m_isNT = false;
|
||||
OSVERSIONINFO info;
|
||||
info.dwOSVersionInfoSize = sizeof(info);
|
||||
if (GetVersionEx(&info)) {
|
||||
m_is95Family = (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
|
||||
if (info.dwPlatformId == VER_PLATFORM_WIN32_NT &&
|
||||
info.dwMajorVersion <= 4) {
|
||||
m_isNT = true;
|
||||
}
|
||||
else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
|
||||
info.dwMajorVersion == 4 &&
|
||||
info.dwMinorVersion == 0) {
|
||||
m_is95 = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check if screen saver is enabled
|
||||
SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &m_wasEnabled, 0);
|
||||
}
|
||||
@@ -104,38 +85,19 @@ CMSWindowsScreenSaver::checkStarted(UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
m_wParam = wParam;
|
||||
m_lParam = lParam;
|
||||
|
||||
// we handle the screen saver differently for the windows
|
||||
// 95 and nt families.
|
||||
if (m_is95Family) {
|
||||
// on windows 95 we wait for the screen saver process
|
||||
// to terminate. get the process.
|
||||
DWORD processID = findScreenSaver();
|
||||
HANDLE process = OpenProcess(SYNCHRONIZE, FALSE, processID);
|
||||
if (process == NULL) {
|
||||
// didn't start
|
||||
LOG((CLOG_DEBUG2 "can't open screen saver process"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// watch for the process to exit
|
||||
watchProcess(process);
|
||||
}
|
||||
else {
|
||||
// on the windows nt family we wait for the desktop to
|
||||
// change until it's neither the Screen-Saver desktop
|
||||
// nor a desktop we can't open (the login desktop).
|
||||
// since windows will send the request-to-start-screen-
|
||||
// saver message even when the screen saver is disabled
|
||||
// we first check that the screen saver is indeed active
|
||||
// before watching for it to stop.
|
||||
if (!isActive()) {
|
||||
LOG((CLOG_DEBUG2 "can't open screen saver desktop"));
|
||||
return false;
|
||||
}
|
||||
|
||||
watchDesktop();
|
||||
// on the windows nt family we wait for the desktop to
|
||||
// change until it's neither the Screen-Saver desktop
|
||||
// nor a desktop we can't open (the login desktop).
|
||||
// since windows will send the request-to-start-screen-
|
||||
// saver message even when the screen saver is disabled
|
||||
// we first check that the screen saver is indeed active
|
||||
// before watching for it to stop.
|
||||
if (!isActive()) {
|
||||
LOG((CLOG_DEBUG2 "can't open screen saver desktop"));
|
||||
return false;
|
||||
}
|
||||
|
||||
watchDesktop();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -193,16 +155,15 @@ void
|
||||
CMSWindowsScreenSaver::deactivate()
|
||||
{
|
||||
bool killed = false;
|
||||
if (!m_is95Family) {
|
||||
// NT runs screen saver in another desktop
|
||||
HDESK desktop = OpenDesktop("Screen-saver", 0, FALSE,
|
||||
DESKTOP_READOBJECTS | DESKTOP_WRITEOBJECTS);
|
||||
if (desktop != NULL) {
|
||||
EnumDesktopWindows(desktop,
|
||||
&CMSWindowsScreenSaver::killScreenSaverFunc,
|
||||
reinterpret_cast<LPARAM>(&killed));
|
||||
CloseDesktop(desktop);
|
||||
}
|
||||
|
||||
// NT runs screen saver in another desktop
|
||||
HDESK desktop = OpenDesktop("Screen-saver", 0, FALSE,
|
||||
DESKTOP_READOBJECTS | DESKTOP_WRITEOBJECTS);
|
||||
if (desktop != NULL) {
|
||||
EnumDesktopWindows(desktop,
|
||||
&CMSWindowsScreenSaver::killScreenSaverFunc,
|
||||
reinterpret_cast<LPARAM>(&killed));
|
||||
CloseDesktop(desktop);
|
||||
}
|
||||
|
||||
// if above failed or wasn't tried, try the windows 95 way
|
||||
@@ -232,68 +193,9 @@ CMSWindowsScreenSaver::deactivate()
|
||||
bool
|
||||
CMSWindowsScreenSaver::isActive() const
|
||||
{
|
||||
if (m_is95) {
|
||||
return (FindWindow("WindowsScreenSaverClass", NULL) != NULL);
|
||||
}
|
||||
else if (m_isNT) {
|
||||
// screen saver runs on a separate desktop
|
||||
HDESK desktop = OpenDesktop("Screen-saver", 0, FALSE, MAXIMUM_ALLOWED);
|
||||
if (desktop == NULL && GetLastError() != ERROR_ACCESS_DENIED) {
|
||||
// desktop doesn't exist so screen saver is not running
|
||||
return false;
|
||||
}
|
||||
|
||||
// desktop exists. this should indicate that the screen saver
|
||||
// is running but an OS bug can cause a valid handle to be
|
||||
// returned even if the screen saver isn't running (Q230117).
|
||||
// we'll try to enumerate the windows on the desktop and, if
|
||||
// there are any, we assume the screen saver is running. (note
|
||||
// that if we don't have permission to enumerate then we'll
|
||||
// assume that the screen saver is not running.) that'd be
|
||||
// easy enough except there's another OS bug (Q198590) that can
|
||||
// cause EnumDesktopWindows() to enumerate the windows of
|
||||
// another desktop if the requested desktop has no windows. to
|
||||
// work around that we have to verify that the enumerated
|
||||
// windows are, in fact, on the expected desktop.
|
||||
CFindScreenSaverInfo info;
|
||||
info.m_desktop = desktop;
|
||||
info.m_window = NULL;
|
||||
EnumDesktopWindows(desktop,
|
||||
&CMSWindowsScreenSaver::findScreenSaverFunc,
|
||||
reinterpret_cast<LPARAM>(&info));
|
||||
|
||||
// done with desktop
|
||||
CloseDesktop(desktop);
|
||||
|
||||
// screen saver is running if a window was found
|
||||
return (info.m_window != NULL);
|
||||
}
|
||||
else {
|
||||
BOOL running;
|
||||
SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
|
||||
return (running != FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CALLBACK
|
||||
CMSWindowsScreenSaver::findScreenSaverFunc(HWND hwnd, LPARAM arg)
|
||||
{
|
||||
CFindScreenSaverInfo* info = reinterpret_cast<CFindScreenSaverInfo*>(arg);
|
||||
|
||||
if (info->m_desktop != NULL) {
|
||||
DWORD threadID = GetWindowThreadProcessId(hwnd, NULL);
|
||||
HDESK desktop = GetThreadDesktop(threadID);
|
||||
if (desktop != NULL && desktop != info->m_desktop) {
|
||||
// stop enumerating -- wrong desktop
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// found a window
|
||||
info->m_window = hwnd;
|
||||
|
||||
// don't need to enumerate further
|
||||
return FALSE;
|
||||
BOOL running;
|
||||
SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
|
||||
return (running != FALSE);
|
||||
}
|
||||
|
||||
BOOL CALLBACK
|
||||
@@ -309,23 +211,6 @@ CMSWindowsScreenSaver::killScreenSaverFunc(HWND hwnd, LPARAM arg)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
DWORD
|
||||
CMSWindowsScreenSaver::findScreenSaver()
|
||||
{
|
||||
// try windows 95 way
|
||||
HWND hwnd = FindWindow("WindowsScreenSaverClass", NULL);
|
||||
|
||||
// get process ID of process that owns the window, if found
|
||||
if (hwnd != NULL) {
|
||||
DWORD processID;
|
||||
GetWindowThreadProcessId(hwnd, &processID);
|
||||
return processID;
|
||||
}
|
||||
|
||||
// not found
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsScreenSaver::watchDesktop()
|
||||
{
|
||||
@@ -382,41 +267,10 @@ CMSWindowsScreenSaver::watchDesktopThread(void*)
|
||||
// wait a bit
|
||||
ARCH->sleep(0.2);
|
||||
|
||||
if (m_isNT) {
|
||||
// get current desktop
|
||||
HDESK desk = OpenInputDesktop(0, FALSE, GENERIC_READ);
|
||||
if (desk == NULL) {
|
||||
// can't open desktop so keep waiting
|
||||
continue;
|
||||
}
|
||||
|
||||
// get current desktop name length
|
||||
DWORD size;
|
||||
GetUserObjectInformation(desk, UOI_NAME, NULL, 0, &size);
|
||||
|
||||
// allocate more space for the name, if necessary
|
||||
if (size > reserved) {
|
||||
reserved = size;
|
||||
name = (TCHAR*)alloca(reserved + sizeof(TCHAR));
|
||||
}
|
||||
|
||||
// get current desktop name
|
||||
GetUserObjectInformation(desk, UOI_NAME, name, size, &size);
|
||||
CloseDesktop(desk);
|
||||
|
||||
// compare name to screen saver desktop name
|
||||
if (_tcsicmp(name, TEXT("Screen-saver")) == 0) {
|
||||
// still the screen saver desktop so keep waiting
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 2000/XP have a sane way to detect a runnin screensaver.
|
||||
BOOL running;
|
||||
SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
|
||||
if (running) {
|
||||
continue;
|
||||
}
|
||||
BOOL running;
|
||||
SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
|
||||
if (running) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// send screen saver deactivation message
|
||||
@@ -452,12 +306,11 @@ CMSWindowsScreenSaver::setSecure(bool secure, bool saveSecureAsInt)
|
||||
return;
|
||||
}
|
||||
|
||||
const TCHAR* isSecure = m_is95Family ? g_isSecure9x : g_isSecureNT;
|
||||
if (saveSecureAsInt) {
|
||||
CArchMiscWindows::setValue(hkey, isSecure, secure ? 1 : 0);
|
||||
CArchMiscWindows::setValue(hkey, g_isSecureNT, secure ? 1 : 0);
|
||||
}
|
||||
else {
|
||||
CArchMiscWindows::setValue(hkey, isSecure, secure ? "1" : "0");
|
||||
CArchMiscWindows::setValue(hkey, g_isSecureNT, secure ? "1" : "0");
|
||||
}
|
||||
|
||||
CArchMiscWindows::closeKey(hkey);
|
||||
@@ -476,15 +329,14 @@ CMSWindowsScreenSaver::isSecure(bool* wasSecureFlagAnInt) const
|
||||
// get the value. the value may be an int or a string, depending
|
||||
// on the version of windows.
|
||||
bool result;
|
||||
const TCHAR* isSecure = m_is95Family ? g_isSecure9x : g_isSecureNT;
|
||||
switch (CArchMiscWindows::typeOfValue(hkey, isSecure)) {
|
||||
switch (CArchMiscWindows::typeOfValue(hkey, g_isSecureNT)) {
|
||||
default:
|
||||
result = false;
|
||||
break;
|
||||
|
||||
case CArchMiscWindows::kUINT: {
|
||||
DWORD value =
|
||||
CArchMiscWindows::readValueInt(hkey, isSecure);
|
||||
CArchMiscWindows::readValueInt(hkey, g_isSecureNT);
|
||||
*wasSecureFlagAnInt = true;
|
||||
result = (value != 0);
|
||||
break;
|
||||
@@ -492,7 +344,7 @@ CMSWindowsScreenSaver::isSecure(bool* wasSecureFlagAnInt) const
|
||||
|
||||
case CArchMiscWindows::kSTRING: {
|
||||
std::string value =
|
||||
CArchMiscWindows::readValueString(hkey, isSecure);
|
||||
CArchMiscWindows::readValueString(hkey, g_isSecureNT);
|
||||
*wasSecureFlagAnInt = false;
|
||||
result = (value != "0");
|
||||
break;
|
||||
|
||||
@@ -60,10 +60,8 @@ private:
|
||||
HWND m_window;
|
||||
};
|
||||
|
||||
static BOOL CALLBACK findScreenSaverFunc(HWND hwnd, LPARAM lParam);
|
||||
static BOOL CALLBACK killScreenSaverFunc(HWND hwnd, LPARAM lParam);
|
||||
|
||||
DWORD findScreenSaver();
|
||||
void watchDesktop();
|
||||
void watchProcess(HANDLE process);
|
||||
void unwatchProcess();
|
||||
@@ -74,9 +72,6 @@ private:
|
||||
bool isSecure(bool* wasSecureAnInt) const;
|
||||
|
||||
private:
|
||||
bool m_is95Family;
|
||||
bool m_is95;
|
||||
bool m_isNT;
|
||||
BOOL m_wasEnabled;
|
||||
bool m_wasSecure;
|
||||
bool m_wasSecureAnInt;
|
||||
|
||||
Reference in New Issue
Block a user