refactor: simpler sni naming
This commit is contained in:
parent
3f269ff463
commit
f20441fa92
|
@ -19,10 +19,8 @@ class Host {
|
|||
static void nameVanished(GDBusConnection*, const gchar*, gpointer);
|
||||
static void proxyReady(GObject*, GAsyncResult*, gpointer);
|
||||
static void registerHost(GObject*, GAsyncResult*, gpointer);
|
||||
static void itemRegistered(SnOrgKdeStatusNotifierWatcher*, const gchar*,
|
||||
gpointer);
|
||||
static void itemUnregistered(SnOrgKdeStatusNotifierWatcher*, const gchar*,
|
||||
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);
|
||||
|
@ -33,7 +31,7 @@ class Host {
|
|||
std::string object_path_;
|
||||
Glib::Dispatcher* dp_;
|
||||
GCancellable* cancellable_ = nullptr;
|
||||
SnOrgKdeStatusNotifierWatcher* watcher_ = nullptr;
|
||||
SnWatcher* watcher_ = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ private:
|
|||
|
||||
Glib::Dispatcher *dp_;
|
||||
GCancellable *cancellable_ = nullptr;
|
||||
SnOrgKdeStatusNotifierItem *proxy_ = nullptr;
|
||||
SnItem *proxy_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules::SNI
|
||||
|
|
|
@ -34,13 +34,13 @@ private:
|
|||
static void nameVanished(GDBusConnection *connection, const char *name,
|
||||
gpointer data);
|
||||
|
||||
void updateRegisteredItems(SnOrgKdeStatusNotifierWatcher *obj);
|
||||
void updateRegisteredItems(SnWatcher *obj);
|
||||
|
||||
uint32_t bus_name_id_;
|
||||
uint32_t watcher_id_;
|
||||
GSList *hosts_ = nullptr;
|
||||
GSList *items_ = nullptr;
|
||||
SnOrgKdeStatusNotifierWatcher *watcher_ = nullptr;
|
||||
SnWatcher *watcher_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules::SNI
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.kde.StatusNotifierItem">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="Item" />
|
||||
<property name="Category" type="s" access="read"/>
|
||||
<property name="Id" type="s" access="read"/>
|
||||
<property name="Title" type="s" access="read"/>
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.kde.StatusNotifierWatcher">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="Watcher" />
|
||||
|
||||
<!-- methods -->
|
||||
<method name="RegisterStatusNotifierItem">
|
||||
<arg name="service" type="s" direction="in"/>
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="RegisterItem" />
|
||||
<arg name="service" type="s" direction="in"/>
|
||||
</method>
|
||||
|
||||
<method name="RegisterStatusNotifierHost">
|
||||
<arg name="service" type="s" direction="in"/>
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="RegisterHost" />
|
||||
<arg name="service" type="s" direction="in"/>
|
||||
</method>
|
||||
|
||||
|
||||
<!-- properties -->
|
||||
|
||||
<property name="RegisteredStatusNotifierItems" type="as" access="read">
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QStringList"/>
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="RegisteredItems" />
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QStringList"/>
|
||||
</property>
|
||||
|
||||
<property name="IsStatusNotifierHostRegistered" type="b" access="read"/>
|
||||
<property name="IsStatusNotifierHostRegistered" type="b" access="read">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="IsHostRegistered" />
|
||||
</property>
|
||||
|
||||
<property name="ProtocolVersion" type="i" access="read"/>
|
||||
|
||||
|
@ -26,17 +32,21 @@
|
|||
<!-- signals -->
|
||||
|
||||
<signal name="StatusNotifierItemRegistered">
|
||||
<arg type="s"/>
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="ItemRegistered" />
|
||||
<arg type="s" direction="out" name="service" />
|
||||
</signal>
|
||||
|
||||
<signal name="StatusNotifierItemUnregistered">
|
||||
<arg type="s"/>
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="ItemUnregistered" />
|
||||
<arg type="s" direction="out" name="service" />
|
||||
</signal>
|
||||
|
||||
<signal name="StatusNotifierHostRegistered">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="HostRegistered" />
|
||||
</signal>
|
||||
|
||||
<signal name="StatusNotifierHostUnregistered">
|
||||
<annotation name="org.gtk.GDBus.C.Name" value="HostUnregistered" />
|
||||
</signal>
|
||||
</interface>
|
||||
</node>
|
|
@ -35,7 +35,7 @@ void Host::nameAppeared(GDBusConnection* connection,
|
|||
// TODO
|
||||
}
|
||||
host->cancellable_ = g_cancellable_new();
|
||||
sn_org_kde_status_notifier_watcher_proxy_new(
|
||||
sn_watcher_proxy_new(
|
||||
connection,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
"org.kde.StatusNotifierWatcher",
|
||||
|
@ -57,8 +57,7 @@ void Host::proxyReady(GObject* src, GAsyncResult* res,
|
|||
gpointer data)
|
||||
{
|
||||
GError* error = nullptr;
|
||||
SnOrgKdeStatusNotifierWatcher* watcher =
|
||||
sn_org_kde_status_notifier_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)) {
|
||||
std::cerr << error->message << std::endl;
|
||||
g_error_free(error);
|
||||
|
@ -71,7 +70,7 @@ void Host::proxyReady(GObject* src, GAsyncResult* res,
|
|||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
sn_org_kde_status_notifier_watcher_call_register_status_notifier_host(
|
||||
sn_watcher_call_register_host(
|
||||
host->watcher_, host->object_path_.c_str(), host->cancellable_,
|
||||
&Host::registerHost, data);
|
||||
}
|
||||
|
@ -80,8 +79,7 @@ void Host::registerHost(GObject* src, GAsyncResult* res,
|
|||
gpointer data)
|
||||
{
|
||||
GError* error = nullptr;
|
||||
sn_org_kde_status_notifier_watcher_call_register_status_notifier_host_finish(
|
||||
SN_ORG_KDE_STATUS_NOTIFIER_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)) {
|
||||
std::cerr << error->message << std::endl;
|
||||
g_error_free(error);
|
||||
|
@ -93,12 +91,11 @@ void Host::registerHost(GObject* src, GAsyncResult* res,
|
|||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
g_signal_connect(host->watcher_, "status-notifier-item-registered",
|
||||
g_signal_connect(host->watcher_, "item-registered",
|
||||
G_CALLBACK(&Host::itemRegistered), data);
|
||||
g_signal_connect(host->watcher_, "status-notifier-item-unregistered",
|
||||
g_signal_connect(host->watcher_, "item-unregistered",
|
||||
G_CALLBACK(&Host::itemUnregistered), data);
|
||||
auto items =
|
||||
sn_org_kde_status_notifier_watcher_dup_registered_status_notifier_items(host->watcher_);
|
||||
auto items = sn_watcher_dup_registered_items(host->watcher_);
|
||||
if (items) {
|
||||
for (uint32_t i = 0; items[i] != nullptr; i += 1) {
|
||||
host->addRegisteredItem(items[i]);
|
||||
|
@ -108,14 +105,14 @@ void Host::registerHost(GObject* src, GAsyncResult* res,
|
|||
}
|
||||
|
||||
void Host::itemRegistered(
|
||||
SnOrgKdeStatusNotifierWatcher* watcher, const gchar* service, gpointer data)
|
||||
SnWatcher* watcher, const gchar* service, gpointer data)
|
||||
{
|
||||
auto host = static_cast<SNI::Host *>(data);
|
||||
host->addRegisteredItem(service);
|
||||
}
|
||||
|
||||
void Host::itemUnregistered(
|
||||
SnOrgKdeStatusNotifierWatcher* watcher, const gchar* service, gpointer data)
|
||||
SnWatcher* watcher, const gchar* service, gpointer data)
|
||||
{
|
||||
auto host = static_cast<SNI::Host *>(data);
|
||||
auto [bus_name, object_path] = host->getBusNameAndObjectPath(service);
|
||||
|
|
|
@ -12,7 +12,7 @@ waybar::modules::SNI::Item::Item(std::string bn, std::string op,
|
|||
event_box.signal_button_press_event().connect(
|
||||
sigc::mem_fun(*this, &Item::handleClick));
|
||||
cancellable_ = g_cancellable_new();
|
||||
sn_org_kde_status_notifier_item_proxy_new_for_bus(
|
||||
sn_item_proxy_new_for_bus(
|
||||
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, bus_name.c_str(),
|
||||
object_path.c_str(), cancellable_, &Item::proxyReady, this);
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ waybar::modules::SNI::Item::Item(std::string bn, std::string op,
|
|||
void waybar::modules::SNI::Item::proxyReady(GObject *obj, GAsyncResult *res,
|
||||
gpointer data) {
|
||||
GError *error = nullptr;
|
||||
SnOrgKdeStatusNotifierItem *proxy =
|
||||
sn_org_kde_status_notifier_item_proxy_new_for_bus_finish(res, &error);
|
||||
SnItem *proxy =
|
||||
sn_item_proxy_new_for_bus_finish(res, &error);
|
||||
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||
g_error_free(error);
|
||||
return;
|
||||
|
@ -227,7 +227,7 @@ waybar::modules::SNI::Item::getIconByName(std::string name, int request_size) {
|
|||
void waybar::modules::SNI::Item::handleActivate(GObject *src, GAsyncResult *res,
|
||||
gpointer data) {
|
||||
auto item = static_cast<SNI::Item *>(data);
|
||||
sn_org_kde_status_notifier_item_call_activate_finish(item->proxy_, res,
|
||||
sn_item_call_activate_finish(item->proxy_, res,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ void waybar::modules::SNI::Item::handleSecondaryActivate(GObject *src,
|
|||
GAsyncResult *res,
|
||||
gpointer data) {
|
||||
auto item = static_cast<SNI::Item *>(data);
|
||||
sn_org_kde_status_notifier_item_call_secondary_activate_finish(item->proxy_,
|
||||
sn_item_call_secondary_activate_finish(item->proxy_,
|
||||
res, nullptr);
|
||||
}
|
||||
|
||||
|
@ -247,11 +247,11 @@ bool waybar::modules::SNI::Item::handleClick(GdkEventButton *const &ev) {
|
|||
}
|
||||
gtk_menu->popup(ev->button, ev->time);
|
||||
} else {
|
||||
sn_org_kde_status_notifier_item_call_activate(
|
||||
sn_item_call_activate(
|
||||
proxy_, ev->x, ev->y, nullptr, &Item::handleActivate, this);
|
||||
}
|
||||
} else if (ev->type == GDK_2BUTTON_PRESS) {
|
||||
sn_org_kde_status_notifier_item_call_secondary_activate(
|
||||
sn_item_call_secondary_activate(
|
||||
proxy_, ev->x, ev->y, nullptr, &Item::handleSecondaryActivate, this);
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -12,7 +12,7 @@ Watcher::Watcher()
|
|||
bus_name_id_ = g_bus_own_name(G_BUS_TYPE_SESSION,
|
||||
"org.kde.StatusNotifierWatcher", flags,
|
||||
&Watcher::busAcquired, nullptr, nullptr, this, nullptr);
|
||||
watcher_ = sn_org_kde_status_notifier_watcher_skeleton_new();
|
||||
watcher_ = sn_watcher_skeleton_new();
|
||||
}
|
||||
|
||||
Watcher::~Watcher()
|
||||
|
@ -32,14 +32,13 @@ void Watcher::busAcquired(GDBusConnection* connection, const gchar* name,
|
|||
return;
|
||||
}
|
||||
g_signal_connect_swapped(host->watcher_,
|
||||
"handle-register-status-notifier-item",
|
||||
"handle-register-item",
|
||||
G_CALLBACK(&Watcher::handleRegisterItem), data);
|
||||
g_signal_connect_swapped(host->watcher_,
|
||||
"handle-register-status-notifier-host",
|
||||
"handle-register-host",
|
||||
G_CALLBACK(&Watcher::handleRegisterHost), data);
|
||||
sn_org_kde_status_notifier_watcher_set_protocol_version(host->watcher_, 0);
|
||||
sn_org_kde_status_notifier_watcher_set_is_status_notifier_host_registered(
|
||||
host->watcher_, TRUE);
|
||||
sn_watcher_set_protocol_version(host->watcher_, 0);
|
||||
sn_watcher_set_is_host_registered(host->watcher_, TRUE);
|
||||
}
|
||||
|
||||
gboolean Watcher::handleRegisterHost(Watcher* obj,
|
||||
|
@ -66,14 +65,11 @@ gboolean Watcher::handleRegisterHost(Watcher* obj,
|
|||
}
|
||||
watch = gfWatchNew(GF_WATCH_TYPE_HOST, service, bus_name, object_path, obj);
|
||||
obj->hosts_ = g_slist_prepend(obj->hosts_, watch);
|
||||
sn_org_kde_status_notifier_watcher_set_is_status_notifier_host_registered(
|
||||
obj->watcher_, TRUE);
|
||||
sn_watcher_set_is_host_registered(obj->watcher_, TRUE);
|
||||
if (g_slist_length(obj->hosts_)) {
|
||||
sn_org_kde_status_notifier_watcher_emit_status_notifier_host_registered(
|
||||
obj->watcher_);
|
||||
sn_watcher_emit_host_registered(obj->watcher_);
|
||||
}
|
||||
sn_org_kde_status_notifier_watcher_complete_register_status_notifier_host(
|
||||
obj->watcher_, invocation);
|
||||
sn_watcher_complete_register_host(obj->watcher_, invocation);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -96,19 +92,16 @@ gboolean Watcher::handleRegisterItem(Watcher* obj,
|
|||
if (watch != nullptr) {
|
||||
g_warning("Status Notifier Item with bus name '%s' and object path '%s' is already registered",
|
||||
bus_name, object_path);
|
||||
sn_org_kde_status_notifier_watcher_complete_register_status_notifier_item(
|
||||
obj->watcher_, invocation);
|
||||
sn_watcher_complete_register_item(obj->watcher_, invocation);
|
||||
return TRUE;
|
||||
}
|
||||
watch = gfWatchNew(GF_WATCH_TYPE_ITEM, service, bus_name, object_path, obj);
|
||||
obj->items_ = g_slist_prepend(obj->items_, watch);
|
||||
obj->updateRegisteredItems(obj->watcher_);
|
||||
gchar* tmp = g_strdup_printf("%s%s", bus_name, object_path);
|
||||
sn_org_kde_status_notifier_watcher_emit_status_notifier_item_registered(
|
||||
obj->watcher_, tmp);
|
||||
sn_watcher_emit_item_registered(obj->watcher_, tmp);
|
||||
g_free(tmp);
|
||||
sn_org_kde_status_notifier_watcher_complete_register_status_notifier_item(
|
||||
obj->watcher_, invocation);
|
||||
sn_watcher_complete_register_item(obj->watcher_, invocation);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -147,22 +140,19 @@ void Watcher::nameVanished(GDBusConnection* connection, const char* name,
|
|||
if (watch->type == GF_WATCH_TYPE_HOST) {
|
||||
watch->watcher->hosts_ = g_slist_remove(watch->watcher->hosts_, watch);
|
||||
if (watch->watcher->hosts_ == nullptr) {
|
||||
sn_org_kde_status_notifier_watcher_set_is_status_notifier_host_registered(
|
||||
watch->watcher->watcher_, FALSE);
|
||||
sn_org_kde_status_notifier_watcher_emit_status_notifier_host_registered(
|
||||
watch->watcher->watcher_);
|
||||
sn_watcher_set_is_host_registered(watch->watcher->watcher_, FALSE);
|
||||
sn_watcher_emit_host_registered(watch->watcher->watcher_);
|
||||
}
|
||||
} else if (watch->type == GF_WATCH_TYPE_ITEM) {
|
||||
watch->watcher->items_ = g_slist_remove(watch->watcher->items_, watch);
|
||||
watch->watcher->updateRegisteredItems(watch->watcher->watcher_);
|
||||
gchar* tmp = g_strdup_printf("%s%s", watch->bus_name, watch->object_path);
|
||||
sn_org_kde_status_notifier_watcher_emit_status_notifier_item_unregistered(
|
||||
watch->watcher->watcher_, tmp);
|
||||
sn_watcher_emit_item_unregistered(watch->watcher->watcher_, tmp);
|
||||
g_free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void Watcher::updateRegisteredItems(SnOrgKdeStatusNotifierWatcher* obj)
|
||||
void Watcher::updateRegisteredItems(SnWatcher* obj)
|
||||
{
|
||||
GVariantBuilder builder;
|
||||
g_variant_builder_init(&builder, G_VARIANT_TYPE("as"));
|
||||
|
@ -174,8 +164,7 @@ void Watcher::updateRegisteredItems(SnOrgKdeStatusNotifierWatcher* obj)
|
|||
}
|
||||
GVariant* variant = g_variant_builder_end(&builder);
|
||||
const gchar** items = g_variant_get_strv(variant, nullptr);
|
||||
sn_org_kde_status_notifier_watcher_set_registered_status_notifier_items(
|
||||
obj, items);
|
||||
sn_watcher_set_registered_items(obj, items);
|
||||
g_variant_unref(variant);
|
||||
g_free(items);
|
||||
}
|
Loading…
Reference in New Issue