mirror of
https://github.com/rad4day/Waybar.git
synced 2025-08-26 07:22:25 +02:00
refactor: lint
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "modules/sni/host.hpp"
|
||||
|
||||
#include <fmt/ostream.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
@@ -32,8 +33,7 @@ Host::~Host() {
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
@@ -45,13 +45,8 @@ void Host::nameAppeared(const Glib::RefPtr<Gio::DBus::Connection>& conn, const G
|
||||
return;
|
||||
}
|
||||
cancellable_ = g_cancellable_new();
|
||||
sn_watcher_proxy_new(conn->gobj(),
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
"org.kde.StatusNotifierWatcher",
|
||||
"/StatusNotifierWatcher",
|
||||
cancellable_,
|
||||
&Host::proxyReady,
|
||||
this);
|
||||
sn_watcher_proxy_new(conn->gobj(), 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) {
|
||||
@@ -62,7 +57,7 @@ void Host::nameVanished(const Glib::RefPtr<Gio::DBus::Connection>& conn, const G
|
||||
}
|
||||
|
||||
void Host::proxyReady(GObject* src, GAsyncResult* res, gpointer data) {
|
||||
GError* error = nullptr;
|
||||
GError* error = nullptr;
|
||||
SnWatcher* watcher = sn_watcher_proxy_new_finish(res, &error);
|
||||
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||
spdlog::error("Host: {}", error->message);
|
||||
@@ -76,8 +71,8 @@ void Host::proxyReady(GObject* src, GAsyncResult* res, gpointer data) {
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
sn_watcher_call_register_host(
|
||||
host->watcher_, host->object_path_.c_str(), host->cancellable_, &Host::registerHost, data);
|
||||
sn_watcher_call_register_host(host->watcher_, host->object_path_.c_str(), host->cancellable_,
|
||||
&Host::registerHost, data);
|
||||
}
|
||||
|
||||
void Host::registerHost(GObject* src, GAsyncResult* res, gpointer data) {
|
||||
|
@@ -31,7 +31,7 @@ struct fmt::formatter<Glib::VariantBase> : formatter<std::string> {
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
static const Glib::ustring SNI_INTERFACE_NAME = sn_item_interface_info()->name;
|
||||
static const unsigned UPDATE_DEBOUNCE_TIME = 10;
|
||||
static const unsigned UPDATE_DEBOUNCE_TIME = 10;
|
||||
|
||||
Item::Item(const std::string& bn, const std::string& op, const Json::Value& config, const Bar& bar)
|
||||
: bus_name(bn),
|
||||
@@ -49,7 +49,7 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
|
||||
show_passive_ = config["show-passive-items"].asBool();
|
||||
}
|
||||
|
||||
auto &window = const_cast<Bar &>(bar).window;
|
||||
auto& window = const_cast<Bar&>(bar).window;
|
||||
window.signal_configure_event().connect_notify(sigc::mem_fun(*this, &Item::onConfigure));
|
||||
event_box.add(image);
|
||||
event_box.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
|
||||
@@ -62,18 +62,12 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
|
||||
cancellable_ = Gio::Cancellable::create();
|
||||
|
||||
auto interface = Glib::wrap(sn_item_interface_info(), true);
|
||||
Gio::DBus::Proxy::create_for_bus(Gio::DBus::BusType::BUS_TYPE_SESSION,
|
||||
bus_name,
|
||||
object_path,
|
||||
SNI_INTERFACE_NAME,
|
||||
sigc::mem_fun(*this, &Item::proxyReady),
|
||||
cancellable_,
|
||||
interface);
|
||||
Gio::DBus::Proxy::create_for_bus(Gio::DBus::BusType::BUS_TYPE_SESSION, bus_name, object_path,
|
||||
SNI_INTERFACE_NAME, sigc::mem_fun(*this, &Item::proxyReady),
|
||||
cancellable_, interface);
|
||||
}
|
||||
|
||||
void Item::onConfigure(GdkEventConfigure* ev) {
|
||||
this->updateImage();
|
||||
}
|
||||
void Item::onConfigure(GdkEventConfigure* ev) { this->updateImage(); }
|
||||
|
||||
void Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& result) {
|
||||
try {
|
||||
@@ -167,16 +161,10 @@ void Item::setProperty(const Glib::ustring& name, Glib::VariantBase& value) {
|
||||
}
|
||||
} catch (const Glib::Error& err) {
|
||||
spdlog::warn("Failed to set tray item property: {}.{}, value = {}, err = {}",
|
||||
id.empty() ? bus_name : id,
|
||||
name,
|
||||
value,
|
||||
err.what());
|
||||
id.empty() ? bus_name : id, name, value, err.what());
|
||||
} catch (const std::exception& err) {
|
||||
spdlog::warn("Failed to set tray item property: {}.{}, value = {}, err = {}",
|
||||
id.empty() ? bus_name : id,
|
||||
name,
|
||||
value,
|
||||
err.what());
|
||||
id.empty() ? bus_name : id, name, value, err.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,8 +187,7 @@ void Item::getUpdatedProperties() {
|
||||
auto params = Glib::VariantContainerBase::create_tuple(
|
||||
{Glib::Variant<Glib::ustring>::create(SNI_INTERFACE_NAME)});
|
||||
proxy_->call("org.freedesktop.DBus.Properties.GetAll",
|
||||
sigc::mem_fun(*this, &Item::processUpdatedProperties),
|
||||
params);
|
||||
sigc::mem_fun(*this, &Item::processUpdatedProperties), params);
|
||||
};
|
||||
|
||||
void Item::processUpdatedProperties(Glib::RefPtr<Gio::AsyncResult>& _result) {
|
||||
@@ -266,11 +253,11 @@ Glib::RefPtr<Gdk::Pixbuf> Item::extractPixBuf(GVariant* variant) {
|
||||
return Glib::RefPtr<Gdk::Pixbuf>{};
|
||||
}
|
||||
GVariant* val;
|
||||
gint lwidth = 0;
|
||||
gint lheight = 0;
|
||||
gint width;
|
||||
gint height;
|
||||
guchar* array = nullptr;
|
||||
gint lwidth = 0;
|
||||
gint lheight = 0;
|
||||
gint width;
|
||||
gint height;
|
||||
guchar* array = nullptr;
|
||||
while (g_variant_iter_loop(it, "(ii@ay)", &width, &height, &val)) {
|
||||
if (width > 0 && height > 0 && val != nullptr && width * height > lwidth * lheight) {
|
||||
auto size = g_variant_get_size(val);
|
||||
@@ -303,14 +290,8 @@ Glib::RefPtr<Gdk::Pixbuf> Item::extractPixBuf(GVariant* variant) {
|
||||
array[i + 2] = array[i + 3];
|
||||
array[i + 3] = alpha;
|
||||
}
|
||||
return Gdk::Pixbuf::create_from_data(array,
|
||||
Gdk::Colorspace::COLORSPACE_RGB,
|
||||
true,
|
||||
8,
|
||||
lwidth,
|
||||
lheight,
|
||||
4 * lwidth,
|
||||
&pixbuf_data_deleter);
|
||||
return Gdk::Pixbuf::create_from_data(array, Gdk::Colorspace::COLORSPACE_RGB, true, 8, lwidth,
|
||||
lheight, 4 * lwidth, &pixbuf_data_deleter);
|
||||
}
|
||||
return Glib::RefPtr<Gdk::Pixbuf>{};
|
||||
}
|
||||
@@ -318,7 +299,7 @@ Glib::RefPtr<Gdk::Pixbuf> Item::extractPixBuf(GVariant* variant) {
|
||||
void Item::updateImage() {
|
||||
auto pixbuf = getIconPixbuf();
|
||||
auto scaled_icon_size = getScaledIconSize();
|
||||
|
||||
|
||||
if (!pixbuf) {
|
||||
pixbuf = getIconByName("image-missing", getScaledIconSize());
|
||||
}
|
||||
@@ -349,7 +330,7 @@ Glib::RefPtr<Gdk::Pixbuf> Item::getIconPixbuf() {
|
||||
}
|
||||
} catch (Glib::Error& e) {
|
||||
spdlog::error("Item '{}': {}", id, static_cast<std::string>(e.what()));
|
||||
}
|
||||
}
|
||||
return getIconByName("image-missing", getScaledIconSize());
|
||||
}
|
||||
|
||||
@@ -374,15 +355,15 @@ Glib::RefPtr<Gdk::Pixbuf> Item::getIconByName(const std::string& name, int reque
|
||||
tmp_size = request_size;
|
||||
}
|
||||
if (!icon_theme_path.empty() &&
|
||||
icon_theme->lookup_icon(
|
||||
name.c_str(), tmp_size, Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE)) {
|
||||
return icon_theme->load_icon(
|
||||
name.c_str(), tmp_size, Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
||||
icon_theme->lookup_icon(name.c_str(), tmp_size,
|
||||
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE)) {
|
||||
return icon_theme->load_icon(name.c_str(), tmp_size,
|
||||
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
||||
}
|
||||
Glib::RefPtr<Gtk::IconTheme> default_theme = Gtk::IconTheme::get_default();
|
||||
default_theme->rescan_if_needed();
|
||||
return default_theme->load_icon(
|
||||
name.c_str(), tmp_size, Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
||||
return default_theme->load_icon(name.c_str(), tmp_size,
|
||||
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
||||
}
|
||||
|
||||
double Item::getScaledIconSize() {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "modules/sni/tray.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "modules/sni/watcher.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
using namespace waybar::modules::SNI;
|
||||
@@ -29,8 +30,8 @@ Watcher::~Watcher() {
|
||||
|
||||
void Watcher::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib::ustring name) {
|
||||
GError* error = nullptr;
|
||||
g_dbus_interface_skeleton_export(
|
||||
G_DBUS_INTERFACE_SKELETON(watcher_), conn->gobj(), "/StatusNotifierWatcher", &error);
|
||||
g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(watcher_), conn->gobj(),
|
||||
"/StatusNotifierWatcher", &error);
|
||||
if (error != nullptr) {
|
||||
// Don't print an error when a watcher is already present
|
||||
if (error->code != 2) {
|
||||
@@ -39,10 +40,10 @@ void Watcher::busAcquired(const Glib::RefPtr<Gio::DBus::Connection>& conn, Glib:
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
g_signal_connect_swapped(
|
||||
watcher_, "handle-register-item", G_CALLBACK(&Watcher::handleRegisterItem), this);
|
||||
g_signal_connect_swapped(
|
||||
watcher_, "handle-register-host", G_CALLBACK(&Watcher::handleRegisterHost), this);
|
||||
g_signal_connect_swapped(watcher_, "handle-register-item",
|
||||
G_CALLBACK(&Watcher::handleRegisterItem), this);
|
||||
g_signal_connect_swapped(watcher_, "handle-register-host",
|
||||
G_CALLBACK(&Watcher::handleRegisterHost), this);
|
||||
}
|
||||
|
||||
gboolean Watcher::handleRegisterHost(Watcher* obj, GDBusMethodInvocation* invocation,
|
||||
@@ -55,22 +56,16 @@ gboolean Watcher::handleRegisterHost(Watcher* obj, GDBusMethodInvocation* invoca
|
||||
object_path = service;
|
||||
}
|
||||
if (g_dbus_is_name(bus_name) == FALSE) {
|
||||
g_dbus_method_invocation_return_error(invocation,
|
||||
G_DBUS_ERROR,
|
||||
G_DBUS_ERROR_INVALID_ARGS,
|
||||
"D-Bus bus name '%s' is not valid",
|
||||
bus_name);
|
||||
g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
|
||||
"D-Bus bus name '%s' is not valid", bus_name);
|
||||
return TRUE;
|
||||
}
|
||||
auto watch = gfWatchFind(obj->hosts_, bus_name, object_path);
|
||||
if (watch != nullptr) {
|
||||
g_dbus_method_invocation_return_error(
|
||||
invocation,
|
||||
G_DBUS_ERROR,
|
||||
G_DBUS_ERROR_INVALID_ARGS,
|
||||
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;
|
||||
}
|
||||
watch = gfWatchNew(GF_WATCH_TYPE_HOST, service, bus_name, object_path, obj);
|
||||
@@ -93,18 +88,14 @@ gboolean Watcher::handleRegisterItem(Watcher* obj, GDBusMethodInvocation* invoca
|
||||
object_path = service;
|
||||
}
|
||||
if (g_dbus_is_name(bus_name) == FALSE) {
|
||||
g_dbus_method_invocation_return_error(invocation,
|
||||
G_DBUS_ERROR,
|
||||
G_DBUS_ERROR_INVALID_ARGS,
|
||||
"D-Bus bus name '%s' is not valid",
|
||||
bus_name);
|
||||
g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
|
||||
"D-Bus bus name '%s' is not valid", bus_name);
|
||||
return TRUE;
|
||||
}
|
||||
auto watch = gfWatchFind(obj->items_, bus_name, object_path);
|
||||
if (watch != nullptr) {
|
||||
g_warning("Status Notifier Item with bus name '%s' and object path '%s' is already registered",
|
||||
bus_name,
|
||||
object_path);
|
||||
bus_name, object_path);
|
||||
sn_watcher_complete_register_item(obj->watcher_, invocation);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -152,13 +143,8 @@ Watcher::GfWatch* Watcher::gfWatchNew(GfWatchType type, const gchar* service, co
|
||||
watch->service = g_strdup(service);
|
||||
watch->bus_name = g_strdup(bus_name);
|
||||
watch->object_path = g_strdup(object_path);
|
||||
watch->watch_id = g_bus_watch_name(G_BUS_TYPE_SESSION,
|
||||
bus_name,
|
||||
G_BUS_NAME_WATCHER_FLAGS_NONE,
|
||||
nullptr,
|
||||
&Watcher::nameVanished,
|
||||
watch,
|
||||
nullptr);
|
||||
watch->watch_id = g_bus_watch_name(G_BUS_TYPE_SESSION, bus_name, G_BUS_NAME_WATCHER_FLAGS_NONE,
|
||||
nullptr, &Watcher::nameVanished, watch, nullptr);
|
||||
return watch;
|
||||
}
|
||||
|
||||
@@ -183,12 +169,12 @@ void Watcher::updateRegisteredItems(SnWatcher* obj) {
|
||||
GVariantBuilder builder;
|
||||
g_variant_builder_init(&builder, G_VARIANT_TYPE("as"));
|
||||
for (GSList* l = items_; l != nullptr; l = g_slist_next(l)) {
|
||||
auto watch = static_cast<GfWatch*>(l->data);
|
||||
auto watch = static_cast<GfWatch*>(l->data);
|
||||
gchar* item = g_strdup_printf("%s%s", watch->bus_name, watch->object_path);
|
||||
g_variant_builder_add(&builder, "s", item);
|
||||
g_free(item);
|
||||
}
|
||||
GVariant* variant = g_variant_builder_end(&builder);
|
||||
GVariant* variant = g_variant_builder_end(&builder);
|
||||
const gchar** items = g_variant_get_strv(variant, nullptr);
|
||||
sn_watcher_set_registered_items(obj, items);
|
||||
g_variant_unref(variant);
|
||||
|
Reference in New Issue
Block a user