diff --git a/DWMBlurGlassExt/Common/DWMStruct.cpp b/DWMBlurGlassExt/Common/DWMStruct.cpp index 4ebf957..558a140 100644 --- a/DWMBlurGlassExt/Common/DWMStruct.cpp +++ b/DWMBlurGlassExt/Common/DWMStruct.cpp @@ -281,6 +281,24 @@ namespace MDWMBlurGlassExt::DWM return DEFCALL_MHOST_METHOD(CVisual::Initialize); } + void CVisual::Show(bool show) + { + if (show) + { + //this->Unhide(); + this->SetOpacity(1.); + this->SendSetOpacity(1.); + //this->ConnectToParent(true); + } + else + { + //this->Hide(); + this->SetOpacity(0.); + this->SendSetOpacity(0.); + //this->ConnectToParent(false); + } + } + HRESULT VisualCollection::RemoveAll() { return DEFCALL_MHOST_METHOD(VisualCollection::RemoveAll); @@ -378,10 +396,10 @@ namespace MDWMBlurGlassExt::DWM { visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[34]); } - if (reinterpret_cast(this)[36]) // legacy - { - visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[36]); - } + //if (reinterpret_cast(this)[36]) // legacy + //{ + // visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[36]); + //} if (reinterpret_cast(this)[37]) // client blur { visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[37]); @@ -393,10 +411,10 @@ namespace MDWMBlurGlassExt::DWM { visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[35]); } - if (reinterpret_cast(this)[37]) // legacy - { - visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[37]); - } + //if (reinterpret_cast(this)[37]) // legacy + //{ + // visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[37]); + //} if (reinterpret_cast(this)[38]) // system backdrop { visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[38]); @@ -412,10 +430,10 @@ namespace MDWMBlurGlassExt::DWM { visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[37]); } - if (reinterpret_cast(this)[39]) // legacy - { - visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[39]); - } + //if (reinterpret_cast(this)[39]) // legacy + //{ + // visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[39]); + //} if (reinterpret_cast(this)[40]) // system backdrop { visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[40]); @@ -431,10 +449,10 @@ namespace MDWMBlurGlassExt::DWM } else { - if (reinterpret_cast(this)[32]) // legacy - { - visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[32]); - } + //if (reinterpret_cast(this)[32]) // legacy + //{ + // visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[32]); + //} if (reinterpret_cast(this)[34]) // accent { visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[34]); @@ -452,33 +470,57 @@ namespace MDWMBlurGlassExt::DWM visuals.emplace_back(nullptr).copy_from(reinterpret_cast(this)[37]); } } + if (os::buildNumber >= 22000) + { + auto legacySolidColorVisual{ GetNCLegacySolidColorVisual() }; + if (legacySolidColorVisual) + { + visuals.emplace_back(nullptr).copy_from(legacySolidColorVisual); + } + } return visuals; } - - void CTopLevelWindow::ShowNCBackgroundVisualList(bool show) + CVisual* CTopLevelWindow::GetNCLegacySolidColorVisual() const { - auto showInternal = [show](CVisual* visual) + CVisual* visual{nullptr}; + + if (os::buildNumber < 22000) { - if (show) + if (reinterpret_cast(this)[36]) // legacy { - //visual->Unhide(); - visual->SetOpacity(1.); - visual->SendSetOpacity(1.); - //visual->ConnectToParent(true); + visual = reinterpret_cast(this)[36]; } - else + } + else if (os::buildNumber < 22621) + { + if (reinterpret_cast(this)[37]) // legacy + { + visual = reinterpret_cast(this)[37]; + } + } + else if (os::buildNumber < 26020) + { + if (reinterpret_cast(this)[39]) // legacy + { + visual = reinterpret_cast(this)[39]; + } + } + else + { + if (reinterpret_cast(this)[32]) // legacy { - //visual->Hide(); - visual->SetOpacity(0.); - visual->SendSetOpacity(0.); - //visual->ConnectToParent(false); + visual = reinterpret_cast(this)[32]; } - }; + } + return visual; + } + void CTopLevelWindow::ShowNCBackgroundVisualList(bool show) + { for (auto visual : GetNCBackgroundVisualList()) { - showInternal(visual.get()); + visual->Show(show); } } @@ -656,10 +698,7 @@ namespace MDWMBlurGlassExt::DWM bool CTopLevelWindow::TreatAsActiveWindow() { - if(os::buildNumber >= 22000) - return (*((BYTE*)this + 624) & 0x40) != 0 || (*(BYTE*)(*((ULONG64*)this + 94) + 675) & 0x10) != 0; - - return (*((BYTE*)this + 592) & 0x40) != 0 || (*(BYTE*)(*((ULONG64*)this + 91) + 611) & 0x20) != 0; + return DEFCALL_MHOST_METHOD(CTopLevelWindow::TreatAsActiveWindow); } RECT* CTopLevelWindow::GetActualWindowRect(RECT* rect, char eraseOffset, char includeNonClient, diff --git a/DWMBlurGlassExt/Common/DWMStruct.h b/DWMBlurGlassExt/Common/DWMStruct.h index 0688502..eeead02 100644 --- a/DWMBlurGlassExt/Common/DWMStruct.h +++ b/DWMBlurGlassExt/Common/DWMStruct.h @@ -139,6 +139,8 @@ namespace MDWMBlurGlassExt::DWM HRESULT MoveToFront(bool unknown); HRESULT Initialize(); + + void Show(bool show); }; struct CContainerVisual : CBaseObject @@ -183,6 +185,7 @@ namespace MDWMBlurGlassExt::DWM CVisual* GetNCAreaBackgroundVisual() const; CVisual* GetClientBlurVisual() const; std::vector> GetNCBackgroundVisualList() const; + CVisual* GetNCLegacySolidColorVisual() const; void ShowNCBackgroundVisualList(bool show); CRgnGeometryProxy* const& GetBorderGeometry() const; diff --git a/DWMBlurGlassExt/Common/DefFunctionList.h b/DWMBlurGlassExt/Common/DefFunctionList.h index 6e020f1..95d0d7f 100644 --- a/DWMBlurGlassExt/Common/DefFunctionList.h +++ b/DWMBlurGlassExt/Common/DefFunctionList.h @@ -44,6 +44,7 @@ namespace MDWMBlurGlassExt { udwm, "CAccent::UpdateAccentBlurRect" }, { udwm, "CAccent::s_IsPolicyActive" }, + { udwm, "CTopLevelWindow::TreatAsActiveWindow" }, { udwm, "CTopLevelWindow::s_ChooseWindowFrameFromStyle" }, { udwm, "CTopLevelWindow::ValidateVisual" }, { udwm, "CTopLevelWindow::UpdateWindowVisuals" }, diff --git a/DWMBlurGlassExt/Section/BackdropMaterials.cpp b/DWMBlurGlassExt/Section/BackdropMaterials.cpp index bc2d2a9..dbe5b46 100644 --- a/DWMBlurGlassExt/Section/BackdropMaterials.cpp +++ b/DWMBlurGlassExt/Section/BackdropMaterials.cpp @@ -677,6 +677,10 @@ namespace MDWMBlurGlassExt backdrop->windowActivated = windowActivated; backdrop->spriteVisual.Size(currentSize); backdrop->spriteVisual.Brush(currentBrush); + if (os::buildNumber < 22000) + { + backdrop->udwmVisual->SetInsetFromParent(&margins); + } return S_OK; } @@ -692,6 +696,19 @@ namespace MDWMBlurGlassExt THROW_IF_FAILED(EnsureBackdropResources()); // Color mode changed useDarkMode = topLevelWindow->GetData()->IsUsingDarkMode(); + // extension changed + if (os::buildNumber < 22000) + { + if (extendToBorders != g_configData.extendBorder) + { + if (g_configData.extendBorder) + { + MARGINS margins{}; + udwmVisual->SetInsetFromParent(&margins); + } + extendToBorders = g_configData.extendBorder; + } + } // Window activation changed windowActivated = topLevelWindow->TreatAsActiveWindow(); // Window size changed @@ -703,16 +720,29 @@ namespace MDWMBlurGlassExt } else { - bool maximized{ static_cast(IsZoomed(hwnd)) }; - RECT windowRect{}; - THROW_HR_IF_NULL(E_INVALIDARG, topLevelWindow->GetActualWindowRect(&windowRect, false, true, false)); - MARGINS margins{}; topLevelWindow->GetBorderMargins(&margins); - newSize = + if (extendToBorders || os::buildNumber >= 22000) { - static_cast(wil::rect_width(windowRect) + (maximized ? margins.cxLeftWidth + margins.cxRightWidth : 0)), - static_cast(wil::rect_height(windowRect) + (maximized ? margins.cyTopHeight + margins.cyBottomHeight : 0)) - }; + bool maximized{ static_cast(IsZoomed(hwnd)) }; + RECT windowRect{}; + THROW_HR_IF_NULL(E_INVALIDARG, topLevelWindow->GetActualWindowRect(&windowRect, false, true, false)); + newSize = + { + static_cast(wil::rect_width(windowRect) + (maximized ? margins.cxLeftWidth + margins.cxRightWidth : 0)), + static_cast(wil::rect_height(windowRect) + (maximized ? margins.cyTopHeight + margins.cyBottomHeight : 0)) + }; + } + else + { + udwmVisual->SetInsetFromParent(&margins); + RECT windowRect{}; + THROW_HR_IF_NULL(E_INVALIDARG, topLevelWindow->GetActualWindowRect(&windowRect, false, true, true)); + newSize = + { + static_cast(wil::rect_width(windowRect)) - 1.f, + static_cast(wil::rect_height(windowRect)) - 1.f + }; + } } if (currentSize != newSize) { @@ -991,7 +1021,7 @@ namespace MDWMBlurGlassExt m_visual->SetDirtyChildren(); } - void CCompositedBackdrop::InitializeVisualTreeClone(CCompositedBackdrop* backdrop) + void CCompositedBackdrop::InitializeVisualTreeClone(CCompositedBackdrop* backdrop, DWM::CTopLevelWindow* window) { if (m_backdropEffect) { @@ -1022,10 +1052,35 @@ namespace MDWMBlurGlassExt { THROW_IF_FAILED(backdrop->m_visual->GetVisualProxy()->SetClip(nullptr)); } + + if (os::buildNumber < 22000) + { + m_borderGeometry = backdrop->m_borderGeometry; + m_extendToBorders = backdrop->m_extendToBorders; + auto visual{ window->GetNCLegacySolidColorVisual() }; + if (visual) + { + if (m_extendToBorders) + { + visual->GetVisualProxy()->SetClip(nullptr); + visual->Show(false); + } + else + { + visual->GetVisualProxy()->SetClip(m_borderGeometry); + visual->Show(true); + } + } + } } CCompositedBackdrop::~CCompositedBackdrop() { + if (m_solidColorVisual) + { + m_solidColorVisual->GetVisualProxy()->SetClip(nullptr); + m_solidColorVisual->Show(true); + } m_visual->GetVisualCollection()->RemoveAll(); } @@ -1117,6 +1172,29 @@ namespace MDWMBlurGlassExt THROW_IF_FAILED(m_visual->GetVisualProxy()->SetClip(nullptr)); } } + + if (os::buildNumber < 22000) + { + auto visual{ window->GetNCLegacySolidColorVisual() }; + auto borderGeometry{ window->GetBorderGeometry() }; + if (visual && (m_borderGeometry != borderGeometry || m_extendToBorders != g_configData.extendBorder)) + { + if (g_configData.extendBorder) + { + visual->GetVisualProxy()->SetClip(nullptr); + visual->Show(false); + } + else + { + visual->GetVisualProxy()->SetClip(borderGeometry); + visual->Show(true); + } + + m_borderGeometry = borderGeometry; + m_extendToBorders = g_configData.extendBorder; + m_solidColorVisual.copy_from(visual); + } + } } std::shared_ptr CBackdropManager::GetOrCreateBackdrop(DWM::CTopLevelWindow* topLevelWindow, diff --git a/DWMBlurGlassExt/Section/BackdropMaterials.h b/DWMBlurGlassExt/Section/BackdropMaterials.h index cd732de..469d828 100644 --- a/DWMBlurGlassExt/Section/BackdropMaterials.h +++ b/DWMBlurGlassExt/Section/BackdropMaterials.h @@ -98,6 +98,7 @@ namespace MDWMBlurGlassExt { bool useDarkMode{ false }; bool windowActivated{ false }; + bool extendToBorders{ false }; winrt::com_ptr interopDCompDevice{ nullptr }; winrt::com_ptr udwmVisual{ nullptr }; @@ -105,6 +106,7 @@ namespace MDWMBlurGlassExt comp::CompositionBrush currentBrush{ nullptr }; comp::SpriteVisual spriteVisual{ nullptr }; winrt::Windows::Foundation::Numerics::float2 currentSize{ 0.f, 0.f }; + MARGINS margins{}; std::chrono::milliseconds crossFadeTime{ 187 }; STDMETHOD(InitializeDCompAndVisual)(); @@ -156,6 +158,9 @@ namespace MDWMBlurGlassExt winrt::com_ptr m_visual{ nullptr }; std::unique_ptr m_backdropEffect{ nullptr }; std::unique_ptr m_glassReflection{ nullptr }; + DWM::CRgnGeometryProxy* m_borderGeometry{ nullptr }; + winrt::com_ptr m_solidColorVisual{nullptr}; + bool m_extendToBorders{ false }; void ConnectPrimaryBackdropToParent(); void ConnectGlassReflectionToParent(); @@ -165,7 +170,7 @@ namespace MDWMBlurGlassExt CCompositedBackdrop(CCompositedBackdrop&& backdrop) = delete; CCompositedBackdrop(const CCompositedBackdrop& backdrop) = delete; ~CCompositedBackdrop(); - void InitializeVisualTreeClone(CCompositedBackdrop* backdrop); + void InitializeVisualTreeClone(CCompositedBackdrop* backdrop, DWM::CTopLevelWindow* window); void UpdateGlassReflection(bool enable); void UpdateBackdropType(MDWMBlurGlass::effectType type); diff --git a/DWMBlurGlassExt/Section/CustomBackdropEffect.cpp b/DWMBlurGlassExt/Section/CustomBackdropEffect.cpp index 2d87ff0..3ab3bff 100644 --- a/DWMBlurGlassExt/Section/CustomBackdropEffect.cpp +++ b/DWMBlurGlassExt/Section/CustomBackdropEffect.cpp @@ -117,7 +117,7 @@ namespace MDWMBlurGlassExt::CustomBackdrop if (SUCCEEDED(hr)) { auto clonedBackdrop{ std::make_shared(g_configData.effectType, g_configData.reflection) }; - backdrop->InitializeVisualTreeClone(clonedBackdrop.get()); + backdrop->InitializeVisualTreeClone(clonedBackdrop.get(), topLevelWindow); g_backdropManager.CreateWithGivenBackdrop(topLevelWindow, clonedBackdrop); } }