diff --git a/.clang-format b/.clang-format index d32bc89..4cfb2df 100644 --- a/.clang-format +++ b/.clang-format @@ -9,4 +9,7 @@ IncludeCategories: Priority: 2 - Regex: '.*' Priority: 3 -IncludeBlocks: Regroup \ No newline at end of file +IncludeBlocks: Regroup + +# remove unused includes +SortIncludes: true diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..f9420da --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,20 @@ +name: ci + +on: + push: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + container: + image: git.rivercry.com/system/bar:latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Configure + run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + + - name: Build + run: cmake --build build --config Release -j "$(nproc)" diff --git a/CMakeLists.txt b/CMakeLists.txt index 484eae6..fd165d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,9 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -DNDEBUG -Wall -Wextra -Wpedantic -Werror") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -Wall -Wextra -Wpedantic") +set(CMAKE_C_COMPILER "clang") +set(CMAKE_CXX_COMPILER "clang++") + find_package(PkgConfig REQUIRED) pkg_check_modules(GTKMM REQUIRED gtkmm-4.0) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ed60a5d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM archlinux:latest + +RUN pacman -Syu --noconfirm --needed \ + base-devel \ + clang \ + lld \ + ninja \ + cmake \ + pkgconf \ + git \ + ca-certificates \ + gtkmm-4.0 \ + gtk4 \ + gtk4-layer-shell \ + webkitgtk-6.0 \ + curl \ + nlohmann-json \ + && pacman -Scc --noconfirm + +ENV CC=clang \ + CXX=clang++ + +WORKDIR /workspace diff --git a/include/services/dbus/mpris.hpp b/include/services/dbus/mpris.hpp index 3c5b6e2..d6b9c79 100644 --- a/include/services/dbus/mpris.hpp +++ b/include/services/dbus/mpris.hpp @@ -1,7 +1,9 @@ #pragma once #include +#include #include +#include "services/dbus/messages.hpp" class MprisController { public: @@ -12,12 +14,15 @@ class MprisController { void next_song(); void previous_song(); + sigc::signal &signal_mpris_updated(); + private: Glib::RefPtr m_connection; Glib::RefPtr m_proxy; + sigc::signal mprisUpdatedSignal; void on_bus_connected(const Glib::RefPtr &result); - void launchNotification(); + void signalNotification(); // Called when the song changes void on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties, diff --git a/include/services/hyprland.hpp b/include/services/hyprland.hpp index 388e0d7..64072c5 100644 --- a/include/services/hyprland.hpp +++ b/include/services/hyprland.hpp @@ -101,7 +101,7 @@ class HyprlandService { int socketFd; /// - void bindSocket(); + void bindHyprlandSocket(); void init(); diff --git a/include/widgets/notification/spotifyNotification.hpp b/include/widgets/notification/spotifyNotification.hpp index 6381b0c..87db4c3 100644 --- a/include/widgets/notification/spotifyNotification.hpp +++ b/include/widgets/notification/spotifyNotification.hpp @@ -1,16 +1,17 @@ -#pragma once +#pragma once #include -#include + #include "services/dbus/messages.hpp" #include "widgets/notification/baseNotification.hpp" -#include "gtkmm/box.h" + #include "gtkmm/centerbox.h" class SpotifyNotification : public BaseNotification { public: SpotifyNotification(std::shared_ptr monitor, MprisPlayer2Message message); virtual ~SpotifyNotification() = default; - private: - std::unique_ptr createButtonBox(MprisPlayer2Message mpris); + + private: + std::unique_ptr createButtonBox(MprisPlayer2Message mpris); }; diff --git a/src/app.cpp b/src/app.cpp index 834c1b9..7487312 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -4,6 +4,7 @@ #include #include "services/dbus/notification.hpp" #include "services/dbus/mpris.hpp" +#include "services/notificationController.hpp" #include "services/textureCache.hpp" App::App() { @@ -13,6 +14,12 @@ App::App() { this->notificationService = std::make_shared(); this->mprisController = std::make_shared(); + auto notificationController = NotificationController::getInstance(); + this->mprisController->signal_mpris_updated().connect( + [notificationController](const MprisPlayer2Message &msg) { + notificationController->showSpotifyNotification(msg); + }); + app->signal_activate().connect([&]() { auto display = Gdk::Display::get_default(); auto monitors = display->get_monitors(); diff --git a/src/services/dbus/mpris.cpp b/src/services/dbus/mpris.cpp index d72e9bc..7b0f73a 100644 --- a/src/services/dbus/mpris.cpp +++ b/src/services/dbus/mpris.cpp @@ -1,11 +1,8 @@ #include "services/dbus/mpris.hpp" -#include "services/dbus/messages.hpp" - #include #include #include "helpers/string.hpp" -#include "services/notificationController.hpp" #include "giomm/dbusconnection.h" #include "giomm/dbusproxy.h" @@ -17,6 +14,11 @@ MprisController::MprisController() { sigc::mem_fun(*this, &MprisController::on_bus_connected)); } +sigc::signal & +MprisController::signal_mpris_updated() { + return mprisUpdatedSignal; +} + void MprisController::on_bus_connected(const Glib::RefPtr &result) { if (!result) { std::cerr << "DBus Connection Error: null async result" << std::endl; @@ -38,7 +40,7 @@ void MprisController::on_bus_connected(const Glib::RefPtr &res std::cout << "Connected to: " << player_bus_name << std::endl; // uncomment if launch notification on start - launchNotification(); + signalNotification(); m_proxy->signal_properties_changed().connect( sigc::mem_fun(*this, &MprisController::on_properties_changed)); @@ -49,7 +51,7 @@ void MprisController::on_bus_connected(const Glib::RefPtr &res } } -void MprisController::launchNotification() { +void MprisController::signalNotification() { if (!m_proxy) { return; } @@ -93,8 +95,6 @@ void MprisController::launchNotification() { artwork_url = art_var.get(); } - auto notifactionController = NotificationController::getInstance(); - MprisPlayer2Message mpris; mpris.title = StringHelper::trimToSize(title, 30); mpris.artist = StringHelper::trimToSize(artist, 30); @@ -102,14 +102,14 @@ void MprisController::launchNotification() { mpris.play_pause = [this]() { this->toggle_play(); }; mpris.next = [this]() { this->next_song(); }; mpris.previous = [this]() { this->previous_song(); }; - notifactionController->showSpotifyNotification(mpris); + mprisUpdatedSignal.emit(mpris); } void MprisController::on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties, const std::vector &) { if (changed_properties.find("Metadata") != changed_properties.end()) { - launchNotification(); + signalNotification(); } } diff --git a/src/services/hyprland.cpp b/src/services/hyprland.cpp index bba56af..09b9ad0 100644 --- a/src/services/hyprland.cpp +++ b/src/services/hyprland.cpp @@ -18,7 +18,7 @@ HyprlandService::HyprlandService() { init(); - bindSocket(); + this->bindHyprlandSocket(); } void HyprlandService::init() { @@ -83,7 +83,7 @@ void HyprlandService::init() { } } -void HyprlandService::bindSocket() { +void HyprlandService::bindHyprlandSocket() { std::string socketPath = HyprSocketHelper::getHyprlandSocketPath(); socketFd = socket(AF_UNIX, SOCK_STREAM, 0); @@ -105,7 +105,8 @@ void HyprlandService::bindSocket() { return; } - GSource *source = g_unix_fd_source_new(socketFd, static_cast(G_IO_IN | G_IO_HUP | G_IO_ERR)); + auto socket_conditions = static_cast(G_IO_IN | G_IO_HUP | G_IO_ERR); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange) + GSource *source = g_unix_fd_source_new(socketFd, socket_conditions); auto onSocketEvent = [](gint fd, GIOCondition , gpointer user_data) -> gboolean { HyprlandService *self = static_cast(user_data); @@ -214,7 +215,6 @@ void HyprlandService::onCloseWindow(std::string windowData) { void HyprlandService::handleSocketMessage(SocketHelper::SocketMessage message) { if (socketEventTypeMap.find(message.eventType) == socketEventTypeMap.end()) { - return; }