Merge pull request #2677 from sjoblomj/master

Using 'image-missing' fallback if no taskbar icon is found
This commit is contained in:
Alexis Rouillard 2023-11-20 14:03:52 +01:00 committed by GitHub
commit 061c68ce92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 3 deletions

View File

@ -22,6 +22,7 @@
#include "util/format.hpp"
#include "util/rewrite_string.hpp"
#include "util/string.hpp"
#include "util/gtk_icon.hpp"
namespace waybar::modules::wlr {
@ -182,11 +183,21 @@ bool Task::image_load_icon(Gtk::Image &image, const Glib::RefPtr<Gtk::IconTheme>
try {
pixbuf = icon_theme->load_icon(ret_icon_name, scaled_icon_size, Gtk::ICON_LOOKUP_FORCE_SIZE);
spdlog::debug("{} Loaded icon '{}'", repr(), ret_icon_name);
} catch (...) {
if (Glib::file_test(ret_icon_name, Glib::FILE_TEST_EXISTS))
if (Glib::file_test(ret_icon_name, Glib::FILE_TEST_EXISTS)) {
pixbuf = load_icon_from_file(ret_icon_name, scaled_icon_size);
else
pixbuf = {};
spdlog::debug("{} Loaded icon from file '{}'", repr(), ret_icon_name);
} else {
try {
pixbuf = DefaultGtkIconThemeWrapper::load_icon("image-missing", scaled_icon_size,
Gtk::IconLookupFlags::ICON_LOOKUP_FORCE_SIZE);
spdlog::debug("{} Loaded icon from resource", repr());
} catch (...) {
pixbuf = {};
spdlog::debug("{} Unable to load icon.", repr());
}
}
}
if (pixbuf) {
@ -304,6 +315,10 @@ Task::Task(const waybar::Bar &bar, const Json::Value &config, Taskbar *tbar,
with_icon_ = true;
}
if (app_id_.empty()) {
handle_app_id("unknown");
}
/* Strip spaces at the beginning and end of the format strings */
format_tooltip_.clear();
if (!config_["tooltip"].isBool() || config_["tooltip"].asBool()) {
@ -392,6 +407,11 @@ void Task::hide_if_ignored() {
}
void Task::handle_app_id(const char *app_id) {
if (app_id_.empty()) {
spdlog::debug(fmt::format("Task ({}) setting app_id to {}", id_, app_id));
} else {
spdlog::debug(fmt::format("Task ({}) overwriting app_id '{}' with '{}'", id_, app_id_, app_id));
}
app_id_ = app_id;
hide_if_ignored();