Add support for multiple icon themes in the config
If there are multiple icon themes defined in the config option 'icon-theme' the module will try from left to right to find an icon. The system default will always be added to this list.pull/766/head
parent
b7e8275d90
commit
06ad35c42b
|
@ -131,7 +131,7 @@ class Taskbar : public waybar::AModule
|
||||||
Gtk::Box box_;
|
Gtk::Box box_;
|
||||||
std::vector<TaskPtr> tasks_;
|
std::vector<TaskPtr> tasks_;
|
||||||
|
|
||||||
Glib::RefPtr<Gtk::IconTheme> icon_theme_;
|
std::vector<Glib::RefPtr<Gtk::IconTheme>> icon_themes_;
|
||||||
|
|
||||||
struct zwlr_foreign_toplevel_manager_v1 *manager_;
|
struct zwlr_foreign_toplevel_manager_v1 *manager_;
|
||||||
struct wl_seat *seat_;
|
struct wl_seat *seat_;
|
||||||
|
@ -154,7 +154,7 @@ class Taskbar : public waybar::AModule
|
||||||
bool show_output(struct wl_output *) const;
|
bool show_output(struct wl_output *) const;
|
||||||
bool all_outputs() const;
|
bool all_outputs() const;
|
||||||
|
|
||||||
Glib::RefPtr<Gtk::IconTheme> icon_theme() const;
|
std::vector<Glib::RefPtr<Gtk::IconTheme>> icon_themes() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace waybar::modules::wlr */
|
} /* namespace waybar::modules::wlr */
|
||||||
|
|
|
@ -25,7 +25,7 @@ Addressed by *wlr/taskbar*
|
||||||
|
|
||||||
*icon-theme*: ++
|
*icon-theme*: ++
|
||||||
typeof: string ++
|
typeof: string ++
|
||||||
The name of the icon-theme that should be used. If omitted, the system default will be used.
|
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*: ++
|
*icon-size*: ++
|
||||||
typeof: integer ++
|
typeof: integer ++
|
||||||
|
|
|
@ -298,12 +298,23 @@ void Task::handle_title(const char *title)
|
||||||
void Task::handle_app_id(const char *app_id)
|
void Task::handle_app_id(const char *app_id)
|
||||||
{
|
{
|
||||||
app_id_ = app_id;
|
app_id_ = app_id;
|
||||||
if (!image_load_icon(icon_, tbar_->icon_theme(), app_id_,
|
|
||||||
config_["icon-size"].isInt() ? config_["icon-size"].asInt() : 16))
|
|
||||||
spdlog::warn("Failed to load icon for {}", app_id);
|
|
||||||
|
|
||||||
if (with_icon_)
|
if (!with_icon_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int icon_size = config_["icon-size"].isInt() ? config_["icon-size"].asInt() : 16;
|
||||||
|
bool found = false;
|
||||||
|
for (auto& icon_theme : tbar_->icon_themes()) {
|
||||||
|
if (image_load_icon(icon_, icon_theme, app_id_, icon_size)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found)
|
||||||
icon_.show();
|
icon_.show();
|
||||||
|
else
|
||||||
|
spdlog::debug("Couldn't find icon for {}", app_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Task::handle_output_enter(struct wl_output *output)
|
void Task::handle_output_enter(struct wl_output *output)
|
||||||
|
@ -555,13 +566,23 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu
|
||||||
|
|
||||||
/* Get the configured icon theme if specified */
|
/* Get the configured icon theme if specified */
|
||||||
if (config_["icon-theme"].isString()) {
|
if (config_["icon-theme"].isString()) {
|
||||||
icon_theme_ = Gtk::IconTheme::create();
|
auto icon_theme_config = config_["icon-theme"].asString();
|
||||||
icon_theme_->set_custom_theme(config_["icon-theme"].asString());
|
size_t start = 0, end = 0;
|
||||||
spdlog::debug("Use custom icon theme: {}.", config_["icon-theme"].asString());
|
|
||||||
} else {
|
do {
|
||||||
spdlog::debug("Use system default icon theme");
|
end = icon_theme_config.find(',', start);
|
||||||
icon_theme_ = Gtk::IconTheme::get_default();
|
auto it_name = trim(icon_theme_config.substr(start, end-start));
|
||||||
|
|
||||||
|
auto it = Gtk::IconTheme::create();
|
||||||
|
it->set_custom_theme(it_name);
|
||||||
|
spdlog::debug("Use custom icon theme: {}", it_name);
|
||||||
|
|
||||||
|
icon_themes_.push_back(it);
|
||||||
|
|
||||||
|
start = end == std::string::npos ? end : end + 1;
|
||||||
|
} while(end != std::string::npos);
|
||||||
}
|
}
|
||||||
|
icon_themes_.push_back(Gtk::IconTheme::get_default());
|
||||||
}
|
}
|
||||||
|
|
||||||
Taskbar::~Taskbar()
|
Taskbar::~Taskbar()
|
||||||
|
@ -677,9 +698,9 @@ bool Taskbar::all_outputs() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::RefPtr<Gtk::IconTheme> Taskbar::icon_theme() const
|
std::vector<Glib::RefPtr<Gtk::IconTheme>> Taskbar::icon_themes() const
|
||||||
{
|
{
|
||||||
return icon_theme_;
|
return icon_themes_;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace waybar::modules::wlr */
|
} /* namespace waybar::modules::wlr */
|
||||||
|
|
Loading…
Reference in New Issue