From 43af1b9ea00eceb32fec081445959c0e9b5dc94c Mon Sep 17 00:00:00 2001 From: twistedlogic Date: Wed, 11 Dec 2024 22:18:00 -0400 Subject: [PATCH 1/7] feat: implement hide vacant for river --- man/waybar-river-tags.5.scd | 5 +++++ src/modules/river/tags.cpp | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/man/waybar-river-tags.5.scd b/man/waybar-river-tags.5.scd index 5669456a..64621229 100644 --- a/man/waybar-river-tags.5.scd +++ b/man/waybar-river-tags.5.scd @@ -31,6 +31,11 @@ Addressed by *river/tags* default: false ++ Enables this module to consume all left over space dynamically. +*hide-vacant*: ++ + typeof: bool ++ + default: false ++ + Only show relevant tags: tags that are either focused or have a window on them. + # EXAMPLE ``` diff --git a/src/modules/river/tags.cpp b/src/modules/river/tags.cpp index 9e7cd5aa..26c8e3ad 100644 --- a/src/modules/river/tags.cpp +++ b/src/modules/river/tags.cpp @@ -189,11 +189,18 @@ bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) { } void Tags::handle_focused_tags(uint32_t tags) { + auto hide_vacant = config_["hide-vacant"].asBool(); for (size_t i = 0; i < buttons_.size(); ++i) { if ((1 << i) & tags) { + if (hide_vacant) { + buttons_[i].set_visible(true); + } buttons_[i].get_style_context()->add_class("focused"); } else { buttons_[i].get_style_context()->remove_class("focused"); + if (hide_vacant && !buttons_[i].get_style_context()->has_class("occupied")) { + buttons_[i].set_visible(false); + } } } } @@ -205,10 +212,17 @@ void Tags::handle_view_tags(struct wl_array *view_tags) { for (; view_tag < end; ++view_tag) { tags |= *view_tag; } + auto hide_vacant = config_["hide-vacant"].asBool(); for (size_t i = 0; i < buttons_.size(); ++i) { if ((1 << i) & tags) { + if (hide_vacant) { + buttons_[i].set_visible(true); + } buttons_[i].get_style_context()->add_class("occupied"); } else { + if (hide_vacant) { + buttons_[i].set_visible(false); + } buttons_[i].get_style_context()->remove_class("occupied"); } } From 8024df0430b2e031aa70fefb9b9655623fa9d412 Mon Sep 17 00:00:00 2001 From: twistedlogic Date: Wed, 11 Dec 2024 22:50:01 -0400 Subject: [PATCH 2/7] fix: edge case where tags get hidden after all views are killed This fixes an edge case where focused tags would get hidden if all clients on a tag get killed --- src/modules/river/tags.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/river/tags.cpp b/src/modules/river/tags.cpp index 26c8e3ad..5ba67f2f 100644 --- a/src/modules/river/tags.cpp +++ b/src/modules/river/tags.cpp @@ -220,7 +220,7 @@ void Tags::handle_view_tags(struct wl_array *view_tags) { } buttons_[i].get_style_context()->add_class("occupied"); } else { - if (hide_vacant) { + if (hide_vacant && !buttons_[i].get_style_context()->has_class("focused")) { buttons_[i].set_visible(false); } buttons_[i].get_style_context()->remove_class("occupied"); From 8e0964ad15688c23c6e0738b76e19686390162e9 Mon Sep 17 00:00:00 2001 From: twistedlogic Date: Thu, 12 Dec 2024 10:11:11 -0400 Subject: [PATCH 3/7] feat: is visible and urgent checks as well --- src/modules/river/tags.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/modules/river/tags.cpp b/src/modules/river/tags.cpp index 5ba67f2f..359e5a23 100644 --- a/src/modules/river/tags.cpp +++ b/src/modules/river/tags.cpp @@ -191,16 +191,19 @@ bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) { void Tags::handle_focused_tags(uint32_t tags) { auto hide_vacant = config_["hide-vacant"].asBool(); for (size_t i = 0; i < buttons_.size(); ++i) { + bool visible = buttons_[i].is_visible(); + bool occupied = buttons_[i].get_style_context()->has_class("occupied"); + bool urgent = buttons_[i].get_style_context()->has_class("urgent"); if ((1 << i) & tags) { - if (hide_vacant) { + if (hide_vacant && !visible) { buttons_[i].set_visible(true); } buttons_[i].get_style_context()->add_class("focused"); } else { - buttons_[i].get_style_context()->remove_class("focused"); - if (hide_vacant && !buttons_[i].get_style_context()->has_class("occupied")) { + if (hide_vacant && !(occupied || urgent)) { buttons_[i].set_visible(false); } + buttons_[i].get_style_context()->remove_class("focused"); } } } @@ -214,13 +217,16 @@ void Tags::handle_view_tags(struct wl_array *view_tags) { } auto hide_vacant = config_["hide-vacant"].asBool(); for (size_t i = 0; i < buttons_.size(); ++i) { + bool visible = buttons_[i].is_visible(); + bool focused = buttons_[i].get_style_context()->has_class("focused"); + bool urgent = buttons_[i].get_style_context()->has_class("urgent"); if ((1 << i) & tags) { - if (hide_vacant) { + if (hide_vacant && !visible) { buttons_[i].set_visible(true); } buttons_[i].get_style_context()->add_class("occupied"); } else { - if (hide_vacant && !buttons_[i].get_style_context()->has_class("focused")) { + if (hide_vacant && !(focused || urgent)) { buttons_[i].set_visible(false); } buttons_[i].get_style_context()->remove_class("occupied"); @@ -229,10 +235,20 @@ void Tags::handle_view_tags(struct wl_array *view_tags) { } void Tags::handle_urgent_tags(uint32_t tags) { + auto hide_vacant = config_["hide-vacant"].asBool(); for (size_t i = 0; i < buttons_.size(); ++i) { + bool visible = buttons_[i].is_visible(); + bool occupied = buttons_[i].get_style_context()->has_class("occupied"); + bool focused = buttons_[i].get_style_context()->has_class("focused"); if ((1 << i) & tags) { + if (hide_vacant && !visible) { + buttons_[i].set_visible(true); + } buttons_[i].get_style_context()->add_class("urgent"); } else { + if (hide_vacant && !(occupied || focused)) { + buttons_[i].set_visible(false); + } buttons_[i].get_style_context()->remove_class("urgent"); } } From d1dac2854a2b58c9baab569370415edff3bba299 Mon Sep 17 00:00:00 2001 From: Ethan Martin Date: Thu, 2 Jan 2025 20:50:39 -0500 Subject: [PATCH 4/7] Allow using wildcards in config include paths Updates `Config::tryExpandPath()` to return a vector of expanded path matches instead of a single path wrapped in an optional, with an empty vector indicating no matches. `Config::resolveConfigIncludes()` iterates over all of these matches, while other instances of path expansion (such as finding the base config path) retain their existing behavior and only use the first match. --- include/config.hpp | 4 ++-- src/ALabel.cpp | 4 ++-- src/config.cpp | 34 ++++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 18a1daed..5256bb46 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -20,8 +20,8 @@ class Config { static std::optional findConfigPath( const std::vector &names, const std::vector &dirs = CONFIG_DIRS); - static std::optional tryExpandPath(const std::string &base, - const std::string &filename); + static std::vector tryExpandPath(const std::string &base, + const std::string &filename); Config() = default; diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 467572f1..c218e402 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -68,11 +68,11 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st // there might be "~" or "$HOME" in original path, try to expand it. auto result = Config::tryExpandPath(menuFile, ""); - if (!result.has_value()) { + if (result.empty()) { throw std::runtime_error("Failed to expand file: " + menuFile); } - menuFile = result.value(); + menuFile = result.front(); // Read the menu descriptor file std::ifstream file(menuFile); if (!file.is_open()) { diff --git a/src/config.cpp b/src/config.cpp index 375dc4cb..7096ba89 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -21,8 +21,8 @@ const std::vector Config::CONFIG_DIRS = { const char *Config::CONFIG_PATH_ENV = "WAYBAR_CONFIG_DIR"; -std::optional Config::tryExpandPath(const std::string &base, - const std::string &filename) { +std::vector Config::tryExpandPath(const std::string &base, + const std::string &filename) { fs::path path; if (!filename.empty()) { @@ -33,33 +33,35 @@ std::optional Config::tryExpandPath(const std::string &base, spdlog::debug("Try expanding: {}", path.string()); + std::vector results; wordexp_t p; if (wordexp(path.c_str(), &p, 0) == 0) { - if (access(*p.we_wordv, F_OK) == 0) { - std::string result = *p.we_wordv; - wordfree(&p); - spdlog::debug("Found config file: {}", path.string()); - return result; + for (size_t i = 0; i < p.we_wordc; i++) { + if (access(p.we_wordv[i], F_OK) == 0) { + results.emplace_back(p.we_wordv[i]); + spdlog::debug("Found config file: {}", p.we_wordv[i]); + } } wordfree(&p); } - return std::nullopt; + + return results; } std::optional Config::findConfigPath(const std::vector &names, const std::vector &dirs) { if (const char *dir = std::getenv(Config::CONFIG_PATH_ENV)) { for (const auto &name : names) { - if (auto res = tryExpandPath(dir, name); res) { - return res; + if (auto res = tryExpandPath(dir, name); !res.empty()) { + return res.front(); } } } for (const auto &dir : dirs) { for (const auto &name : names) { - if (auto res = tryExpandPath(dir, name); res) { - return res; + if (auto res = tryExpandPath(dir, name); !res.empty()) { + return res.front(); } } } @@ -92,11 +94,15 @@ void Config::resolveConfigIncludes(Json::Value &config, int depth) { if (includes.isArray()) { for (const auto &include : includes) { spdlog::info("Including resource file: {}", include.asString()); - setupConfig(config, tryExpandPath(include.asString(), "").value_or(""), ++depth); + for (const auto &match : tryExpandPath(include.asString(), "")) { + setupConfig(config, match, depth + 1); + } } } else if (includes.isString()) { spdlog::info("Including resource file: {}", includes.asString()); - setupConfig(config, tryExpandPath(includes.asString(), "").value_or(""), ++depth); + for (const auto &match : tryExpandPath(includes.asString(), "")) { + setupConfig(config, match, depth + 1); + } } } From 865121b21dcdf3bf6733562e90a94efeeeb006ff Mon Sep 17 00:00:00 2001 From: "Sv. Lockal" Date: Sat, 4 Jan 2025 10:28:14 +0000 Subject: [PATCH 5/7] Fix compilation with libc++ This file uses std::sort and does not import correct header. Compilation with libstdc++ worked due to some indirect import, but compilation with LLVM libc++ fails. --- src/util/regex_collection.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/regex_collection.cpp b/src/util/regex_collection.cpp index 929e67cd..51dd6ff7 100644 --- a/src/util/regex_collection.cpp +++ b/src/util/regex_collection.cpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace waybar::util { From 6a29abb49e9aa1acd591d98dadb9cd1d6b6d3fff Mon Sep 17 00:00:00 2001 From: Alex Murkoff <413x1nkp@gmail.com> Date: Fri, 10 Jan 2025 15:27:41 +0700 Subject: [PATCH 6/7] fix: never sleep cava when sleep_timer is 0 --- src/modules/cava.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/cava.cpp b/src/modules/cava.cpp index f16d3f63..405a351a 100644 --- a/src/modules/cava.cpp +++ b/src/modules/cava.cpp @@ -139,7 +139,7 @@ auto waybar::modules::Cava::update() -> void { } } - if (silence_ && prm_.sleep_timer) { + if (silence_ && prm_.sleep_timer != 0) { if (sleep_counter_ <= (int)(std::chrono::milliseconds(prm_.sleep_timer * 1s) / frame_time_milsec_)) { ++sleep_counter_; @@ -147,7 +147,7 @@ auto waybar::modules::Cava::update() -> void { } } - if (!silence_) { + if (!silence_ || prm_.sleep_timer == 0) { downThreadDelay(frame_time_milsec_, suspend_silence_delay_); // Process: execute cava pthread_mutex_lock(&audio_data_.lock); From 0992bf1b879a4780aa47d5847ac5e15e3fd2f150 Mon Sep 17 00:00:00 2001 From: Pol Rivero <65060696+pol-rivero@users.noreply.github.com> Date: Thu, 9 Jan 2025 07:33:52 +0100 Subject: [PATCH 7/7] Escape tray tooltip text Fix errors when the tooltip set by the tray apps contains markup characters --- src/modules/sni/item.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/sni/item.cpp b/src/modules/sni/item.cpp index 6c4ec8c0..b3e84885 100644 --- a/src/modules/sni/item.cpp +++ b/src/modules/sni/item.cpp @@ -124,7 +124,8 @@ ToolTip get_variant(const Glib::VariantBase& value) { result.text = get_variant(container.get_child(2)); auto description = get_variant(container.get_child(3)); if (!description.empty()) { - result.text = fmt::format("{}\n{}", result.text, description); + auto escapedDescription = Glib::Markup::escape_text(description); + result.text = fmt::format("{}\n{}", result.text, escapedDescription); } return result; }