[FancyZones]Modern apps snapping fix, refactor and tests (#29499)

* popup windows check

* use minimize maximize buttons check

* update test utils

* added tests

* define types for easier testing

* changed checks order

* remove option check

* upd test

* remove FZ popup option

* max min buttons -> caption

* calculator test

* updated excluded tests

* add asserts to child window test

* update window creation

* splash screen refactor

* remove hotfix part

* replace style checking functions

* remove no longer necessary check

* tool window check fix

* fix mouse snapping check

* added check and test for non-root window

* spelling

* Revert "remove FZ popup option"

This reverts commit 26732ad683.

* skip child window tests in CI

* remove the option

* remove the constant

* updated tests
This commit is contained in:
Seraphima Zykova
2023-11-21 21:41:55 +01:00
committed by GitHub
parent 1a8007ca0a
commit f9cbff6976
21 changed files with 335 additions and 185 deletions

View File

@@ -5,52 +5,68 @@
#include <FancyZonesLib/VirtualDesktop.h>
#include <FancyZonesLib/WindowUtils.h>
bool FancyZonesWindowProcessing::IsProcessable(HWND window) noexcept
FancyZonesWindowProcessing::ProcessabilityType FancyZonesWindowProcessing::DefineWindowType(HWND window) noexcept
{
const bool isSplashScreen = FancyZonesWindowUtils::IsSplashScreen(window);
if (isSplashScreen)
{
return false;
}
const bool windowMinimized = IsIconic(window);
if (windowMinimized)
{
return false;
return ProcessabilityType::Minimized;
}
const bool standard = FancyZonesWindowUtils::IsStandardWindow(window);
if (!standard)
auto style = GetWindowLong(window, GWL_STYLE);
auto exStyle = GetWindowLong(window, GWL_EXSTYLE);
if (!FancyZonesWindowUtils::HasStyle(style, WS_VISIBLE))
{
return false;
return ProcessabilityType::NotVisible;
}
// popup could be the window we don't want to snap: start menu, notification popup, tray window, etc.
// also, popup could be the windows we want to snap disregarding the "allowSnapPopupWindows" setting, e.g. Telegram
bool isPopup = FancyZonesWindowUtils::IsPopupWindow(window) && !FancyZonesWindowUtils::HasThickFrameAndMinimizeMaximizeButtons(window);
if (isPopup && !FancyZonesSettings::settings().allowSnapPopupWindows)
if (FancyZonesWindowUtils::HasStyle(exStyle, WS_EX_TOOLWINDOW))
{
return false;
return ProcessabilityType::ToolWindow;
}
if (!FancyZonesWindowUtils::IsRoot(window))
{
// child windows such as buttons, combo boxes, etc.
return ProcessabilityType::NonRootWindow;
}
bool isPopup = FancyZonesWindowUtils::HasStyle(style, WS_POPUP);
bool hasThickFrame = FancyZonesWindowUtils::HasStyle(style, WS_THICKFRAME);
bool hasCaption = FancyZonesWindowUtils::HasStyle(style, WS_CAPTION);
if (isPopup && !(hasThickFrame && hasCaption))
{
// popup windows we want to snap: e.g. Calculator, Telegram
// popup windows we don't want to snap: start menu, notification popup, tray window, etc.
// WS_CAPTION is used for filtering out menus,
// e.g., in Edge "Running as admin" menu when creating a new PowerToys issue.
return ProcessabilityType::NonProcessablePopupWindow;
}
// allow child windows
auto hasOwner = FancyZonesWindowUtils::HasVisibleOwner(window);
if (hasOwner && !FancyZonesSettings::settings().allowSnapChildWindows)
{
return false;
return ProcessabilityType::ChildWindow;
}
if (FancyZonesWindowUtils::IsExcluded(window))
{
return false;
return ProcessabilityType::Excluded;
}
// Switch between virtual desktops results with posting same windows messages that also indicate
// creation of new window. We need to check if window being processed is on currently active desktop.
if (!VirtualDesktop::instance().IsWindowOnCurrentDesktop(window))
{
return false;
return ProcessabilityType::NotCurrentVirtualDesktop;
}
return true;
return ProcessabilityType::Processable;
}
bool FancyZonesWindowProcessing::IsProcessable(HWND window) noexcept
{
return DefineWindowType(window) == ProcessabilityType::Processable;
}