From a8a1a4985f2a36e66f62fb52d2b807b091cc94dc Mon Sep 17 00:00:00 2001 From: MisterPine Date: Mon, 10 Jul 2023 23:48:18 +0200 Subject: [PATCH] Add removed secondary identifier (class for xwayland under sway) --- include/AAppIconLabel.hpp | 3 ++- src/AAppIconLabel.cpp | 19 ++++++++++++++----- src/modules/hyprland/window.cpp | 2 +- src/modules/sway/window.cpp | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/AAppIconLabel.hpp b/include/AAppIconLabel.hpp index a2ae4f59..d09ab14a 100644 --- a/include/AAppIconLabel.hpp +++ b/include/AAppIconLabel.hpp @@ -16,7 +16,8 @@ class AAppIconLabel : public AIconLabel { auto update() -> void override; protected: - void updateAppIconName(const std::string &app_identifier); + void updateAppIconName(const std::string &app_identifier, + const std::string &alternative_app_identifier); void updateAppIcon(); unsigned app_icon_size_{24}; bool update_app_icon_{true}; diff --git a/src/AAppIconLabel.cpp b/src/AAppIconLabel.cpp index 6e3d1641..a238143b 100644 --- a/src/AAppIconLabel.cpp +++ b/src/AAppIconLabel.cpp @@ -24,7 +24,8 @@ AAppIconLabel::AAppIconLabel(const Json::Value& config, const std::string& name, image_.set_pixel_size(app_icon_size_); } -std::optional getDesktopFilePath(const std::string& app_identifier) { +std::optional getDesktopFilePath(const std::string& app_identifier, + const std::string& alternative_app_identifier) { const auto data_dirs = Glib::get_system_data_dirs(); for (const auto& data_dir : data_dirs) { const auto data_app_dir = data_dir + "applications/"; @@ -32,12 +33,19 @@ std::optional getDesktopFilePath(const std::string& app_identifier) if (std::filesystem::exists(desktop_file_path)) { return desktop_file_path; } + if (!alternative_app_identifier.empty()) { + desktop_file_path = data_app_dir + alternative_app_identifier + ".desktop"; + if (std::filesystem::exists(desktop_file_path)) { + return desktop_file_path; + } + } } return {}; } -std::optional getIconName(const std::string& app_identifier) { - const auto desktop_file_path = getDesktopFilePath(app_identifier); +std::optional getIconName(const std::string& app_identifier, + const std::string& alternative_app_identifier) { + const auto desktop_file_path = getDesktopFilePath(app_identifier, alternative_app_identifier); if (!desktop_file_path.has_value()) { // Try some heuristics to find a matching icon @@ -90,12 +98,13 @@ std::optional getIconName(const std::string& app_identifier) { return {}; } -void AAppIconLabel::updateAppIconName(const std::string& app_identifier) { +void AAppIconLabel::updateAppIconName(const std::string& app_identifier, + const std::string& alternative_app_identifier) { if (!iconEnabled()) { return; } - const auto icon_name = getIconName(app_identifier); + const auto icon_name = getIconName(app_identifier, alternative_app_identifier); if (icon_name.has_value()) { app_icon_name_ = icon_name.value(); } else { diff --git a/src/modules/hyprland/window.cpp b/src/modules/hyprland/window.cpp index cb7bf756..f3b2a767 100644 --- a/src/modules/hyprland/window.cpp +++ b/src/modules/hyprland/window.cpp @@ -152,7 +152,7 @@ void Window::queryActiveWorkspace() { } window_data_ = WindowData::parse(*active_window); - updateAppIconName(window_data_.class_name); + updateAppIconName(window_data_.class_name, window_data_.initial_class_name); std::vector workspace_windows; std::copy_if(clients.begin(), clients.end(), std::back_inserter(workspace_windows), [&](Json::Value window) { diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index ef076285..06acdcaa 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -43,7 +43,7 @@ void Window::onCmd(const struct Ipc::ipc_response& res) { auto output = payload["output"].isString() ? payload["output"].asString() : ""; std::tie(app_nb_, floating_count_, windowId_, window_, app_id_, app_class_, shell_, layout_) = getFocusedNode(payload["nodes"], output); - updateAppIconName(app_id_); + updateAppIconName(app_id_, app_class_); dp.emit(); } catch (const std::exception& e) { spdlog::error("Window: {}", e.what());