SYNERGY-1088 Windows client ignores prevent sleeping option

This commit is contained in:
Serhii Hadzhilov
2021-07-23 15:27:16 +03:00
parent 8dd68abf56
commit 1dfafb03dc
4 changed files with 82 additions and 11 deletions

View File

@ -0,0 +1,37 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MSWindowsPowerManager.h"
#include "arch/win32/ArchMiscWindows.h"
MSWindowsPowerManager::~MSWindowsPowerManager()
{
enableSleep();
}
void MSWindowsPowerManager::disableSleep()
{
ArchMiscWindows::addBusyState(ArchMiscWindows::kSYSTEM);
ArchMiscWindows::addBusyState(ArchMiscWindows::kDISPLAY);
}
void MSWindowsPowerManager::enableSleep()
{
// allow the system to enter power saving mode
ArchMiscWindows::removeBusyState(ArchMiscWindows::kSYSTEM);
ArchMiscWindows::removeBusyState(ArchMiscWindows::kDISPLAY);
}

View File

@ -0,0 +1,38 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2021 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MSWINDOWSPOWERMANAGER_H
#define MSWINDOWSPOWERMANAGER_H
class MSWindowsPowerManager
{
public:
~MSWindowsPowerManager();
/**
* @brief Prevents the system from sleep automatically
*/
void disableSleep();
/**
* @brief Enable automatically sleeping
*/
void enableSleep();
};
#endif // MSWINDOWSPOWERMANAGER_H

View File

@ -164,6 +164,10 @@ MSWindowsScreen::MSWindowsScreen(
LOG((CLOG_ERR "failed to get desktop path, no drop target available, error=%d", GetLastError()));
}
if (App::instance().argsBase().m_preventSleep) {
m_powerManager.disableSleep();
}
OleInitialize(0);
m_dropWindow = createDropWindow(m_class, "DropWindow");
m_dropTarget = new MSWindowsDropTarget();
@ -248,11 +252,6 @@ MSWindowsScreen::enable()
// watch jump zones
m_hook.setMode(kHOOK_WATCH_JUMP_ZONE);
}
if (App::instance().argsBase().m_preventSleep) {
ArchMiscWindows::addBusyState(ArchMiscWindows::kSYSTEM);
ArchMiscWindows::addBusyState(ArchMiscWindows::kDISPLAY);
}
}
void
@ -268,11 +267,6 @@ MSWindowsScreen::disable()
// enable special key sequences on win95 family
enableSpecialKeys(true);
}
else {
// allow the system to enter power saving mode
ArchMiscWindows::removeBusyState(ArchMiscWindows::kSYSTEM);
ArchMiscWindows::removeBusyState(ArchMiscWindows::kDISPLAY);
}
// tell key state
m_keyState->disable();
@ -2086,4 +2080,4 @@ MSWindowsScreen::updateScrollDirection()
});
scrollDirectionUpdateThread.detach();
}
}
}

View File

@ -19,6 +19,7 @@
#pragma once
#include "platform/MSWindowsHook.h"
#include "platform/MSWindowsPowerManager.h"
#include "synergy/PlatformScreen.h"
#include "synergy/DragInformation.h"
#include "platform/synwinhk.h"
@ -374,4 +375,5 @@ private:
// -1 for natural scrolling direction, 1 otherwise
SInt32 m_scrollDirectionMouse = 1;
SInt32 m_scrollDirectionTouchpad = 1;
MSWindowsPowerManager m_powerManager;
};