Add removed secondary identifier

(class for xwayland under sway)
This commit is contained in:
MisterPine 2023-07-10 23:48:18 +02:00
parent 31683d9e2a
commit a8a1a4985f
No known key found for this signature in database
GPG Key ID: 5481659D1D983422
4 changed files with 18 additions and 8 deletions

View File

@ -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};

View File

@ -24,7 +24,8 @@ AAppIconLabel::AAppIconLabel(const Json::Value& config, const std::string& name,
image_.set_pixel_size(app_icon_size_);
}
std::optional<std::string> getDesktopFilePath(const std::string& app_identifier) {
std::optional<std::string> 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<std::string> 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<Glib::ustring> getIconName(const std::string& app_identifier) {
const auto desktop_file_path = getDesktopFilePath(app_identifier);
std::optional<Glib::ustring> 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<Glib::ustring> 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 {

View File

@ -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<Json::Value> workspace_windows;
std::copy_if(clients.begin(), clients.end(), std::back_inserter(workspace_windows),
[&](Json::Value window) {

View File

@ -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());