From 92c576cd089ad5fffb47bbbdff6788f2695443d1 Mon Sep 17 00:00:00 2001 From: Nathaniel van Diepen Date: Tue, 16 Jan 2024 17:37:40 -0700 Subject: [PATCH] Get DBus to work --- applications/display-server/dbusinterface.cpp | 24 ++++++++----------- applications/display-server/dbusinterface.h | 2 +- applications/display-server/main.cpp | 3 ++- applications/test/main.cpp | 3 --- shared/liboxide/meta.h | 1 - 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/applications/display-server/dbusinterface.cpp b/applications/display-server/dbusinterface.cpp index a199513ca..7c6890d45 100644 --- a/applications/display-server/dbusinterface.cpp +++ b/applications/display-server/dbusinterface.cpp @@ -5,7 +5,10 @@ #include #include -DbusInterface::DbusInterface(QObject* parent) : QObject(parent) {} +DbusInterface::DbusInterface(QObject* parent) : QObject(parent){ + // Needed to trick QtDBus into exposing the object + setProperty("__init__", true); +} void DbusInterface::registerService(){ #ifdef EPAPER @@ -17,31 +20,24 @@ void DbusInterface::registerService(){ qFatal("Failed to connect to system bus."); } QDBusConnectionInterface* interface = bus.interface(); - auto reply = interface->registerService(BLIGHT_SERVICE); - bus.registerService(BLIGHT_SERVICE); - if(!reply.isValid()){ - QDBusError ex = reply.error(); - qFatal("Unable to register service: %s", ex.message().toStdString().c_str()); - } if(!bus.registerObject("/", this, QDBusConnection::ExportAllContents)){ qFatal("Unable to register interface: %s", bus.lastError().message().toStdString().c_str()); } if(!bus.objectRegisteredAt("/")){ qFatal("Object not appearing!"); } - if(!bus.registerObject(BLIGHT_SERVICE_PATH, this, QDBusConnection::ExportAllContents)){ - qFatal("Unable to register interface: %s", bus.lastError().message().toStdString().c_str()); - } - if(!bus.objectRegisteredAt(BLIGHT_SERVICE_PATH)){ - qFatal("Object not appearing!"); + auto reply = interface->registerService(BLIGHT_SERVICE); + bus.registerService(BLIGHT_SERVICE); + if(!reply.isValid()){ + QDBusError ex = reply.error(); + qFatal("Unable to register service: %s", ex.message().toStdString().c_str()); } - O_DEBUG("Object registered to " BLIGHT_SERVICE_PATH); connect( interface, &QDBusConnectionInterface::serviceOwnerChanged, this, &DbusInterface::serviceOwnerChanged - ); + ); O_DEBUG("Connected service to bus"); } diff --git a/applications/display-server/dbusinterface.h b/applications/display-server/dbusinterface.h index bc61854ca..7fca36ebe 100644 --- a/applications/display-server/dbusinterface.h +++ b/applications/display-server/dbusinterface.h @@ -10,7 +10,7 @@ #include "../../shared/liboxide/meta.h" -class DbusInterface : public QObject, public QDBusContext { +class DbusInterface : public QObject, protected QDBusContext { Q_OBJECT Q_CLASSINFO("Version", OXIDE_INTERFACE_VERSION) Q_CLASSINFO("D-Bus Interface", BLIGHT_INTERFACE) diff --git a/applications/display-server/main.cpp b/applications/display-server/main.cpp index 27fd2a762..55ecfc6f0 100755 --- a/applications/display-server/main.cpp +++ b/applications/display-server/main.cpp @@ -148,6 +148,7 @@ int main(int argc, char* argv[]){ if(engine.rootObjects().isEmpty()){ qFatal("Failed to load main layout"); } - DbusInterface(qApp).registerService(); + DbusInterface interface(qApp); + interface.registerService(); return app.exec(); } diff --git a/applications/test/main.cpp b/applications/test/main.cpp index d5cdda103..553d01fd7 100644 --- a/applications/test/main.cpp +++ b/applications/test/main.cpp @@ -49,9 +49,6 @@ int main(int argc, char *argv[]){ if(res.isError()){ qFatal("Failed to get connection: %s", res.error().message().toStdString().c_str()); } - if(!res.isValid()){ - qFatal("Failed to get connection: Invalid DBus response"); - } auto qfd = res.value(); if(!qfd.isValid()){ qFatal("Failed to get connection: Invalid file descriptor"); diff --git a/shared/liboxide/meta.h b/shared/liboxide/meta.h index d5023e55b..d913eaf7f 100644 --- a/shared/liboxide/meta.h +++ b/shared/liboxide/meta.h @@ -98,6 +98,5 @@ #define OXIDE_SCREENSHOT_INTERFACE OXIDE_SERVICE ".Screenshot" #define BLIGHT_SERVICE "codes.eeems.blight1" -#define BLIGHT_SERVICE_PATH "/codes/eeems/blight1" #define BLIGHT_INTERFACE BLIGHT_SERVICE ".Compositor" /*! @} */