Use the same StatusNotifierWatcher for all trays

This commit is contained in:
Guillaume Maudoux
2020-02-19 12:06:35 +01:00
parent 9b0660e751
commit 047c2929c1
4 changed files with 20 additions and 7 deletions

View File

@ -21,7 +21,7 @@ class Tray : public AModule {
static inline std::size_t nb_hosts_ = 0;
Gtk::Box box_;
SNI::Watcher watcher_;
SNI::Watcher::singleton watcher_;
SNI::Host host_;
};

View File

@ -7,10 +7,24 @@
namespace waybar::modules::SNI {
class Watcher {
private:
Watcher();
public:
Watcher(std::size_t id);
~Watcher();
using singleton = std::shared_ptr<Watcher>;
static singleton getInstance() {
static std::weak_ptr<Watcher> weak;
std::shared_ptr<Watcher> strong = weak.lock();
if (!strong) {
strong = std::shared_ptr<Watcher>(new Watcher());
weak = strong;
}
return strong;
}
private:
typedef enum { GF_WATCH_TYPE_HOST, GF_WATCH_TYPE_ITEM } GfWatchType;
@ -34,7 +48,6 @@ class Watcher {
void updateRegisteredItems(SnWatcher *obj);
uint32_t bus_name_id_;
uint32_t watcher_id_;
GSList * hosts_ = nullptr;
GSList * items_ = nullptr;
SnWatcher *watcher_ = nullptr;