[QuickAccent] A check is added to applications running under other ap… (#26808)

* [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 <stefan@janeasystems.com>
This commit is contained in:
gokcekantarci 2023-06-23 22:53:15 +03:00 committed by GitHub
parent b8a253fda6
commit 8cb632a0c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 11 deletions

View File

@ -30,3 +30,36 @@ inline bool find_folder_in_path(const std::wstring& where, const std::vector<std
} }
return false; return false;
} }
#define MAX_TITLE_LENGTH 255
inline bool check_excluded_app_with_title(const HWND& hwnd, std::wstring& processPath, const std::vector<std::wstring>& 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<DWORD>(processPath.length()));
return find_app_name_in_path(processPath, excludedApps);
}
inline bool check_excluded_app(const HWND& hwnd, std::wstring& processPath, const std::vector<std::wstring>& excludedApps)
{
bool res = find_app_name_in_path(processPath, excludedApps);
if (!res)
{
res = check_excluded_app_with_title(hwnd, processPath, excludedApps);
}
return res;
}

View File

@ -593,7 +593,8 @@ bool SuperSonar<D>::IsForegroundAppExcluded()
{ {
auto processPath = get_process_path(foregroundApp); auto processPath = get_process_path(foregroundApp);
CharUpperBuffW(processPath.data(), static_cast<DWORD>(processPath.length())); CharUpperBuffW(processPath.data(), static_cast<DWORD>(processPath.length()));
return find_app_name_in_path(processPath, m_excludedApps);
return check_excluded_app(foregroundApp, processPath, m_excludedApps);
} }
else else
{ {

View File

@ -24,7 +24,8 @@ bool isExcluded(HWND window)
{ {
auto processPath = get_process_path(window); auto processPath = get_process_path(window);
CharUpperBuffW(processPath.data(), static_cast<DWORD>(processPath.length())); CharUpperBuffW(processPath.data(), static_cast<DWORD>(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) : AlwaysOnTop::AlwaysOnTop(bool useLLKH) :

View File

@ -26,6 +26,7 @@ namespace NonLocalizable
enum DWMWINDOWATTRIBUTE_CUSTOM enum DWMWINDOWATTRIBUTE_CUSTOM
{ {
DWMWA_WINDOW_CORNER_PREFERENCE = 33 DWMWA_WINDOW_CORNER_PREFERENCE = 33
}; };
enum DWM_WINDOW_CORNER_PREFERENCE enum DWM_WINDOW_CORNER_PREFERENCE
@ -227,12 +228,12 @@ bool FancyZonesWindowUtils::IsCandidateForZoning(HWND window)
std::wstring processPath = get_process_path_waiting_uwp(window); std::wstring processPath = get_process_path_waiting_uwp(window);
CharUpperBuffW(const_cast<std::wstring&>(processPath).data(), static_cast<DWORD>(processPath.length())); CharUpperBuffW(const_cast<std::wstring&>(processPath).data(), static_cast<DWORD>(processPath.length()));
if (IsExcludedByUser(processPath)) if (IsExcludedByUser(window, processPath))
{ {
return false; return false;
} }
if (IsExcludedByDefault(processPath)) if (IsExcludedByDefault(window, processPath))
{ {
return false; return false;
} }
@ -267,12 +268,12 @@ bool FancyZonesWindowUtils::IsProcessOfWindowElevated(HWND window)
return false; 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<std::wstring> defaultExcludedFolders = { NonLocalizable::SystemAppsFolder }; static std::vector<std::wstring> defaultExcludedFolders = { NonLocalizable::SystemAppsFolder };
if (find_folder_in_path(processPath, defaultExcludedFolders)) if (find_folder_in_path(processPath, defaultExcludedFolders))
@ -281,7 +282,7 @@ bool FancyZonesWindowUtils::IsExcludedByDefault(const std::wstring& processPath)
} }
static std::vector<std::wstring> defaultExcludedApps = { NonLocalizable::PowerToysAppFZEditor, NonLocalizable::CoreWindow, NonLocalizable::SearchUI }; static std::vector<std::wstring> 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 void FancyZonesWindowUtils::SwitchToWindow(HWND window) noexcept

View File

@ -23,8 +23,8 @@ namespace FancyZonesWindowUtils
bool HasThickFrameAndMinimizeMaximizeButtons(HWND window) noexcept; bool HasThickFrameAndMinimizeMaximizeButtons(HWND window) noexcept;
bool IsCandidateForZoning(HWND window); bool IsCandidateForZoning(HWND window);
bool IsProcessOfWindowElevated(HWND window); // If HWND is already dead, we assume it wasn't elevated bool IsProcessOfWindowElevated(HWND window); // If HWND is already dead, we assume it wasn't elevated
bool IsExcludedByUser(const std::wstring& processPath) noexcept; bool IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept;
bool IsExcludedByDefault(const std::wstring& processPath) noexcept; bool IsExcludedByDefault(const HWND& hwnd, std::wstring& processPath) noexcept;
void SwitchToWindow(HWND window) 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) void SizeWindowToRect(HWND window, RECT rect) noexcept; // Parameter rect must be in screen coordinates (e.g. obtained from GetWindowRect)

View File

@ -131,7 +131,7 @@ namespace winrt::PowerToys::PowerAccentKeyboardService::implementation
auto processPath = get_process_path(foregroundApp); auto processPath = get_process_path(foregroundApp);
CharUpperBuffW(processPath.data(), static_cast<DWORD>(processPath.length())); CharUpperBuffW(processPath.data(), static_cast<DWORD>(processPath.length()));
m_prevForegroundAppExcl = { foregroundApp, m_prevForegroundAppExcl = { foregroundApp,
find_app_name_in_path(processPath, m_settings.excludedApps) }; check_excluded_app(foregroundApp, processPath, m_settings.excludedApps) };
return m_prevForegroundAppExcl.second; return m_prevForegroundAppExcl.second;
} }