[FancyZones] Set correct corner preference when snapping windows on Windows 11 (#16542)

* [FancyZones] Set correct corner preference when snapping windows on Windows 11

* Changed magic numbers to use enum values.

* Added missing words to spell check list.

* Changed note: to todo: for future visibility

* Changed note: to todo: for future visibility
This commit is contained in:
Tore Lervik 2022-03-07 12:50:37 +01:00 committed by GitHub
parent 81f61630cb
commit b20e991a35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -501,6 +501,7 @@ dllmain
dlls
DNLEN
doctype
DONOTROUND
DONTVALIDATEPATH
dotnet
DOverlay
@ -543,6 +544,8 @@ Dwmp
DWMSENDICONICLIVEPREVIEWBITMAP
DWMSENDICONICTHUMBNAIL
DWMWA
DWMWCP
DWMWINDOWATTRIBUTE
DWMWINDOWMAXIMIZEDCHANGE
dword
dworigin
@ -1817,6 +1820,7 @@ robocopy
Roboto
roslyn
Rothera
ROUNDSMALL
royvou
Rpc
RRF

View File

@ -19,6 +19,21 @@ namespace NonLocalizable
const wchar_t SystemAppsFolder[] = L"SYSTEMAPPS";
}
// Placeholder enums since dwmapi.h doesn't have these until SDK 22000.
// TODO: Remove once SDK targets 22000 or above.
enum DWMWINDOWATTRIBUTE_CUSTOM
{
DWMWA_WINDOW_CORNER_PREFERENCE = 33
};
enum DWM_WINDOW_CORNER_PREFERENCE
{
DWMWCP_DEFAULT = 0,
DWMWCP_DONOTROUND = 1,
DWMWCP_ROUND = 2,
DWMWCP_ROUNDSMALL = 3
};
namespace
{
BOOL CALLBACK saveDisplayToVector(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data)
@ -316,6 +331,11 @@ void FancyZonesWindowUtils::SizeWindowToRect(HWND window, RECT rect) noexcept
ScreenToWorkAreaCoords(window, rect);
placement.rcNormalPosition = rect;
// Set window corner preference on Windows 11 to "Do not round"
int corner_preference = DWMWCP_DONOTROUND;
DwmSetWindowAttribute(window, DWMWA_WINDOW_CORNER_PREFERENCE, &corner_preference, sizeof(corner_preference));
placement.flags |= WPF_ASYNCWINDOWPLACEMENT;
::SetWindowPlacement(window, &placement);
@ -373,6 +393,11 @@ void FancyZonesWindowUtils::RestoreWindowSize(HWND window) noexcept
SizeWindowToRect(window, rect);
}
// Set window corner preference on Windows 11 to "Default"
// TODO: Should probably store preference from before snap
int corner_preference = DWMWCP_DEFAULT;
DwmSetWindowAttribute(window, DWMWA_WINDOW_CORNER_PREFERENCE, &corner_preference, sizeof(corner_preference));
::RemoveProp(window, ZonedWindowProperties::PropertyRestoreSizeID);
}
}