Skip to content

Commit

Permalink
Fix Linux DBus sleep/wakeup handler
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Jan 10, 2024
1 parent 5b94d91 commit 83c1f62
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions sources/hyperhdr/SuspendHandlerLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,27 @@ namespace {

SuspendHandler::SuspendHandler()
{
if (!QDBusConnection::sessionBus().isConnected())
QDBusConnection bus = QDBusConnection::systemBus();

if (!bus.isConnected())
{
std::cout << "SYSTEM BUS IS NOT CONNECTED!" << std::endl;
return;
}
if (!QDBusConnection::sessionBus().connect(UPOWER_SERVICE, UPOWER_PATH, UPOWER_INTER, "PrepareForSleep", this, SLOT(sleeping(bool))))

if (!bus.connect(UPOWER_SERVICE, UPOWER_PATH, UPOWER_INTER, "PrepareForSleep", this, SLOT(sleeping(bool))))
std::cout << "COULD NOT REGISTER SLEEP HANDLER!" << std::endl;
else
std::cout << "SLEEP HANDLER REGISTERED!" << std::endl;
}

SuspendHandler::~SuspendHandler()
{
if (QDBusConnection::sessionBus().isConnected())
QDBusConnection bus = QDBusConnection::systemBus();

if (bus.isConnected())
{
if (!QDBusConnection::sessionBus().disconnect(UPOWER_SERVICE, UPOWER_PATH, UPOWER_INTER, "PrepareForSleep", this, SLOT(sleeping(bool))))
if (!bus.disconnect(UPOWER_SERVICE, UPOWER_PATH, UPOWER_INTER, "PrepareForSleep", this, SLOT(sleeping(bool))))
std::cout << "COULD NOT DEREGISTER SLEEP HANDLER!" << std::endl;
else
std::cout << "SLEEP HANDLER DEREGISTERED!" << std::endl;
Expand All @@ -74,8 +78,14 @@ SuspendHandler::~SuspendHandler()
void SuspendHandler::sleeping(bool sleep)
{
if (sleep)
{
std::cout << "OS event: going sleep" << std::endl;
emit SignalHibernate(false);
}
else
{
std::cout << "OS event: wake up" << std::endl;
emit SignalHibernate(true);
}
}

0 comments on commit 83c1f62

Please sign in to comment.