From 8cb632a0c289f1e7eaef1bf8a88bb77080bfdb44 Mon Sep 17 00:00:00 2001 From: gokcekantarci <115616017+gokcekantarci@users.noreply.github.com> Date: Fri, 23 Jun 2023 22:53:15 +0300 Subject: [PATCH] =?UTF-8?q?[QuickAccent]=20A=20check=20is=20added=20to=20a?= =?UTF-8?q?pplications=20running=20under=20other=20ap=E2=80=A6=20(#26808)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [QuickAccent] A check is added to applications running under other applications with window name for excluding. * [QuickAccent] Check moved under a general function and applied all modules includes excludeapp * [QuickAccent] Function name revised * [QuickAccent] check_excluded_app_with_title function moved to excluded_apps.h * [QuickAccent] New function created for clean code. * Reuse check_excluded_app_with_title --------- Co-authored-by: Stefan Markovic --- src/common/utils/excluded_apps.h | 33 +++++++++++++++++++ .../MouseUtils/FindMyMouse/FindMyMouse.cpp | 3 +- .../alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp | 3 +- .../fancyzones/FancyZonesLib/WindowUtils.cpp | 13 ++++---- .../fancyzones/FancyZonesLib/WindowUtils.h | 4 +-- .../KeyboardListener.cpp | 2 +- 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/common/utils/excluded_apps.h b/src/common/utils/excluded_apps.h index 36c42b2d21..bbfdd93562 100644 --- a/src/common/utils/excluded_apps.h +++ b/src/common/utils/excluded_apps.h @@ -30,3 +30,36 @@ inline bool find_folder_in_path(const std::wstring& where, const std::vector& excludedApps) +{ + WCHAR title[MAX_TITLE_LENGTH]; + int len = GetWindowTextW(hwnd, title, MAX_TITLE_LENGTH); + if (len <= 0) + { + return false; + } + + std::wstring titleStr(title); + auto lastBackslashPos = processPath.find_last_of(L'\\'); + if (lastBackslashPos != std::wstring::npos) + { + processPath = processPath.substr(0, lastBackslashPos + 1); // retain up to the last backslash + processPath.append(titleStr); // append the title + } + CharUpperBuffW(processPath.data(), static_cast(processPath.length())); + return find_app_name_in_path(processPath, excludedApps); +} + +inline bool check_excluded_app(const HWND& hwnd, 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); + } + + return res; +} diff --git a/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp b/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp index f768931d97..b1d1bf4f18 100644 --- a/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp +++ b/src/modules/MouseUtils/FindMyMouse/FindMyMouse.cpp @@ -593,7 +593,8 @@ bool SuperSonar::IsForegroundAppExcluded() { auto processPath = get_process_path(foregroundApp); CharUpperBuffW(processPath.data(), static_cast(processPath.length())); - return find_app_name_in_path(processPath, m_excludedApps); + + return check_excluded_app(foregroundApp, processPath, m_excludedApps); } else { diff --git a/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp b/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp index b61b75ea8d..31c774ea91 100644 --- a/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp +++ b/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp @@ -24,7 +24,8 @@ bool isExcluded(HWND window) { auto processPath = get_process_path(window); CharUpperBuffW(processPath.data(), static_cast(processPath.length())); - return find_app_name_in_path(processPath, AlwaysOnTopSettings::settings().excludedApps); + + return check_excluded_app(window, processPath, AlwaysOnTopSettings::settings().excludedApps); } AlwaysOnTop::AlwaysOnTop(bool useLLKH) : diff --git a/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp b/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp index c9252ba5df..40f22ea802 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp +++ b/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp @@ -26,6 +26,7 @@ namespace NonLocalizable enum DWMWINDOWATTRIBUTE_CUSTOM { DWMWA_WINDOW_CORNER_PREFERENCE = 33 + }; enum DWM_WINDOW_CORNER_PREFERENCE @@ -227,12 +228,12 @@ bool FancyZonesWindowUtils::IsCandidateForZoning(HWND window) std::wstring processPath = get_process_path_waiting_uwp(window); CharUpperBuffW(const_cast(processPath).data(), static_cast(processPath.length())); - if (IsExcludedByUser(processPath)) + if (IsExcludedByUser(window, processPath)) { return false; } - if (IsExcludedByDefault(processPath)) + if (IsExcludedByDefault(window, processPath)) { return false; } @@ -267,12 +268,12 @@ bool FancyZonesWindowUtils::IsProcessOfWindowElevated(HWND window) return false; } -bool FancyZonesWindowUtils::IsExcludedByUser(const std::wstring& processPath) noexcept +bool FancyZonesWindowUtils::IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept { - return (find_app_name_in_path(processPath, FancyZonesSettings::settings().excludedAppsArray)); + return (check_excluded_app(hwnd, processPath, FancyZonesSettings::settings().excludedAppsArray)); } -bool FancyZonesWindowUtils::IsExcludedByDefault(const std::wstring& processPath) noexcept +bool FancyZonesWindowUtils::IsExcludedByDefault(const HWND& hwnd, std::wstring& processPath) noexcept { static std::vector defaultExcludedFolders = { NonLocalizable::SystemAppsFolder }; if (find_folder_in_path(processPath, defaultExcludedFolders)) @@ -281,7 +282,7 @@ bool FancyZonesWindowUtils::IsExcludedByDefault(const std::wstring& processPath) } static std::vector defaultExcludedApps = { NonLocalizable::PowerToysAppFZEditor, NonLocalizable::CoreWindow, NonLocalizable::SearchUI }; - return (find_app_name_in_path(processPath, defaultExcludedApps)); + return (check_excluded_app(hwnd, processPath, defaultExcludedApps)); } void FancyZonesWindowUtils::SwitchToWindow(HWND window) noexcept diff --git a/src/modules/fancyzones/FancyZonesLib/WindowUtils.h b/src/modules/fancyzones/FancyZonesLib/WindowUtils.h index d935587e42..9659d78b9c 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowUtils.h +++ b/src/modules/fancyzones/FancyZonesLib/WindowUtils.h @@ -23,8 +23,8 @@ namespace FancyZonesWindowUtils bool HasThickFrameAndMinimizeMaximizeButtons(HWND window) noexcept; bool IsCandidateForZoning(HWND window); bool IsProcessOfWindowElevated(HWND window); // If HWND is already dead, we assume it wasn't elevated - bool IsExcludedByUser(const std::wstring& processPath) noexcept; - bool IsExcludedByDefault(const std::wstring& processPath) noexcept; + bool IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept; + bool IsExcludedByDefault(const HWND& hwnd, 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) diff --git a/src/modules/poweraccent/PowerAccentKeyboardService/KeyboardListener.cpp b/src/modules/poweraccent/PowerAccentKeyboardService/KeyboardListener.cpp index 79aee387fc..11ba7afc93 100644 --- a/src/modules/poweraccent/PowerAccentKeyboardService/KeyboardListener.cpp +++ b/src/modules/poweraccent/PowerAccentKeyboardService/KeyboardListener.cpp @@ -131,7 +131,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation auto processPath = get_process_path(foregroundApp); CharUpperBuffW(processPath.data(), static_cast(processPath.length())); m_prevForegroundAppExcl = { foregroundApp, - find_app_name_in_path(processPath, m_settings.excludedApps) }; + check_excluded_app(foregroundApp, processPath, m_settings.excludedApps) }; return m_prevForegroundAppExcl.second; }