Compare commits

..

18 Commits

Author SHA1 Message Date
23727eed8a fix: hosting-monitor classes not recheck on monitor disconnect/waybar restart
Some checks failed
Nix-Tests / nix-flake-check (push) Has been cancelled
linux / build (c++20, alpine) (push) Has been cancelled
linux / build (c++20, archlinux) (push) Has been cancelled
linux / build (c++20, debian) (push) Has been cancelled
linux / build (c++20, fedora) (push) Has been cancelled
linux / build (c++20, gentoo) (push) Has been cancelled
linux / build (c++20, opensuse) (push) Has been cancelled
freebsd / build (push) Has been cancelled
clang-format / lint (push) Has been cancelled
2026-03-02 18:40:41 +03:00
0a42b6c706 conflict 2026-02-23 15:42:08 +03:00
688197c8c8 fixing workspaces 2026-02-23 15:38:11 +03:00
Alexis Rouillard
6fa8ad3430 Merge pull request #4849 from 44vladimirov/power_switch_events
battery: power switch events
2026-02-22 18:32:08 +01:00
Alexis Rouillard
54e7451cf0 Merge pull request #4856 from Cprakhar/feat/tooltip-format-cpu
feat: add tooltip-format config option in cpu module
2026-02-20 17:36:17 +01:00
Alexis Rouillard
d31b131f80 Merge pull request #4874 from GG2R10/fix/cava-silence-fix
fix(cava): remove silent CSS class on reactivation
2026-02-19 21:55:22 +01:00
GG2R10
9c871c90a7 fix: move silence_ = false inside idle lambda 2026-02-19 15:12:23 -05:00
Alexis Rouillard
a74adc54e5 Merge pull request #4863 from olliestone/fix-aappiconlabel-image-visibility
fix: ensure AAppIconLabel image remains not visibile if icons are disabled
2026-02-18 20:47:27 +01:00
Alexis Rouillard
14a30cd4b7 Merge pull request #4869 from cebem1nt/master
bump: niri/workspaces: change icons priority
2026-02-17 15:45:35 +01:00
cebem1nt
f1140f00f9 niri/workspaces: change icons priority 2026-02-17 11:23:27 -03:00
Ollie Stone
6f9dee979b fix: ensure AAppIconLabel image remains not visibile if icons are
disabled
2026-02-15 18:39:28 +00:00
Prakhar Chhalotre
2337d308ce Merge branch 'master' into feat/tooltip-format-cpu 2026-02-14 03:28:29 +05:30
Prakhar Chhalotre
4ac539206f feat: add tooltip-format config option in cpu module 2026-02-13 02:00:17 +05:30
Alexey Vladimirov
7110c455e2 fix of example config typos 2026-02-12 02:12:00 +03:00
Alexey Vladimirov
3bcadfdf5a battery: power switch events 2026-02-12 01:42:30 +03:00
9af70bfe42 Merge branch 'master' into feat-mpd_smart_title 2025-10-23 19:25:00 +03:00
0acc5a1405 feat: merged updates 2025-10-08 13:53:48 +03:00
d59e7c98d5 feat: added smart title param 2025-10-08 13:52:24 +03:00
19 changed files with 98 additions and 67 deletions

View File

