feat(tray): multiple hosts
This commit is contained in:
parent
f00be0b552
commit
0b1b0eb1a7
|
@ -26,6 +26,7 @@ class Bar {
|
||||||
std::string output_name;
|
std::string output_name;
|
||||||
uint32_t wl_name;
|
uint32_t wl_name;
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
|
uint32_t nb_tray_hosts = 0;
|
||||||
private:
|
private:
|
||||||
static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t,
|
static void handleLogicalPosition(void *, struct zxdg_output_v1 *, int32_t,
|
||||||
int32_t);
|
int32_t);
|
||||||
|
|
|
@ -10,7 +10,8 @@ namespace waybar::modules::SNI {
|
||||||
|
|
||||||
class Host {
|
class Host {
|
||||||
public:
|
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>&)>&);
|
const std::function<void(std::unique_ptr<Item>&)>&);
|
||||||
~Host();
|
~Host();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include "bar.hpp"
|
||||||
#include "util/json.hpp"
|
#include "util/json.hpp"
|
||||||
#include "IModule.hpp"
|
#include "IModule.hpp"
|
||||||
#include "modules/sni/watcher.hpp"
|
#include "modules/sni/watcher.hpp"
|
||||||
|
@ -11,7 +12,7 @@ namespace waybar::modules::SNI {
|
||||||
|
|
||||||
class Tray : public IModule {
|
class Tray : public IModule {
|
||||||
public:
|
public:
|
||||||
Tray(const Json::Value&);
|
Tray(Bar& bar, const Json::Value&);
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
operator Gtk::Widget &();
|
operator Gtk::Widget &();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// "height": 30, // Waybar height
|
// "height": 30, // Waybar height
|
||||||
// "width": 1280, // Waybar width
|
// "width": 1280, // Waybar width
|
||||||
// Choose the order of the modules
|
// 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-center": ["sway/window"],
|
||||||
"modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "battery#bat2", "clock", "tray"],
|
"modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "battery#bat2", "clock", "tray"],
|
||||||
// Modules configuration
|
// Modules configuration
|
||||||
|
|
|
@ -33,7 +33,7 @@ waybar::IModule* waybar::Factory::makeModule(const std::string &name) const
|
||||||
}
|
}
|
||||||
#ifdef HAVE_DBUSMENU
|
#ifdef HAVE_DBUSMENU
|
||||||
if (ref == "tray") {
|
if (ref == "tray") {
|
||||||
return new waybar::modules::SNI::Tray(config_[name]);
|
return new waybar::modules::SNI::Tray(bar_, config_[name]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBNL
|
#ifdef HAVE_LIBNL
|
||||||
|
|
|
@ -4,10 +4,11 @@
|
||||||
|
|
||||||
using namespace waybar::modules::SNI;
|
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)
|
const std::function<void(std::unique_ptr<Item>&)>& on_remove)
|
||||||
: bus_name_("org.kde.StatusNotifierHost-" + std::to_string(getpid()) + "-1"),
|
: bus_name_("org.kde.StatusNotifierHost-" + std::to_string(getpid()) + "-" + std::to_string(id)),
|
||||||
object_path_("/StatusNotifierHost"),
|
object_path_("/StatusNotifierHost/" + std::to_string(id)),
|
||||||
bus_name_id_(Gio::DBus::own_name(Gio::DBus::BusType::BUS_TYPE_SESSION, bus_name_,
|
bus_name_id_(Gio::DBus::own_name(Gio::DBus::BusType::BUS_TYPE_SESSION, bus_name_,
|
||||||
sigc::mem_fun(*this, &Host::busAcquired))),
|
sigc::mem_fun(*this, &Host::busAcquired))),
|
||||||
config_(config), on_add_(on_add), on_remove_(on_remove)
|
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)
|
bool waybar::modules::SNI::Item::makeMenu(GdkEventButton *const &ev)
|
||||||
{
|
{
|
||||||
std::cout << bus_name << std::endl;
|
|
||||||
if (gtk_menu == nullptr) {
|
if (gtk_menu == nullptr) {
|
||||||
if (!menu.empty()) {
|
if (!menu.empty()) {
|
||||||
dbus_menu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data());
|
dbus_menu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data());
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
waybar::modules::SNI::Tray::Tray(const Json::Value &config)
|
waybar::modules::SNI::Tray::Tray(Bar& bar, const Json::Value &config)
|
||||||
: config_(config), watcher_(), host_(config,
|
: config_(config), watcher_(), host_(bar.nb_tray_hosts, config,
|
||||||
std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
||||||
std::bind(&Tray::onRemove, 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()) {
|
if (config_["spacing"].isUInt()) {
|
||||||
box_.set_spacing(config_["spacing"].asUInt());
|
box_.set_spacing(config_["spacing"].asUInt());
|
||||||
}
|
}
|
||||||
|
bar.nb_tray_hosts += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::SNI::Tray::onAdd(std::unique_ptr<Item>& item)
|
void waybar::modules::SNI::Tray::onAdd(std::unique_ptr<Item>& item)
|
||||||
|
|
Loading…
Reference in New Issue