mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor(tray): more cpp binding
This commit is contained in:
parent
8db94f7efd
commit
36652158ad
@ -8,7 +8,7 @@ namespace waybar::modules::SNI {
|
|||||||
class Watcher {
|
class Watcher {
|
||||||
public:
|
public:
|
||||||
Watcher();
|
Watcher();
|
||||||
~Watcher();
|
~Watcher() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef enum { GF_WATCH_TYPE_HOST, GF_WATCH_TYPE_ITEM } GfWatchType;
|
typedef enum { GF_WATCH_TYPE_HOST, GF_WATCH_TYPE_ITEM } GfWatchType;
|
||||||
@ -22,7 +22,7 @@ private:
|
|||||||
guint watch_id;
|
guint watch_id;
|
||||||
} GfWatch;
|
} GfWatch;
|
||||||
|
|
||||||
static void busAcquired(GDBusConnection *, const gchar *, gpointer);
|
void busAcquired(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
|
||||||
static gboolean handleRegisterHost(Watcher *, GDBusMethodInvocation *,
|
static gboolean handleRegisterHost(Watcher *, GDBusMethodInvocation *,
|
||||||
const gchar *);
|
const gchar *);
|
||||||
static gboolean handleRegisterItem(Watcher *, GDBusMethodInvocation *,
|
static gboolean handleRegisterItem(Watcher *, GDBusMethodInvocation *,
|
||||||
|
@ -5,37 +5,28 @@
|
|||||||
using namespace waybar::modules::SNI;
|
using namespace waybar::modules::SNI;
|
||||||
|
|
||||||
Watcher::Watcher()
|
Watcher::Watcher()
|
||||||
{
|
: bus_name_id_(Gio::DBus::own_name(Gio::DBus::BusType::BUS_TYPE_SESSION,
|
||||||
GBusNameOwnerFlags flags = static_cast<GBusNameOwnerFlags>(
|
"org.kde.StatusNotifierWatcher", sigc::mem_fun(*this, &Watcher::busAcquired),
|
||||||
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT
|
Gio::DBus::SlotNameAcquired(), Gio::DBus::SlotNameLost(),
|
||||||
| G_BUS_NAME_OWNER_FLAGS_REPLACE);
|
Gio::DBus::BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | Gio::DBus::BUS_NAME_OWNER_FLAGS_REPLACE)),
|
||||||
bus_name_id_ = g_bus_own_name(G_BUS_TYPE_SESSION,
|
watcher_(sn_watcher_skeleton_new())
|
||||||
"org.kde.StatusNotifierWatcher", flags,
|
|
||||||
&Watcher::busAcquired, nullptr, nullptr, this, nullptr);
|
|
||||||
watcher_ = sn_watcher_skeleton_new();
|
|
||||||
sn_watcher_set_protocol_version(watcher_, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Watcher::~Watcher()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watcher::busAcquired(GDBusConnection* connection, const gchar* name,
|
void Watcher::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib::ustring name)
|
||||||
gpointer data)
|
|
||||||
{
|
{
|
||||||
GError* error = nullptr;
|
GError* error = nullptr;
|
||||||
auto host = static_cast<SNI::Watcher*>(data);
|
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(watcher_),
|
||||||
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(host->watcher_),
|
conn->gobj(), "/StatusNotifierWatcher", &error);
|
||||||
connection, "/StatusNotifierWatcher", &error);
|
|
||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
std::cerr << error->message << std::endl;
|
std::cerr << error->message << std::endl;
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g_signal_connect_swapped(host->watcher_, "handle-register-item",
|
g_signal_connect_swapped(watcher_, "handle-register-item",
|
||||||
G_CALLBACK(&Watcher::handleRegisterItem), data);
|
G_CALLBACK(&Watcher::handleRegisterItem), this);
|
||||||
g_signal_connect_swapped(host->watcher_, "handle-register-host",
|
g_signal_connect_swapped(watcher_, "handle-register-host",
|
||||||
G_CALLBACK(&Watcher::handleRegisterHost), data);
|
G_CALLBACK(&Watcher::handleRegisterHost), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean Watcher::handleRegisterHost(Watcher* obj,
|
gboolean Watcher::handleRegisterHost(Watcher* obj,
|
||||||
|
Loading…
Reference in New Issue
Block a user