mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor(tray): cleanup and fixes
This commit is contained in:
@ -7,7 +7,7 @@ namespace waybar {
|
||||
|
||||
class ALabel : public IModule {
|
||||
public:
|
||||
ALabel(const Json::Value&, const std::string format);
|
||||
ALabel(const Json::Value&, const std::string& format);
|
||||
virtual ~ALabel() = default;
|
||||
virtual auto update() -> void;
|
||||
virtual std::string getIcon(uint16_t, const std::string& alt = "");
|
||||
@ -24,7 +24,7 @@ class ALabel : public IModule {
|
||||
bool handleToggle(GdkEventButton* const& ev);
|
||||
bool handleScroll(GdkEventScroll*);
|
||||
bool alt = false;
|
||||
const std::string default_format_;
|
||||
const std::string& default_format_;
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef FILESYSTEM_EXPERIMENTAL
|
||||
#include <experimental/filesystem>
|
||||
#include <experimental/filesystem>
|
||||
#else
|
||||
#include <filesystem>
|
||||
#include <filesystem>
|
||||
#endif
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
40
include/modules/sni/host.hpp
Normal file
40
include/modules/sni/host.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include <json/json.h>
|
||||
#include <tuple>
|
||||
#include <dbus-status-notifier-watcher.h>
|
||||
#include "modules/sni/item.hpp"
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
class Host {
|
||||
public:
|
||||
Host(const Json::Value&, const std::function<void(std::unique_ptr<Item>&)>&,
|
||||
const std::function<void(std::unique_ptr<Item>&)>&);
|
||||
~Host();
|
||||
private:
|
||||
void busAcquired(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
|
||||
void nameAppeared(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring, const Glib::ustring&);
|
||||
void nameVanished(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
|
||||
static void proxyReady(GObject*, GAsyncResult*, gpointer);
|
||||
static void registerHost(GObject*, GAsyncResult*, gpointer);
|
||||
static void itemRegistered(SnWatcher*, const gchar*, gpointer);
|
||||
static void itemUnregistered(SnWatcher*, const gchar*, gpointer);
|
||||
|
||||
std::tuple<std::string, std::string> getBusNameAndObjectPath(const std::string);
|
||||
void addRegisteredItem(std::string service);
|
||||
|
||||
std::vector<std::unique_ptr<Item>> items_;
|
||||
const std::string bus_name_;
|
||||
const std::string object_path_;
|
||||
std::size_t bus_name_id_;
|
||||
std::size_t watcher_id_;
|
||||
GCancellable* cancellable_ = nullptr;
|
||||
SnWatcher* watcher_ = nullptr;
|
||||
const Json::Value &config_;
|
||||
std::function<void(std::unique_ptr<Item>&)> on_add_;
|
||||
std::function<void(std::unique_ptr<Item>&)> on_remove_;
|
||||
};
|
||||
|
||||
}
|
@ -5,24 +5,25 @@
|
||||
#include <json/json.h>
|
||||
#include <libdbusmenu-gtk/dbusmenu-gtk.h>
|
||||
#ifdef FILESYSTEM_EXPERIMENTAL
|
||||
#include <experimental/filesystem>
|
||||
#include <experimental/filesystem>
|
||||
#else
|
||||
#include <filesystem>
|
||||
#include <filesystem>
|
||||
#endif
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
class Item {
|
||||
public:
|
||||
Item(std::string, std::string, Glib::Dispatcher*, Json::Value);
|
||||
Item(std::string, std::string, const Json::Value&);
|
||||
~Item() = default;
|
||||
|
||||
std::string bus_name;
|
||||
std::string object_path;
|
||||
Gtk::EventBox *event_box;
|
||||
|
||||
int icon_size;
|
||||
int effective_icon_size;
|
||||
Gtk::Image *image;
|
||||
Gtk::Image image;
|
||||
Gtk::EventBox event_box;
|
||||
std::string category;
|
||||
std::string id;
|
||||
std::string status;
|
||||
@ -35,26 +36,25 @@ public:
|
||||
std::string attention_icon_name;
|
||||
std::string attention_movie_name;
|
||||
std::string icon_theme_path;
|
||||
DbusmenuGtkMenu *menu = nullptr;
|
||||
std::string menu;
|
||||
DbusmenuGtkMenu *dbus_menu = nullptr;
|
||||
Gtk::Menu *gtk_menu = nullptr;
|
||||
bool item_is_menu;
|
||||
|
||||
private:
|
||||
static void proxyReady(GObject *obj, GAsyncResult *res, gpointer data);
|
||||
static void getAll(GObject *obj, GAsyncResult *res, gpointer data);
|
||||
static void handleActivate(GObject *, GAsyncResult *, gpointer);
|
||||
static void handleSecondaryActivate(GObject *, GAsyncResult *, gpointer);
|
||||
|
||||
void updateImage();
|
||||
bool showMenu(GdkEventButton *const &ev);
|
||||
Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant *variant);
|
||||
Glib::RefPtr<Gdk::Pixbuf> getIconByName(std::string name, int size);
|
||||
static void onMenuDestroyed(Item *self);
|
||||
bool makeMenu(GdkEventButton *const &ev);
|
||||
bool handleClick(GdkEventButton *const & /*ev*/);
|
||||
|
||||
Glib::Dispatcher *dp_;
|
||||
Glib::RefPtr<Gio::DBus::Connection> conn_;
|
||||
GCancellable *cancellable_ = nullptr;
|
||||
SnItem *proxy_ = nullptr;
|
||||
Json::Value config_;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules::SNI
|
@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include <json/json.h>
|
||||
#include <tuple>
|
||||
#include <dbus-status-notifier-watcher.h>
|
||||
#include "modules/sni/sni.hpp"
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
class Host {
|
||||
public:
|
||||
Host(Glib::Dispatcher*, const Json::Value&);
|
||||
std::vector<Item> items;
|
||||
private:
|
||||
static void busAcquired(GDBusConnection*, const gchar*, gpointer);
|
||||
static void nameAppeared(GDBusConnection*, const gchar*, const gchar*,
|
||||
gpointer);
|
||||
static void nameVanished(GDBusConnection*, const gchar*, gpointer);
|
||||
static void proxyReady(GObject*, GAsyncResult*, gpointer);
|
||||
static void registerHost(GObject*, GAsyncResult*, gpointer);
|
||||
static void itemRegistered(SnWatcher*, const gchar*, gpointer);
|
||||
static void itemUnregistered(SnWatcher*, const gchar*, gpointer);
|
||||
|
||||
std::tuple<std::string, std::string> getBusNameAndObjectPath(const gchar*);
|
||||
void addRegisteredItem(const gchar* service);
|
||||
|
||||
uint32_t bus_name_id_;
|
||||
uint32_t watcher_id_;
|
||||
std::string bus_name_;
|
||||
std::string object_path_;
|
||||
Glib::Dispatcher* dp_;
|
||||
GCancellable* cancellable_ = nullptr;
|
||||
SnWatcher* watcher_ = nullptr;
|
||||
const Json::Value &config_;
|
||||
};
|
||||
|
||||
}
|
@ -4,8 +4,8 @@
|
||||
#include <thread>
|
||||
#include "util/json.hpp"
|
||||
#include "IModule.hpp"
|
||||
#include "modules/sni/snw.hpp"
|
||||
#include "modules/sni/snh.hpp"
|
||||
#include "modules/sni/watcher.hpp"
|
||||
#include "modules/sni/host.hpp"
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
@ -15,6 +15,9 @@ class Tray : public IModule {
|
||||
auto update() -> void;
|
||||
operator Gtk::Widget &();
|
||||
private:
|
||||
void onAdd(std::unique_ptr<Item>& item);
|
||||
void onRemove(std::unique_ptr<Item>& item);
|
||||
|
||||
std::thread thread_;
|
||||
const Json::Value& config_;
|
||||
Gtk::Box box_;
|
||||
|
Reference in New Issue
Block a user