From 83c1f62d2dfb85b5f81fd0c057ddf00490e0def9 Mon Sep 17 00:00:00 2001 From: Awawa <69086569+awawa-dev@users.noreply.github.com> Date: Thu, 11 Jan 2024 00:59:09 +0100 Subject: [PATCH] Fix Linux DBus sleep/wakeup handler --- sources/hyperhdr/SuspendHandlerLinux.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sources/hyperhdr/SuspendHandlerLinux.cpp b/sources/hyperhdr/SuspendHandlerLinux.cpp index 6d05ac7c8..46b45a96d 100644 --- a/sources/hyperhdr/SuspendHandlerLinux.cpp +++ b/sources/hyperhdr/SuspendHandlerLinux.cpp @@ -48,13 +48,15 @@ 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; @@ -62,9 +64,11 @@ SuspendHandler::SuspendHandler() 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; @@ -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); + } }