[compat] fix logind DBus on non-linux unixes (#2648)

Backported from FreeBSD ports patches

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2648
Reviewed-by: crueter <crueter@eden-emu.dev>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Co-authored-by: lizzie <lizzie@eden-emu.dev>
Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie
2025-10-02 23:39:59 +02:00
committed by crueter
parent de594c8792
commit 9173eec402

View File

@@ -1770,16 +1770,25 @@ void GMainWindow::OnDisplayTitleBars(bool show) {
void GMainWindow::SetupPrepareForSleep() {
#ifdef __unix__
auto bus = QDBusConnection::systemBus();
if (bus.isConnected()) {
if (auto bus = QDBusConnection::systemBus(); bus.isConnected()) {
// See https://github.com/ConsoleKit2/ConsoleKit2/issues/150
#ifdef __linux__
const auto dbus_logind_service = QStringLiteral("org.freedesktop.login1");
const auto dbus_logind_path = QStringLiteral("/org/freedesktop/login1");
const auto dbus_logind_manager_if = QStringLiteral("org.freedesktop.login1.Manager");
//const auto dbus_logind_session_if = QStringLiteral("org.freedesktop.login1.Session");
#else
const auto dbus_logind_service = QStringLiteral("org.freedesktop.ConsoleKit");
const auto dbus_logind_path = QStringLiteral("/org/freedesktop/ConsoleKit/Manager");
const auto dbus_logind_manager_if = QStringLiteral("org.freedesktop.ConsoleKit.Manager");
//const auto dbus_logind_session_if = QStringLiteral("org.freedesktop.ConsoleKit.Session");
#endif
const bool success = bus.connect(
QStringLiteral("org.freedesktop.login1"), QStringLiteral("/org/freedesktop/login1"),
QStringLiteral("org.freedesktop.login1.Manager"), QStringLiteral("PrepareForSleep"),
dbus_logind_service, dbus_logind_path,
dbus_logind_manager_if, QStringLiteral("PrepareForSleep"),
QStringLiteral("b"), this, SLOT(OnPrepareForSleep(bool)));
if (!success) {
if (!success)
LOG_WARNING(Frontend, "Couldn't register PrepareForSleep signal");
}
} else {
LOG_WARNING(Frontend, "QDBusConnection system bus is not connected");
}