mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
3f2eb0b492 | |||
4f773ea268 | |||
047473e5a4 | |||
ed3e4b1395 | |||
16b01e1059 | |||
1ae490c8f7 | |||
0d0a3be483 | |||
a1c4b9bb0c | |||
a55a1ae866 | |||
07d8dfb3d6 | |||
5010227e6b |
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
|
#include <json/json.h>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <dbus-status-notifier-watcher.h>
|
#include <dbus-status-notifier-watcher.h>
|
||||||
#include "modules/sni/sni.hpp"
|
#include "modules/sni/sni.hpp"
|
||||||
@ -10,7 +10,7 @@ namespace waybar::modules::SNI {
|
|||||||
|
|
||||||
class Host {
|
class Host {
|
||||||
public:
|
public:
|
||||||
Host(Glib::Dispatcher*);
|
Host(Glib::Dispatcher*, const Json::Value&);
|
||||||
std::vector<Item> items;
|
std::vector<Item> items;
|
||||||
private:
|
private:
|
||||||
static void busAcquired(GDBusConnection*, const gchar*, gpointer);
|
static void busAcquired(GDBusConnection*, const gchar*, gpointer);
|
||||||
@ -32,6 +32,7 @@ class Host {
|
|||||||
Glib::Dispatcher* dp_;
|
Glib::Dispatcher* dp_;
|
||||||
GCancellable* cancellable_ = nullptr;
|
GCancellable* cancellable_ = nullptr;
|
||||||
SnWatcher* watcher_ = nullptr;
|
SnWatcher* watcher_ = nullptr;
|
||||||
|
const Json::Value &config_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
#include <dbus-status-notifier-item.h>
|
#include <dbus-status-notifier-item.h>
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
|
#include <json/json.h>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
namespace waybar::modules::SNI {
|
namespace waybar::modules::SNI {
|
||||||
|
|
||||||
class Item {
|
class Item {
|
||||||
public:
|
public:
|
||||||
Item(std::string, std::string, Glib::Dispatcher *);
|
Item(std::string, std::string, Glib::Dispatcher*, Json::Value);
|
||||||
|
|
||||||
std::string bus_name;
|
std::string bus_name;
|
||||||
std::string object_path;
|
std::string object_path;
|
||||||
@ -39,6 +41,7 @@ private:
|
|||||||
static void handleSecondaryActivate(GObject *, GAsyncResult *, gpointer);
|
static void handleSecondaryActivate(GObject *, GAsyncResult *, gpointer);
|
||||||
|
|
||||||
void updateImage();
|
void updateImage();
|
||||||
|
void updateMenu();
|
||||||
Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant *variant);
|
Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant *variant);
|
||||||
Glib::RefPtr<Gdk::Pixbuf> getIconByName(std::string name, int size);
|
Glib::RefPtr<Gdk::Pixbuf> getIconByName(std::string name, int size);
|
||||||
bool handleClick(GdkEventButton *const & /*ev*/);
|
bool handleClick(GdkEventButton *const & /*ev*/);
|
||||||
@ -46,6 +49,7 @@ private:
|
|||||||
Glib::Dispatcher *dp_;
|
Glib::Dispatcher *dp_;
|
||||||
GCancellable *cancellable_ = nullptr;
|
GCancellable *cancellable_ = nullptr;
|
||||||
SnItem *proxy_ = nullptr;
|
SnItem *proxy_ = nullptr;
|
||||||
|
Json::Value config_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::SNI
|
} // namespace waybar::modules::SNI
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cstring>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
project(
|
project(
|
||||||
'waybar', 'cpp', 'c',
|
'waybar', 'cpp', 'c',
|
||||||
version: '0.1.2',
|
version: '0.1.3',
|
||||||
license: 'MIT',
|
license: 'MIT',
|
||||||
default_options : [
|
default_options : [
|
||||||
'cpp_std=c++17',
|
'cpp_std=c++17',
|
||||||
@ -33,6 +33,7 @@ wayland_protos = dependency('wayland-protocols')
|
|||||||
wlroots = dependency('wlroots', fallback: ['wlroots', 'wlroots'])
|
wlroots = dependency('wlroots', fallback: ['wlroots', 'wlroots'])
|
||||||
gtkmm = dependency('gtkmm-3.0')
|
gtkmm = dependency('gtkmm-3.0')
|
||||||
dbusmenu_gtk = dependency('dbusmenu-gtk3-0.4', required: get_option('dbusmenu-gtk'))
|
dbusmenu_gtk = dependency('dbusmenu-gtk3-0.4', required: get_option('dbusmenu-gtk'))
|
||||||
|
giounix = dependency('gio-unix-2.0', required: get_option('dbusmenu-gtk'))
|
||||||
jsoncpp = dependency('jsoncpp')
|
jsoncpp = dependency('jsoncpp')
|
||||||
sigcpp = dependency('sigc++-2.0')
|
sigcpp = dependency('sigc++-2.0')
|
||||||
libnl = dependency('libnl-3.0', required: get_option('libnl'))
|
libnl = dependency('libnl-3.0', required: get_option('libnl'))
|
||||||
@ -98,6 +99,7 @@ executable(
|
|||||||
wayland_cursor,
|
wayland_cursor,
|
||||||
gtkmm,
|
gtkmm,
|
||||||
dbusmenu_gtk,
|
dbusmenu_gtk,
|
||||||
|
giounix,
|
||||||
libnl,
|
libnl,
|
||||||
libnlgen,
|
libnlgen,
|
||||||
libpulse
|
libpulse
|
||||||
@ -109,7 +111,7 @@ executable(
|
|||||||
install_data(
|
install_data(
|
||||||
'./resources/config',
|
'./resources/config',
|
||||||
'./resources/style.css',
|
'./resources/style.css',
|
||||||
install_dir: '/etc/xdg/waybar',
|
install_dir: join_paths(get_option('out'), 'etc/xdg/waybar')
|
||||||
)
|
)
|
||||||
|
|
||||||
clangtidy = find_program('clang-tidy', required: false)
|
clangtidy = find_program('clang-tidy', required: false)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
option('libnl', type: 'feature', value: 'auto', description: 'Enable libnl support for network related features')
|
option('libnl', type: 'feature', value: 'auto', description: 'Enable libnl support for network related features')
|
||||||
option('pulseaudio', type: 'feature', value: 'auto', description: 'Enable support for pulseaudio')
|
option('pulseaudio', type: 'feature', value: 'auto', description: 'Enable support for pulseaudio')
|
||||||
option('dbusmenu-gtk', type: 'feature', value: 'auto', description: 'Enable support for tray')
|
option('dbusmenu-gtk', type: 'feature', value: 'auto', description: 'Enable support for tray')
|
||||||
|
option('out', type: 'string', value : '/', description: 'output prefix directory')
|
||||||
|
@ -62,7 +62,7 @@ client_protos_headers += gdbus_header.process('./dbus-menu.xml')
|
|||||||
lib_client_protos = static_library(
|
lib_client_protos = static_library(
|
||||||
'client_protos',
|
'client_protos',
|
||||||
client_protos_src + client_protos_headers,
|
client_protos_src + client_protos_headers,
|
||||||
dependencies: [wayland_client, gtkmm],
|
dependencies: [wayland_client, gtkmm, giounix],
|
||||||
include_directories: include_directories('..'),
|
include_directories: include_directories('..'),
|
||||||
) # for the include directory
|
) # for the include directory
|
||||||
|
|
||||||
|
@ -26,6 +26,10 @@
|
|||||||
"sway/window": {
|
"sway/window": {
|
||||||
"max-length": 50
|
"max-length": 50
|
||||||
},
|
},
|
||||||
|
"tray": {
|
||||||
|
// "icon-size": 21,
|
||||||
|
"spacing": 10
|
||||||
|
},
|
||||||
"clock": {
|
"clock": {
|
||||||
"format-alt": "{:%Y-%m-%d}"
|
"format-alt": "{:%Y-%m-%d}"
|
||||||
},
|
},
|
||||||
|
@ -93,4 +93,4 @@ window#waybar {
|
|||||||
|
|
||||||
#tray {
|
#tray {
|
||||||
background-color: #2980b9;
|
background-color: #2980b9;
|
||||||
}
|
}
|
@ -89,7 +89,7 @@ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context* /*context*/,
|
|||||||
pa->volume_ = std::round(volume * 100.0f);
|
pa->volume_ = std::round(volume * 100.0f);
|
||||||
pa->muted_ = i->mute != 0;
|
pa->muted_ = i->mute != 0;
|
||||||
pa->desc_ = i->description;
|
pa->desc_ = i->description;
|
||||||
pa->port_name_ = i->active_port->name;
|
pa->port_name_ = i->active_port ? i->active_port->name : "Unknown";
|
||||||
pa->dp.emit();
|
pa->dp.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
using namespace waybar::modules::SNI;
|
using namespace waybar::modules::SNI;
|
||||||
|
|
||||||
Host::Host(Glib::Dispatcher* dp)
|
Host::Host(Glib::Dispatcher* dp, const Json::Value &config)
|
||||||
: dp_(dp)
|
: dp_(dp), config_(config)
|
||||||
{
|
{
|
||||||
GBusNameOwnerFlags flags = static_cast<GBusNameOwnerFlags>(
|
GBusNameOwnerFlags flags = static_cast<GBusNameOwnerFlags>(
|
||||||
G_BUS_NAME_OWNER_FLAGS_NONE);
|
G_BUS_NAME_OWNER_FLAGS_NONE);
|
||||||
@ -146,5 +146,5 @@ std::tuple<std::string, std::string> Host::getBusNameAndObjectPath(
|
|||||||
void Host::addRegisteredItem(const gchar* service)
|
void Host::addRegisteredItem(const gchar* service)
|
||||||
{
|
{
|
||||||
auto [bus_name, object_path] = getBusNameAndObjectPath(service);
|
auto [bus_name, object_path] = getBusNameAndObjectPath(service);
|
||||||
items.emplace_back(bus_name, object_path, dp_);
|
items.emplace_back(bus_name, object_path, dp_, config_);
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,13 @@
|
|||||||
#include <libdbusmenu-gtk/dbusmenu-gtk.h>
|
#include <libdbusmenu-gtk/dbusmenu-gtk.h>
|
||||||
|
|
||||||
waybar::modules::SNI::Item::Item(std::string bn, std::string op,
|
waybar::modules::SNI::Item::Item(std::string bn, std::string op,
|
||||||
Glib::Dispatcher *dp)
|
Glib::Dispatcher *dp, Json::Value config)
|
||||||
: bus_name(bn), object_path(op), event_box(), icon_size(16),
|
: bus_name(bn), object_path(op), event_box(), icon_size(16),
|
||||||
effective_icon_size(0), image(Gtk::manage(new Gtk::Image())), dp_(dp) {
|
effective_icon_size(0), image(Gtk::manage(new Gtk::Image())),
|
||||||
|
dp_(dp), config_(config) {
|
||||||
|
if (config_["icon-size"].isUInt()) {
|
||||||
|
icon_size = config_["icon-size"].asUInt();
|
||||||
|
}
|
||||||
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(
|
||||||
@ -20,8 +24,7 @@ waybar::modules::SNI::Item::Item(std::string bn, std::string op,
|
|||||||
void waybar::modules::SNI::Item::proxyReady(GObject *obj, GAsyncResult *res,
|
void waybar::modules::SNI::Item::proxyReady(GObject *obj, GAsyncResult *res,
|
||||||
gpointer data) {
|
gpointer data) {
|
||||||
GError *error = nullptr;
|
GError *error = nullptr;
|
||||||
SnItem *proxy =
|
SnItem *proxy = sn_item_proxy_new_for_bus_finish(res, &error);
|
||||||
sn_item_proxy_new_for_bus_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)) {
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
return;
|
return;
|
||||||
@ -113,6 +116,7 @@ void waybar::modules::SNI::Item::getAll(GObject *obj, GAsyncResult *res,
|
|||||||
item->icon_theme_path.c_str());
|
item->icon_theme_path.c_str());
|
||||||
}
|
}
|
||||||
item->updateImage();
|
item->updateImage();
|
||||||
|
item->updateMenu();
|
||||||
item->dp_->emit();
|
item->dp_->emit();
|
||||||
// TODO: handle change
|
// TODO: handle change
|
||||||
}
|
}
|
||||||
@ -165,45 +169,50 @@ waybar::modules::SNI::Item::extractPixBuf(GVariant *variant) {
|
|||||||
return Glib::RefPtr<Gdk::Pixbuf>{};
|
return Glib::RefPtr<Gdk::Pixbuf>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void waybar::modules::SNI::Item::updateMenu()
|
||||||
|
{
|
||||||
|
event_box.set_tooltip_text(title);
|
||||||
|
if (!menu.empty()) {
|
||||||
|
auto *dbmenu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data());
|
||||||
|
if (dbmenu) {
|
||||||
|
gtk_menu = Glib::wrap(GTK_MENU(dbmenu), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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_pixel_size(icon_size);
|
||||||
if (!icon_name.empty()) {
|
if (!icon_name.empty()) {
|
||||||
auto pixbuf = getIconByName(icon_name, icon_size);
|
try {
|
||||||
if (pixbuf->gobj() == nullptr) {
|
|
||||||
// Try to find icons specified by path and filename
|
// Try to find icons specified by path and filename
|
||||||
try {
|
if (std::filesystem::exists(icon_name)) {
|
||||||
pixbuf = Gdk::Pixbuf::create_from_file(icon_name);
|
auto pixbuf = Gdk::Pixbuf::create_from_file(icon_name);
|
||||||
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->scale_simple(icon_size - 2, icon_size - 2,
|
pixbuf = pixbuf->scale_simple(icon_size, icon_size,
|
||||||
Gdk::InterpType::INTERP_BILINEAR);
|
Gdk::InterpType::INTERP_BILINEAR);
|
||||||
|
image->set(pixbuf);
|
||||||
}
|
}
|
||||||
} catch (Glib::Error &e) {
|
} else {
|
||||||
std::cerr << "Exception: " << e.what() << std::endl;
|
image->set(getIconByName(icon_name, icon_size));
|
||||||
pixbuf = getIconByName("image-missing", icon_size);
|
|
||||||
}
|
}
|
||||||
|
} catch (Glib::Error &e) {
|
||||||
|
std::cerr << "Exception: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
if (pixbuf->gobj() == nullptr) {
|
|
||||||
pixbuf = getIconByName("image-missing", icon_size);
|
|
||||||
}
|
|
||||||
image->set(pixbuf);
|
|
||||||
} else if (icon_pixmap) {
|
} else if (icon_pixmap) {
|
||||||
|
// An icon extracted may be the wrong size for the tray
|
||||||
|
icon_pixmap = icon_pixmap->scale_simple(icon_size, icon_size,
|
||||||
|
Gdk::InterpType::INTERP_BILINEAR);
|
||||||
image->set(icon_pixmap);
|
image->set(icon_pixmap);
|
||||||
} else {
|
|
||||||
image->set_from_icon_name("image-missing", Gtk::ICON_SIZE_MENU);
|
|
||||||
image->set_pixel_size(icon_size);
|
|
||||||
}
|
|
||||||
if (!menu.empty()) {
|
|
||||||
auto *dbmenu = dbusmenu_gtkmenu_new(bus_name.data(), menu.data());
|
|
||||||
if (dbmenu)
|
|
||||||
gtk_menu = Glib::wrap(GTK_MENU(dbmenu), false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Pixbuf>
|
Glib::RefPtr<Gdk::Pixbuf>
|
||||||
waybar::modules::SNI::Item::getIconByName(std::string name, int request_size) {
|
waybar::modules::SNI::Item::getIconByName(std::string name, int request_size) {
|
||||||
int icon_size = 0;
|
int tmp_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();
|
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());
|
||||||
@ -211,32 +220,30 @@ waybar::modules::SNI::Item::getIconByName(std::string name, int request_size) {
|
|||||||
for (auto const &size : sizes) {
|
for (auto const &size : sizes) {
|
||||||
// -1 == scalable
|
// -1 == scalable
|
||||||
if (size == request_size || size == -1) {
|
if (size == request_size || size == -1) {
|
||||||
icon_size = request_size;
|
tmp_size = request_size;
|
||||||
break;
|
break;
|
||||||
} else if (size < request_size || size > icon_size) {
|
} else if (size < request_size || size > tmp_size) {
|
||||||
icon_size = size;
|
tmp_size = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (icon_size == 0) {
|
if (tmp_size == 0) {
|
||||||
icon_size = request_size;
|
tmp_size = request_size;
|
||||||
}
|
}
|
||||||
return icon_theme->load_icon(name.c_str(), icon_size,
|
return icon_theme->load_icon(name.c_str(), tmp_size,
|
||||||
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::SNI::Item::handleActivate(GObject *src, GAsyncResult *res,
|
void waybar::modules::SNI::Item::handleActivate(GObject *src, GAsyncResult *res,
|
||||||
gpointer data) {
|
gpointer data) {
|
||||||
auto item = static_cast<SNI::Item *>(data);
|
auto item = static_cast<SNI::Item *>(data);
|
||||||
sn_item_call_activate_finish(item->proxy_, res,
|
sn_item_call_activate_finish(item->proxy_, res, nullptr);
|
||||||
nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::SNI::Item::handleSecondaryActivate(GObject *src,
|
void waybar::modules::SNI::Item::handleSecondaryActivate(GObject *src,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer data) {
|
gpointer data) {
|
||||||
auto item = static_cast<SNI::Item *>(data);
|
auto item = static_cast<SNI::Item *>(data);
|
||||||
sn_item_call_secondary_activate_finish(item->proxy_,
|
sn_item_call_secondary_activate_finish(item->proxy_, res, nullptr);
|
||||||
res, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waybar::modules::SNI::Item::handleClick(GdkEventButton *const &ev) {
|
bool waybar::modules::SNI::Item::handleClick(GdkEventButton *const &ev) {
|
||||||
|
@ -3,11 +3,17 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
waybar::modules::SNI::Tray::Tray(const Json::Value &config)
|
waybar::modules::SNI::Tray::Tray(const Json::Value &config)
|
||||||
: config_(config), watcher_(), host_(&dp) {}
|
: config_(config), watcher_(), host_(&dp, config)
|
||||||
|
{
|
||||||
|
if (config_["spacing"].isUInt()) {
|
||||||
|
box_.set_spacing(config_["spacing"].asUInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto waybar::modules::SNI::Tray::update() -> void {
|
auto waybar::modules::SNI::Tray::update() -> void {
|
||||||
|
auto childrens = box_.get_children();
|
||||||
|
childrens.erase(childrens.begin(), childrens.end());
|
||||||
for (auto &item : host_.items) {
|
for (auto &item : host_.items) {
|
||||||
item.event_box.set_tooltip_text(item.title);
|
|
||||||
box_.pack_start(item.event_box);
|
box_.pack_start(item.event_box);
|
||||||
}
|
}
|
||||||
if (box_.get_children().size() > 0) {
|
if (box_.get_children().size() > 0) {
|
||||||
@ -18,4 +24,6 @@ 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_;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user