From cf4643e1b3ef164caf9f21e8c5b12b7c8e705677 Mon Sep 17 00:00:00 2001 From: Zachary Hall Date: Tue, 17 Dec 2024 11:06:29 -0800 Subject: [PATCH] Support old sdbus-c++, for Debian and other stable distros --- CMakeLists.txt | 21 ++++++++++++--------- config.cmake.h.in | 3 ++- dbus.cpp | 28 ++++++++++++++-------------- dbus.hpp | 30 +++++++++++++++++++++++++----- 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 526fcfd..3688aad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -422,9 +422,17 @@ else() endif() if (ENABLE_DBUS) find_package(sdbus-c++ 2.0) - if(NOT ${sdbus-c++_FOUND}) - set(ENABLE_DBUS OFF) - message("Warning: Dbus support not found - Not enabling DBus. This program requires version 2.0 or later.") + if(${sdbus-c++_FOUND}) + set(OLD_SDBUS OFF) + else() + find_package(sdbus-c++) + if (${sdbus-c++_FOUND}) + set(OLD_SDBUS ON) + else() + set(OLD_SDBUS ON) + set(ENABLE_DBUS OFF) + message("Warning: Dbus support not found - Not enabling DBus. This program requires version 2.0 or later.") + endif() endif() endif() set(SDL2_TARGET SDL2::SDL2) @@ -436,12 +444,7 @@ endif() if(BUILD_PROTOBUF) add_subdirectory(subprojects/protobuf) else() - if (CMAKE_SYSTEM_NAME STREQUAL "Haiku") find_package(Protobuf REQUIRED) - else() - find_package(protobuf REQUIRED) - find_package(absl CONFIG REQUIRED) - endif() endif() if (${ENABLE_DBUS}) @@ -571,7 +574,7 @@ if(DEFINED EMSCRIPTEN) copy_to_bindir(assets/ForkAwesome/css/fork-awesome.min.css.map fork-awesome.min.css.map) endif() target_link_libraries(${TARGET_NAME} PUBLIC liblooper ${UI_BACKENDS} ${PLAYBACK_BACKENDS}) -install(TARGETS ${TARGET_NAME} ${EXTRA_LIBS}) +install(TARGETS ${TARGET_NAME} ${EXTRA_LIBS} ${UI_BACKENDS} ${PLAYBACK_BACKENDS}) if (${BUILD_SDL2}) install(EXPORT SDL2-static SDL2main) endif() diff --git a/config.cmake.h.in b/config.cmake.h.in index 2da5dc2..b483c10 100644 --- a/config.cmake.h.in +++ b/config.cmake.h.in @@ -2,7 +2,8 @@ #define TAG "@TAG@" #define LOCALE_DIR "@LOCALE_DIR@" #cmakedefine01 DEBUG_MODE_VALUE +#cmakedefine01 OLD_SDBUS #if DEBUG_MODE_VALUE==1 #define DEBUG_MODE #endif -#undef DEBUG_MODE_VALUE \ No newline at end of file +#undef DEBUG_MODE_VALUE diff --git a/dbus.cpp b/dbus.cpp index ceb2399..5012b06 100644 --- a/dbus.cpp +++ b/dbus.cpp @@ -6,7 +6,7 @@ #include #ifdef DBUS_ENABLED MprisAPI::MprisAPI(sdbus::IConnection &connection, std::string objectPath, DBusAPI *dbus_api) - : AdaptorInterfaces(connection, sdbus::ObjectPath{objectPath}) + : AdaptorInterfaces(connection, OBJECT_PATH(objectPath)) , dbus_api(dbus_api) , connection(connection) { @@ -57,12 +57,12 @@ void MprisAPI::Rate(const double &value) { std::map MprisAPI::Metadata() { std::map output; if (!dbus_api->IsStopped()) { - output["mpris:length"] = sdbus::Variant{(int64_t)(dbus_api->Length() * 1000000)}; - output["mpris:trackid"] = sdbus::Variant{playing_track_id}; - output["xesam:title"] = sdbus::Variant{dbus_api->FileTitle()}; - output["xesam:url"] = sdbus::Variant{dbus_api->FilePath()}; + output["mpris:length"] = VARIANT((int64_t)(dbus_api->Length() * 1000000)); + output["mpris:trackid"] = VARIANT(playing_track_id); + output["xesam:title"] = VARIANT(dbus_api->FileTitle()); + output["xesam:url"] = VARIANT(dbus_api->FilePath()); } else { - output["mpris:trackid"] = sdbus::Variant{empty_track_id}; + output["mpris:trackid"] = VARIANT(empty_track_id); } return output; } @@ -90,11 +90,11 @@ std::vector MprisAPI::GetTracksMetadata(const std::vector &T if (!dbus_api->IsStopped()) { output.push_back(Metadata()); auto streams = dbus_api->playback->get_streams(); - int i = 0; + int i = 0; for (auto stream : streams) { std::map meta; - meta["mpris:trackid"] = sdbus::Variant{fmt::format("{}{}", streamPrefix, i)}; - meta["xesam:title"] = sdbus::Variant{stream.name}; + meta["mpris:trackid"] = VARIANT(fmt::format("{}{}", streamPrefix, i)); + meta["xesam:title"] = VARIANT(stream.name); i++; } } @@ -123,7 +123,7 @@ std::vector MprisAPI::Tracks() { auto streams = dbus_api->playback->get_streams(); int i = 0; for (auto stream : streams) { - output.push_back(sdbus::ObjectPath{fmt::format("{}{}", streamPrefix, i)}); + output.push_back(OBJECT_PATH(fmt::format("{}{}", streamPrefix, i))); i++; } return output; @@ -143,14 +143,14 @@ DBusAPI::DBusAPI(Playback *playback, bool daemon) } #else DBusAPI::DBusAPI(Playback *playback, sdbus::IConnection &connection, std::string objectPath, bool daemon) - : AdaptorInterfaces(connection, sdbus::ObjectPath{objectPath}) + : AdaptorInterfaces(connection, OBJECT_PATH(objectPath)) , daemon(daemon) , playback(playback) , connection(connection) { registerAdaptor(); playback->register_handle(this); - auto mprisConnection = sdbus::createSessionBusConnection(sdbus::ServiceName{"org.mpris.MediaPlayer2.Looper"}); + auto mprisConnection = sdbus::createSessionBusConnection(SERVICE_NAME("org.mpris.MediaPlayer2.Looper")); auto &mprisConRef = *mprisConnection.release(); mpris = new MprisAPI(mprisConRef, "/org/mpris/MediaPlayer2", this); threadFunc = std::thread([this]() { @@ -166,7 +166,7 @@ const char *DBusAPI::objectPath = "/com/complecwaft/looper"; const char *DBusAPI::busName = "com.complecwaft.looper"; DBusAPI *DBusAPI::Create(Playback *playback, bool daemon) { #ifdef DBUS_ENABLED - auto connection = sdbus::createSessionBusConnection(sdbus::ServiceName{busName}); + auto connection = sdbus::createSessionBusConnection(sdbus::ServiceName(busName)); auto &con_ref = *connection.release(); return new DBusAPI(playback, con_ref, objectPath, daemon); #else @@ -590,7 +590,7 @@ DBusAPISender *DBusAPISender::Create() { } #ifdef DBUS_ENABLED DBusAPISender::DBusAPISender(sdbus::IConnection &connection, std::string busName, std::string objectPath) - : ProxyInterfaces(connection, sdbus::BusName{busName}, sdbus::ObjectPath{objectPath}) { + : ProxyInterfaces(connection, BUS_NAME(busName), OBJECT_PATH(objectPath)) { registerProxy(); DEBUG.writeln("Pinging DBus API to check for its existance."); Ping(); diff --git a/dbus.hpp b/dbus.hpp index 4d30584..bbe2e49 100644 --- a/dbus.hpp +++ b/dbus.hpp @@ -12,6 +12,26 @@ #include #include #ifdef DBUS_ENABLED +#ifdef OLD_SDBUS +#define OBJECT_PATH(path) path +#define VARIANT(value) value +#define BUS_NAME(name) name +#define SERVICE_NAME(name) name +#define MEMBER_NAME(name) name +#define INTERFACE_NAME(name) name +namespace sdbus { + typedef std::string MemberName; + typedef std::string ServiceName; +} +#else +#define OBJECT_PATH(path) sdbus::ObjectPath{path} +#define VARIANT(value) sdbus::Variant{value} +#define BUS_NAME(name) sdbus::BusName{name} +#define SERVICE_NAME(name) sdbus::ServiceName{name} +#define MEMBER_NAME(name) sdbus::MemberName{name} +#define INTERFACE_NAME(name) sdbus::InterfaceName{name} +#endif + class DBusAPI; class MprisAPI : public sdbus::AdaptorInterfaces { friend class DBusAPI; @@ -25,15 +45,15 @@ class MprisAPI : public sdbus::AdaptorInterfaces properties) { std::vector property_vec; for (auto property : properties) { - property_vec.push_back(sdbus::MemberName{property}); - } - emitPropertiesChangedSignal(sdbus::InterfaceName{interface}, property_vec); + property_vec.push_back(MEMBER_NAME(property)); + } + emitPropertiesChangedSignal(INTERFACE_NAME(interface), property_vec); } public: #define meta_t std::map #define track_id_t sdbus::ObjectPath - const sdbus::ObjectPath playing_track_id = sdbus::ObjectPath{"/com/complecwaft/Looper/PlayingTrack"}; - const sdbus::ObjectPath empty_track_id = sdbus::ObjectPath{"/org/mpris/MediaPlayer2/TrackList/NoTrack"}; + const sdbus::ObjectPath playing_track_id = OBJECT_PATH("/com/complecwaft/Looper/PlayingTrack"); + const sdbus::ObjectPath empty_track_id = OBJECT_PATH("/org/mpris/MediaPlayer2/TrackList/NoTrack"); inline void Raise() override { } void Quit() override;