From 0b1b0eb1a73f0867c7b0adbe10141cb54cab81e1 Mon Sep 17 00:00:00 2001 From: Alexis Date: Thu, 22 Nov 2018 16:20:49 +0100 Subject: [PATCH] feat(tray): multiple hosts --- include/bar.hpp | 1 + include/modules/sni/host.hpp | 3 ++- include/modules/sni/tray.hpp | 3 ++- resources/config | 2 +- src/factory.cpp | 2 +- src/modules/sni/host.cpp | 7 ++++--- src/modules/sni/item.cpp | 1 - src/modules/sni/tray.cpp | 5 +++-- 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index a948eaca..55f392ac 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -26,6 +26,7 @@ class Bar { std::string output_name; uint32_t wl_name; bool visible = true; + uint32_t nb_tray_hosts = 0; private: static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t, int32_t); diff --git a/include/modules/sni/host.hpp b/include/modules/sni/host.hpp index 7115a950..5f952fd8 100644 --- a/include/modules/sni/host.hpp +++ b/include/modules/sni/host.hpp @@ -10,7 +10,8 @@ namespace waybar::modules::SNI { class Host { public: - Host(const Json::Value&, const std::function&)>&, + Host(const std::size_t id, const Json::Value&, + const std::function&)>&, const std::function&)>&); ~Host(); private: diff --git a/include/modules/sni/tray.hpp b/include/modules/sni/tray.hpp index fbc31419..afcb7057 100644 --- a/include/modules/sni/tray.hpp +++ b/include/modules/sni/tray.hpp @@ -2,6 +2,7 @@ #include #include +#include "bar.hpp" #include "util/json.hpp" #include "IModule.hpp" #include "modules/sni/watcher.hpp" @@ -11,7 +12,7 @@ namespace waybar::modules::SNI { class Tray : public IModule { public: - Tray(const Json::Value&); + Tray(Bar& bar, const Json::Value&); auto update() -> void; operator Gtk::Widget &(); private: diff --git a/resources/config b/resources/config index b9e751ce..66a75ff0 100644 --- a/resources/config +++ b/resources/config @@ -4,7 +4,7 @@ // "height": 30, // Waybar height // "width": 1280, // Waybar width // Choose the order of the modules - "modules-left": ["sway/workspaces", "sway/mode", "custom/spotify"], + "modules-left": ["sway/workspaces", "sway/mode", "custom/spotify", "tray"], "modules-center": ["sway/window"], "modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "battery#bat2", "clock", "tray"], // Modules configuration diff --git a/src/factory.cpp b/src/factory.cpp index 4fba8704..5db627e1 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -33,7 +33,7 @@ waybar::IModule* waybar::Factory::makeModule(const std::string &name) const } #ifdef HAVE_DBUSMENU if (ref == "tray") { - return new waybar::modules::SNI::Tray(config_[name]); + return new waybar::modules::SNI::Tray(bar_, config_[name]); } #endif #ifdef HAVE_LIBNL diff --git a/src/modules/sni/host.cpp b/src/modules/sni/host.cpp index a5b07fb4..6f5b9f07 100644 --- a/src/modules/sni/host.cpp +++ b/src/modules/sni/host.cpp @@ -4,10 +4,11 @@ using namespace waybar::modules::SNI; -Host::Host(const Json::Value &config, const std::function&)>& on_add, +Host::Host(const std::size_t id, const Json::Value &config, + const std::function&)>& on_add, const std::function&)>& on_remove) -: bus_name_("org.kde.StatusNotifierHost-" + std::to_string(getpid()) + "-1"), - object_path_("/StatusNotifierHost"), +: bus_name_("org.kde.StatusNotifierHost-" + std::to_string(getpid()) + "-" + std::to_string(id)), + object_path_("/StatusNotifierHost/" + std::to_string(id)), bus_name_id_(Gio::DBus::own_name(Gio::DBus::BusType::BUS_TYPE_SESSION, bus_name_, sigc::mem_fun(*this, &Host::busAcquired))), config_(config), on_add_(on_add), on_remove_(on_remove) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index de1ebd45..60687dc3 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -228,7 +228,6 @@ void waybar::modules::SNI::Item::onMenuDestroyed(Item *self) bool waybar::modules::SNI::Item::makeMenu(GdkEventButton *const &ev) { - std::cout << bus_name << std::endl; if (gtk_menu == nullptr) { if (!menu.empty()) { dbus_menu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data()); diff --git a/src/modules/sni/tray.cpp b/src/modules/sni/tray.cpp index c119a337..4b8f9eb2 100644 --- a/src/modules/sni/tray.cpp +++ b/src/modules/sni/tray.cpp @@ -2,8 +2,8 @@ #include -waybar::modules::SNI::Tray::Tray(const Json::Value &config) - : config_(config), watcher_(), host_(config, +waybar::modules::SNI::Tray::Tray(Bar& bar, const Json::Value &config) + : config_(config), watcher_(), host_(bar.nb_tray_hosts, config, std::bind(&Tray::onAdd, this, std::placeholders::_1), std::bind(&Tray::onRemove, this, std::placeholders::_1)) { @@ -11,6 +11,7 @@ waybar::modules::SNI::Tray::Tray(const Json::Value &config) if (config_["spacing"].isUInt()) { box_.set_spacing(config_["spacing"].asUInt()); } + bar.nb_tray_hosts += 1; } void waybar::modules::SNI::Tray::onAdd(std::unique_ptr& item)