WIP sni dbus-menu support.
parent
0eee8eade7
commit
108b1092e5
|
@ -11,7 +11,8 @@ class Item {
|
|||
~Item();
|
||||
int icon_size;
|
||||
int effective_icon_size;
|
||||
Gtk::Image* image;
|
||||
Gtk::Widget* widget = nullptr;
|
||||
Gtk::Image* image = nullptr;
|
||||
std::string category;
|
||||
std::string id;
|
||||
std::string status;
|
||||
|
|
|
@ -32,6 +32,7 @@ wayland_cursor = dependency('wayland-cursor')
|
|||
wayland_protos = dependency('wayland-protocols')
|
||||
wlroots = dependency('wlroots', fallback: ['wlroots', 'wlroots'])
|
||||
gtkmm = dependency('gtkmm-3.0')
|
||||
dbusmenu_gtk = dependency('dbusmenu-gtk3-0.4')
|
||||
jsoncpp = dependency('jsoncpp')
|
||||
sigcpp = dependency('sigc++-2.0')
|
||||
libnl = dependency('libnl-3.0', required: false)
|
||||
|
@ -90,6 +91,7 @@ executable(
|
|||
libinput,
|
||||
wayland_cursor,
|
||||
gtkmm,
|
||||
dbusmenu_gtk,
|
||||
libnl,
|
||||
libnlgen,
|
||||
libpulse
|
||||
|
|
|
@ -54,10 +54,14 @@ client_protos_headers += gdbus_header.process('./dbus-status-notifier-watcher.xm
|
|||
client_protos_src += gdbus_code.process('./dbus-status-notifier-item.xml')
|
||||
client_protos_headers += gdbus_header.process('./dbus-status-notifier-item.xml')
|
||||
|
||||
client_protos_src += gdbus_code.process('./dbus-menu.xml')
|
||||
client_protos_headers += gdbus_header.process('./dbus-menu.xml')
|
||||
|
||||
lib_client_protos = static_library(
|
||||
'client_protos',
|
||||
client_protos_src + client_protos_headers,
|
||||
dependencies: [wayland_client, gtkmm]
|
||||
dependencies: [wayland_client, gtkmm],
|
||||
include_directories: include_directories('..'),
|
||||
) # for the include directory
|
||||
|
||||
client_protos = declare_dependency(
|
||||
|
|
|
@ -142,7 +142,7 @@ int waybar::modules::Network::getExternalInterface()
|
|||
int ifidx = -1;
|
||||
|
||||
/* Prepare request. */
|
||||
uint32_t reqlen = NLMSG_SPACE(sizeof(*rt));
|
||||
constexpr uint32_t reqlen = NLMSG_SPACE(sizeof(*rt));
|
||||
char req[reqlen] = {0};
|
||||
|
||||
/* Build the RTM_GETROUTE request. */
|
||||
|
@ -228,7 +228,7 @@ int waybar::modules::Network::getExternalInterface()
|
|||
break;
|
||||
}
|
||||
for (uint32_t i = 0; i < dstlen; i += 1) {
|
||||
c |= *(unsigned char *)(RTA_DATA(attr) + i);
|
||||
c |= *((unsigned char *)RTA_DATA(attr) + i);
|
||||
}
|
||||
has_destination = (c == 0);
|
||||
break;
|
||||
|
|
|
@ -1,26 +1,24 @@
|
|||
#include "modules/sni/sni.hpp"
|
||||
|
||||
#include <libdbusmenu-gtk/dbusmenu-gtk.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
waybar::modules::SNI::Item::Item(std::string bus_name, std::string object_path,
|
||||
Glib::Dispatcher &dp)
|
||||
: icon_size(16), effective_icon_size(0),
|
||||
image(Gtk::manage(new Gtk::Image())),
|
||||
bus_name_(bus_name), object_path_(object_path), dp_(dp)
|
||||
{
|
||||
image(Gtk::manage(new Gtk::Image())), bus_name_(bus_name),
|
||||
object_path_(object_path), dp_(dp) {
|
||||
cancellable_ = g_cancellable_new();
|
||||
sn_org_kde_status_notifier_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);
|
||||
sn_org_kde_status_notifier_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);
|
||||
}
|
||||
|
||||
waybar::modules::SNI::Item::~Item()
|
||||
{
|
||||
}
|
||||
waybar::modules::SNI::Item::~Item() {}
|
||||
|
||||
void waybar::modules::SNI::Item::proxyReady(GObject *obj, GAsyncResult *res,
|
||||
gpointer data)
|
||||
{
|
||||
gpointer data) {
|
||||
GError *error = nullptr;
|
||||
SnOrgKdeStatusNotifierItem *proxy =
|
||||
sn_org_kde_status_notifier_item_proxy_new_for_bus_finish(res, &error);
|
||||
|
@ -37,15 +35,21 @@ void waybar::modules::SNI::Item::proxyReady(GObject* obj, GAsyncResult* res,
|
|||
}
|
||||
auto conn = g_dbus_proxy_get_connection(G_DBUS_PROXY(proxy));
|
||||
g_dbus_connection_call(conn, item->bus_name_.c_str(),
|
||||
item->object_path_.c_str(), "org.freedesktop.DBus.Properties", "GetAll",
|
||||
item->object_path_.c_str(),
|
||||
"org.freedesktop.DBus.Properties", "GetAll",
|
||||
g_variant_new("(s)", "org.kde.StatusNotifierItem"),
|
||||
G_VARIANT_TYPE("(a{sv})"), G_DBUS_CALL_FLAGS_NONE, -1,
|
||||
item->cancellable_, &Item::getAll, data);
|
||||
}
|
||||
|
||||
static auto nonull(const char *c) {
|
||||
if (c != nullptr)
|
||||
return c;
|
||||
return "";
|
||||
}
|
||||
|
||||
void waybar::modules::SNI::Item::getAll(GObject *obj, GAsyncResult *res,
|
||||
gpointer data)
|
||||
{
|
||||
gpointer data) {
|
||||
GError *error = nullptr;
|
||||
auto conn = G_DBUS_CONNECTION(obj);
|
||||
GVariant *properties = g_dbus_connection_call_finish(conn, res, &error);
|
||||
|
@ -65,35 +69,35 @@ void waybar::modules::SNI::Item::getAll(GObject* obj, GAsyncResult* res,
|
|||
GVariant *value;
|
||||
while (g_variant_iter_next(it, "{sv}", &key, &value)) {
|
||||
if (g_strcmp0(key, "Category") == 0) {
|
||||
item->category = g_variant_dup_string(value, nullptr);
|
||||
item->category = nonull(g_variant_dup_string(value, nullptr));
|
||||
} else if (g_strcmp0(key, "Id") == 0) {
|
||||
item->id = g_variant_dup_string(value, nullptr);
|
||||
item->id = nonull(g_variant_dup_string(value, nullptr));
|
||||
} else if (g_strcmp0(key, "Title") == 0) {
|
||||
item->title = g_variant_dup_string(value, nullptr);
|
||||
item->title = nonull(g_variant_dup_string(value, nullptr));
|
||||
} else if (g_strcmp0(key, "Status") == 0) {
|
||||
item->status = g_variant_dup_string(value, nullptr);
|
||||
item->status = nonull(g_variant_dup_string(value, nullptr));
|
||||
} else if (g_strcmp0(key, "WindowId") == 0) {
|
||||
item->window_id = g_variant_get_int32(value);
|
||||
} else if (g_strcmp0(key, "IconName") == 0) {
|
||||
item->icon_name = g_variant_dup_string(value, nullptr);
|
||||
item->icon_name = nonull(g_variant_dup_string(value, nullptr));
|
||||
} else if (g_strcmp0(key, "IconPixmap") == 0) {
|
||||
// TODO: icon pixmap
|
||||
} else if (g_strcmp0(key, "OverlayIconName") == 0) {
|
||||
item->overlay_icon_name = g_variant_dup_string(value, nullptr);
|
||||
item->overlay_icon_name = nonull(g_variant_dup_string(value, nullptr));
|
||||
} else if (g_strcmp0(key, "OverlayIconPixmap") == 0) {
|
||||
// TODO: overlay_icon_pixmap
|
||||
} else if (g_strcmp0(key, "AttentionIconName") == 0) {
|
||||
item->attention_icon_name = g_variant_dup_string(value, nullptr);
|
||||
item->attention_icon_name = nonull(g_variant_dup_string(value, nullptr));
|
||||
} else if (g_strcmp0(key, "AttentionIconPixmap") == 0) {
|
||||
// TODO: attention_icon_pixmap
|
||||
} else if (g_strcmp0(key, "AttentionMovieName") == 0) {
|
||||
item->attention_movie_name = g_variant_dup_string(value, nullptr);
|
||||
item->attention_movie_name = nonull(g_variant_dup_string(value, nullptr));
|
||||
} else if (g_strcmp0(key, "ToolTip") == 0) {
|
||||
// TODO: tooltip
|
||||
} else if (g_strcmp0(key, "IconThemePath") == 0) {
|
||||
item->icon_theme_path = g_variant_dup_string(value, nullptr);
|
||||
item->icon_theme_path = nonull(g_variant_dup_string(value, nullptr));
|
||||
} else if (g_strcmp0(key, "Menu") == 0) {
|
||||
item->menu = g_variant_dup_string(value, nullptr);
|
||||
item->menu = nonull(g_variant_dup_string(value, nullptr));
|
||||
} else if (g_strcmp0(key, "ItemIsMenu") == 0) {
|
||||
item->item_is_menu = g_variant_get_boolean(value);
|
||||
}
|
||||
|
@ -103,8 +107,9 @@ void waybar::modules::SNI::Item::getAll(GObject* obj, GAsyncResult* res,
|
|||
g_variant_iter_free(it);
|
||||
g_variant_unref(properties);
|
||||
if (item->id.empty() || item->category.empty() || item->status.empty()) {
|
||||
std::cerr << "Invalid Status Notifier Item: " + item->bus_name_ + ","
|
||||
+ item->object_path_ << std::endl;
|
||||
std::cerr << "Invalid Status Notifier Item: " + item->bus_name_ + "," +
|
||||
item->object_path_
|
||||
<< std::endl;
|
||||
return;
|
||||
}
|
||||
if (!item->icon_theme_path.empty()) {
|
||||
|
@ -117,18 +122,23 @@ void waybar::modules::SNI::Item::getAll(GObject* obj, GAsyncResult* res,
|
|||
// TODO: handle change
|
||||
}
|
||||
|
||||
void waybar::modules::SNI::Item::updateImage()
|
||||
{
|
||||
void waybar::modules::SNI::Item::updateImage() {
|
||||
if (!icon_name.empty()) {
|
||||
auto pixbuf = getIconByName(icon_name, icon_size);
|
||||
if (pixbuf->gobj() == nullptr) {
|
||||
// Try to find icons specified by path and filename
|
||||
try {
|
||||
pixbuf = Gdk::Pixbuf::create_from_file(icon_name);
|
||||
if (pixbuf->gobj() != nullptr) {
|
||||
// An icon specified by path and filename may be the wrong size for the tray
|
||||
// An icon specified by path and filename may be the wrong size for
|
||||
// the tray
|
||||
pixbuf->scale_simple(icon_size - 2, icon_size - 2,
|
||||
Gdk::InterpType::INTERP_BILINEAR);
|
||||
}
|
||||
} catch (Glib::Error &e) {
|
||||
std::cerr << "Exception: " << e.what() << std::endl;
|
||||
pixbuf = getIconByName("image-missing", icon_size);
|
||||
}
|
||||
}
|
||||
if (pixbuf->gobj() == nullptr) {
|
||||
pixbuf = getIconByName("image-missing", icon_size);
|
||||
|
@ -138,14 +148,37 @@ void waybar::modules::SNI::Item::updateImage()
|
|||
image->set_from_icon_name("image-missing", Gtk::ICON_SIZE_MENU);
|
||||
image->set_pixel_size(icon_size);
|
||||
}
|
||||
auto *evt_box = Gtk::manage(new Gtk::EventBox());
|
||||
evt_box->add(*image);
|
||||
widget = evt_box;
|
||||
if (!menu.empty()) {
|
||||
auto *dbmenu = dbusmenu_gtkmenu_new(bus_name_.data(), menu.data());
|
||||
Gtk::Menu *dmenu = Glib::wrap(GTK_MENU(dbmenu), false);
|
||||
if (dbmenu && dmenu) {
|
||||
widget->signal_button_press_event().connect(
|
||||
[this, dmenu](GdkEventButton *btn) {
|
||||
if (!dmenu->get_parent()) {
|
||||
dmenu->reparent(*image);
|
||||
}
|
||||
if (!dmenu->get_attach_widget()) {
|
||||
dmenu->attach_to_widget(*widget);
|
||||
}
|
||||
dmenu->popup(btn->button, btn->time);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
widget->signal_button_press_event().connect([this](GdkEventButton *btn) {
|
||||
std::cout << this->menu << std::endl;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Glib::RefPtr<Gdk::Pixbuf> waybar::modules::SNI::Item::getIconByName(
|
||||
std::string name, int request_size)
|
||||
{
|
||||
Glib::RefPtr<Gdk::Pixbuf>
|
||||
waybar::modules::SNI::Item::getIconByName(std::string name, int request_size) {
|
||||
int icon_size = 0;
|
||||
Glib::RefPtr<Gtk::IconTheme> icon_theme =
|
||||
Gtk::IconTheme::get_default();
|
||||
Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default();
|
||||
icon_theme->rescan_if_needed();
|
||||
auto sizes = icon_theme->get_icon_sizes(name.c_str());
|
||||
for (auto size : sizes) {
|
||||
|
|
|
@ -3,15 +3,14 @@
|
|||
#include <iostream>
|
||||
|
||||
waybar::modules::SNI::Tray::Tray(const Json::Value &config)
|
||||
: config_(config), watcher_(), host_(dp)
|
||||
{
|
||||
}
|
||||
: config_(config), watcher_(), host_(dp) {}
|
||||
|
||||
auto waybar::modules::SNI::Tray::update() -> void
|
||||
{
|
||||
auto waybar::modules::SNI::Tray::update() -> void {
|
||||
for (auto item : host_.items) {
|
||||
item.image->set_tooltip_text(item.title);
|
||||
box_.pack_start(*item.image);
|
||||
if (item.widget) {
|
||||
item.widget->set_tooltip_text(item.title);
|
||||
box_.pack_start(*item.widget);
|
||||
}
|
||||
}
|
||||
if (box_.get_children().size() > 0) {
|
||||
box_.set_name("tray");
|
||||
|
@ -21,6 +20,4 @@ auto waybar::modules::SNI::Tray::update() -> void
|
|||
}
|
||||
}
|
||||
|
||||
waybar::modules::SNI::Tray::operator Gtk::Widget &() {
|
||||
return box_;
|
||||
}
|
||||
waybar::modules::SNI::Tray::operator Gtk::Widget &() { return box_; }
|
||||
|
|
Loading…
Reference in New Issue