mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(pulseaudio): volume icons
This commit is contained in:
parent
ea9a08d473
commit
1555cb71e1
@ -6,6 +6,7 @@
|
||||
#include <iostream>
|
||||
#include <fmt/format.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <algorithm>
|
||||
#include "util/chrono.hpp"
|
||||
#include "IModule.hpp"
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <pulse/pulseaudio.h>
|
||||
#include <json/json.h>
|
||||
#include <fmt/format.h>
|
||||
#include <algorithm>
|
||||
#include "IModule.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
@ -13,6 +14,7 @@ namespace waybar::modules {
|
||||
auto update() -> void;
|
||||
operator Gtk::Widget &();
|
||||
private:
|
||||
std::string _getIcon(uint16_t percentage);
|
||||
static void _subscribeCb(pa_context *context,
|
||||
pa_subscription_event_type_t type, uint32_t idx, void *data);
|
||||
static void _contextStateCb(pa_context *c, void *data);
|
||||
|
@ -14,7 +14,7 @@
|
||||
"format": "{}% "
|
||||
},
|
||||
"battery": {
|
||||
"format": "{value}% {icon}",
|
||||
"format": "{capacity}% {icon}",
|
||||
"format-icons": ["", "", "", "", ""]
|
||||
},
|
||||
"network": {
|
||||
@ -22,8 +22,9 @@
|
||||
"format": "{essid} ({signalStrength}%) "
|
||||
},
|
||||
"pulseaudio": {
|
||||
"format": "{}% ",
|
||||
"format-muted": ""
|
||||
"format": "{volume}% {icon}",
|
||||
"format-muted": "",
|
||||
"format-icons": ["", ""]
|
||||
},
|
||||
"custom/spotify": {
|
||||
"format": " {}",
|
||||
|
@ -48,8 +48,9 @@ auto waybar::modules::Battery::update() -> void
|
||||
total += capacity;
|
||||
}
|
||||
uint16_t capacity = total / _batteries.size();
|
||||
auto format = _config["format"] ? _config["format"].asString() : "{}%";
|
||||
_label.set_text(fmt::format(format, fmt::arg("value", capacity),
|
||||
auto format = _config["format"]
|
||||
? _config["format"].asString() : "{capacity}%";
|
||||
_label.set_text(fmt::format(format, fmt::arg("capacity", capacity),
|
||||
fmt::arg("icon", _getIcon(capacity))));
|
||||
_label.set_tooltip_text(status);
|
||||
if (charging)
|
||||
@ -68,8 +69,9 @@ auto waybar::modules::Battery::update() -> void
|
||||
std::string waybar::modules::Battery::_getIcon(uint16_t percentage)
|
||||
{
|
||||
if (!_config["format-icons"] || !_config["format-icons"].isArray()) return "";
|
||||
auto step = 100 / _config["format-icons"].size();
|
||||
return _config["format-icons"][percentage / step].asString();
|
||||
auto size = _config["format-icons"].size();
|
||||
auto idx = std::clamp(percentage / (100 / size), 0U, size - 1);
|
||||
return _config["format-icons"][idx].asString();
|
||||
}
|
||||
|
||||
waybar::modules::Battery::operator Gtk::Widget &()
|
||||
|
@ -16,7 +16,7 @@ waybar::modules::Network::Network(Json::Value config)
|
||||
auto waybar::modules::Network::update() -> void
|
||||
{
|
||||
_getInfo();
|
||||
auto format = _config["format"] ? _config["format"].asString() : "{}";
|
||||
auto format = _config["format"] ? _config["format"].asString() : "{essid}";
|
||||
_label.set_text(fmt::format(format,
|
||||
fmt::arg("essid", _essid),
|
||||
fmt::arg("signaldBm", _signalStrengthdBm),
|
||||
|
@ -97,17 +97,27 @@ void waybar::modules::Pulseaudio::_serverInfoCb(pa_context *context,
|
||||
|
||||
auto waybar::modules::Pulseaudio::update() -> void
|
||||
{
|
||||
auto format = _config["format"] ? _config["format"].asString() : "{}%";
|
||||
auto format = _config["format"] ? _config["format"].asString() : "{volume}%";
|
||||
if (_muted) {
|
||||
format =
|
||||
_config["format-muted"] ? _config["format-muted"].asString() : format;
|
||||
_label.get_style_context()->add_class("muted");
|
||||
} else
|
||||
_label.get_style_context()->remove_class("muted");
|
||||
_label.set_label(fmt::format(format, _volume));
|
||||
_label.set_label(fmt::format(format,
|
||||
fmt::arg("volume", _volume),
|
||||
fmt::arg("icon", _getIcon(_volume))));
|
||||
_label.set_tooltip_text(_desc);
|
||||
}
|
||||
|
||||
std::string waybar::modules::Pulseaudio::_getIcon(uint16_t percentage)
|
||||
{
|
||||
if (!_config["format-icons"] || !_config["format-icons"].isArray()) return "";
|
||||
auto size = _config["format-icons"].size();
|
||||
auto idx = std::clamp(percentage / (100 / size), 0U, size - 1);
|
||||
return _config["format-icons"][idx].asString();
|
||||
}
|
||||
|
||||
waybar::modules::Pulseaudio::operator Gtk::Widget &() {
|
||||
return _label;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user