From e92b0a86b5595a3c130f9c2fded724c71ac89d35 Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Mon, 7 Apr 2025 20:33:18 +0200 Subject: [PATCH 1/2] wlr/taskbar: find icon by title as fallback --- src/modules/wlr/taskbar.cpp | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 30e4ee48..3c188dd0 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -382,9 +382,40 @@ std::string Task::state_string(bool shortened) const { return res.substr(0, res.size() - 1); } -void Task::handle_title(const char *title) { - title_ = title; - hide_if_ignored(); +void Task::handle_title(const char* title) { + title_ = title; + hide_if_ignored(); + + // Skip if we already have app info or no title + if (app_info_ || title_.empty()) { + return; + } + + // Try exact title match + app_info_ = get_desktop_app_info(title_); + + // Try lowercase version if still needed + if (!app_info_) { + std::string lower_title = title_; + std::transform(lower_title.begin(), lower_title.end(), lower_title.begin(), ::tolower); + app_info_ = get_desktop_app_info(lower_title); + } + + // If we found a match, update name and icon + if (app_info_) { + name_ = app_info_->get_display_name(); + spdlog::info("Found desktop file via title fallback: {}", name_); + + if (with_icon_) { + const int icon_size = config_["icon-size"].isInt() ? config_["icon-size"].asInt() : 16; + for (auto& icon_theme : tbar_->icon_themes()) { + if (image_load_icon(icon_, icon_theme, app_info_, icon_size)) { + icon_.show(); + break; + } + } + } + } } void Task::set_minimize_hint() { From addf44d9457ae6f17e73cb4b428b7d3be242390c Mon Sep 17 00:00:00 2001 From: Clemens Horn Date: Mon, 7 Apr 2025 20:51:35 +0200 Subject: [PATCH 2/2] test --- src/modules/wlr/taskbar.cpp | 59 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index 3c188dd0..1169425a 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -383,39 +383,38 @@ std::string Task::state_string(bool shortened) const { } void Task::handle_title(const char* title) { - title_ = title; - hide_if_ignored(); + if (title_.empty()) { + spdlog::debug(fmt::format("Task ({}) setting title to {}", id_, title_)); + } else { + spdlog::debug(fmt::format("Task ({}) overwriting title '{}' with '{}'", id_, title_, title)); + } + title_ = title; + hide_if_ignored(); - // Skip if we already have app info or no title - if (app_info_ || title_.empty()) { - return; + if (!with_icon_ && !with_name_ || app_info_) { + return; + } + + set_app_info_from_app_id_list(title_); + name_ = app_info_ ? app_info_->get_display_name() : title; + + 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_info_, icon_size)) { + found = true; + break; } + } - // Try exact title match - app_info_ = get_desktop_app_info(title_); - - // Try lowercase version if still needed - if (!app_info_) { - std::string lower_title = title_; - std::transform(lower_title.begin(), lower_title.end(), lower_title.begin(), ::tolower); - app_info_ = get_desktop_app_info(lower_title); - } - - // If we found a match, update name and icon - if (app_info_) { - name_ = app_info_->get_display_name(); - spdlog::info("Found desktop file via title fallback: {}", name_); - - if (with_icon_) { - const int icon_size = config_["icon-size"].isInt() ? config_["icon-size"].asInt() : 16; - for (auto& icon_theme : tbar_->icon_themes()) { - if (image_load_icon(icon_, icon_theme, app_info_, icon_size)) { - icon_.show(); - break; - } - } - } - } + if (found) + icon_.show(); + else + spdlog::debug("Couldn't find icon for {}", title_); } void Task::set_minimize_hint() {