mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
9fae5efc06 | |||
7f1f217d84 | |||
1ea0c1f9dd | |||
4626cbef63 | |||
85f845ca43 |
@ -24,6 +24,7 @@ class Battery : public ALabel {
|
|||||||
void worker();
|
void worker();
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
|
util::SleeperThread threadTimer_;
|
||||||
std::vector<fs::path> batteries_;
|
std::vector<fs::path> batteries_;
|
||||||
int fd_;
|
int fd_;
|
||||||
};
|
};
|
||||||
|
@ -36,14 +36,16 @@ foreach p : client_protocols
|
|||||||
client_protos_headers += wayland_scanner_client.process(xml)
|
client_protos_headers += wayland_scanner_client.process(xml)
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
|
gdbus_codegen = find_program('gdbus-codegen')
|
||||||
|
|
||||||
gdbus_code = generator(
|
gdbus_code = generator(
|
||||||
find_program('gdbus-codegen'),
|
gdbus_codegen,
|
||||||
output: '@BASENAME@.c',
|
output: '@BASENAME@.c',
|
||||||
arguments: ['--c-namespace', 'Sn', '--body', '--output', '@OUTPUT@', '@INPUT@']
|
arguments: ['--c-namespace', 'Sn', '--body', '--output', '@OUTPUT@', '@INPUT@']
|
||||||
)
|
)
|
||||||
|
|
||||||
gdbus_header = generator(
|
gdbus_header = generator(
|
||||||
find_program('gdbus-codegen'),
|
gdbus_codegen,
|
||||||
output: '@BASENAME@.h',
|
output: '@BASENAME@.h',
|
||||||
arguments: ['--c-namespace', 'Sn', '--header', '--output', '@OUTPUT@', '@INPUT@']
|
arguments: ['--c-namespace', 'Sn', '--header', '--output', '@OUTPUT@', '@INPUT@']
|
||||||
)
|
)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// Choose the order of the modules
|
// Choose the order of the modules
|
||||||
"modules-left": ["sway/workspaces", "custom/spotify"],
|
"modules-left": ["sway/workspaces", "custom/spotify"],
|
||||||
"modules-center": ["sway/window"],
|
"modules-center": ["sway/window"],
|
||||||
"modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "clock", "tray"],
|
"modules-right": ["pulseaudio", "network", "cpu", "memory", "battery", "battery#bat2", "clock", "tray"],
|
||||||
// Modules configuration
|
// Modules configuration
|
||||||
// "sway/workspaces": {
|
// "sway/workspaces": {
|
||||||
// "disable-scroll": true,
|
// "disable-scroll": true,
|
||||||
@ -39,6 +39,9 @@
|
|||||||
"format": "{capacity}% {icon}",
|
"format": "{capacity}% {icon}",
|
||||||
"format-icons": ["", "", "", "", ""]
|
"format-icons": ["", "", "", "", ""]
|
||||||
},
|
},
|
||||||
|
"battery#bat2": {
|
||||||
|
"bat": "BAT2"
|
||||||
|
},
|
||||||
"network": {
|
"network": {
|
||||||
// "interface": "wlp2s0", // (Optional) To force the use of this interface
|
// "interface": "wlp2s0", // (Optional) To force the use of this interface
|
||||||
"format-wifi": "{essid} ({signalStrength}%) ",
|
"format-wifi": "{essid} ({signalStrength}%) ",
|
||||||
|
@ -7,43 +7,44 @@ waybar::Factory::Factory(Bar& bar, const Json::Value& config)
|
|||||||
waybar::IModule* waybar::Factory::makeModule(const std::string &name) const
|
waybar::IModule* waybar::Factory::makeModule(const std::string &name) const
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (name == "battery") {
|
auto ref = name.substr(0, name.find("#"));
|
||||||
|
if (ref == "battery") {
|
||||||
return new waybar::modules::Battery(config_[name]);
|
return new waybar::modules::Battery(config_[name]);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_SWAY
|
#ifdef HAVE_SWAY
|
||||||
if (name == "sway/workspaces") {
|
if (ref == "sway/workspaces") {
|
||||||
return new waybar::modules::sway::Workspaces(bar_, config_[name]);
|
return new waybar::modules::sway::Workspaces(bar_, config_[name]);
|
||||||
}
|
}
|
||||||
if (name == "sway/window") {
|
if (ref == "sway/window") {
|
||||||
return new waybar::modules::sway::Window(bar_, config_[name]);
|
return new waybar::modules::sway::Window(bar_, config_[name]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (name == "memory") {
|
if (ref == "memory") {
|
||||||
return new waybar::modules::Memory(config_[name]);
|
return new waybar::modules::Memory(config_[name]);
|
||||||
}
|
}
|
||||||
if (name == "cpu") {
|
if (ref == "cpu") {
|
||||||
return new waybar::modules::Cpu(config_[name]);
|
return new waybar::modules::Cpu(config_[name]);
|
||||||
}
|
}
|
||||||
if (name == "clock") {
|
if (ref == "clock") {
|
||||||
return new waybar::modules::Clock(config_[name]);
|
return new waybar::modules::Clock(config_[name]);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_DBUSMENU
|
#ifdef HAVE_DBUSMENU
|
||||||
if (name == "tray") {
|
if (ref == "tray") {
|
||||||
return new waybar::modules::SNI::Tray(config_[name]);
|
return new waybar::modules::SNI::Tray(config_[name]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBNL
|
#ifdef HAVE_LIBNL
|
||||||
if (name == "network") {
|
if (ref == "network") {
|
||||||
return new waybar::modules::Network(config_[name]);
|
return new waybar::modules::Network(config_[name]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBPULSE
|
#ifdef HAVE_LIBPULSE
|
||||||
if (name == "pulseaudio") {
|
if (ref == "pulseaudio") {
|
||||||
return new waybar::modules::Pulseaudio(config_[name]);
|
return new waybar::modules::Pulseaudio(config_[name]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (name.compare(0, 7, "custom/") == 0 && name.size() > 7) {
|
if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) {
|
||||||
return new waybar::modules::Custom(name.substr(7), config_[name]);
|
return new waybar::modules::Custom(ref.substr(7), config_[name]);
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
auto err = fmt::format("Disabling module \"{}\", {}", name, e.what());
|
auto err = fmt::format("Disabling module \"{}\", {}", name, e.what());
|
||||||
|
@ -4,16 +4,27 @@ waybar::modules::Battery::Battery(const Json::Value& config)
|
|||||||
: ALabel(config, "{capacity}%")
|
: ALabel(config, "{capacity}%")
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
for (auto const& node : fs::directory_iterator(data_dir_)) {
|
if (config_["bat"]) {
|
||||||
if (fs::is_directory(node) && fs::exists(node / "capacity")
|
auto dir = data_dir_ / config_["bat"].asString();
|
||||||
&& fs::exists(node / "status") && fs::exists(node / "uevent")) {
|
if (fs::is_directory(dir) && fs::exists(dir / "capacity")
|
||||||
batteries_.push_back(node);
|
&& fs::exists(dir / "status") && fs::exists(dir / "uevent")) {
|
||||||
|
batteries_.push_back(dir);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (auto const& node : fs::directory_iterator(data_dir_)) {
|
||||||
|
if (fs::is_directory(node) && fs::exists(node / "capacity")
|
||||||
|
&& fs::exists(node / "status") && fs::exists(node / "uevent")) {
|
||||||
|
batteries_.push_back(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (fs::filesystem_error &e) {
|
} catch (fs::filesystem_error &e) {
|
||||||
throw std::runtime_error(e.what());
|
throw std::runtime_error(e.what());
|
||||||
}
|
}
|
||||||
if (batteries_.empty()) {
|
if (batteries_.empty()) {
|
||||||
|
if (config_["bat"]) {
|
||||||
|
throw std::runtime_error("No battery named " + config_["bat"].asString());
|
||||||
|
}
|
||||||
throw std::runtime_error("No batteries.");
|
throw std::runtime_error("No batteries.");
|
||||||
}
|
}
|
||||||
fd_ = inotify_init1(IN_CLOEXEC);
|
fd_ = inotify_init1(IN_CLOEXEC);
|
||||||
@ -36,12 +47,18 @@ void waybar::modules::Battery::worker()
|
|||||||
{
|
{
|
||||||
// Trigger first values
|
// Trigger first values
|
||||||
update();
|
update();
|
||||||
|
uint32_t interval = config_["interval"] ? config_["interval"].asUInt() : 60;
|
||||||
|
threadTimer_ = [this, interval] {
|
||||||
|
thread_.sleep_for(chrono::seconds(interval));
|
||||||
|
dp.emit();
|
||||||
|
};
|
||||||
thread_ = [this] {
|
thread_ = [this] {
|
||||||
struct inotify_event event = {0};
|
struct inotify_event event = {0};
|
||||||
int nbytes = read(fd_, &event, sizeof(event));
|
int nbytes = read(fd_, &event, sizeof(event));
|
||||||
if (nbytes != sizeof(event)) {
|
if (nbytes != sizeof(event)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
threadTimer_.stop();
|
||||||
dp.emit();
|
dp.emit();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context* /*context*/,
|
|||||||
float volume = static_cast<float>(pa_cvolume_avg(&(i->volume)))
|
float volume = static_cast<float>(pa_cvolume_avg(&(i->volume)))
|
||||||
/ float{PA_VOLUME_NORM};
|
/ float{PA_VOLUME_NORM};
|
||||||
pa->sink_idx_ = i->index;
|
pa->sink_idx_ = i->index;
|
||||||
pa->volume_ = 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->name;
|
||||||
|
@ -32,7 +32,7 @@ void Host::nameAppeared(GDBusConnection* connection,
|
|||||||
{
|
{
|
||||||
auto host = static_cast<SNI::Host *>(data);
|
auto host = static_cast<SNI::Host *>(data);
|
||||||
if (host->cancellable_ != nullptr) {
|
if (host->cancellable_ != nullptr) {
|
||||||
std::cout << "WTF" << std::endl;
|
// TODO
|
||||||
}
|
}
|
||||||
host->cancellable_ = g_cancellable_new();
|
host->cancellable_ = g_cancellable_new();
|
||||||
sn_org_kde_status_notifier_watcher_proxy_new(
|
sn_org_kde_status_notifier_watcher_proxy_new(
|
||||||
@ -110,7 +110,6 @@ void Host::registerHost(GObject* src, GAsyncResult* res,
|
|||||||
void Host::itemRegistered(
|
void Host::itemRegistered(
|
||||||
SnOrgKdeStatusNotifierWatcher* watcher, const gchar* service, gpointer data)
|
SnOrgKdeStatusNotifierWatcher* watcher, const gchar* service, gpointer data)
|
||||||
{
|
{
|
||||||
std::cout << "Item registered" << std::endl;
|
|
||||||
auto host = static_cast<SNI::Host *>(data);
|
auto host = static_cast<SNI::Host *>(data);
|
||||||
host->addRegisteredItem(service);
|
host->addRegisteredItem(service);
|
||||||
}
|
}
|
||||||
@ -123,7 +122,6 @@ void Host::itemUnregistered(
|
|||||||
for (auto it = host->items.begin(); it != host->items.end(); ++it) {
|
for (auto it = host->items.begin(); it != host->items.end(); ++it) {
|
||||||
if (it->bus_name == bus_name && it->object_path == object_path) {
|
if (it->bus_name == bus_name && it->object_path == object_path) {
|
||||||
host->items.erase(it);
|
host->items.erase(it);
|
||||||
std::cout << "Item Unregistered" << std::endl;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ void Watcher::busAcquired(GDBusConnection* connection, const gchar* name,
|
|||||||
sn_org_kde_status_notifier_watcher_set_protocol_version(host->watcher_, 0);
|
sn_org_kde_status_notifier_watcher_set_protocol_version(host->watcher_, 0);
|
||||||
sn_org_kde_status_notifier_watcher_set_is_status_notifier_host_registered(
|
sn_org_kde_status_notifier_watcher_set_is_status_notifier_host_registered(
|
||||||
host->watcher_, TRUE);
|
host->watcher_, TRUE);
|
||||||
std::cout << "Bus aquired" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean Watcher::handleRegisterHost(Watcher* obj,
|
gboolean Watcher::handleRegisterHost(Watcher* obj,
|
||||||
@ -75,7 +74,6 @@ gboolean Watcher::handleRegisterHost(Watcher* obj,
|
|||||||
}
|
}
|
||||||
sn_org_kde_status_notifier_watcher_complete_register_status_notifier_host(
|
sn_org_kde_status_notifier_watcher_complete_register_status_notifier_host(
|
||||||
obj->watcher_, invocation);
|
obj->watcher_, invocation);
|
||||||
std::cout << "Host registered: " << bus_name << std::endl;
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user