diff --git a/src/common/utils/excluded_apps.h b/src/common/utils/excluded_apps.h index bbfdd93562..fed45a8b83 100644 --- a/src/common/utils/excluded_apps.h +++ b/src/common/utils/excluded_apps.h @@ -32,7 +32,7 @@ inline bool find_folder_in_path(const std::wstring& where, const std::vector& excludedApps) +inline bool check_excluded_app_with_title(const HWND& hwnd, const std::vector& excludedApps) { WCHAR title[MAX_TITLE_LENGTH]; int len = GetWindowTextW(hwnd, title, MAX_TITLE_LENGTH); @@ -42,23 +42,25 @@ inline bool check_excluded_app_with_title(const HWND& hwnd, std::wstring& proces } std::wstring titleStr(title); - auto lastBackslashPos = processPath.find_last_of(L'\\'); - if (lastBackslashPos != std::wstring::npos) + CharUpperBuffW(titleStr.data(), static_cast(titleStr.length())); + + for (const auto& app : excludedApps) { - processPath = processPath.substr(0, lastBackslashPos + 1); // retain up to the last backslash - processPath.append(titleStr); // append the title + if (titleStr.contains(app)) + { + return true; + } } - CharUpperBuffW(processPath.data(), static_cast(processPath.length())); - return find_app_name_in_path(processPath, excludedApps); + return false; } -inline bool check_excluded_app(const HWND& hwnd, std::wstring& processPath, const std::vector& excludedApps) +inline bool check_excluded_app(const HWND& hwnd, const std::wstring& processPath, const std::vector& excludedApps) { bool res = find_app_name_in_path(processPath, excludedApps); if (!res) { - res = check_excluded_app_with_title(hwnd, processPath, excludedApps); + res = check_excluded_app_with_title(hwnd, excludedApps); } return res; diff --git a/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp b/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp index 14a9074180..fb68945154 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp +++ b/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp @@ -202,12 +202,12 @@ bool FancyZonesWindowUtils::IsExcluded(HWND window) return false; } -bool FancyZonesWindowUtils::IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept +bool FancyZonesWindowUtils::IsExcludedByUser(const HWND& hwnd, const std::wstring& processPath) noexcept { return (check_excluded_app(hwnd, processPath, FancyZonesSettings::settings().excludedAppsArray)); } -bool FancyZonesWindowUtils::IsExcludedByDefault(const HWND& hwnd, std::wstring& processPath) noexcept +bool FancyZonesWindowUtils::IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) noexcept { static std::vector defaultExcludedFolders = { NonLocalizable::SystemAppsFolder }; if (find_folder_in_path(processPath, defaultExcludedFolders)) diff --git a/src/modules/fancyzones/FancyZonesLib/WindowUtils.h b/src/modules/fancyzones/FancyZonesLib/WindowUtils.h index d330e36e09..72ea73e96f 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowUtils.h +++ b/src/modules/fancyzones/FancyZonesLib/WindowUtils.h @@ -27,8 +27,8 @@ namespace FancyZonesWindowUtils bool IsProcessOfWindowElevated(HWND window); // If HWND is already dead, we assume it wasn't elevated bool IsExcluded(HWND window); - bool IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept; - bool IsExcludedByDefault(const HWND& hwnd, std::wstring& processPath) noexcept; + bool IsExcludedByUser(const HWND& hwnd, const std::wstring& processPath) noexcept; + bool IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) noexcept; void SwitchToWindow(HWND window) noexcept; void SizeWindowToRect(HWND window, RECT rect) noexcept; // Parameter rect must be in screen coordinates (e.g. obtained from GetWindowRect)