Skip to content

Commit

Permalink
Merge pull request #124 from ALTaleX531/master
Browse files Browse the repository at this point in the history
Fix #121 and optimize animation
  • Loading branch information
Maplespe committed Feb 7, 2024
2 parents 9af2186 + 9947766 commit d48bc8b
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 46 deletions.
109 changes: 74 additions & 35 deletions DWMBlurGlassExt/Common/DWMStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,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);
Expand Down Expand Up @@ -393,10 +411,10 @@ namespace MDWMBlurGlassExt::DWM
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[34]);
}
if (reinterpret_cast<CVisual* const*>(this)[36]) // legacy
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[36]);
}
//if (reinterpret_cast<CVisual* const*>(this)[36]) // legacy
//{
// visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[36]);
//}
if (reinterpret_cast<CVisual* const*>(this)[37]) // client blur
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[37]);
Expand All @@ -408,10 +426,10 @@ namespace MDWMBlurGlassExt::DWM
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[35]);
}
if (reinterpret_cast<CVisual* const*>(this)[37]) // legacy
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[37]);
}
//if (reinterpret_cast<CVisual* const*>(this)[37]) // legacy
//{
// visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[37]);
//}
if (reinterpret_cast<CVisual* const*>(this)[38]) // system backdrop
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[38]);
Expand All @@ -427,10 +445,10 @@ namespace MDWMBlurGlassExt::DWM
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[37]);
}
if (reinterpret_cast<CVisual* const*>(this)[39]) // legacy
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[39]);
}
//if (reinterpret_cast<CVisual* const*>(this)[39]) // legacy
//{
// visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[39]);
//}
if (reinterpret_cast<CVisual* const*>(this)[40]) // system backdrop
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[40]);
Expand All @@ -446,10 +464,10 @@ namespace MDWMBlurGlassExt::DWM
}
else
{
if (reinterpret_cast<CVisual* const*>(this)[32]) // legacy
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[32]);
}
//if (reinterpret_cast<CVisual* const*>(this)[32]) // legacy
//{
// visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[32]);
//}
if (reinterpret_cast<CVisual* const*>(this)[34]) // accent
{
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(this)[34]);
Expand All @@ -467,33 +485,57 @@ namespace MDWMBlurGlassExt::DWM
visuals.emplace_back(nullptr).copy_from(reinterpret_cast<CVisual* const*>(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<CVisual* const*>(this)[36]) // legacy
{
//visual->Unhide();
visual->SetOpacity(1.);
visual->SendSetOpacity(1.);
//visual->ConnectToParent(true);
visual = reinterpret_cast<CVisual* const*>(this)[36];
}
else
}
else if (os::buildNumber < 22621)
{
if (reinterpret_cast<CVisual* const*>(this)[37]) // legacy
{
visual = reinterpret_cast<CVisual* const*>(this)[37];
}
}
else if (os::buildNumber < 26020)
{
if (reinterpret_cast<CVisual* const*>(this)[39]) // legacy
{
visual = reinterpret_cast<CVisual* const*>(this)[39];
}
}
else
{
if (reinterpret_cast<CVisual* const*>(this)[32]) // legacy
{
//visual->Hide();
visual->SetOpacity(0.);
visual->SendSetOpacity(0.);
//visual->ConnectToParent(false);
visual = reinterpret_cast<CVisual* const*>(this)[32];
}
};
}
return visual;
}

void CTopLevelWindow::ShowNCBackgroundVisualList(bool show)
{
for (auto visual : GetNCBackgroundVisualList())
{
showInternal(visual.get());
visual->Show(show);
}
}

Expand Down Expand Up @@ -671,10 +713,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,
Expand Down
3 changes: 3 additions & 0 deletions DWMBlurGlassExt/Common/DWMStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ namespace MDWMBlurGlassExt::DWM
HRESULT MoveToFront(bool unknown);

HRESULT Initialize();

