feat(tray): multiple hosts

This commit is contained in:
Alexis 2018-11-22 16:20:49 +01:00
parent f00be0b552
commit 0b1b0eb1a7
8 changed files with 14 additions and 10 deletions

View File

@ -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);

View File

@ -10,7 +10,8 @@ namespace waybar::modules::SNI {
class Host {
public:
Host(const Json::Value&, const std::function<void(std::unique_ptr<Item>&)>&,
Host(const std::size_t id, const Json::Value&,
const std::function<void(std::unique_ptr<Item>&)>&,
const std::function<void(std::unique_ptr<Item>&)>&);
~Host();
private:

View File

@ -2,6 +2,7 @@
#include <fmt/format.h>
#include <thread>
#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:

View File

@ -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

View File

@ -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

View File

@ -4,10 +4,11 @@
using namespace waybar::modules::SNI;
Host::Host(const Json::Value &config, const std::function<void(std::unique_ptr<Item>&)>& on_add,
Host::Host(const std::size_t id, const Json::Value &config,
const std::function<void(std::unique_ptr<Item>&)>& on_add,
const std::function<void(std::unique_ptr<Item>&)>& 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)

View File

@ -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());

View File

@ -2,8 +2,8 @@
#include <iostream>
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>& item)