mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor: format tray && partial fix for #235
This commit is contained in:
parent
93a1bafb46
commit
346ec68578
@ -1,23 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glibmm/refptr.h>
|
#include <dbus-status-notifier-watcher.h>
|
||||||
#include <giomm.h>
|
#include <giomm.h>
|
||||||
|
#include <glibmm/refptr.h>
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <dbus-status-notifier-watcher.h>
|
|
||||||
#include "modules/sni/item.hpp"
|
#include "modules/sni/item.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::SNI {
|
namespace waybar::modules::SNI {
|
||||||
|
|
||||||
class Host {
|
class Host {
|
||||||
public:
|
public:
|
||||||
Host(const std::size_t id, const Json::Value&,
|
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>&)>&);
|
const std::function<void(std::unique_ptr<Item>&)>&);
|
||||||
~Host();
|
~Host();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void busAcquired(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
|
void busAcquired(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
|
||||||
void nameAppeared(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring, const 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);
|
void nameVanished(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
|
||||||
static void proxyReady(GObject*, GAsyncResult*, gpointer);
|
static void proxyReady(GObject*, GAsyncResult*, gpointer);
|
||||||
static void registerHost(GObject*, GAsyncResult*, gpointer);
|
static void registerHost(GObject*, GAsyncResult*, gpointer);
|
||||||
@ -39,4 +40,4 @@ class Host {
|
|||||||
const std::function<void(std::unique_ptr<Item>&)> on_remove_;
|
const std::function<void(std::unique_ptr<Item>&)> on_remove_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace waybar::modules::SNI
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <dbus-status-notifier-item.h>
|
#include <dbus-status-notifier-item.h>
|
||||||
#include <glibmm/refptr.h>
|
|
||||||
#include <giomm/dbusproxy.h>
|
#include <giomm/dbusproxy.h>
|
||||||
|
#include <glibmm/refptr.h>
|
||||||
#include <gtkmm/eventbox.h>
|
#include <gtkmm/eventbox.h>
|
||||||
#include <gtkmm/image.h>
|
|
||||||
#include <gtkmm/icontheme.h>
|
#include <gtkmm/icontheme.h>
|
||||||
|
#include <gtkmm/image.h>
|
||||||
#include <gtkmm/menu.h>
|
#include <gtkmm/menu.h>
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include <libdbusmenu-gtk/dbusmenu-gtk.h>
|
#include <libdbusmenu-gtk/dbusmenu-gtk.h>
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include "bar.hpp"
|
|
||||||
#include "util/json.hpp"
|
|
||||||
#include "IModule.hpp"
|
#include "IModule.hpp"
|
||||||
#include "modules/sni/watcher.hpp"
|
#include "bar.hpp"
|
||||||
#include "modules/sni/host.hpp"
|
#include "modules/sni/host.hpp"
|
||||||
|
#include "modules/sni/watcher.hpp"
|
||||||
|
#include "util/json.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::SNI {
|
namespace waybar::modules::SNI {
|
||||||
|
|
||||||
@ -15,6 +15,7 @@ class Tray : public IModule {
|
|||||||
~Tray() = default;
|
~Tray() = default;
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
operator Gtk::Widget&();
|
operator Gtk::Widget&();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onAdd(std::unique_ptr<Item>& item);
|
void onAdd(std::unique_ptr<Item>& item);
|
||||||
void onRemove(std::unique_ptr<Item>& item);
|
void onRemove(std::unique_ptr<Item>& item);
|
||||||
@ -26,4 +27,4 @@ class Tray : public IModule {
|
|||||||
SNI::Host host_;
|
SNI::Host host_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace waybar::modules::SNI
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <dbus-status-notifier-watcher.h>
|
||||||
#include <giomm.h>
|
#include <giomm.h>
|
||||||
#include <glibmm/refptr.h>
|
#include <glibmm/refptr.h>
|
||||||
#include <dbus-status-notifier-watcher.h>
|
|
||||||
|
|
||||||
namespace waybar::modules::SNI {
|
namespace waybar::modules::SNI {
|
||||||
|
|
||||||
class Watcher {
|
class Watcher {
|
||||||
public:
|
public:
|
||||||
Watcher();
|
Watcher();
|
||||||
~Watcher() = default;
|
~Watcher();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef enum { GF_WATCH_TYPE_HOST, GF_WATCH_TYPE_ITEM } GfWatchType;
|
typedef enum { GF_WATCH_TYPE_HOST, GF_WATCH_TYPE_ITEM } GfWatchType;
|
||||||
@ -24,16 +24,12 @@ private:
|
|||||||
} GfWatch;
|
} GfWatch;
|
||||||
|
|
||||||
void busAcquired(const Glib::RefPtr<Gio::DBus::Connection> &, Glib::ustring);
|
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 *, const gchar *);
|
||||||
static gboolean handleRegisterItem(Watcher *, GDBusMethodInvocation *,
|
static GfWatch *gfWatchFind(GSList *list, const gchar *bus_name, const gchar *object_path);
|
||||||
const gchar *);
|
static GfWatch *gfWatchNew(GfWatchType, const gchar *, const gchar *, const gchar *, Watcher *);
|
||||||
static GfWatch *gfWatchFind(GSList *list, const gchar *bus_name,
|
static void nameVanished(GDBusConnection *connection, const char *name, gpointer data);
|
||||||
const gchar *object_path);
|
static void gfWatchFree(gpointer data);
|
||||||
static GfWatch *gfWatchNew(GfWatchType, const gchar *, const gchar *,
|
|
||||||
const gchar *, Watcher *);
|
|
||||||
static void nameVanished(GDBusConnection *connection, const char *name,
|
|
||||||
gpointer data);
|
|
||||||
|
|
||||||
void updateRegisteredItems(SnWatcher *obj);
|
void updateRegisteredItems(SnWatcher *obj);
|
||||||
|
|
||||||
@ -42,7 +38,8 @@ private:
|
|||||||
GSList *hosts_ = nullptr;
|
GSList *hosts_ = nullptr;
|
||||||
GSList *items_ = nullptr;
|
GSList *items_ = nullptr;
|
||||||
SnWatcher *watcher_ = nullptr;
|
SnWatcher *watcher_ = nullptr;
|
||||||
|
gulong handler_item_id_;
|
||||||
|
gulong handler_host_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::SNI
|
} // namespace waybar::modules::SNI
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "client.hpp"
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "client.hpp"
|
||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
||||||
@ -8,8 +8,7 @@ static Client* client;
|
|||||||
|
|
||||||
} // namespace waybar
|
} // namespace waybar
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[]) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
waybar::Client c(argc, argv);
|
waybar::Client c(argc, argv);
|
||||||
waybar::client = &c;
|
waybar::client = &c;
|
||||||
|
@ -7,52 +7,42 @@ using namespace waybar::modules::SNI;
|
|||||||
Host::Host(const std::size_t id, const Json::Value& config,
|
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_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()) + "-" + std::to_string(id)),
|
: bus_name_("org.kde.StatusNotifierHost-" + std::to_string(getpid()) + "-" +
|
||||||
|
std::to_string(id)),
|
||||||
object_path_("/StatusNotifierHost/" + 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_,
|
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) {}
|
||||||
|
|
||||||
Host::~Host()
|
Host::~Host() { Gio::DBus::unwatch_name(bus_name_id_); }
|
||||||
{
|
|
||||||
Gio::DBus::unwatch_name(bus_name_id_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Host::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib::ustring name)
|
void Host::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib::ustring name) {
|
||||||
{
|
|
||||||
watcher_id_ = Gio::DBus::watch_name(conn, "org.kde.StatusNotifierWatcher",
|
watcher_id_ = Gio::DBus::watch_name(conn, "org.kde.StatusNotifierWatcher",
|
||||||
sigc::mem_fun(*this, &Host::nameAppeared), sigc::mem_fun(*this, &Host::nameVanished));
|
sigc::mem_fun(*this, &Host::nameAppeared),
|
||||||
|
sigc::mem_fun(*this, &Host::nameVanished));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::nameAppeared(const Glib::RefPtr<Gio::DBus::Connection>& conn, const Glib::ustring name,
|
void Host::nameAppeared(const Glib::RefPtr<Gio::DBus::Connection>& conn, const Glib::ustring name,
|
||||||
const Glib::ustring& name_owner)
|
const Glib::ustring& name_owner) {
|
||||||
{
|
|
||||||
if (cancellable_ != nullptr) {
|
if (cancellable_ != nullptr) {
|
||||||
// TODO
|
// TODO
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cancellable_ = g_cancellable_new();
|
cancellable_ = g_cancellable_new();
|
||||||
sn_watcher_proxy_new(
|
sn_watcher_proxy_new(conn->gobj(), G_DBUS_PROXY_FLAGS_NONE, "org.kde.StatusNotifierWatcher",
|
||||||
conn->gobj(),
|
"/StatusNotifierWatcher", cancellable_, &Host::proxyReady, this);
|
||||||
G_DBUS_PROXY_FLAGS_NONE,
|
|
||||||
"org.kde.StatusNotifierWatcher",
|
|
||||||
"/StatusNotifierWatcher",
|
|
||||||
cancellable_, &Host::proxyReady, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::nameVanished(const Glib::RefPtr<Gio::DBus::Connection>& conn, const Glib::ustring name)
|
void Host::nameVanished(const Glib::RefPtr<Gio::DBus::Connection>& conn, const Glib::ustring name) {
|
||||||
{
|
|
||||||
g_cancellable_cancel(cancellable_);
|
g_cancellable_cancel(cancellable_);
|
||||||
g_clear_object(&cancellable_);
|
g_clear_object(&cancellable_);
|
||||||
g_clear_object(&watcher_);
|
g_clear_object(&watcher_);
|
||||||
items_.clear();
|
items_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::proxyReady(GObject* src, GAsyncResult* res,
|
void Host::proxyReady(GObject* src, GAsyncResult* res, gpointer data) {
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GError* error = nullptr;
|
GError* error = nullptr;
|
||||||
SnWatcher* watcher = sn_watcher_proxy_new_finish(res, &error);
|
SnWatcher* watcher = sn_watcher_proxy_new_finish(res, &error);
|
||||||
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||||
@ -67,14 +57,11 @@ void Host::proxyReady(GObject* src, GAsyncResult* res,
|
|||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sn_watcher_call_register_host(
|
sn_watcher_call_register_host(host->watcher_, host->object_path_.c_str(), host->cancellable_,
|
||||||
host->watcher_, host->object_path_.c_str(), host->cancellable_,
|
|
||||||
&Host::registerHost, data);
|
&Host::registerHost, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::registerHost(GObject* src, GAsyncResult* res,
|
void Host::registerHost(GObject* src, GAsyncResult* res, gpointer data) {
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GError* error = nullptr;
|
GError* error = nullptr;
|
||||||
sn_watcher_call_register_host_finish(SN_WATCHER(src), res, &error);
|
sn_watcher_call_register_host_finish(SN_WATCHER(src), res, &error);
|
||||||
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||||
@ -88,10 +75,8 @@ void Host::registerHost(GObject* src, GAsyncResult* res,
|
|||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g_signal_connect(host->watcher_, "item-registered",
|
g_signal_connect(host->watcher_, "item-registered", G_CALLBACK(&Host::itemRegistered), data);
|
||||||
G_CALLBACK(&Host::itemRegistered), data);
|
g_signal_connect(host->watcher_, "item-unregistered", G_CALLBACK(&Host::itemUnregistered), data);
|
||||||
g_signal_connect(host->watcher_, "item-unregistered",
|
|
||||||
G_CALLBACK(&Host::itemUnregistered), data);
|
|
||||||
auto items = sn_watcher_dup_registered_items(host->watcher_);
|
auto items = sn_watcher_dup_registered_items(host->watcher_);
|
||||||
if (items) {
|
if (items) {
|
||||||
for (uint32_t i = 0; items[i] != nullptr; i += 1) {
|
for (uint32_t i = 0; items[i] != nullptr; i += 1) {
|
||||||
@ -101,15 +86,12 @@ void Host::registerHost(GObject* src, GAsyncResult* res,
|
|||||||
g_strfreev(items);
|
g_strfreev(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::itemRegistered(SnWatcher* watcher, const gchar* service, gpointer data)
|
void Host::itemRegistered(SnWatcher* watcher, const gchar* service, gpointer data) {
|
||||||
{
|
|
||||||
auto host = static_cast<SNI::Host*>(data);
|
auto host = static_cast<SNI::Host*>(data);
|
||||||
host->addRegisteredItem(service);
|
host->addRegisteredItem(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::itemUnregistered(
|
void Host::itemUnregistered(SnWatcher* watcher, const gchar* service, gpointer data) {
|
||||||
SnWatcher* watcher, const gchar* service, gpointer data)
|
|
||||||
{
|
|
||||||
auto host = static_cast<SNI::Host*>(data);
|
auto host = static_cast<SNI::Host*>(data);
|
||||||
auto [bus_name, object_path] = host->getBusNameAndObjectPath(service);
|
auto [bus_name, object_path] = host->getBusNameAndObjectPath(service);
|
||||||
for (auto it = host->items_.begin(); it != host->items_.end(); ++it) {
|
for (auto it = host->items_.begin(); it != host->items_.end(); ++it) {
|
||||||
@ -121,9 +103,7 @@ void Host::itemUnregistered(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::string, std::string> Host::getBusNameAndObjectPath(
|
std::tuple<std::string, std::string> Host::getBusNameAndObjectPath(const std::string service) {
|
||||||
const std::string service)
|
|
||||||
{
|
|
||||||
auto it = service.find("/");
|
auto it = service.find("/");
|
||||||
if (it != std::string::npos) {
|
if (it != std::string::npos) {
|
||||||
return {service.substr(0, it), service.substr(it)};
|
return {service.substr(0, it), service.substr(it)};
|
||||||
@ -131,8 +111,7 @@ std::tuple<std::string, std::string> Host::getBusNameAndObjectPath(
|
|||||||
return {service, "/StatusNotifierItem"};
|
return {service, "/StatusNotifierItem"};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::addRegisteredItem(std::string service)
|
void Host::addRegisteredItem(std::string service) {
|
||||||
{
|
|
||||||
auto [bus_name, object_path] = getBusNameAndObjectPath(service);
|
auto [bus_name, object_path] = getBusNameAndObjectPath(service);
|
||||||
items_.emplace_back(new Item(bus_name, object_path, config_));
|
items_.emplace_back(new Item(bus_name, object_path, config_));
|
||||||
on_add_(items_.back());
|
on_add_(items_.back());
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "modules/sni/item.hpp"
|
#include "modules/sni/item.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <glibmm/main.h>
|
#include <glibmm/main.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace Glib;
|
using namespace Glib;
|
||||||
|
|
||||||
@ -9,22 +9,25 @@ static const ustring SNI_INTERFACE_NAME = sn_item_interface_info()->name;
|
|||||||
static const unsigned UPDATE_DEBOUNCE_TIME = 10;
|
static const unsigned UPDATE_DEBOUNCE_TIME = 10;
|
||||||
|
|
||||||
waybar::modules::SNI::Item::Item(std::string bn, std::string op, const Json::Value& config)
|
waybar::modules::SNI::Item::Item(std::string bn, std::string op, const Json::Value& config)
|
||||||
: bus_name(bn), object_path(op), icon_size(16), effective_icon_size(0),
|
: bus_name(bn),
|
||||||
icon_theme(Gtk::IconTheme::create()), update_pending_(false) {
|
object_path(op),
|
||||||
|
icon_size(16),
|
||||||
|
effective_icon_size(0),
|
||||||
|
icon_theme(Gtk::IconTheme::create()),
|
||||||
|
update_pending_(false) {
|
||||||
if (config["icon-size"].isUInt()) {
|
if (config["icon-size"].isUInt()) {
|
||||||
icon_size = config["icon-size"].asUInt();
|
icon_size = config["icon-size"].asUInt();
|
||||||
}
|
}
|
||||||
default_icon_path_ = Gtk::IconTheme::get_default()->get_search_path();
|
default_icon_path_ = Gtk::IconTheme::get_default()->get_search_path();
|
||||||
event_box.add(image);
|
event_box.add(image);
|
||||||
event_box.add_events(Gdk::BUTTON_PRESS_MASK);
|
event_box.add_events(Gdk::BUTTON_PRESS_MASK);
|
||||||
event_box.signal_button_press_event().connect(
|
event_box.signal_button_press_event().connect(sigc::mem_fun(*this, &Item::handleClick));
|
||||||
sigc::mem_fun(*this, &Item::handleClick));
|
|
||||||
|
|
||||||
cancellable_ = Gio::Cancellable::create();
|
cancellable_ = Gio::Cancellable::create();
|
||||||
|
|
||||||
auto interface = Glib::wrap(sn_item_interface_info(), true);
|
auto interface = Glib::wrap(sn_item_interface_info(), true);
|
||||||
Gio::DBus::Proxy::create_for_bus(Gio::DBus::BusType::BUS_TYPE_SESSION, bus_name,
|
Gio::DBus::Proxy::create_for_bus(Gio::DBus::BusType::BUS_TYPE_SESSION, bus_name, object_path,
|
||||||
object_path, SNI_INTERFACE_NAME, sigc::mem_fun(*this, &Item::proxyReady),
|
SNI_INTERFACE_NAME, sigc::mem_fun(*this, &Item::proxyReady),
|
||||||
cancellable_, interface);
|
cancellable_, interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,19 +45,19 @@ void waybar::modules::SNI::Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& resu
|
|||||||
this->proxy_->signal_signal().connect(sigc::mem_fun(*this, &Item::onSignal));
|
this->proxy_->signal_signal().connect(sigc::mem_fun(*this, &Item::onSignal));
|
||||||
|
|
||||||
if (this->id.empty() || this->category.empty() || this->status.empty()) {
|
if (this->id.empty() || this->category.empty() || this->status.empty()) {
|
||||||
std::cerr << "Invalid Status Notifier Item: " + this->bus_name + "," +
|
std::cerr << "Invalid Status Notifier Item: " + this->bus_name + "," + this->object_path
|
||||||
this->object_path << std::endl;
|
<< std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->updateImage();
|
this->updateImage();
|
||||||
// this->event_box.set_tooltip_text(this->title);
|
// this->event_box.set_tooltip_text(this->title);
|
||||||
|
|
||||||
} catch (const Glib::Error& err) {
|
} catch (const Glib::Error& err) {
|
||||||
g_error("Failed to create DBus Proxy for %s %s: %s", bus_name.c_str(),
|
g_error("Failed to create DBus Proxy for %s %s: %s", bus_name.c_str(), object_path.c_str(),
|
||||||
object_path.c_str(), err.what().c_str());
|
err.what().c_str());
|
||||||
} catch (const std::exception& err) {
|
} catch (const std::exception& err) {
|
||||||
g_error("Failed to create DBus Proxy for %s %s: %s", bus_name.c_str(),
|
g_error("Failed to create DBus Proxy for %s %s: %s", bus_name.c_str(), object_path.c_str(),
|
||||||
object_path.c_str(), err.what());
|
err.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,9 +66,7 @@ T get_variant(VariantBase& value) {
|
|||||||
return VariantBase::cast_dynamic<Variant<T>>(value).get();
|
return VariantBase::cast_dynamic<Variant<T>>(value).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void waybar::modules::SNI::Item::setProperty(const ustring& name, VariantBase& value) {
|
||||||
waybar::modules::SNI::Item::setProperty(const ustring& name,
|
|
||||||
VariantBase& value) {
|
|
||||||
if (name == "Category") {
|
if (name == "Category") {
|
||||||
category = get_variant<std::string>(value);
|
category = get_variant<std::string>(value);
|
||||||
} else if (name == "Id") {
|
} else if (name == "Id") {
|
||||||
@ -106,20 +107,15 @@ waybar::modules::SNI::Item::setProperty(const ustring& name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void waybar::modules::SNI::Item::getUpdatedProperties() {
|
||||||
waybar::modules::SNI::Item::getUpdatedProperties() {
|
|
||||||
update_pending_ = false;
|
update_pending_ = false;
|
||||||
|
|
||||||
auto params = VariantContainerBase::create_tuple({
|
auto params = VariantContainerBase::create_tuple({Variant<ustring>::create(SNI_INTERFACE_NAME)});
|
||||||
Variant<ustring>::create(SNI_INTERFACE_NAME)
|
|
||||||
});
|
|
||||||
proxy_->call("org.freedesktop.DBus.Properties.GetAll",
|
proxy_->call("org.freedesktop.DBus.Properties.GetAll",
|
||||||
sigc::mem_fun(*this, &Item::processUpdatedProperties), params);
|
sigc::mem_fun(*this, &Item::processUpdatedProperties), params);
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void waybar::modules::SNI::Item::processUpdatedProperties(Glib::RefPtr<Gio::AsyncResult>& _result) {
|
||||||
waybar::modules::SNI::Item::processUpdatedProperties(
|
|
||||||
Glib::RefPtr<Gio::AsyncResult>& _result) {
|
|
||||||
try {
|
try {
|
||||||
auto result = proxy_->call_finish(_result);
|
auto result = proxy_->call_finish(_result);
|
||||||
// extract "a{sv}" from VariantContainerBase
|
// extract "a{sv}" from VariantContainerBase
|
||||||
@ -145,27 +141,21 @@ waybar::modules::SNI::Item::processUpdatedProperties(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void waybar::modules::SNI::Item::onSignal(const ustring& sender_name, const ustring& signal_name,
|
||||||
waybar::modules::SNI::Item::onSignal(const ustring& sender_name,
|
const VariantContainerBase& arguments) {
|
||||||
const ustring& signal_name, const VariantContainerBase& arguments) {
|
|
||||||
if (!update_pending_ && signal_name.compare(0, 3, "New") == 0) {
|
if (!update_pending_ && signal_name.compare(0, 3, "New") == 0) {
|
||||||
/* Debounce signals and schedule update of all properties.
|
/* Debounce signals and schedule update of all properties.
|
||||||
* Based on behavior of Plasma dataengine for StatusNotifierItem.
|
* Based on behavior of Plasma dataengine for StatusNotifierItem.
|
||||||
*/
|
*/
|
||||||
update_pending_ = true;
|
update_pending_ = true;
|
||||||
Glib::signal_timeout().connect_once(
|
Glib::signal_timeout().connect_once(sigc::mem_fun(*this, &Item::getUpdatedProperties),
|
||||||
sigc::mem_fun(*this, &Item::getUpdatedProperties), UPDATE_DEBOUNCE_TIME);
|
UPDATE_DEBOUNCE_TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void pixbuf_data_deleter(const guint8* data) { g_free((void*)data); }
|
||||||
|
|
||||||
static void
|
Glib::RefPtr<Gdk::Pixbuf> waybar::modules::SNI::Item::extractPixBuf(GVariant* variant) {
|
||||||
pixbuf_data_deleter(const guint8* data) {
|
|
||||||
g_free((void*) data);
|
|
||||||
}
|
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Pixbuf>
|
|
||||||
waybar::modules::SNI::Item::extractPixBuf(GVariant *variant) {
|
|
||||||
GVariantIter* it;
|
GVariantIter* it;
|
||||||
g_variant_get(variant, "a(iiay)", &it);
|
g_variant_get(variant, "a(iiay)", &it);
|
||||||
if (it == nullptr) {
|
if (it == nullptr) {
|
||||||
@ -178,8 +168,7 @@ waybar::modules::SNI::Item::extractPixBuf(GVariant *variant) {
|
|||||||
gint height;
|
gint height;
|
||||||
guchar* array = nullptr;
|
guchar* array = nullptr;
|
||||||
while (g_variant_iter_loop(it, "(ii@ay)", &width, &height, &val)) {
|
while (g_variant_iter_loop(it, "(ii@ay)", &width, &height, &val)) {
|
||||||
if (width > 0 && height > 0 && val != nullptr &&
|
if (width > 0 && height > 0 && val != nullptr && width * height > lwidth * lheight) {
|
||||||
width * height > lwidth * lheight) {
|
|
||||||
auto size = g_variant_get_size(val);
|
auto size = g_variant_get_size(val);
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (size == 4U * width * height) {
|
if (size == 4U * width * height) {
|
||||||
@ -206,15 +195,13 @@ waybar::modules::SNI::Item::extractPixBuf(GVariant *variant) {
|
|||||||
array[i + 2] = array[i + 3];
|
array[i + 2] = array[i + 3];
|
||||||
array[i + 3] = alpha;
|
array[i + 3] = alpha;
|
||||||
}
|
}
|
||||||
return Gdk::Pixbuf::create_from_data(array, Gdk::Colorspace::COLORSPACE_RGB,
|
return Gdk::Pixbuf::create_from_data(array, Gdk::Colorspace::COLORSPACE_RGB, true, 8, lwidth,
|
||||||
true, 8, lwidth, lheight, 4 * lwidth,
|
lheight, 4 * lwidth, &pixbuf_data_deleter);
|
||||||
&pixbuf_data_deleter);
|
|
||||||
}
|
}
|
||||||
return Glib::RefPtr<Gdk::Pixbuf>{};
|
return Glib::RefPtr<Gdk::Pixbuf>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::SNI::Item::updateImage()
|
void waybar::modules::SNI::Item::updateImage() {
|
||||||
{
|
|
||||||
image.set_from_icon_name("image-missing", Gtk::ICON_SIZE_MENU);
|
image.set_from_icon_name("image-missing", Gtk::ICON_SIZE_MENU);
|
||||||
image.set_pixel_size(icon_size);
|
image.set_pixel_size(icon_size);
|
||||||
if (!icon_name.empty()) {
|
if (!icon_name.empty()) {
|
||||||
@ -229,8 +216,7 @@ void waybar::modules::SNI::Item::updateImage()
|
|||||||
if (pixbuf->gobj() != nullptr) {
|
if (pixbuf->gobj() != nullptr) {
|
||||||
// An icon specified by path and filename may be the wrong size for
|
// An icon specified by path and filename may be the wrong size for
|
||||||
// the tray
|
// the tray
|
||||||
pixbuf = pixbuf->scale_simple(icon_size, icon_size,
|
pixbuf = pixbuf->scale_simple(icon_size, icon_size, Gdk::InterpType::INTERP_BILINEAR);
|
||||||
Gdk::InterpType::INTERP_BILINEAR);
|
|
||||||
image.set(pixbuf);
|
image.set(pixbuf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -241,14 +227,13 @@ void waybar::modules::SNI::Item::updateImage()
|
|||||||
}
|
}
|
||||||
} else if (icon_pixmap) {
|
} else if (icon_pixmap) {
|
||||||
// An icon extracted may be the wrong size for the tray
|
// An icon extracted may be the wrong size for the tray
|
||||||
icon_pixmap = icon_pixmap->scale_simple(icon_size, icon_size,
|
icon_pixmap = icon_pixmap->scale_simple(icon_size, icon_size, Gdk::InterpType::INTERP_BILINEAR);
|
||||||
Gdk::InterpType::INTERP_BILINEAR);
|
|
||||||
image.set(icon_pixmap);
|
image.set(icon_pixmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Pixbuf>
|
Glib::RefPtr<Gdk::Pixbuf> waybar::modules::SNI::Item::getIconByName(std::string name,
|
||||||
waybar::modules::SNI::Item::getIconByName(std::string name, int request_size) {
|
int request_size) {
|
||||||
int tmp_size = 0;
|
int tmp_size = 0;
|
||||||
icon_theme->rescan_if_needed();
|
icon_theme->rescan_if_needed();
|
||||||
auto sizes = icon_theme->get_icon_sizes(name.c_str());
|
auto sizes = icon_theme->get_icon_sizes(name.c_str());
|
||||||
@ -272,14 +257,12 @@ waybar::modules::SNI::Item::getIconByName(std::string name, int request_size) {
|
|||||||
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::SNI::Item::onMenuDestroyed(Item *self)
|
void waybar::modules::SNI::Item::onMenuDestroyed(Item* self) {
|
||||||
{
|
|
||||||
self->gtk_menu = nullptr;
|
self->gtk_menu = nullptr;
|
||||||
self->dbus_menu = nullptr;
|
self->dbus_menu = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waybar::modules::SNI::Item::makeMenu(GdkEventButton *const &ev)
|
bool waybar::modules::SNI::Item::makeMenu(GdkEventButton* const& ev) {
|
||||||
{
|
|
||||||
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());
|
||||||
@ -303,10 +286,8 @@ bool waybar::modules::SNI::Item::makeMenu(GdkEventButton *const &ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool waybar::modules::SNI::Item::handleClick(GdkEventButton* const& ev) {
|
bool waybar::modules::SNI::Item::handleClick(GdkEventButton* const& ev) {
|
||||||
auto parameters = VariantContainerBase::create_tuple({
|
auto parameters = VariantContainerBase::create_tuple(
|
||||||
Variant<int>::create(ev->x),
|
{Variant<int>::create(ev->x), Variant<int>::create(ev->y)});
|
||||||
Variant<int>::create(ev->y)
|
|
||||||
});
|
|
||||||
if ((ev->button == 1 && item_is_menu) || ev->button == 3) {
|
if ((ev->button == 1 && item_is_menu) || ev->button == 3) {
|
||||||
if (!makeMenu(ev)) {
|
if (!makeMenu(ev)) {
|
||||||
proxy_->call("ContextMenu", parameters);
|
proxy_->call("ContextMenu", parameters);
|
||||||
|
@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
waybar::modules::SNI::Tray::Tray(const std::string& id, const Bar& bar,
|
waybar::modules::SNI::Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||||
const Json::Value &config)
|
|
||||||
: config_(config),
|
: config_(config),
|
||||||
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
||||||
watcher_(), host_(nb_hosts_, config,
|
watcher_(),
|
||||||
std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
||||||
std::bind(&Tray::onRemove, this, std::placeholders::_1))
|
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
|
||||||
{
|
|
||||||
std::cout << "Tray is in beta, so there may be bugs or even be unusable." << std::endl;
|
std::cout << "Tray is in beta, so there may be bugs or even be unusable." << std::endl;
|
||||||
if (config_["spacing"].isUInt()) {
|
if (config_["spacing"].isUInt()) {
|
||||||
box_.set_spacing(config_["spacing"].asUInt());
|
box_.set_spacing(config_["spacing"].asUInt());
|
||||||
@ -17,14 +15,12 @@ waybar::modules::SNI::Tray::Tray(const std::string& id, const Bar& bar,
|
|||||||
nb_hosts_ += 1;
|
nb_hosts_ += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::SNI::Tray::onAdd(std::unique_ptr<Item>& item)
|
void waybar::modules::SNI::Tray::onAdd(std::unique_ptr<Item>& item) {
|
||||||
{
|
|
||||||
box_.pack_start(item->event_box);
|
box_.pack_start(item->event_box);
|
||||||
dp.emit();
|
dp.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::SNI::Tray::onRemove(std::unique_ptr<Item>& item)
|
void waybar::modules::SNI::Tray::onRemove(std::unique_ptr<Item>& item) {
|
||||||
{
|
|
||||||
box_.remove(item->event_box);
|
box_.remove(item->event_box);
|
||||||
dp.emit();
|
dp.emit();
|
||||||
}
|
}
|
||||||
@ -38,6 +34,4 @@ auto waybar::modules::SNI::Tray::update() -> void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
waybar::modules::SNI::Tray::operator Gtk::Widget &() {
|
waybar::modules::SNI::Tray::operator Gtk::Widget&() { return box_; }
|
||||||
return box_;
|
|
||||||
}
|
|
||||||
|
@ -6,32 +6,49 @@ using namespace waybar::modules::SNI;
|
|||||||
|
|
||||||
Watcher::Watcher()
|
Watcher::Watcher()
|
||||||
: bus_name_id_(Gio::DBus::own_name(Gio::DBus::BusType::BUS_TYPE_SESSION,
|
: bus_name_id_(Gio::DBus::own_name(Gio::DBus::BusType::BUS_TYPE_SESSION,
|
||||||
"org.kde.StatusNotifierWatcher", sigc::mem_fun(*this, &Watcher::busAcquired),
|
"org.kde.StatusNotifierWatcher",
|
||||||
|
sigc::mem_fun(*this, &Watcher::busAcquired),
|
||||||
Gio::DBus::SlotNameAcquired(), Gio::DBus::SlotNameLost(),
|
Gio::DBus::SlotNameAcquired(), Gio::DBus::SlotNameLost(),
|
||||||
Gio::DBus::BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | Gio::DBus::BUS_NAME_OWNER_FLAGS_REPLACE)),
|
Gio::DBus::BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
||||||
watcher_(sn_watcher_skeleton_new())
|
Gio::DBus::BUS_NAME_OWNER_FLAGS_REPLACE)),
|
||||||
{
|
watcher_(sn_watcher_skeleton_new()) {}
|
||||||
|
|
||||||
|
Watcher::~Watcher() {
|
||||||
|
if (bus_name_id_ > 0) {
|
||||||
|
g_bus_unown_name(bus_name_id_);
|
||||||
|
bus_name_id_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watcher::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib::ustring name)
|
if (hosts_ != NULL) {
|
||||||
{
|
g_slist_free_full(hosts_, gfWatchFree);
|
||||||
|
hosts_ = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (items_ != NULL) {
|
||||||
|
g_slist_free_full(items_, gfWatchFree);
|
||||||
|
items_ = NULL;
|
||||||
|
}
|
||||||
|
g_signal_handler_disconnect(watcher_, handler_host_id_);
|
||||||
|
g_signal_handler_disconnect(watcher_, handler_item_id_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Watcher::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib::ustring name) {
|
||||||
GError* error = nullptr;
|
GError* error = nullptr;
|
||||||
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(watcher_),
|
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(watcher_), conn->gobj(),
|
||||||
conn->gobj(), "/StatusNotifierWatcher", &error);
|
"/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(watcher_, "handle-register-item",
|
handler_item_id_ = g_signal_connect_swapped(watcher_, "handle-register-item",
|
||||||
G_CALLBACK(&Watcher::handleRegisterItem), this);
|
G_CALLBACK(&Watcher::handleRegisterItem), this);
|
||||||
g_signal_connect_swapped(watcher_, "handle-register-host",
|
handler_host_id_ = g_signal_connect_swapped(watcher_, "handle-register-host",
|
||||||
G_CALLBACK(&Watcher::handleRegisterHost), this);
|
G_CALLBACK(&Watcher::handleRegisterHost), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean Watcher::handleRegisterHost(Watcher* obj,
|
gboolean Watcher::handleRegisterHost(Watcher* obj, GDBusMethodInvocation* invocation,
|
||||||
GDBusMethodInvocation* invocation, const gchar* service)
|
const gchar* service) {
|
||||||
{
|
|
||||||
const gchar* bus_name = service;
|
const gchar* bus_name = service;
|
||||||
const gchar* object_path = "/StatusNotifierHost";
|
const gchar* object_path = "/StatusNotifierHost";
|
||||||
|
|
||||||
@ -40,14 +57,15 @@ gboolean Watcher::handleRegisterHost(Watcher* obj,
|
|||||||
object_path = service;
|
object_path = service;
|
||||||
}
|
}
|
||||||
if (g_dbus_is_name(bus_name) == FALSE) {
|
if (g_dbus_is_name(bus_name) == FALSE) {
|
||||||
g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
|
g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
|
||||||
G_DBUS_ERROR_INVALID_ARGS, "D-Bus bus name '%s' is not valid", bus_name);
|
"D-Bus bus name '%s' is not valid", bus_name);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
auto watch = gfWatchFind(obj->hosts_, bus_name, object_path);
|
auto watch = gfWatchFind(obj->hosts_, bus_name, object_path);
|
||||||
if (watch != nullptr) {
|
if (watch != nullptr) {
|
||||||
g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
|
g_dbus_method_invocation_return_error(
|
||||||
G_DBUS_ERROR_INVALID_ARGS, "Status Notifier Host with bus name '%s' and object path '%s' is already registered",
|
invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
|
||||||
|
"Status Notifier Host with bus name '%s' and object path '%s' is already registered",
|
||||||
bus_name, object_path);
|
bus_name, object_path);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -61,9 +79,8 @@ gboolean Watcher::handleRegisterHost(Watcher* obj,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean Watcher::handleRegisterItem(Watcher* obj,
|
gboolean Watcher::handleRegisterItem(Watcher* obj, GDBusMethodInvocation* invocation,
|
||||||
GDBusMethodInvocation* invocation, const gchar* service)
|
const gchar* service) {
|
||||||
{
|
|
||||||
const gchar* bus_name = service;
|
const gchar* bus_name = service;
|
||||||
const gchar* object_path = "/StatusNotifierItem";
|
const gchar* object_path = "/StatusNotifierItem";
|
||||||
|
|
||||||
@ -72,8 +89,8 @@ gboolean Watcher::handleRegisterItem(Watcher* obj,
|
|||||||
object_path = service;
|
object_path = service;
|
||||||
}
|
}
|
||||||
if (g_dbus_is_name(bus_name) == FALSE) {
|
if (g_dbus_is_name(bus_name) == FALSE) {
|
||||||
g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR,
|
g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
|
||||||
G_DBUS_ERROR_INVALID_ARGS, "D-Bus bus name '%s' is not valid", bus_name);
|
"D-Bus bus name '%s' is not valid", bus_name);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
auto watch = gfWatchFind(obj->items_, bus_name, object_path);
|
auto watch = gfWatchFind(obj->items_, bus_name, object_path);
|
||||||
@ -94,36 +111,45 @@ gboolean Watcher::handleRegisterItem(Watcher* obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Watcher::GfWatch* Watcher::gfWatchFind(GSList* list, const gchar* bus_name,
|
Watcher::GfWatch* Watcher::gfWatchFind(GSList* list, const gchar* bus_name,
|
||||||
const gchar* object_path)
|
const gchar* object_path) {
|
||||||
{
|
|
||||||
for (GSList* l = list; l != nullptr; l = g_slist_next(l)) {
|
for (GSList* l = list; l != nullptr; l = g_slist_next(l)) {
|
||||||
GfWatch* watch = static_cast<GfWatch*>(l->data);
|
GfWatch* watch = static_cast<GfWatch*>(l->data);
|
||||||
if (g_strcmp0 (watch->bus_name, bus_name) == 0
|
if (g_strcmp0(watch->bus_name, bus_name) == 0 &&
|
||||||
&& g_strcmp0 (watch->object_path, object_path) == 0) {
|
g_strcmp0(watch->object_path, object_path) == 0) {
|
||||||
return watch;
|
return watch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Watcher::GfWatch* Watcher::gfWatchNew(GfWatchType type, const gchar* service,
|
void Watcher::gfWatchFree(gpointer data) {
|
||||||
const gchar* bus_name, const gchar* object_path, Watcher* watcher)
|
GfWatch* watch;
|
||||||
{
|
|
||||||
|
watch = (GfWatch*)data;
|
||||||
|
|
||||||
|
if (watch->watch_id > 0) g_bus_unwatch_name(watch->watch_id);
|
||||||
|
|
||||||
|
g_free(watch->service);
|
||||||
|
g_free(watch->bus_name);
|
||||||
|
g_free(watch->object_path);
|
||||||
|
|
||||||
|
g_free(watch);
|
||||||
|
}
|
||||||
|
|
||||||
|
Watcher::GfWatch* Watcher::gfWatchNew(GfWatchType type, const gchar* service, const gchar* bus_name,
|
||||||
|
const gchar* object_path, Watcher* watcher) {
|
||||||
GfWatch* watch = g_new0(GfWatch, 1);
|
GfWatch* watch = g_new0(GfWatch, 1);
|
||||||
watch->type = type;
|
watch->type = type;
|
||||||
watch->watcher = watcher;
|
watch->watcher = watcher;
|
||||||
watch->service = g_strdup(service);
|
watch->service = g_strdup(service);
|
||||||
watch->bus_name = g_strdup(bus_name);
|
watch->bus_name = g_strdup(bus_name);
|
||||||
watch->object_path = g_strdup(object_path);
|
watch->object_path = g_strdup(object_path);
|
||||||
watch->watch_id = g_bus_watch_name(G_BUS_TYPE_SESSION, bus_name,
|
watch->watch_id = g_bus_watch_name(G_BUS_TYPE_SESSION, bus_name, G_BUS_NAME_WATCHER_FLAGS_NONE,
|
||||||
G_BUS_NAME_WATCHER_FLAGS_NONE, nullptr, &Watcher::nameVanished, watch,
|
nullptr, &Watcher::nameVanished, watch, nullptr);
|
||||||
nullptr);
|
|
||||||
return watch;
|
return watch;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watcher::nameVanished(GDBusConnection* connection, const char* name,
|
void Watcher::nameVanished(GDBusConnection* connection, const char* name, gpointer data) {
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
auto watch = static_cast<GfWatch*>(data);
|
auto watch = static_cast<GfWatch*>(data);
|
||||||
if (watch->type == GF_WATCH_TYPE_HOST) {
|
if (watch->type == GF_WATCH_TYPE_HOST) {
|
||||||
watch->watcher->hosts_ = g_slist_remove(watch->watcher->hosts_, watch);
|
watch->watcher->hosts_ = g_slist_remove(watch->watcher->hosts_, watch);
|
||||||
@ -140,8 +166,7 @@ void Watcher::nameVanished(GDBusConnection* connection, const char* name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Watcher::updateRegisteredItems(SnWatcher* obj)
|
void Watcher::updateRegisteredItems(SnWatcher* obj) {
|
||||||
{
|
|
||||||
GVariantBuilder builder;
|
GVariantBuilder builder;
|
||||||
g_variant_builder_init(&builder, G_VARIANT_TYPE("as"));
|
g_variant_builder_init(&builder, G_VARIANT_TYPE("as"));
|
||||||
for (GSList* l = items_; l != nullptr; l = g_slist_next(l)) {
|
for (GSList* l = items_; l != nullptr; l = g_slist_next(l)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user