Merge branch 'Alexays:master' into hyprland/windowcount
This commit is contained in:
@ -20,8 +20,8 @@ class Config {
|
|||||||
static std::optional<std::string> findConfigPath(
|
static std::optional<std::string> findConfigPath(
|
||||||
const std::vector<std::string> &names, const std::vector<std::string> &dirs = CONFIG_DIRS);
|
const std::vector<std::string> &names, const std::vector<std::string> &dirs = CONFIG_DIRS);
|
||||||
|
|
||||||
static std::optional<std::string> tryExpandPath(const std::string &base,
|
static std::vector<std::string> tryExpandPath(const std::string &base,
|
||||||
const std::string &filename);
|
const std::string &filename);
|
||||||
|
|
||||||
Config() = default;
|
Config() = default;
|
||||||
|
|
||||||
|
@ -31,6 +31,11 @@ Addressed by *river/tags*
|
|||||||
default: false ++
|
default: false ++
|
||||||
Enables this module to consume all left over space dynamically.
|
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
|
# EXAMPLE
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -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.
|
// there might be "~" or "$HOME" in original path, try to expand it.
|
||||||
auto result = Config::tryExpandPath(menuFile, "");
|
auto result = Config::tryExpandPath(menuFile, "");
|
||||||
if (!result.has_value()) {
|
if (result.empty()) {
|
||||||
throw std::runtime_error("Failed to expand file: " + menuFile);
|
throw std::runtime_error("Failed to expand file: " + menuFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
menuFile = result.value();
|
menuFile = result.front();
|
||||||
// Read the menu descriptor file
|
// Read the menu descriptor file
|
||||||
std::ifstream file(menuFile);
|
std::ifstream file(menuFile);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
|
@ -21,8 +21,8 @@ const std::vector<std::string> Config::CONFIG_DIRS = {
|
|||||||
|
|
||||||
const char *Config::CONFIG_PATH_ENV = "WAYBAR_CONFIG_DIR";
|
const char *Config::CONFIG_PATH_ENV = "WAYBAR_CONFIG_DIR";
|
||||||
|
|
||||||
std::optional<std::string> Config::tryExpandPath(const std::string &base,
|
std::vector<std::string> Config::tryExpandPath(const std::string &base,
|
||||||
const std::string &filename) {
|
const std::string &filename) {
|
||||||
fs::path path;
|
fs::path path;
|
||||||
|
|
||||||
if (!filename.empty()) {
|
if (!filename.empty()) {
|
||||||
@ -33,33 +33,35 @@ std::optional<std::string> Config::tryExpandPath(const std::string &base,
|
|||||||
|
|
||||||
spdlog::debug("Try expanding: {}", path.string());
|
spdlog::debug("Try expanding: {}", path.string());
|
||||||
|
|
||||||
|
std::vector<std::string> results;
|
||||||
wordexp_t p;
|
wordexp_t p;
|
||||||
if (wordexp(path.c_str(), &p, 0) == 0) {
|
if (wordexp(path.c_str(), &p, 0) == 0) {
|
||||||
if (access(*p.we_wordv, F_OK) == 0) {
|
for (size_t i = 0; i < p.we_wordc; i++) {
|
||||||
std::string result = *p.we_wordv;
|
if (access(p.we_wordv[i], F_OK) == 0) {
|
||||||
wordfree(&p);
|
results.emplace_back(p.we_wordv[i]);
|
||||||
spdlog::debug("Found config file: {}", path.string());
|
spdlog::debug("Found config file: {}", p.we_wordv[i]);
|
||||||
return result;
|
}
|
||||||
}
|
}
|
||||||
wordfree(&p);
|
wordfree(&p);
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> Config::findConfigPath(const std::vector<std::string> &names,
|
std::optional<std::string> Config::findConfigPath(const std::vector<std::string> &names,
|
||||||
const std::vector<std::string> &dirs) {
|
const std::vector<std::string> &dirs) {
|
||||||
if (const char *dir = std::getenv(Config::CONFIG_PATH_ENV)) {
|
if (const char *dir = std::getenv(Config::CONFIG_PATH_ENV)) {
|
||||||
for (const auto &name : names) {
|
for (const auto &name : names) {
|
||||||
if (auto res = tryExpandPath(dir, name); res) {
|
if (auto res = tryExpandPath(dir, name); !res.empty()) {
|
||||||
return res;
|
return res.front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &dir : dirs) {
|
for (const auto &dir : dirs) {
|
||||||
for (const auto &name : names) {
|
for (const auto &name : names) {
|
||||||
if (auto res = tryExpandPath(dir, name); res) {
|
if (auto res = tryExpandPath(dir, name); !res.empty()) {
|
||||||
return res;
|
return res.front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,11 +94,15 @@ void Config::resolveConfigIncludes(Json::Value &config, int depth) {
|
|||||||
if (includes.isArray()) {
|
if (includes.isArray()) {
|
||||||
for (const auto &include : includes) {
|
for (const auto &include : includes) {
|
||||||
spdlog::info("Including resource file: {}", include.asString());
|
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()) {
|
} else if (includes.isString()) {
|
||||||
spdlog::info("Including resource file: {}", includes.asString());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ auto waybar::modules::Cava::update() -> void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (silence_ && prm_.sleep_timer) {
|
if (silence_ && prm_.sleep_timer != 0) {
|
||||||
if (sleep_counter_ <=
|
if (sleep_counter_ <=
|
||||||
(int)(std::chrono::milliseconds(prm_.sleep_timer * 1s) / frame_time_milsec_)) {
|
(int)(std::chrono::milliseconds(prm_.sleep_timer * 1s) / frame_time_milsec_)) {
|
||||||
++sleep_counter_;
|
++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_);
|
downThreadDelay(frame_time_milsec_, suspend_silence_delay_);
|
||||||
// Process: execute cava
|
// Process: execute cava
|
||||||
pthread_mutex_lock(&audio_data_.lock);
|
pthread_mutex_lock(&audio_data_.lock);
|
||||||
|
@ -189,10 +189,20 @@ bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Tags::handle_focused_tags(uint32_t tags) {
|
void Tags::handle_focused_tags(uint32_t tags) {
|
||||||
|
auto hide_vacant = config_["hide-vacant"].asBool();
|
||||||
for (size_t i = 0; i < buttons_.size(); ++i) {
|
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 ((1 << i) & tags) {
|
||||||
|
if (hide_vacant && !visible) {
|
||||||
|
buttons_[i].set_visible(true);
|
||||||
|
}
|
||||||
buttons_[i].get_style_context()->add_class("focused");
|
buttons_[i].get_style_context()->add_class("focused");
|
||||||
} else {
|
} else {
|
||||||
|
if (hide_vacant && !(occupied || urgent)) {
|
||||||
|
buttons_[i].set_visible(false);
|
||||||
|
}
|
||||||
buttons_[i].get_style_context()->remove_class("focused");
|
buttons_[i].get_style_context()->remove_class("focused");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,20 +215,40 @@ void Tags::handle_view_tags(struct wl_array *view_tags) {
|
|||||||
for (; view_tag < end; ++view_tag) {
|
for (; view_tag < end; ++view_tag) {
|
||||||
tags |= *view_tag;
|
tags |= *view_tag;
|
||||||
}
|
}
|
||||||
|
auto hide_vacant = config_["hide-vacant"].asBool();
|
||||||
for (size_t i = 0; i < buttons_.size(); ++i) {
|
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 ((1 << i) & tags) {
|
||||||
|
if (hide_vacant && !visible) {
|
||||||
|
buttons_[i].set_visible(true);
|
||||||
|
}
|
||||||
buttons_[i].get_style_context()->add_class("occupied");
|
buttons_[i].get_style_context()->add_class("occupied");
|
||||||
} else {
|
} else {
|
||||||
|
if (hide_vacant && !(focused || urgent)) {
|
||||||
|
buttons_[i].set_visible(false);
|
||||||
|
}
|
||||||
buttons_[i].get_style_context()->remove_class("occupied");
|
buttons_[i].get_style_context()->remove_class("occupied");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tags::handle_urgent_tags(uint32_t 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) {
|
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 ((1 << i) & tags) {
|
||||||
|
if (hide_vacant && !visible) {
|
||||||
|
buttons_[i].set_visible(true);
|
||||||
|
}
|
||||||
buttons_[i].get_style_context()->add_class("urgent");
|
buttons_[i].get_style_context()->add_class("urgent");
|
||||||
} else {
|
} else {
|
||||||
|
if (hide_vacant && !(occupied || focused)) {
|
||||||
|
buttons_[i].set_visible(false);
|
||||||
|
}
|
||||||
buttons_[i].get_style_context()->remove_class("urgent");
|
buttons_[i].get_style_context()->remove_class("urgent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,8 @@ ToolTip get_variant<ToolTip>(const Glib::VariantBase& value) {
|
|||||||
result.text = get_variant<Glib::ustring>(container.get_child(2));
|
result.text = get_variant<Glib::ustring>(container.get_child(2));
|
||||||
auto description = get_variant<Glib::ustring>(container.get_child(3));
|
auto description = get_variant<Glib::ustring>(container.get_child(3));
|
||||||
if (!description.empty()) {
|
if (!description.empty()) {
|
||||||
result.text = fmt::format("<b>{}</b>\n{}", result.text, description);
|
auto escapedDescription = Glib::Markup::escape_text(description);
|
||||||
|
result.text = fmt::format("<b>{}</b>\n{}", result.text, escapedDescription);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <json/value.h>
|
#include <json/value.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace waybar::util {
|
namespace waybar::util {
|
||||||
|
Reference in New Issue
Block a user