2021-07-23 15:22:28 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2021-07-23 15:22:28 +00:00
|
|
|
*/
|
2025-01-24 00:11:17 +00:00
|
|
|
|
2021-07-23 15:22:28 +00:00
|
|
|
#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-10-17 18:04:35 +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-10-17 18:04:35 +00:00
|
|
|
XWindowsPowerManager::~XWindowsPowerManager()
|
|
|
|
|
{
|
|
|
|
|
enableSleep();
|
|
|
|
|
}
|
2021-07-23 15:22:28 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void XWindowsPowerManager::disableSleep() const
|
|
|
|
|
{
|
|
|
|
|
if (!sleepInhibitCall(true, ArchSystemUnix::InhibitScreenServices::kScreenSaver) &&
|
|
|
|
|
!sleepInhibitCall(true, ArchSystemUnix::InhibitScreenServices::kSessionManager)) {
|
2025-01-21 12:14:08 +00:00
|
|
|
LOG((CLOG_WARN "failed to prevent system from going to sleep"));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2021-07-23 15:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void XWindowsPowerManager::enableSleep() const
|
|
|
|
|
{
|
|
|
|
|
if (!sleepInhibitCall(false, ArchSystemUnix::InhibitScreenServices::kScreenSaver) &&
|
|
|
|
|
!sleepInhibitCall(false, ArchSystemUnix::InhibitScreenServices::kSessionManager)) {
|
2025-01-21 12:14:08 +00:00
|
|
|
LOG((CLOG_WARN "failed to enable system idle sleep"));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2021-07-23 15:22:28 +00:00
|
|
|
}
|