Compare commits

..

5 Commits
0.1.0 ... 0.1.1

Author SHA1 Message Date
9fae5efc06 feat: use interval thread until got inotify event 2018-10-25 17:39:15 +02:00
7f1f217d84 feat: multiple config per modules 2018-10-25 17:30:26 +02:00
1ea0c1f9dd chore: find gdbus-codegen once 2018-10-25 16:42:01 +02:00
4626cbef63 fix(pulseaudio): round volume 2018-10-25 13:57:35 +02:00
85f845ca43 refactor: remove debug 2018-10-25 13:49:30 +02:00
8 changed files with 44 additions and 24 deletions

View File

@ -24,6 +24,7 @@ class Battery : public ALabel {
void worker();
util::SleeperThread thread_;
util::SleeperThread threadTimer_;
std::vector<fs::path> batteries_;
int fd_;
};

View File

@ -36,14 +36,16 @@ foreach p : client_protocols
client_protos_headers += wayland_scanner_client.process(xml)
endforeach
gdbus_codegen = find_program('gdbus-codegen')
gdbus_code = generator(
find_program('gdbus-codegen'),
gdbus_codegen,
output: '@BASENAME@.c',
arguments: ['--c-namespace', 'Sn', '--body', '--output', '@OUTPUT@', '@INPUT@']
)
gdbus_header = generator(
find_program('gdbus-codegen'),
gdbus_codegen,
output: '@BASENAME@.h',
arguments: ['--c-namespace', 'Sn', '--header', '--output', '@OUTPUT@', '@INPUT@']
)

View File

@ -6,7 +6,7 @@
// Choose the order of the modules
"modules-left": ["sway/workspaces", "custom/spotify"],
"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
// "sway/workspaces": {
// "disable-scroll": true,
@ -39,6 +39,9 @@
"format": "{capacity}% {icon}",
"format-icons": ["", "", "", "", ""]
},
"battery#bat2": {
"bat": "BAT2"
},
"network": {
// "interface": "wlp2s0", // (Optional) To force the use of this interface
"format-wifi": "{essid} ({signalStrength}%) ",

View File

@ -7,43 +7,44 @@ waybar::Factory::Factory(Bar& bar, const Json::Value& config)
waybar::IModule* waybar::Factory::makeModule(const std::string &name) const
{
try {
if (name == "battery") {
auto ref = name.substr(0, name.find("#"));
if (ref == "battery") {
return new waybar::modules::Battery(config_[name]);
}
#ifdef HAVE_SWAY
if (name == "sway/workspaces") {
if (ref == "sway/workspaces") {
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]);
}
#endif
if (name == "memory") {
if (ref == "memory") {
return new waybar::modules::Memory(config_[name]);
}
if (name == "cpu") {
if (ref == "cpu") {
return new waybar::modules::Cpu(config_[name]);
}
if (name == "clock") {
if (ref == "clock") {
return new waybar::modules::Clock(config_[name]);
}
#ifdef HAVE_DBUSMENU
if (name == "tray") {
if (ref == "tray") {
return new waybar::modules::SNI::Tray(config_[name]);
}
#endif
#ifdef HAVE_LIBNL
if (name == "network") {
if (ref == "network") {
return new waybar::modules::Network(config_[name]);
}
#endif
#ifdef HAVE_LIBPULSE
if (name == "pulseaudio") {
if (ref == "pulseaudio") {
return new waybar::modules::Pulseaudio(config_[name]);
}
#endif
if (name.compare(0, 7, "custom/") == 0 && name.size() > 7) {
return new waybar::modules::Custom(name.substr(7), config_[name]);
if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) {
return new waybar::modules::Custom(ref.substr(7), config_[name]);
}
} catch (const std::exception& e) {
auto err = fmt::format("Disabling module \"{}\", {}", name, e.what());

View File

@ -4,16 +4,27 @@ waybar::modules::Battery::Battery(const Json::Value& config)
: ALabel(config, "{capacity}%")
{
try {
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);
if (config_["bat"]) {
auto dir = data_dir_ / config_["bat"].asString();
if (fs::is_directory(dir) && fs::exists(dir / "capacity")
&& 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) {
throw std::runtime_error(e.what());
}
if (batteries_.empty()) {
if (config_["bat"]) {
throw std::runtime_error("No battery named " + config_["bat"].asString());
}
throw std::runtime_error("No batteries.");
}
fd_ = inotify_init1(IN_CLOEXEC);
@ -36,12 +47,18 @@ void waybar::modules::Battery::worker()
{
// Trigger first values
update();
uint32_t interval = config_["interval"] ? config_["interval"].asUInt() : 60;
threadTimer_ = [this, interval] {
thread_.sleep_for(chrono::seconds(interval));
dp.emit();
};
thread_ = [this] {
struct inotify_event event = {0};
int nbytes = read(fd_, &event, sizeof(event));
if (nbytes != sizeof(event)) {
return;
}
threadTimer_.stop();
dp.emit();
};
}

View File

@ -86,7 +86,7 @@ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context* /*context*/,
float volume = static_cast<float>(pa_cvolume_avg(&(i->volume)))
/ float{PA_VOLUME_NORM};
pa->sink_idx_ = i->index;
pa->volume_ = volume * 100.0f;
pa->volume_ = std::round(volume * 100.0f);
pa->muted_ = i->mute != 0;
pa->desc_ = i->description;
pa->port_name_ = i->active_port->name;

View File

@ -32,7 +32,7 @@ void Host::nameAppeared(GDBusConnection* connection,
{
auto host = static_cast<SNI::Host *>(data);
if (host->cancellable_ != nullptr) {
std::cout << "WTF" << std::endl;
// TODO
}
host->cancellable_ = g_cancellable_new();
sn_org_kde_status_notifier_watcher_proxy_new(
@ -110,7 +110,6 @@ void Host::registerHost(GObject* src, GAsyncResult* res,
void Host::itemRegistered(
SnOrgKdeStatusNotifierWatcher* watcher, const gchar* service, gpointer data)
{
std::cout << "Item registered" << std::endl;
auto host = static_cast<SNI::Host *>(data);
host->addRegisteredItem(service);
}
@ -123,7 +122,6 @@ void Host::itemUnregistered(
for (auto it = host->items.begin(); it != host->items.end(); ++it) {
if (it->bus_name == bus_name && it->object_path == object_path) {
host->items.erase(it);
std::cout << "Item Unregistered" << std::endl;
break;
}
}

View File

@ -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_is_status_notifier_host_registered(
host->watcher_, TRUE);
std::cout << "Bus aquired" << std::endl;
}
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(
obj->watcher_, invocation);
std::cout << "Host registered: " << bus_name << std::endl;
return TRUE;
}