void Show(bool show);
};

struct CContainerVisual : CBaseObject
Expand Down Expand Up @@ -204,6 +206,7 @@ namespace MDWMBlurGlassExt::DWM
CVisual* GetNCAreaBackgroundVisual() const;
CVisual* GetClientBlurVisual() const;
std::vector<winrt::com_ptr<CVisual>> GetNCBackgroundVisualList() const;
CVisual* GetNCLegacySolidColorVisual() const;
void ShowNCBackgroundVisualList(bool show);

CRgnGeometryProxy* const& GetBorderGeometry() const;
Expand Down
1 change: 1 addition & 0 deletions DWMBlurGlassExt/Common/DefFunctionList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
96 changes: 87 additions & 9 deletions DWMBlurGlassExt/Section/BackdropMaterials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand All @@ -703,16 +720,29 @@ namespace MDWMBlurGlassExt
}
else
{
bool maximized{ static_cast<bool>(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<float>(wil::rect_width(windowRect) + (maximized ? margins.cxLeftWidth + margins.cxRightWidth : 0)),
static_cast<float>(wil::rect_height(windowRect) + (maximized ? margins.cyTopHeight + margins.cyBottomHeight : 0))
};
bool maximized{ static_cast<bool>(IsZoomed(hwnd)) };
RECT windowRect{};
THROW_HR_IF_NULL(E_INVALIDARG, topLevelWindow->GetActualWindowRect(&windowRect, false, true, false));
newSize =
{
static_cast<float>(wil::rect_width(windowRect) + (maximized ? margins.cxLeftWidth + margins.cxRightWidth : 0)),
static_cast<float>(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<float>(wil::rect_width(windowRect)) - 1.f,
static_cast<float>(wil::rect_height(windowRect)) - 1.f
};
}
}
if (currentSize != newSize)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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<CCompositedBackdrop> CBackdropManager::GetOrCreateBackdrop(DWM::CTopLevelWindow* topLevelWindow,
Expand Down
7 changes: 6 additions & 1 deletion DWMBlurGlassExt/Section/BackdropMaterials.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ namespace MDWMBlurGlassExt
{
bool useDarkMode{ false };
bool windowActivated{ false };
bool extendToBorders{ false };

winrt::com_ptr<DCompPrivate::IDCompositionDesktopDevicePartner> interopDCompDevice{ nullptr };
winrt::com_ptr<DWM::CVisual> udwmVisual{ nullptr };
winrt::com_ptr<DCompPrivate::InteropCompositionTarget> interopCompositionTarget{ nullptr };
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)();
Expand Down Expand Up @@ -156,6 +158,9 @@ namespace MDWMBlurGlassExt
winrt::com_ptr<DWM::CVisual> m_visual{ nullptr };
std::unique_ptr<CBackdropEffect> m_backdropEffect{ nullptr };
std::unique_ptr<CGlassReflectionBackdrop> m_glassReflection{ nullptr };
DWM::CRgnGeometryProxy* m_borderGeometry{ nullptr };
winrt::com_ptr<DWM::CVisual> m_solidColorVisual{nullptr};
bool m_extendToBorders{ false };

void ConnectPrimaryBackdropToParent();
void ConnectGlassReflectionToParent();
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion DWMBlurGlassExt/Section/CustomBackdropEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace MDWMBlurGlassExt::CustomBackdrop
if (SUCCEEDED(hr))
{
auto clonedBackdrop{ std::make_shared<CCompositedBackdrop>(g_configData.effectType, g_configData.reflection) };
backdrop->InitializeVisualTreeClone(clonedBackdrop.get());
backdrop->InitializeVisualTreeClone(clonedBackdrop.get(), topLevelWindow);
g_backdropManager.CreateWithGivenBackdrop(topLevelWindow, clonedBackdrop);
}
}
Expand Down

0 comments on commit d48bc8b

Please sign in to comment.