From 9c2b5efe7b5f9acd934595fcd8f27d2404ea0668 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 15 Jul 2021 08:52:02 +0200 Subject: [PATCH 1/8] Support per-device icon in pulseaudio --- include/ALabel.hpp | 2 +- include/modules/pulseaudio.hpp | 2 +- man/waybar-pulseaudio.5.scd | 4 ++++ src/ALabel.cpp | 2 +- src/modules/pulseaudio.cpp | 12 +++++++----- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index 5b9ac54..d8a5b50 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -14,7 +14,7 @@ class ALabel : public AModule { virtual ~ALabel() = default; virtual auto update() -> void; virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0); - virtual std::string getIcon(uint16_t, std::vector &alts, uint16_t max = 0); + virtual std::string getIcon(uint16_t, const std::vector &alts, uint16_t max = 0); protected: Gtk::Label label_; diff --git a/include/modules/pulseaudio.hpp b/include/modules/pulseaudio.hpp index 5f17620..9b36dfe 100644 --- a/include/modules/pulseaudio.hpp +++ b/include/modules/pulseaudio.hpp @@ -24,7 +24,7 @@ class Pulseaudio : public ALabel { static void volumeModifyCb(pa_context*, int, void*); bool handleScroll(GdkEventScroll* e); - const std::string getPortIcon() const; + const std::vector getPulseIcon() const; pa_threaded_mainloop* mainloop_; pa_mainloop_api* mainloop_api_; diff --git a/man/waybar-pulseaudio.5.scd b/man/waybar-pulseaudio.5.scd index d894290..7de1028 100644 --- a/man/waybar-pulseaudio.5.scd +++ b/man/waybar-pulseaudio.5.scd @@ -109,6 +109,9 @@ Additionally you can control the volume by scrolling *up* or *down* while the cu # ICONS: The following strings for *format-icons* are supported. + +- the device name + If they are found in the current PulseAudio port name, the corresponding icons will be selected. - *default* (Shown, when no other port is found) @@ -131,6 +134,7 @@ If they are found in the current PulseAudio port name, the corresponding icons w "format-bluetooth": "{volume}% {icon}", "format-muted": "", "format-icons": { + "alsa_output.pci-0000_00_1f.3.analog-stereo": "", "headphones": "", "handsfree": "", "headset": "", diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 8d9c9b4..dd41a32 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -76,7 +76,7 @@ std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_ return ""; } -std::string ALabel::getIcon(uint16_t percentage, std::vector& alts, uint16_t max) { +std::string ALabel::getIcon(uint16_t percentage, const std::vector& alts, uint16_t max) { auto format_icons = config_["format-icons"]; if (format_icons.isObject()) { std::string _alt = "default"; diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 3fbe956..a7cdcec 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -194,15 +194,17 @@ static const std::array ports = { "phone", }; -const std::string waybar::modules::Pulseaudio::getPortIcon() const { +const std::vector waybar::modules::Pulseaudio::getPulseIcon() const { + std::vector res = {default_sink_name_}; std::string nameLC = port_name_ + form_factor_; std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower); for (auto const &port : ports) { if (nameLC.find(port) != std::string::npos) { - return port; + res.push_back(port); + return res; } } - return port_name_; + return res; } auto waybar::modules::Pulseaudio::update() -> void { @@ -252,7 +254,7 @@ auto waybar::modules::Pulseaudio::update() -> void { fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume_), fmt::arg("source_desc", source_desc_), - fmt::arg("icon", getIcon(volume_, getPortIcon())))); + fmt::arg("icon", getIcon(volume_, getPulseIcon())))); getState(volume_); if (tooltipEnabled()) { @@ -267,7 +269,7 @@ auto waybar::modules::Pulseaudio::update() -> void { fmt::arg("format_source", format_source), fmt::arg("source_volume", source_volume_), fmt::arg("source_desc", source_desc_), - fmt::arg("icon", getIcon(volume_, getPortIcon())))); + fmt::arg("icon", getIcon(volume_, getPulseIcon())))); } else { label_.set_tooltip_text(desc_); } From 948eba92a540b52443b1e0b0a414b7ec6de83cab Mon Sep 17 00:00:00 2001 From: dmitry Date: Tue, 13 Jul 2021 04:49:19 +0300 Subject: [PATCH 2/8] Update dockerfiles --- Dockerfiles/alpine | 2 +- Dockerfiles/archlinux | 2 +- Dockerfiles/debian | 2 +- Dockerfiles/fedora | 2 +- Dockerfiles/opensuse | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfiles/alpine b/Dockerfiles/alpine index 21d1cbb..c0e032f 100644 --- a/Dockerfiles/alpine +++ b/Dockerfiles/alpine @@ -2,4 +2,4 @@ FROM alpine:latest -RUN apk add --no-cache git meson alpine-sdk libinput-dev wayland-dev wayland-protocols mesa-dev libxkbcommon-dev eudev-dev pixman-dev gtkmm3-dev jsoncpp-dev pugixml-dev libnl3-dev pulseaudio-dev libmpdclient-dev sndio-dev scdoc +RUN apk add --no-cache git meson alpine-sdk libinput-dev wayland-dev wayland-protocols mesa-dev libxkbcommon-dev eudev-dev pixman-dev gtkmm3-dev jsoncpp-dev pugixml-dev libnl3-dev pulseaudio-dev libmpdclient-dev sndio-dev scdoc libxkbcommon diff --git a/Dockerfiles/archlinux b/Dockerfiles/archlinux index e5a53ef..40a1b2e 100644 --- a/Dockerfiles/archlinux +++ b/Dockerfiles/archlinux @@ -3,4 +3,4 @@ FROM archlinux:base-devel RUN pacman -Syu --noconfirm && \ - pacman -S git meson base-devel libinput wayland wayland-protocols pixman libxkbcommon mesa gtkmm3 jsoncpp pugixml scdoc libpulse libdbusmenu-gtk3 libmpdclient gobject-introspection --noconfirm + pacman -S git meson base-devel libinput wayland wayland-protocols pixman libxkbcommon mesa gtkmm3 jsoncpp pugixml scdoc libpulse libdbusmenu-gtk3 libmpdclient gobject-introspection --noconfirm libxkbcommon diff --git a/Dockerfiles/debian b/Dockerfiles/debian index cee1744..f7f6e63 100644 --- a/Dockerfiles/debian +++ b/Dockerfiles/debian @@ -3,5 +3,5 @@ FROM debian:sid RUN apt-get update && \ - apt-get install -y build-essential meson ninja-build git pkg-config libinput10 libpugixml-dev libinput-dev wayland-protocols libwayland-client0 libwayland-cursor0 libwayland-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev libxkbcommon-dev libudev-dev libpixman-1-dev libgtkmm-3.0-dev libjsoncpp-dev scdoc libdbusmenu-gtk3-dev libnl-3-dev libnl-genl-3-dev libpulse-dev libmpdclient-dev gobject-introspection libgirepository1.0-dev && \ + apt-get install -y build-essential meson ninja-build git pkg-config libinput10 libpugixml-dev libinput-dev wayland-protocols libwayland-client0 libwayland-cursor0 libwayland-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev libxkbcommon-dev libudev-dev libpixman-1-dev libgtkmm-3.0-dev libjsoncpp-dev scdoc libdbusmenu-gtk3-dev libnl-3-dev libnl-genl-3-dev libpulse-dev libmpdclient-dev gobject-introspection libgirepository1.0-dev libxkbcommon && \ apt-get clean diff --git a/Dockerfiles/fedora b/Dockerfiles/fedora index 77c77cb..470ceb7 100644 --- a/Dockerfiles/fedora +++ b/Dockerfiles/fedora @@ -8,5 +8,5 @@ RUN dnf install -y @c-development git-core meson scdoc 'pkgconfig(date)' \ 'pkgconfig(jsoncpp)' 'pkgconfig(libinput)' 'pkgconfig(libmpdclient)' \ 'pkgconfig(libnl-3.0)' 'pkgconfig(libnl-genl-3.0)' 'pkgconfig(libpulse)' \ 'pkgconfig(libudev)' 'pkgconfig(pugixml)' 'pkgconfig(sigc++-2.0)' 'pkgconfig(spdlog)' \ - 'pkgconfig(wayland-client)' 'pkgconfig(wayland-cursor)' 'pkgconfig(wayland-protocols)' && \ + 'pkgconfig(wayland-client)' 'pkgconfig(wayland-cursor)' 'pkgconfig(wayland-protocols)' 'pkgconfig(xkbcommon)' && \ dnf clean all -y diff --git a/Dockerfiles/opensuse b/Dockerfiles/opensuse index 5b664fb..eb231fd 100644 --- a/Dockerfiles/opensuse +++ b/Dockerfiles/opensuse @@ -4,4 +4,4 @@ FROM opensuse/tumbleweed:latest RUN zypper -n up && \ zypper -n install -t pattern devel_C_C++ && \ - zypper -n install git meson clang libinput10 libinput-devel pugixml-devel libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel scdoc + zypper -n install git meson clang libinput10 libinput-devel pugixml-devel libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel scdoc libxkbcommon From 2506c0104a12e017721849ff9b5541b5675e4c7a Mon Sep 17 00:00:00 2001 From: Anakael Date: Fri, 16 Jul 2021 11:37:58 +0300 Subject: [PATCH 3/8] Update Dockerfiles/fedora Co-authored-by: Aleksei Bavshin --- Dockerfiles/fedora | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfiles/fedora b/Dockerfiles/fedora index 470ceb7..a61dcd3 100644 --- a/Dockerfiles/fedora +++ b/Dockerfiles/fedora @@ -8,5 +8,5 @@ RUN dnf install -y @c-development git-core meson scdoc 'pkgconfig(date)' \ 'pkgconfig(jsoncpp)' 'pkgconfig(libinput)' 'pkgconfig(libmpdclient)' \ 'pkgconfig(libnl-3.0)' 'pkgconfig(libnl-genl-3.0)' 'pkgconfig(libpulse)' \ 'pkgconfig(libudev)' 'pkgconfig(pugixml)' 'pkgconfig(sigc++-2.0)' 'pkgconfig(spdlog)' \ - 'pkgconfig(wayland-client)' 'pkgconfig(wayland-cursor)' 'pkgconfig(wayland-protocols)' 'pkgconfig(xkbcommon)' && \ + 'pkgconfig(wayland-client)' 'pkgconfig(wayland-cursor)' 'pkgconfig(wayland-protocols)' 'pkgconfig(xkbregistry)' && \ dnf clean all -y From 86a43b904214613b2470db65746367b7721bd929 Mon Sep 17 00:00:00 2001 From: Roosembert Palacios Date: Tue, 20 Jul 2021 10:11:55 +0200 Subject: [PATCH 4/8] pulseaudio: Control currently running sink In a system with multiple sinks, the default sink may not always be the once currently being used. It is more useful to control the currently active sink rather than an unused one. This patch does not make any difference if the system only uses the default sink. Signed-off-by: Roosembert Palacios --- include/modules/pulseaudio.hpp | 3 ++- src/modules/pulseaudio.cpp | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/modules/pulseaudio.hpp b/include/modules/pulseaudio.hpp index 5f17620..f636c00 100644 --- a/include/modules/pulseaudio.hpp +++ b/include/modules/pulseaudio.hpp @@ -38,7 +38,8 @@ class Pulseaudio : public ALabel { std::string form_factor_; std::string desc_; std::string monitor_; - std::string default_sink_name_; + std::string current_sink_name_; + bool current_sink_running_; // SOURCE uint32_t source_idx_{0}; uint16_t source_volume_; diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 3fbe956..c0299fc 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -151,8 +151,24 @@ void waybar::modules::Pulseaudio::sourceInfoCb(pa_context * /*context*/, const p */ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, int /*eol*/, void *data) { + if (i == nullptr) + return; + auto pa = static_cast(data); - if (i != nullptr && pa->default_sink_name_ == i->name) { + if (pa->current_sink_name_ == i->name) { + if (i->state != PA_SINK_RUNNING) { + pa->current_sink_running_ = false; + } else { + pa->current_sink_running_ = true; + } + } + + if (!pa->current_sink_running_ && i->state == PA_SINK_RUNNING) { + pa->current_sink_name_ = i->name; + pa->current_sink_running_ = true; + } + + if (pa->current_sink_name_ == i->name) { pa->pa_volume_ = i->volume; float volume = static_cast(pa_cvolume_avg(&(pa->pa_volume_))) / float{PA_VOLUME_NORM}; pa->sink_idx_ = i->index; @@ -175,11 +191,11 @@ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context * /*context*/, const pa_ void waybar::modules::Pulseaudio::serverInfoCb(pa_context *context, const pa_server_info *i, void *data) { auto pa = static_cast(data); - pa->default_sink_name_ = i->default_sink_name; + pa->current_sink_name_ = i->default_sink_name; pa->default_source_name_ = i->default_source_name; - pa_context_get_sink_info_by_name(context, i->default_sink_name, sinkInfoCb, data); - pa_context_get_source_info_by_name(context, i->default_source_name, sourceInfoCb, data); + pa_context_get_sink_info_list(context, sinkInfoCb, data); + pa_context_get_source_info_list(context, sourceInfoCb, data); } static const std::array ports = { From 6f2bfd43bf2a92ffefd880c6923af757b6565665 Mon Sep 17 00:00:00 2001 From: Lars Christensen Date: Tue, 20 Jul 2021 15:25:05 +0200 Subject: [PATCH 5/8] Fix pulseaudio icon name compilation error --- src/modules/pulseaudio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index bd90375..cf42780 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -211,7 +211,7 @@ static const std::array ports = { }; const std::vector waybar::modules::Pulseaudio::getPulseIcon() const { - std::vector res = {default_sink_name_}; + std::vector res = {default_source_name_}; std::string nameLC = port_name_ + form_factor_; std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower); for (auto const &port : ports) { From 67d482d28b46ee6f89d69016ec3451bbe8653f11 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 21 Jul 2021 09:23:52 +0200 Subject: [PATCH 6/8] Update opensuse --- Dockerfiles/opensuse | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfiles/opensuse b/Dockerfiles/opensuse index eb231fd..1015e5c 100644 --- a/Dockerfiles/opensuse +++ b/Dockerfiles/opensuse @@ -3,5 +3,7 @@ FROM opensuse/tumbleweed:latest RUN zypper -n up && \ + zypper -n addrepo https://download.opensuse.org/repositories/X11:Wayland/openSUSE_Tumbleweed/X11:Wayland.repo && \ + zypper -n refresh && \ zypper -n install -t pattern devel_C_C++ && \ zypper -n install git meson clang libinput10 libinput-devel pugixml-devel libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel scdoc libxkbcommon From 1f5c07a07f5f35dd531177ad1e86251b0a6565a4 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 21 Jul 2021 09:27:54 +0200 Subject: [PATCH 7/8] Update debian --- Dockerfiles/debian | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfiles/debian b/Dockerfiles/debian index f7f6e63..7c9e0b0 100644 --- a/Dockerfiles/debian +++ b/Dockerfiles/debian @@ -3,5 +3,5 @@ FROM debian:sid RUN apt-get update && \ - apt-get install -y build-essential meson ninja-build git pkg-config libinput10 libpugixml-dev libinput-dev wayland-protocols libwayland-client0 libwayland-cursor0 libwayland-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev libxkbcommon-dev libudev-dev libpixman-1-dev libgtkmm-3.0-dev libjsoncpp-dev scdoc libdbusmenu-gtk3-dev libnl-3-dev libnl-genl-3-dev libpulse-dev libmpdclient-dev gobject-introspection libgirepository1.0-dev libxkbcommon && \ + apt-get install -y build-essential meson ninja-build git pkg-config libinput10 libpugixml-dev libinput-dev wayland-protocols libwayland-client0 libwayland-cursor0 libwayland-dev libegl1-mesa-dev libgles2-mesa-dev libgbm-dev libxkbcommon-dev libudev-dev libpixman-1-dev libgtkmm-3.0-dev libjsoncpp-dev scdoc libdbusmenu-gtk3-dev libnl-3-dev libnl-genl-3-dev libpulse-dev libmpdclient-dev gobject-introspection libgirepository1.0-dev libxkbcommon-dev && \ apt-get clean From 7f5fd1ac8648d1301c2840d328567c120317b285 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 21 Jul 2021 09:30:47 +0200 Subject: [PATCH 8/8] Update opensuse --- Dockerfiles/opensuse | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfiles/opensuse b/Dockerfiles/opensuse index 1015e5c..a88aa7d 100644 --- a/Dockerfiles/opensuse +++ b/Dockerfiles/opensuse @@ -3,7 +3,7 @@ FROM opensuse/tumbleweed:latest RUN zypper -n up && \ - zypper -n addrepo https://download.opensuse.org/repositories/X11:Wayland/openSUSE_Tumbleweed/X11:Wayland.repo && \ + zypper addrepo https://download.opensuse.org/repositories/X11:Wayland/openSUSE_Tumbleweed/X11:Wayland.repo | echo 'a' && \ zypper -n refresh && \ zypper -n install -t pattern devel_C_C++ && \ zypper -n install git meson clang libinput10 libinput-devel pugixml-devel libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel scdoc libxkbcommon