Skip to content

Commit

Permalink
bump to 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTaleX531 committed Jun 19, 2024
1 parent feec002 commit 1bed383
Show file tree
Hide file tree
Showing 25 changed files with 745 additions and 553 deletions.
3 changes: 1 addition & 2 deletions OpenGlass/AcrylicBackdrop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ namespace OpenGlass::AcrylicBackdrop

wu::Color GetEffectiveTintColor(wu::Color tintColor, float tintOpacity, std::optional<float> luminosityOpacity)
{
const double tintOpacityModifier{ GetTintOpacityModifier(tintColor) };
if (luminosityOpacity)
{
tintColor.A = static_cast<BYTE>(round(tintColor.A * tintOpacity));
Expand Down Expand Up @@ -161,7 +160,7 @@ namespace OpenGlass::AcrylicBackdrop
// NOTE: There is currently a bug where the names of BlendEffectMode::Luminosity and BlendEffectMode::Color are flipped->
// This should be changed to Luminosity when/if the bug is fixed->
luminosityBlendEffect->SetBlendMode(D2D1_BLEND_MODE_COLOR);
luminosityBlendEffect->SetBackground(Utils::CreateBlurredBackdrop(compositor, blurAmount));
luminosityBlendEffect->SetBackground(Utils::CreateBlurredBackdrop(blurAmount));
luminosityBlendEffect->SetForeground(*luminosityColorEffect);

auto colorBlendEffect{ winrt::make_self<Win2D::BlendEffect>() };
Expand Down
84 changes: 9 additions & 75 deletions OpenGlass/BackdropFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,93 +186,27 @@ void BackdropFactory::UpdateConfiguration(ConfigurationFramework::UpdateType typ
{
if (type & ConfigurationFramework::UpdateType::Backdrop)
{
DWORD value{ 0 };

value = 30;
LOG_IF_FAILED(
wil::reg::get_value_dword_nothrow(
ConfigurationFramework::GetDwmKey(),
L"BlurDeviation",
&value
)
);
g_blurAmount = std::clamp(static_cast<float>(value) / 10.f * 3.f, 0.f, 250.f);

value = 63;
LOG_IF_FAILED(
wil::reg::get_value_dword_nothrow(
ConfigurationFramework::GetDwmKey(),
L"GlassOpacity",
&value
)
);
g_glassOpacity = std::clamp(static_cast<float>(value) / 100.f, 0.f, 1.f);

value = 0;
LOG_IF_FAILED(
wil::reg::get_value_dword_nothrow(
ConfigurationFramework::GetDwmKey(),
L"ColorizationColorBalance",
&value
)
);
g_colorBalance = std::clamp(static_cast<float>(value) / 100.f, 0.f, 1.f);
value = 43;
LOG_IF_FAILED(
wil::reg::get_value_dword_nothrow(
ConfigurationFramework::GetDwmKey(),
L"ColorizationAfterglowBalance",
&value
)
);
g_afterglowBalance = std::clamp(static_cast<float>(value) / 100.f, 0.f, 1.f);

value = 15;
LOG_IF_FAILED(
wil::reg::get_value_dword_nothrow(
ConfigurationFramework::GetDwmKey(),
L"GlassLuminosity",
&value
)
);
g_luminosity = std::clamp(static_cast<float>(value) / 100.f, 0.f, 1.f);
g_blurAmount = std::clamp(static_cast<float>(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"BlurDeviation", 30)) / 10.f * 3.f, 0.f, 250.f);
g_glassOpacity = std::clamp(static_cast<float>(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"GlassOpacity", 63)) / 100.f, 0.f, 1.f);
g_colorBalance = std::clamp(static_cast<float>(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"ColorizationColorBalance", 0)) / 100.f, 0.f, 1.f);
g_afterglowBalance = std::clamp(static_cast<float>(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"ColorizationAfterglowBalance", 43)) / 100.f, 0.f, 1.f);
g_luminosity = std::clamp(static_cast<float>(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"GlassLuminosity", 15)) / 100.f, 0.f, 1.f);

WCHAR materialTexturePath[MAX_PATH + 1]{};
LOG_IF_FAILED(
wil::reg::get_value_string_nothrow(
ConfigurationFramework::GetDwmKey(),
L"CustomThemeMaterial",
materialTexturePath
)
);
ConfigurationFramework::DwmGetStringFromHKCUAndHKLM(L"CustomThemeMaterial", materialTexturePath);
if (g_materialTexturePath != materialTexturePath)
{
g_materialTexturePath = materialTexturePath;
g_materialTextureBrush = nullptr;
}
value = 2;
LOG_IF_FAILED(
wil::reg::get_value_dword_nothrow(
ConfigurationFramework::GetDwmKey(),
L"MaterialOpacity",
&value
)
);
g_materialOpacity = std::clamp(static_cast<float>(value) / 100.f, 0.f, 1.f);

g_materialOpacity = std::clamp(static_cast<float>(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"MaterialOpacity", 2)) / 100.f, 0.f, 1.f);
if (!g_materialTextureBrush)
{
g_materialTextureBrush = CreateMaterialTextureBrush();
}

