2021-07-23 15:22:28 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
|
*
|
|
|
|
|
* 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 "XWindowsPowerManager.h"
|
|
|
|
|
#include "arch/Arch.h"
|
|
|
|
|
#include "base/Log.h"
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
namespace {
|
2021-07-23 15:22:28 +00:00
|
|
|
|
2024-07-16 13:36:44 +00:00
|
|
|
bool sleepInhibitCall(
|
|
|
|
|
bool state, ArchSystemUnix::InhibitScreenServices serviceID) {
|
2024-07-02 19:07:06 +00:00
|
|
|
std::string error;
|
2021-07-23 15:22:28 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (!ArchSystemUnix::DBusInhibitScreenCall(serviceID, state, error)) {
|
|
|
|
|
LOG((CLOG_DEBUG "dbus inhibit error %s", error.c_str()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-07-23 15:22:28 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return true;
|
2021-07-23 15:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
} // namespace
|
2021-07-23 15:22:28 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
XWindowsPowerManager::~XWindowsPowerManager() { enableSleep(); }
|
2021-07-23 15:22:28 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void XWindowsPowerManager::disableSleep() const {
|
2024-07-16 13:36:44 +00:00
|
|
|
if (!sleepInhibitCall(
|
|
|
|
|
true, ArchSystemUnix::InhibitScreenServices::kScreenSaver) &&
|
2024-07-02 19:07:06 +00:00
|
|
|
!sleepInhibitCall(
|
|
|
|
|
true, ArchSystemUnix::InhibitScreenServices::kSessionManager)) {
|
|
|
|
|
LOG((CLOG_INFO "failed to prevent system from going to sleep"));
|
|
|
|
|
}
|
2021-07-23 15:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
void XWindowsPowerManager::enableSleep() const {
|
2024-07-16 13:36:44 +00:00
|
|
|
if (!sleepInhibitCall(
|
|
|
|
|
false, ArchSystemUnix::InhibitScreenServices::kScreenSaver) &&
|
2024-07-02 19:07:06 +00:00
|
|
|
!sleepInhibitCall(
|
|
|
|
|
false, ArchSystemUnix::InhibitScreenServices::kSessionManager)) {
|
|
|
|
|
LOG((CLOG_INFO "failed to enable system idle sleep"));
|
|
|
|
|
}
|
2021-07-23 15:22:28 +00:00
|
|
|
}
|