@@ -182,6 +182,7 @@ Every entry in the *events* object consists of a *<event-name>* (typeof: *string
- *on-<status>-<state>* - *on-<status>-<state>*
- *on-<status>-<capacity>* - *on-<status>-<capacity>*
- *on-<status>*
Where: Where:
@@ -203,7 +204,9 @@ Where:
"events": { "events": {
"on-discharging-warning": "notify-send -u normal 'Low Battery'", "on-discharging-warning": "notify-send -u normal 'Low Battery'",
"on-discharging-critical": "notify-send -u critical 'Very Low Battery'", "on-discharging-critical": "notify-send -u critical 'Very Low Battery'",
"on-charging-100": "notify-send -u normal 'Battery Full!'" "on-charging-100": "notify-send -u normal 'Battery Full!'",
"on-discharging": "notify-send -u normal 'Power Switch' Discharging",
"on-charging": "notify-send -u normal 'Power Switch' Charging'"
}, },
"format": "{capacity}% {icon}", "format": "{capacity}% {icon}",
"format-icons": ["", "", "", "", ""], "format-icons": ["", "", "", "", ""],

View File

@@ -505,18 +505,6 @@ cava = dependency('libcava',
eproxy = dependency('epoxy', required: false) eproxy = dependency('epoxy', required: false)
if cava.found()
add_project_arguments('-DHAVE_LIBCAVA', language: 'cpp')
src_files += files('src/modules/cava/cavaRaw.cpp',
'src/modules/cava/cava_backend.cpp')
man_files += files('man/waybar-cava.5.scd')
if eproxy.found()
add_project_arguments('-DHAVE_LIBCAVAGLSL', language: 'cpp')
src_files += files('src/modules/cava/cavaGLSL.cpp')
endif
endif
if libgps.found() if libgps.found()
add_project_arguments('-DHAVE_LIBGPS', language: 'cpp') add_project_arguments('-DHAVE_LIBGPS', language: 'cpp')
src_files += files('src/modules/gps.cpp') src_files += files('src/modules/gps.cpp')

View File

@@ -151,7 +151,7 @@ void AAppIconLabel::updateAppIconName(const std::string& app_identifier,
} }
void AAppIconLabel::updateAppIcon() { void AAppIconLabel::updateAppIcon() {
if (update_app_icon_) { if (update_app_icon_ || (!iconEnabled() && image_.get_visible())) {
update_app_icon_ = false; update_app_icon_ = false;
if (app_icon_name_.empty()) { if (app_icon_name_.empty()) {
image_.set_visible(false); image_.set_visible(false);

View File

@@ -114,7 +114,7 @@
#ifdef HAVE_LIBGPS #ifdef HAVE_LIBGPS
#include "modules/gps.hpp" #include "modules/gps.hpp"
#endif #endif
#include "modules/cava/cava_frontend.hpp" // #include "modules/cava/cava_frontend.hpp"
#include "modules/cffi.hpp" #include "modules/cffi.hpp"
#include "modules/custom.hpp" #include "modules/custom.hpp"
#include "modules/image.hpp" #include "modules/image.hpp"
@@ -339,9 +339,6 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name,
return new waybar::modules::Wireplumber(id, config_[name]); return new waybar::modules::Wireplumber(id, config_[name]);
} }
#endif #endif
if (ref == "cava") {
return waybar::modules::cava::getModule(id, config_[name]);
}
#ifdef HAVE_SYSTEMD_MONITOR #ifdef HAVE_SYSTEMD_MONITOR
if (ref == "systemd-failed-units") { if (ref == "systemd-failed-units") {
return new waybar::modules::SystemdFailedUnits(id, config_[name]); return new waybar::modules::SystemdFailedUnits(id, config_[name]);

View File

@@ -790,16 +790,19 @@ void waybar::modules::Battery::processEvents(std::string& state, std::string& st
if (!events.isObject() || events.empty()) { if (!events.isObject() || events.empty()) {
return; return;
} }
std::string event_name = fmt::format("on-{}-{}", status == "discharging" ? status : "charging", auto exec = [](Json::Value const& event) {
state.empty() ? std::to_string(capacity) : state); if (!event.isString()) return;
if (auto command = event.asString(); !command.empty()) {
util::command::exec(command, "");
}
};
std::string status_name = status == "discharging" ? "on-discharging" : "on-charging";
std::string event_name = status_name + '-' + (state.empty() ? std::to_string(capacity) : state);
if (last_event_ != event_name) { if (last_event_ != event_name) {
spdlog::debug("battery: triggering event {}", event_name); spdlog::debug("battery: triggering event {}", event_name);
if (events[event_name].isString()) { exec(events[event_name]);
std::string exec = events[event_name].asString(); if (!last_event_.empty() && last_event_[3] != event_name[3]) {
// Execute the command if it is not empty exec(events[status_name]);
if (!exec.empty()) {
util::command::exec(exec, "");
}
} }
last_event_ = event_name; last_event_ = event_name;
} }

View File

@@ -26,6 +26,7 @@ void waybar::modules::cava::Cava::pause_resume() { backend_->doPauseResume(); }
auto waybar::modules::cava::Cava::onUpdate(const std::string& input) -> void { auto waybar::modules::cava::Cava::onUpdate(const std::string& input) -> void {
Glib::signal_idle().connect_once([this, input]() { Glib::signal_idle().connect_once([this, input]() {
if (silence_) { if (silence_) {
silence_ = false;
label_.get_style_context()->remove_class("silent"); label_.get_style_context()->remove_class("silent");
if (!label_.get_style_context()->has_class("updated")) if (!label_.get_style_context()->has_class("updated"))
label_.get_style_context()->add_class("updated"); label_.get_style_context()->add_class("updated");
@@ -38,7 +39,6 @@ auto waybar::modules::cava::Cava::onUpdate(const std::string& input) -> void {
label_.show(); label_.show();
ALabel::update(); ALabel::update();
}); });
silence_ = false;
} }
auto waybar::modules::cava::Cava::onSilence() -> void { auto waybar::modules::cava::Cava::onSilence() -> void {

View File

@@ -26,9 +26,7 @@ auto waybar::modules::Cpu::update() -> void {
auto [load1, load5, load15] = Load::getLoad(); auto [load1, load5, load15] = Load::getLoad();
auto [cpu_usage, tooltip] = CpuUsage::getCpuUsage(prev_times_); auto [cpu_usage, tooltip] = CpuUsage::getCpuUsage(prev_times_);
auto [max_frequency, min_frequency, avg_frequency] = CpuFrequency::getCpuFrequency(); auto [max_frequency, min_frequency, avg_frequency] = CpuFrequency::getCpuFrequency();
if (tooltipEnabled()) {
label_.set_tooltip_markup(tooltip);
}
auto format = format_; auto format = format_;
auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0]; auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0];
auto state = getState(total_usage); auto state = getState(total_usage);
@@ -56,6 +54,15 @@ auto waybar::modules::Cpu::update() -> void {
store.push_back(fmt::arg(icon_format.c_str(), getIcon(cpu_usage[i], icons))); store.push_back(fmt::arg(icon_format.c_str(), getIcon(cpu_usage[i], icons)));
} }
label_.set_markup(fmt::vformat(format, store)); label_.set_markup(fmt::vformat(format, store));
if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) {
tooltip = config_["tooltip-format"].asString();
label_.set_tooltip_markup(fmt::vformat(tooltip, store));
} else {
label_.set_tooltip_markup(tooltip);
}
}
} }
// Call parent update // Call parent update

View File

@@ -20,12 +20,7 @@ waybar::modules::CpuFrequency::CpuFrequency(const std::string& id, const Json::V
auto waybar::modules::CpuFrequency::update() -> void { auto waybar::modules::CpuFrequency::update() -> void {
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
auto [max_frequency, min_frequency, avg_frequency] = CpuFrequency::getCpuFrequency(); auto [max_frequency, min_frequency, avg_frequency] = CpuFrequency::getCpuFrequency();
if (tooltipEnabled()) {
auto tooltip =
fmt::format("Minimum frequency: {}\nAverage frequency: {}\nMaximum frequency: {}\n",
min_frequency, avg_frequency, max_frequency);
label_.set_tooltip_markup(tooltip);
}
auto format = format_; auto format = format_;
auto state = getState(avg_frequency); auto state = getState(avg_frequency);
if (!state.empty() && config_["format-" + state].isString()) { if (!state.empty() && config_["format-" + state].isString()) {
@@ -43,6 +38,18 @@ auto waybar::modules::CpuFrequency::update() -> void {
store.push_back(fmt::arg("min_frequency", min_frequency)); store.push_back(fmt::arg("min_frequency", min_frequency));
store.push_back(fmt::arg("avg_frequency", avg_frequency)); store.push_back(fmt::arg("avg_frequency", avg_frequency));
label_.set_markup(fmt::vformat(format, store)); label_.set_markup(fmt::vformat(format, store));
if (tooltipEnabled()) {
std::string tooltip;
if (config_["tooltip-format"].isString()) {
tooltip = config_["tooltip-format"].asString();
label_.set_tooltip_markup(fmt::vformat(tooltip, store));
} else {
tooltip = "Minimum frequency: {}\nAverage frequency: {}\nMaximum frequency: {}\n";
label_.set_tooltip_markup(
fmt::format(fmt::runtime(tooltip), min_frequency, avg_frequency, max_frequency));
}
}
} }
// Call parent update // Call parent update

View File

@@ -20,9 +20,7 @@ waybar::modules::CpuUsage::CpuUsage(const std::string& id, const Json::Value& co
auto waybar::modules::CpuUsage::update() -> void { auto waybar::modules::CpuUsage::update() -> void {
// TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both
auto [cpu_usage, tooltip] = CpuUsage::getCpuUsage(prev_times_); auto [cpu_usage, tooltip] = CpuUsage::getCpuUsage(prev_times_);
if (tooltipEnabled()) {
label_.set_tooltip_markup(tooltip);
}
auto format = format_; auto format = format_;
auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0]; auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0];
auto state = getState(total_usage); auto state = getState(total_usage);
@@ -46,6 +44,15 @@ auto waybar::modules::CpuUsage::update() -> void {
store.push_back(fmt::arg(icon_format.c_str(), getIcon(cpu_usage[i], icons))); store.push_back(fmt::arg(icon_format.c_str(), getIcon(cpu_usage[i], icons)));
} }
label_.set_markup(fmt::vformat(format, store)); label_.set_markup(fmt::vformat(format, store));
if (tooltipEnabled()) {
if (config_["tooltip-format"].isString()) {
tooltip = config_["tooltip-format"].asString();
label_.set_tooltip_markup(fmt::vformat(tooltip, store));
} else {
label_.set_tooltip_markup(tooltip);
}
}
} }
// Call parent update // Call parent update

View File

@@ -11,8 +11,8 @@
namespace waybar::modules::hyprland { namespace waybar::modules::hyprland {
Workspace::Workspace(const Json::Value& workspace_data, Workspaces& workspace_manager, Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_manager,
const Json::Value& clients_data) const Json::Value &clients_data)
: m_workspaceManager(workspace_manager), : m_workspaceManager(workspace_manager),
m_id(workspace_data["id"].asInt()), m_id(workspace_data["id"].asInt()),
m_name(workspace_data["name"].asString()), m_name(workspace_data["name"].asString()),
@@ -45,8 +45,8 @@ Workspace::Workspace(const Json::Value& workspace_data, Workspaces& workspace_ma
initializeWindowMap(clients_data); initializeWindowMap(clients_data);
} }
void addOrRemoveClass(const Glib::RefPtr<Gtk::StyleContext>& context, bool condition, void addOrRemoveClass(const Glib::RefPtr<Gtk::StyleContext> &context, bool condition,
const std::string& class_name) { const std::string &class_name) {
if (condition) { if (condition) {
context->add_class(class_name); context->add_class(class_name);
} else { } else {
@@ -54,9 +54,9 @@ void addOrRemoveClass(const Glib::RefPtr<Gtk::StyleContext>& context, bool condi
} }
} }
std::optional<WindowRepr> Workspace::closeWindow(WindowAddress const& addr) { std::optional<WindowRepr> Workspace::closeWindow(WindowAddress const &addr) {
auto it = std::ranges::find_if(m_windowMap, auto it = std::ranges::find_if(m_windowMap,
[&addr](const auto& window) { return window.address == addr; }); [&addr](const auto &window) { return window.address == addr; });
// If the vector contains the address, remove it and return the window representation // If the vector contains the address, remove it and return the window representation
if (it != m_windowMap.end()) { if (it != m_windowMap.end()) {
WindowRepr windowRepr = *it; WindowRepr windowRepr = *it;
@@ -66,7 +66,7 @@ std::optional<WindowRepr> Workspace::closeWindow(WindowAddress const& addr) {
return std::nullopt; return std::nullopt;
} }
bool Workspace::handleClicked(GdkEventButton* bt) const { bool Workspace::handleClicked(GdkEventButton *bt) const {
if (bt->type == GDK_BUTTON_PRESS) { if (bt->type == GDK_BUTTON_PRESS) {
try { try {
if (id() > 0) { // normal if (id() > 0) { // normal
@@ -87,14 +87,14 @@ bool Workspace::handleClicked(GdkEventButton* bt) const {
m_ipc.getSocket1Reply("dispatch togglespecialworkspace"); m_ipc.getSocket1Reply("dispatch togglespecialworkspace");
} }
return true; return true;
} catch (const std::exception& e) { } catch (const std::exception &e) {
spdlog::error("Failed to dispatch workspace: {}", e.what()); spdlog::error("Failed to dispatch workspace: {}", e.what());
} }
} }
return false; return false;
} }
void Workspace::initializeWindowMap(const Json::Value& clients_data) { void Workspace::initializeWindowMap(const Json::Value &clients_data) {
m_windowMap.clear(); m_windowMap.clear();
for (auto client : clients_data) { for (auto client : clients_data) {
if (client["workspace"]["id"].asInt() == id()) { if (client["workspace"]["id"].asInt() == id()) {
@@ -103,10 +103,10 @@ void Workspace::initializeWindowMap(const Json::Value& clients_data) {
} }
} }
void Workspace::setActiveWindow(WindowAddress const& addr) { void Workspace::setActiveWindow(WindowAddress const &addr) {
std::optional<long> activeIdx; std::optional<long> activeIdx;
for (size_t i = 0; i < m_windowMap.size(); ++i) { for (size_t i = 0; i < m_windowMap.size(); ++i) {
auto& window = m_windowMap[i]; auto &window = m_windowMap[i];
bool isActive = (window.address == addr); bool isActive = (window.address == addr);
window.setActive(isActive); window.setActive(isActive);
if (isActive) { if (isActive) {
@@ -133,7 +133,7 @@ void Workspace::insertWindow(WindowCreationPayload create_window_payload) {
if (!repr.empty() || m_workspaceManager.enableTaskbar()) { if (!repr.empty() || m_workspaceManager.enableTaskbar()) {
auto addr = create_window_payload.getAddress(); auto addr = create_window_payload.getAddress();
auto it = std::ranges::find_if( auto it = std::ranges::find_if(
m_windowMap, [&addr](const auto& window) { return window.address == addr; }); m_windowMap, [&addr](const auto &window) { return window.address == addr; });
// If the vector contains the address, update the window representation, otherwise insert it // If the vector contains the address, update the window representation, otherwise insert it
if (it != m_windowMap.end()) { if (it != m_windowMap.end()) {
*it = repr; *it = repr;
@@ -144,7 +144,7 @@ void Workspace::insertWindow(WindowCreationPayload create_window_payload) {
} }
}; };
bool Workspace::onWindowOpened(WindowCreationPayload const& create_window_payload) { bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_payload) {
if (create_window_payload.getWorkspaceName() == name()) { if (create_window_payload.getWorkspaceName() == name()) {
insertWindow(create_window_payload); insertWindow(create_window_payload);
return true; return true;
@@ -152,7 +152,7 @@ bool Workspace::onWindowOpened(WindowCreationPayload const& create_window_payloa
return false; return false;
} }
std::string& Workspace::selectIcon(std::map<std::string, std::string>& icons_map) { std::string &Workspace::selectIcon(std::map<std::string, std::string> &icons_map) {
spdlog::trace("Selecting icon for workspace {}", name()); spdlog::trace("Selecting icon for workspace {}", name());
if (isUrgent()) { if (isUrgent()) {
auto urgentIconIt = icons_map.find("urgent"); auto urgentIconIt = icons_map.find("urgent");
@@ -209,7 +209,7 @@ std::string& Workspace::selectIcon(std::map<std::string, std::string>& icons_map
return m_name; return m_name;
} }
void Workspace::update(const std::string& workspace_icon) { void Workspace::update(const std::string &workspace_icon) {
if (this->m_workspaceManager.persistentOnly() && !this->isPersistent()) { if (this->m_workspaceManager.persistentOnly() && !this->isPersistent()) {
m_button.hide(); m_button.hide();
return; return;
@@ -248,7 +248,7 @@ void Workspace::update(const std::string& workspace_icon) {
bool isNotFirst = false; bool isNotFirst = false;
for (const auto& window_repr : m_windowMap) { for (const auto &window_repr : m_windowMap) {
if (isNotFirst) { if (isNotFirst) {
windows.append(windowSeparator); windows.append(windowSeparator);
} }
@@ -276,10 +276,10 @@ bool Workspace::isEmpty() const {
// If there are windows but they are all ignored, consider the workspace empty // If there are windows but they are all ignored, consider the workspace empty
return std::all_of( return std::all_of(
m_windowMap.begin(), m_windowMap.end(), m_windowMap.begin(), m_windowMap.end(),
[this, &ignore_list](const auto& window_repr) { return shouldSkipWindow(window_repr); }); [this, &ignore_list](const auto &window_repr) { return shouldSkipWindow(window_repr); });
} }
void Workspace::updateTaskbar(const std::string& workspace_icon) { void Workspace::updateTaskbar(const std::string &workspace_icon) {
for (auto child : m_content.get_children()) { for (auto child : m_content.get_children()) {
if (child != &m_labelBefore) { if (child != &m_labelBefore) {
m_content.remove(*child); m_content.remove(*child);
@@ -287,7 +287,7 @@ void Workspace::updateTaskbar(const std::string& workspace_icon) {
} }
bool isFirst = true; bool isFirst = true;
auto processWindow = [&](const WindowRepr& window_repr) { auto processWindow = [&](const WindowRepr &window_repr) {
if (shouldSkipWindow(window_repr)) { if (shouldSkipWindow(window_repr)) {
return; // skip return; // skip
} }
@@ -300,7 +300,7 @@ void Workspace::updateTaskbar(const std::string& workspace_icon) {
} }
auto window_box = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_HORIZONTAL); auto window_box = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_HORIZONTAL);
window_box->set_tooltip_markup(window_repr.window_title); window_box->set_tooltip_text(window_repr.window_title);
window_box->get_style_context()->add_class("taskbar-window"); window_box->get_style_context()->add_class("taskbar-window");
if (window_repr.isActive) { if (window_repr.isActive) {
window_box->get_style_context()->add_class("active"); window_box->get_style_context()->add_class("active");
@@ -343,7 +343,7 @@ void Workspace::updateTaskbar(const std::string& workspace_icon) {
processWindow(*it); processWindow(*it);
} }
} else { } else {
for (const auto& window_repr : m_windowMap) { for (const auto &window_repr : m_windowMap) {
processWindow(window_repr); processWindow(window_repr);
} }
} }
@@ -358,7 +358,7 @@ void Workspace::updateTaskbar(const std::string& workspace_icon) {
} }
} }
bool Workspace::handleClick(const GdkEventButton* event_button, WindowAddress const& addr) const { bool Workspace::handleClick(const GdkEventButton *event_button, WindowAddress const &addr) const {
if (event_button->type == GDK_BUTTON_PRESS) { if (event_button->type == GDK_BUTTON_PRESS) {
std::string command = std::regex_replace(m_workspaceManager.onClickWindow(), std::string command = std::regex_replace(m_workspaceManager.onClickWindow(),
std::regex("\\{address\\}"), "0x" + addr); std::regex("\\{address\\}"), "0x" + addr);
@@ -372,9 +372,9 @@ bool Workspace::handleClick(const GdkEventButton* event_button, WindowAddress co
return true; return true;
} }
bool Workspace::shouldSkipWindow(const WindowRepr& window_repr) const { bool Workspace::shouldSkipWindow(const WindowRepr &window_repr) const {
auto ignore_list = m_workspaceManager.getIgnoredWindows(); auto ignore_list = m_workspaceManager.getIgnoredWindows();
auto it = std::ranges::find_if(ignore_list, [&window_repr](const auto& ignoreItem) { auto it = std::ranges::find_if(ignore_list, [&window_repr](const auto &ignoreItem) {
return std::regex_match(window_repr.window_class, ignoreItem) || return std::regex_match(window_repr.window_class, ignoreItem) ||
std::regex_match(window_repr.window_title, ignoreItem); std::regex_match(window_repr.window_title, ignoreItem);
}); });

View File

@@ -3,6 +3,8 @@
#include <fmt/chrono.h> #include <fmt/chrono.h>
#include <glibmm/ustring.h> #include <glibmm/ustring.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <string>
#include <regex>
#include <system_error> #include <system_error>
#include <util/sanitize_str.hpp> #include <util/sanitize_str.hpp>
@@ -118,7 +120,7 @@ void waybar::modules::MPD::setLabel() {
auto format = format_; auto format = format_;
Glib::ustring artist, album_artist, album, title; Glib::ustring artist, album_artist, album, title;
std::string date, filename, uri; std::string date, filename, uri, titleSmart;
int song_pos = 0, queue_length = 0, volume = 0; int song_pos = 0, queue_length = 0, volume = 0;
std::chrono::seconds elapsedTime, totalTime; std::chrono::seconds elapsedTime, totalTime;
@@ -152,6 +154,21 @@ void waybar::modules::MPD::setLabel() {
date = sanitize_string(getTag(MPD_TAG_DATE)); date = sanitize_string(getTag(MPD_TAG_DATE));
filename = sanitize_string(getFilename()); filename = sanitize_string(getFilename());
uri = mpd_song_get_uri(song_.get()); uri = mpd_song_get_uri(song_.get());
if (title == "n/a" || artist == "n/a") {
titleSmart = std::regex_replace(filename, std::regex(R"((\s*$$.*?$$)|(\.(mp3|m4a|opus|ogx))$)"), "");
} else {
// Remove content within parentheses from the title
std::string cleanedTitle = std::regex_replace(static_cast<std::string>(title),
std::regex(R"(\([^)]*\))"),
"");
// Also trim any trailing spaces that might be left after removing parentheses
cleanedTitle = std::regex_replace(cleanedTitle, std::regex(R"(\s+$)"), "");
titleSmart = static_cast<std::string>(artist) + " - " + cleanedTitle;
}
song_pos = mpd_status_get_song_pos(status_.get()) + 1; song_pos = mpd_status_get_song_pos(status_.get()) + 1;
volume = mpd_status_get_volume(status_.get()); volume = mpd_status_get_volume(status_.get());
if (volume < 0) { if (volume < 0) {
@@ -175,6 +192,7 @@ void waybar::modules::MPD::setLabel() {
album_artist = album_artist.substr(0, config_["album-artist-len"].asInt()); album_artist = album_artist.substr(0, config_["album-artist-len"].asInt());
if (config_["album-len"].isInt()) album = album.substr(0, config_["album-len"].asInt()); if (config_["album-len"].isInt()) album = album.substr(0, config_["album-len"].asInt());
if (config_["title-len"].isInt()) title = title.substr(0, config_["title-len"].asInt()); if (config_["title-len"].isInt()) title = title.substr(0, config_["title-len"].asInt());
if (config_["title-len"].isInt()) titleSmart = titleSmart.substr(0, config_["title-len"].asInt());
try { try {
auto text = fmt::format( auto text = fmt::format(
@@ -185,7 +203,8 @@ void waybar::modules::MPD::setLabel() {
fmt::arg("songPosition", song_pos), fmt::arg("queueLength", queue_length), fmt::arg("songPosition", song_pos), fmt::arg("queueLength", queue_length),
fmt::arg("stateIcon", stateIcon), fmt::arg("consumeIcon", consumeIcon), fmt::arg("stateIcon", stateIcon), fmt::arg("consumeIcon", consumeIcon),
fmt::arg("randomIcon", randomIcon), fmt::arg("repeatIcon", repeatIcon), fmt::arg("randomIcon", randomIcon), fmt::arg("repeatIcon", repeatIcon),
fmt::arg("singleIcon", singleIcon), fmt::arg("filename", filename), fmt::arg("uri", uri)); fmt::arg("singleIcon", singleIcon), fmt::arg("filename", filename), fmt::arg("uri", uri),
fmt::arg("titleSmart", titleSmart));
if (text.empty()) { if (text.empty()) {
label_.hide(); label_.hide();
} else { } else {

View File

@@ -174,11 +174,11 @@ std::string Workspaces::getIcon(const std::string& value, const Json::Value& ws)
if (ws["is_urgent"].asBool() && icons["urgent"]) return icons["urgent"].asString(); if (ws["is_urgent"].asBool() && icons["urgent"]) return icons["urgent"].asString();
if (ws["active_window_id"].isNull() && icons["empty"]) return icons["empty"].asString(); if (ws["is_active"].asBool() && icons["active"]) return icons["active"].asString();
if (ws["is_focused"].asBool() && icons["focused"]) return icons["focused"].asString(); if (ws["is_focused"].asBool() && icons["focused"]) return icons["focused"].asString();
if (ws["is_active"].asBool() && icons["active"]) return icons["active"].asString(); if (ws["active_window_id"].isNull() && icons["empty"]) return icons["empty"].asString();
if (ws["name"]) { if (ws["name"]) {
const auto& name = ws["name"].asString(); const auto& name = ws["name"].asString();

0
subprojects/.wraplock Normal file
View File