value = 0;
LOG_IF_FAILED(
wil::reg::get_value_dword_nothrow(
ConfigurationFramework::GetDwmKey(),
L"GlassType",
&value
)
);
g_type = static_cast<BackdropType>(std::clamp(value, 0ul, 4ul));
g_type = static_cast<BackdropType>(std::clamp(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"GlassType", 0), 0ul, 4ul));
// mica is not available in windows 10
if (os::buildNumber < os::build_w11_21h2 && g_type == BackdropType::Mica)
{
Expand Down
105 changes: 61 additions & 44 deletions OpenGlass/BackdropManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,30 @@ namespace OpenGlass::BackdropManager
// 0x20000 UpdateIcon
// 0x100000 UpdateColorization
// ...
window->SetDirtyFlags(0x4000);
window->SetDirtyFlags(0x10000);
window->SetDirtyFlags(0x20000);
window->SetDirtyFlags(0x40000);
window->SetDirtyFlags(0x100000);
window->SetDirtyFlags(0x400000);
window->SetDirtyFlags(0x2000000);
window->SetDirtyFlags(0x4000000);

if (os::buildNumber >= os::build_w11_22h2)
{
if (kind == CompositedBackdropKind::SystemBackdrop)
{
window->OnSystemBackdropUpdated();
}
}
else
{
window->SetDirtyFlags(0x10000);
}
if (kind == CompositedBackdropKind::Accent)
{
window->OnAccentPolicyUpdated();
}
window->OnClipUpdated();
if (os::buildNumber >= os::build_w10_1903)
{
window->OnClipUpdated();
}
else
{
window->OnBlurBehindUpdated();
}
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
}
Expand Down Expand Up @@ -168,9 +172,13 @@ namespace OpenGlass::BackdropManager
{
return m_udwmVisual.get();
}
auto GetDCompVisual() const
{
return m_dcompVisual.as<wuc::Visual>();
}
bool CanBeTrimmed() override
{
if (m_kind != CompositedBackdropKind::Accent || !m_visible)
if (m_kind != CompositedBackdropKind::Accent && (!m_visible || m_window->IsTrullyMinimized()))
{
return true;
}
Expand Down Expand Up @@ -267,11 +275,11 @@ namespace OpenGlass::BackdropManager
UninitializeVisual();
}

void SetClientBlurRegion(HRGN region) override {}
void SetCaptionRegion(HRGN region) override {}
void SetBorderRegion(HRGN region) override {}
void SetAccentRect(LPCRECT lprc) override {}
void SetGdiWindowRegion(HRGN region) override {}
void SetClientBlurRegion(HRGN /*region*/) override {}
void SetCaptionRegion(HRGN /*region*/) override {}
void SetBorderRegion(HRGN /*region*/) override {}
void SetAccentRect(LPCRECT /*lprc*/) override {}
void SetGdiWindowRegion(HRGN /*region*/) override {}
void ValidateVisual() override {}
void UpdateNCBackground() override {}
bool CanBeTrimmed() override
Expand All @@ -284,21 +292,22 @@ namespace OpenGlass::BackdropManager
winrt::com_ptr<CCompositedBackdropVisual> m_compositedBackdropVisual{ nullptr };
public:
CClonedCompositedBackdropVisual(uDwm::CTopLevelWindow* window, const CCompositedBackdropVisual* compositedBackdropVisual) :
uDwm::CClonedBackdropVisual{ window->GetNonClientVisual(), compositedBackdropVisual->GetuDwmVisual() }
uDwm::CClonedBackdropVisual{ window->GetNonClientVisual(), compositedBackdropVisual->GetDCompVisual() }
{
winrt::copy_from_abi(m_compositedBackdropVisual, compositedBackdropVisual);
InitializeVisual();
OnDeviceLost();
}
virtual ~CClonedCompositedBackdropVisual()
{
UninitializeVisual();
m_compositedBackdropVisual = nullptr;
}

void SetClientBlurRegion(HRGN region) override {}
void SetCaptionRegion(HRGN region) override {}
void SetBorderRegion(HRGN region) override {}
void SetAccentRect(LPCRECT lprc) override {}
void SetGdiWindowRegion(HRGN region) override {}
void SetClientBlurRegion(HRGN /*region*/) override {}
void SetCaptionRegion(HRGN /*region*/) override {}
void SetBorderRegion(HRGN /*region*/) override {}
void SetAccentRect(LPCRECT /*lprc*/) override {}
void SetGdiWindowRegion(HRGN /*region*/) override {}
void ValidateVisual() override {}
void UpdateNCBackground() override {}
bool CanBeTrimmed() override
Expand Down Expand Up @@ -351,10 +360,7 @@ HRESULT BackdropManager::CCompositedBackdropVisual::InitializeVisual()

void BackdropManager::CCompositedBackdropVisual::UninitializeVisual()
{
if (m_isWaitingForAnimationComplete)
{
CancelAnimationCompleteWait();
}
CancelAnimationCompleteWait();

m_roundedGeometry = nullptr;
m_pathGeometry = nullptr;
Expand Down Expand Up @@ -388,10 +394,14 @@ void BackdropManager::CCompositedBackdropVisual::OnBackdropRegionChanged(wil::un

if (m_visible != isVisible)
{
m_containerVisual.IsVisible(isVisible);
m_dcompVisual.as<wuc::Visual>().IsVisible(isVisible);
m_visible = isVisible;
}

if (!m_visible)
{
return;
}
wfn::float3 offset{ static_cast<float>(regionBox.left), static_cast<float>(regionBox.top), 0.f };
m_containerVisual.Offset(offset);
m_containerVisual.Size({ static_cast<float>(max(wil::rect_width(regionBox), 0)), static_cast<float>(max(wil::rect_height(regionBox), 0)) });
Expand Down Expand Up @@ -444,7 +454,7 @@ void BackdropManager::CCompositedBackdropVisual::OnBackdropBrushUpdated()
m_backdropBrushChanged = true;
}

auto color{ m_window->GetCurrentColorizationColor() };
auto color{ !Configuration::g_forceAccentColorization ? m_window->GetCurrentColorizationColor() : (active ? Configuration::g_accentColor : Configuration::g_accentColorInactive) };
if (color != m_color)
{
m_shouldPlayCrossFadeAnimation = true;
Expand Down Expand Up @@ -480,29 +490,37 @@ void BackdropManager::CCompositedBackdropVisual::OnBackdropBrushChanged()
{
m_shouldPlayCrossFadeAnimation = false;
}
if (m_isWaitingForAnimationComplete)
{
CancelAnimationCompleteWait();
}
CancelAnimationCompleteWait();

if (m_shouldPlayCrossFadeAnimation && Configuration::g_crossfadeTime.count())
{
auto compositor{ m_backdropBrush.Compositor() };
auto crossfadeBrush{ Utils::CreateCrossFadeBrush(compositor, m_previousBackdropBrush, m_backdropBrush) };

m_isWaitingForAnimationComplete = true;
m_waitingForAnimationCompleteBatch = compositor.CreateScopedBatch(wuc::CompositionBatchTypes::Animation);
// the completed handler won't be called under windows 10 2004, idk why...
if (os::buildNumber >= os::build_w10_2004)
{
auto strongThis{ get_strong() };
auto handler = [strongThis](auto sender, auto args)
{
strongThis->CancelAnimationCompleteWait();
strongThis->m_spriteVisual.Brush(strongThis->m_backdropBrush);
};
m_isWaitingForAnimationComplete = true;
Utils::ThisModule_AddRef();
crossfadeBrush.StartAnimation(L"Crossfade.Weight", Utils::CreateCrossFadeAnimation(compositor, Configuration::g_crossfadeTime));
m_waitingForAnimationCompleteBatch.End();
m_waitingForAnimationCompleteToken = m_waitingForAnimationCompleteBatch.Completed(handler);

m_waitingForAnimationCompleteBatch = compositor.CreateScopedBatch(wuc::CompositionBatchTypes::Animation);
{
auto strongThis{ get_strong() };
auto handler = [strongThis](auto sender, auto args)
{
strongThis->CancelAnimationCompleteWait();
strongThis->m_spriteVisual.Brush(strongThis->m_backdropBrush);
};

crossfadeBrush.StartAnimation(L"Crossfade.Weight", Utils::CreateCrossFadeAnimation(compositor, Configuration::g_animationEasingFunction, Configuration::g_crossfadeTime));

m_waitingForAnimationCompleteToken = m_waitingForAnimationCompleteBatch.Completed(handler);
m_waitingForAnimationCompleteBatch.End();
}
}
else
{
crossfadeBrush.StartAnimation(L"Crossfade.Weight", Utils::CreateCrossFadeAnimation(compositor, Configuration::g_animationEasingFunction, Configuration::g_crossfadeTime));
}

m_spriteVisual.Brush(crossfadeBrush);
Expand Down Expand Up @@ -706,7 +724,6 @@ void BackdropManager::CCompositedBackdropVisual::ValidateVisual()
{
if (m_visible)
{
BOOL valid{ FALSE };
if (!uDwm::CheckDeviceState(m_dcompDevice))
{
OnDeviceLost();
Expand Down
5 changes: 5 additions & 0 deletions OpenGlass/BackdropManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ namespace OpenGlass::BackdropManager
{
inline float g_roundRectRadius{ 0.f };
inline bool g_overrideBorder{ false };
inline char g_animationEasingFunction{ 0 };
inline wf::TimeSpan g_crossfadeTime{ std::chrono::milliseconds{ 87 } };

inline bool g_forceAccentColorization{ false };
inline DWORD g_accentColor{ 0 };
inline DWORD g_accentColorInactive{ 0 };
}

size_t GetCount();
Expand Down
Loading

0 comments on commit 1bed383

Please sign in to comment.