From bc112eaae114403e19145bf64e898c499772385c Mon Sep 17 00:00:00 2001 From: Till Smejkal Date: Tue, 7 Jul 2020 11:22:08 +0200 Subject: [PATCH] Convert icon-theme option to array|string Use the config support of using arrays in its options instead of the complicated and error-prone parsing of the string. --- man/waybar-wlr-taskbar.5.scd | 2 +- src/modules/wlr/taskbar.cpp | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/man/waybar-wlr-taskbar.5.scd b/man/waybar-wlr-taskbar.5.scd index 24946e1a..f0444122 100644 --- a/man/waybar-wlr-taskbar.5.scd +++ b/man/waybar-wlr-taskbar.5.scd @@ -24,7 +24,7 @@ Addressed by *wlr/taskbar* The format, how information should be displayed. *icon-theme*: ++ - typeof: string ++ + typeof: array|string ++ The names of the icon-themes that should be used to find an icon. The list will be traversed from left to right. If omitted, the system default will be used. *icon-size*: ++ diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index b440dfc4..23a91661 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -579,22 +579,24 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu } /* Get the configured icon theme if specified */ - if (config_["icon-theme"].isString()) { - auto icon_theme_config = config_["icon-theme"].asString(); - size_t start = 0, end = 0; - - do { - end = icon_theme_config.find(',', start); - auto it_name = trim(icon_theme_config.substr(start, end-start)); + if (config_["icon-theme"].isArray()) { + for (auto& c : config_["icon-theme"]) { + auto it_name = c.asString(); auto it = Gtk::IconTheme::create(); it->set_custom_theme(it_name); spdlog::debug("Use custom icon theme: {}", it_name); icon_themes_.push_back(it); + } + } else if (config_["icon-theme"].isString()) { + auto it_name = config_["icon-theme"].asString(); - start = end == std::string::npos ? end : end + 1; - } while(end != std::string::npos); + auto it = Gtk::IconTheme::create(); + it->set_custom_theme(it_name); + spdlog::debug("Use custom icon theme: {}", it_name); + + icon_themes_.push_back(it); } icon_themes_.push_back(Gtk::IconTheme::get_default()); }