feat(tray): multiple hosts
This commit is contained in:
parent
f00be0b552
commit
0b1b0eb1a7
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue