From 1b6d7a1aae899449cf98f26430bf7f85f2fceafb Mon Sep 17 00:00:00 2001 From: kfh83 <85626296+kfh83@users.noreply.github.com> Date: Tue, 16 Jul 2024 03:52:11 -0300 Subject: [PATCH 01/17] Implement effects TODO: Active/Inactive differentiation, remove splitting (or atleast make it toggleable again), unhardcode values --- OpenGlass/ColorEffect.hpp | 1 + OpenGlass/CustomBlurEffect.cpp | 175 ++++++++++++++++++++++++++++++- OpenGlass/CustomBlurEffect.hpp | 10 ++ OpenGlass/OpenGlass.vcxproj.user | 4 + 4 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 OpenGlass/ColorEffect.hpp create mode 100644 OpenGlass/OpenGlass.vcxproj.user diff --git a/OpenGlass/ColorEffect.hpp b/OpenGlass/ColorEffect.hpp new file mode 100644 index 0000000..50e9667 --- /dev/null +++ b/OpenGlass/ColorEffect.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/OpenGlass/CustomBlurEffect.cpp b/OpenGlass/CustomBlurEffect.cpp index 7344171..babcf67 100644 --- a/OpenGlass/CustomBlurEffect.cpp +++ b/OpenGlass/CustomBlurEffect.cpp @@ -53,10 +53,74 @@ HRESULT CCustomBlurEffect::Initialize() ) ); + // imma try n put whats relevant here + // ts is jus creating the effects + + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1Composite, + m_compositeEffect.put() + ) + ); + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1Composite, + m_compositeEffect_pass2.put() + ) + ); + + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1Tint, + m_tintEffect.put() + ) + ); + + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1Saturation, + m_saturationEffect.put() + ) + ); + + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1ColorMatrix, + m_ColorizationAfterglowBalance.put() + ) + ); + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1ColorMatrix, + m_ColorizationBlurBalance.put() + ) + ); + + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1ColorMatrix, + m_ColorizationColorBalance.put() + ) + ); + + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1Flood, + m_ColorizationColor.put() + ) + ); + /* RETURN_IF_FAILED( m_cropInputEffect->SetValue(D2D1_PROPERTY_CACHED, TRUE) );*/ + + + // now here we start setting values n shit or atleast the default values + // imma have to investigate later in the file whats being done but otherwise + + + RETURN_IF_FAILED( m_cropInputEffect->SetValue( D2D1_CROP_PROP_BORDER_MODE, @@ -74,7 +138,7 @@ HRESULT CCustomBlurEffect::Initialize() RETURN_IF_FAILED( m_scaleDownEffect->SetValue( D2D1_SCALE_PROP_INTERPOLATION_MODE, - D2D1_SCALE_INTERPOLATION_MODE_LINEAR + D2D1_SCALE_INTERPOLATION_MODE_ANISOTROPIC ) ); m_borderEffect->SetInputEffect(0, m_scaleDownEffect.get()); @@ -104,7 +168,110 @@ HRESULT CCustomBlurEffect::Initialize() D2D1_DIRECTIONALBLURKERNEL_DIRECTION_Y ) ); - m_scaleUpEffect->SetInputEffect(0, m_directionalBlurYEffect.get()); + + + // okay my conclusion is that i shouldnt tamper with whatever was already set up (no point in removing the scales or adding gaussian blur) + // so since all of the blur work is done here, starting my part of it: + + // hardcoded values whatever + float ColorizationAfterglowBalance = 0.43f; + float ColorizationBlurBalance = 0.49f; + float ColorizationColorBalance = 0.08f; + + // afterglow + m_saturationEffect->SetInputEffect(0, m_directionalBlurYEffect.get()); + RETURN_IF_FAILED( + m_saturationEffect->SetValue( + D2D1_SATURATION_PROP_SATURATION, + 0.0f + ) + ); + + m_tintEffect->SetInputEffect(0, m_saturationEffect.get()); + RETURN_IF_FAILED( + m_tintEffect->SetValue( + D2D1_TINT_PROP_COLOR, + D2D1::Vector4F(116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f, 1.0f) + ) + ); + + + D2D1_MATRIX_5X4_F AfterglowBalanceM = D2D1::Matrix5x4F(ColorizationAfterglowBalance, 0.f, 0.f, 0.f, + 0.f, ColorizationAfterglowBalance, 0.f, 0.f, + 0.f, 0.f, ColorizationAfterglowBalance, 0.f, + 0.f, 0.f, 0.f, 1.f, + 0.f, 0.f, 0.f, 0.f); + + m_ColorizationAfterglowBalance->SetInputEffect(0, m_tintEffect.get()); + RETURN_IF_FAILED( + m_ColorizationAfterglowBalance->SetValue( + D2D1_COLORMATRIX_PROP_COLOR_MATRIX, + AfterglowBalanceM + ) + ); + + // afterglow done + + // heres blur balance + D2D1_MATRIX_5X4_F BlurBalanceM = D2D1::Matrix5x4F(ColorizationBlurBalance, 0.f, 0.f, 0.f, + 0.f, ColorizationBlurBalance, 0.f, 0.f, + 0.f, 0.f, ColorizationBlurBalance, 0.f, + 0.f, 0.f, 0.f, 1.f, + 0.f, 0.f, 0.f, 0.f); + + m_ColorizationBlurBalance->SetInputEffect(0, m_directionalBlurYEffect.get()); + RETURN_IF_FAILED( + m_ColorizationBlurBalance->SetValue( + D2D1_COLORMATRIX_PROP_COLOR_MATRIX, + BlurBalanceM + ) + ); + + // and finally ColorizationColor + + RETURN_IF_FAILED( + m_ColorizationColor->SetValue( + D2D1_FLOOD_PROP_COLOR, + D2D1::Vector4F(116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f, 1.0f) + ) + ); + + D2D1_MATRIX_5X4_F ColorBalanceM = D2D1::Matrix5x4F(ColorizationColorBalance, 0.f, 0.f, 0.f, + 0.f, ColorizationColorBalance, 0.f, 0.f, + 0.f, 0.f, ColorizationColorBalance, 0.f, + 0.f, 0.f, 0.f, 1.f, + 0.f, 0.f, 0.f, 0.f); + + m_ColorizationColorBalance->SetInputEffect(0, m_ColorizationColor.get()); + RETURN_IF_FAILED( + m_ColorizationColorBalance->SetValue( + D2D1_COLORMATRIX_PROP_COLOR_MATRIX, + ColorBalanceM + ) + ); + + + // imma blend it together jus to see + m_compositeEffect->SetInputEffect(0, m_ColorizationBlurBalance.get()); + m_compositeEffect->SetInputEffect(1, m_ColorizationAfterglowBalance.get()); + RETURN_IF_FAILED( + m_compositeEffect->SetValue( + D2D1_COMPOSITE_PROP_MODE, + D2D1_COMPOSITE_MODE_PLUS + ) + ); + + m_compositeEffect_pass2->SetInputEffect(0, m_compositeEffect.get()); + m_compositeEffect_pass2->SetInputEffect(1, m_ColorizationColorBalance.get()); + RETURN_IF_FAILED( + m_compositeEffect_pass2->SetValue( + D2D1_COMPOSITE_PROP_MODE, + D2D1_COMPOSITE_MODE_PLUS + ) + ); + // okay + + m_scaleUpEffect->SetInputEffect(0, m_compositeEffect_pass2.get()); RETURN_IF_FAILED(m_scaleUpEffect->SetValue(D2D1_SCALE_PROP_SHARPNESS, 1.f)); RETURN_IF_FAILED( m_scaleUpEffect->SetValue( @@ -112,12 +279,14 @@ HRESULT CCustomBlurEffect::Initialize() D2D1_BORDER_MODE_HARD ) ); + RETURN_IF_FAILED( m_scaleUpEffect->SetValue( D2D1_SCALE_PROP_INTERPOLATION_MODE, - D2D1_SCALE_INTERPOLATION_MODE_LINEAR + D2D1_SCALE_INTERPOLATION_MODE_ANISOTROPIC ) ); + m_initialized = true; return S_OK; diff --git a/OpenGlass/CustomBlurEffect.hpp b/OpenGlass/CustomBlurEffect.hpp index a2c62b5..87f45ae 100644 --- a/OpenGlass/CustomBlurEffect.hpp +++ b/OpenGlass/CustomBlurEffect.hpp @@ -56,6 +56,16 @@ namespace OpenGlass winrt::com_ptr m_directionalBlurXEffect{}; winrt::com_ptr m_directionalBlurYEffect{}; winrt::com_ptr m_scaleUpEffect{}; + + // new stuff + winrt::com_ptr m_compositeEffect{}; + winrt::com_ptr m_compositeEffect_pass2{}; + winrt::com_ptr m_saturationEffect{}; + winrt::com_ptr m_tintEffect{}; + winrt::com_ptr m_ColorizationAfterglowBalance{}; + winrt::com_ptr m_ColorizationBlurBalance{}; + winrt::com_ptr m_ColorizationColorBalance{}; + winrt::com_ptr m_ColorizationColor{}; static const float k_optimizations[16]; static float DetermineOutputScale(float size, float blurAmount); diff --git a/OpenGlass/OpenGlass.vcxproj.user b/OpenGlass/OpenGlass.vcxproj.user new file mode 100644 index 0000000..0f14913 --- /dev/null +++ b/OpenGlass/OpenGlass.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From 1c5e25968bd0337abf231e56be670c409397c252 Mon Sep 17 00:00:00 2001 From: kfh83 <85626296+kfh83@users.noreply.github.com> Date: Tue, 16 Jul 2024 03:53:06 -0300 Subject: [PATCH 02/17] Delete OpenGlass/ColorEffect.hpp oops --- OpenGlass/ColorEffect.hpp | 1 - 1 file changed, 1 deletion(-) delete mode 100644 OpenGlass/ColorEffect.hpp diff --git a/OpenGlass/ColorEffect.hpp b/OpenGlass/ColorEffect.hpp deleted file mode 100644 index 50e9667..0000000 --- a/OpenGlass/ColorEffect.hpp +++ /dev/null @@ -1 +0,0 @@ -#pragma once From bb8409c69b7b8e4a8f8a4263b6350a21089b4780 Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Tue, 16 Jul 2024 18:40:53 +0100 Subject: [PATCH 03/17] begin work on params from registry --- OpenGlass/CustomBlurEffect.cpp | 173 +++++++++++++++++++++++++++---- OpenGlass/CustomBlurEffect.hpp | 20 +++- OpenGlass/GlassEffectManager.cpp | 26 ++++- OpenGlass/GlassEffectManager.hpp | 11 +- OpenGlass/GlassFramework.cpp | 4 + OpenGlass/GlassRenderer.cpp | 13 ++- OpenGlass/GlassSharedData.hpp | 3 + OpenGlass/framework.hpp | 11 +- 8 files changed, 224 insertions(+), 37 deletions(-) diff --git a/OpenGlass/CustomBlurEffect.cpp b/OpenGlass/CustomBlurEffect.cpp index babcf67..26db720 100644 --- a/OpenGlass/CustomBlurEffect.cpp +++ b/OpenGlass/CustomBlurEffect.cpp @@ -53,6 +53,116 @@ HRESULT CCustomBlurEffect::Initialize() ) ); + /* + RETURN_IF_FAILED( + m_cropInputEffect->SetValue(D2D1_PROPERTY_CACHED, TRUE) + );*/ + RETURN_IF_FAILED( + m_cropInputEffect->SetValue( + D2D1_CROP_PROP_BORDER_MODE, + D2D1_BORDER_MODE_SOFT + ) + ); + m_scaleDownEffect->SetInputEffect(0, m_cropInputEffect.get()); + RETURN_IF_FAILED(m_scaleDownEffect->SetValue(D2D1_SCALE_PROP_SHARPNESS, 1.f)); + RETURN_IF_FAILED( + m_scaleDownEffect->SetValue( + D2D1_SCALE_PROP_BORDER_MODE, + D2D1_BORDER_MODE_HARD + ) + ); + RETURN_IF_FAILED( + m_scaleDownEffect->SetValue( + D2D1_SCALE_PROP_INTERPOLATION_MODE, + D2D1_SCALE_INTERPOLATION_MODE_LINEAR + ) + ); + m_borderEffect->SetInputEffect(0, m_scaleDownEffect.get()); + RETURN_IF_FAILED( + m_borderEffect->SetValue( + D2D1_BORDER_PROP_EDGE_MODE_X, + D2D1_BORDER_EDGE_MODE_MIRROR + ) + ); + RETURN_IF_FAILED( + m_borderEffect->SetValue( + D2D1_BORDER_PROP_EDGE_MODE_Y, + D2D1_BORDER_EDGE_MODE_MIRROR + ) + ); + m_directionalBlurXEffect->SetInputEffect(0, m_borderEffect.get()); + RETURN_IF_FAILED( + m_directionalBlurXEffect->SetValue( + D2D1_DIRECTIONALBLURKERNEL_PROP_DIRECTION, + D2D1_DIRECTIONALBLURKERNEL_DIRECTION_X + ) + ); + m_directionalBlurYEffect->SetInputEffect(0, m_directionalBlurXEffect.get()); + RETURN_IF_FAILED( + m_directionalBlurYEffect->SetValue( + D2D1_DIRECTIONALBLURKERNEL_PROP_DIRECTION, + D2D1_DIRECTIONALBLURKERNEL_DIRECTION_Y + ) + ); + m_scaleUpEffect->SetInputEffect(0, m_directionalBlurYEffect.get()); + RETURN_IF_FAILED(m_scaleUpEffect->SetValue(D2D1_SCALE_PROP_SHARPNESS, 1.f)); + RETURN_IF_FAILED( + m_scaleUpEffect->SetValue( + D2D1_SCALE_PROP_BORDER_MODE, + D2D1_BORDER_MODE_HARD + ) + ); + RETURN_IF_FAILED( + m_scaleUpEffect->SetValue( + D2D1_SCALE_PROP_INTERPOLATION_MODE, + D2D1_SCALE_INTERPOLATION_MODE_LINEAR + ) + ); + m_initialized = true; + + return S_OK; +} + +// CropInput -> ScaleDown (optional) -> Border -> DirectionalBlurX -> DirectionalBlurY -> ScaleUp (optional) +HRESULT CCustomBlurEffect::InitializeAero() +{ + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1Crop, + m_cropInputEffect.put() + ) + ); + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1Scale, + m_scaleDownEffect.put() + ) + ); + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1Border, + m_borderEffect.put() + ) + ); + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1DirectionalBlurKernel, + m_directionalBlurXEffect.put() + ) + ); + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1DirectionalBlurKernel, + m_directionalBlurYEffect.put() + ) + ); + RETURN_IF_FAILED( + m_deviceContext->CreateEffect( + CLSID_D2D1Scale, + m_scaleUpEffect.put() + ) + ); + // imma try n put whats relevant here // ts is jus creating the effects @@ -174,9 +284,9 @@ HRESULT CCustomBlurEffect::Initialize() // so since all of the blur work is done here, starting my part of it: // hardcoded values whatever - float ColorizationAfterglowBalance = 0.43f; - float ColorizationBlurBalance = 0.49f; - float ColorizationColorBalance = 0.08f; + m_colorizationAfterglowBalanceVal = 0.43f; + m_colorizationBlurBalanceVal = 0.49f; + m_colorizationColorBalanceVal = 0.08f; // afterglow m_saturationEffect->SetInputEffect(0, m_directionalBlurYEffect.get()); @@ -196,9 +306,9 @@ HRESULT CCustomBlurEffect::Initialize() ); - D2D1_MATRIX_5X4_F AfterglowBalanceM = D2D1::Matrix5x4F(ColorizationAfterglowBalance, 0.f, 0.f, 0.f, - 0.f, ColorizationAfterglowBalance, 0.f, 0.f, - 0.f, 0.f, ColorizationAfterglowBalance, 0.f, + D2D1_MATRIX_5X4_F AfterglowBalanceM = D2D1::Matrix5x4F(m_colorizationAfterglowBalanceVal, 0.f, 0.f, 0.f, + 0.f, m_colorizationAfterglowBalanceVal, 0.f, 0.f, + 0.f, 0.f, m_colorizationAfterglowBalanceVal, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f); @@ -213,9 +323,9 @@ HRESULT CCustomBlurEffect::Initialize() // afterglow done // heres blur balance - D2D1_MATRIX_5X4_F BlurBalanceM = D2D1::Matrix5x4F(ColorizationBlurBalance, 0.f, 0.f, 0.f, - 0.f, ColorizationBlurBalance, 0.f, 0.f, - 0.f, 0.f, ColorizationBlurBalance, 0.f, + D2D1_MATRIX_5X4_F BlurBalanceM = D2D1::Matrix5x4F(m_colorizationBlurBalanceVal, 0.f, 0.f, 0.f, + 0.f, m_colorizationBlurBalanceVal, 0.f, 0.f, + 0.f, 0.f, m_colorizationBlurBalanceVal, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f); @@ -236,9 +346,9 @@ HRESULT CCustomBlurEffect::Initialize() ) ); - D2D1_MATRIX_5X4_F ColorBalanceM = D2D1::Matrix5x4F(ColorizationColorBalance, 0.f, 0.f, 0.f, - 0.f, ColorizationColorBalance, 0.f, 0.f, - 0.f, 0.f, ColorizationColorBalance, 0.f, + D2D1_MATRIX_5X4_F ColorBalanceM = D2D1::Matrix5x4F(m_colorizationColorBalanceVal, 0.f, 0.f, 0.f, + 0.f, m_colorizationColorBalanceVal, 0.f, 0.f, + 0.f, 0.f, m_colorizationColorBalanceVal, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f); @@ -317,12 +427,38 @@ HRESULT STDMETHODCALLTYPE CCustomBlurEffect::Invalidate( ID2D1Image* inputImage, const D2D1_RECT_F& imageRectangle, const D2D1_RECT_F& imageBounds, - float blurAmount + float blurAmount, + float colorizationAfterglowBalanceVal, + float colorizationBlurBalanceVal, + float colorizationColorBalanceVal, + Type type ) { - if (!m_initialized) + colorizationAfterglowBalanceVal = 0.49f; + colorizationBlurBalanceVal = 0.796f; + colorizationBlurBalanceVal = 0.08f; + if (!inputImage) return S_FALSE; + + bool recalculateParams{ false }; + if (m_blurAmount != blurAmount || m_colorizationAfterglowBalanceVal != colorizationAfterglowBalanceVal || + m_colorizationBlurBalanceVal != colorizationBlurBalanceVal || + m_colorizationColorBalanceVal != colorizationColorBalanceVal) + { + m_blurAmount = blurAmount; + m_colorizationAfterglowBalanceVal = colorizationAfterglowBalanceVal; + m_colorizationBlurBalanceVal = colorizationBlurBalanceVal; + m_colorizationColorBalanceVal = colorizationColorBalanceVal; + recalculateParams = true; + } + + //todo: fix handling type changes at runtime + if (!m_initialized || m_type != type) { - RETURN_IF_FAILED(Initialize()); + m_type = type; + if (m_type == Type::Blur) + RETURN_IF_FAILED(Initialize()); + else if (m_type == Type::Aero) + RETURN_IF_FAILED(InitializeAero()); } if (m_effectInput != inputImage) { @@ -330,12 +466,7 @@ HRESULT STDMETHODCALLTYPE CCustomBlurEffect::Invalidate( m_cropInputEffect->SetInput(0, inputImage); } - bool recalculateParams{ false }; - if (m_blurAmount != blurAmount) - { - m_blurAmount = blurAmount; - recalculateParams = true; - } + if (memcmp(&m_imageRectangle, &imageRectangle, sizeof(D2D1_RECT_F)) != 0) { m_imageRectangle = imageRectangle; diff --git a/OpenGlass/CustomBlurEffect.hpp b/OpenGlass/CustomBlurEffect.hpp index 87f45ae..75f618a 100644 --- a/OpenGlass/CustomBlurEffect.hpp +++ b/OpenGlass/CustomBlurEffect.hpp @@ -23,7 +23,7 @@ namespace OpenGlass D2D1_DIRECTIONALBLURKERNEL_OPTIMIZATION_TRANSFORM_IDENDITY, D2D1_DIRECTIONALBLURKERNEL_OPTIMIZATION_TRANSFORM_SCALE }; - + // [Guid("01AA613C-2376-4B95-8A74-B94CA840D4D1")] DECLARE_INTERFACE_IID_(ICustomBlurEffect, IUnknown, "01AA613C-2376-4B95-8A74-B94CA840D4D1") { @@ -31,7 +31,11 @@ namespace OpenGlass ID2D1Image* inputImage, const D2D1_RECT_F& imageRectangle, const D2D1_RECT_F& imageBounds, - float blurAmount + float blurAmount, + float colorizationAfterglowBalanceVal, + float colorizationBlurBalanceVal, + float colorizationColorBalanceVal, + Type type ) = 0; virtual HRESULT STDMETHODCALLTYPE Draw( CONST D2D1_RECT_F & bounds, @@ -46,6 +50,7 @@ namespace OpenGlass { bool m_initialized{ false }; float m_blurAmount{ 9.f }; + Type m_type{Type::Blur}; D2D1_RECT_F m_imageRectangle{}; ID2D1Image* m_effectInput{ nullptr }; winrt::com_ptr m_effectOutput{ nullptr }; @@ -67,9 +72,14 @@ namespace OpenGlass winrt::com_ptr m_ColorizationColorBalance{}; winrt::com_ptr m_ColorizationColor{}; + float m_colorizationAfterglowBalanceVal = 0.43f; + float m_colorizationBlurBalanceVal = 0.49f; + float m_colorizationColorBalanceVal = 0.08f; + static const float k_optimizations[16]; static float DetermineOutputScale(float size, float blurAmount); HRESULT Initialize(); + HRESULT InitializeAero(); public: CCustomBlurEffect(ID2D1DeviceContext* deviceContext); @@ -77,7 +87,11 @@ namespace OpenGlass ID2D1Image* inputImage, const D2D1_RECT_F& imageRectangle, const D2D1_RECT_F& imageBounds, - float blurAmount + float blurAmount, + float colorizationAfterglowBalanceVal, + float colorizationBlurBalanceVal, + float colorizationColorBalanceVal, + Type type ) override; HRESULT STDMETHODCALLTYPE Draw( CONST D2D1_RECT_F& bounds, diff --git a/OpenGlass/GlassEffectManager.cpp b/OpenGlass/GlassEffectManager.cpp index fbb3117..9755908 100644 --- a/OpenGlass/GlassEffectManager.cpp +++ b/OpenGlass/GlassEffectManager.cpp @@ -28,6 +28,10 @@ namespace OpenGlass::GlassEffectManager winrt::com_ptr m_blurBuffer{ nullptr }; winrt::com_ptr m_customBlurEffect{ nullptr }; + float m_colorizationAfterglowBalanceVal; + float m_colorizationBlurBalanceVal; + float m_colorizationColorBalanceVal; + HRESULT Initialize(); public: CGlassEffect(ID2D1DeviceContext* deviceContext) { winrt::copy_from_abi(m_deviceContext, deviceContext); } @@ -35,7 +39,11 @@ namespace OpenGlass::GlassEffectManager void STDMETHODCALLTYPE SetGlassRenderingParameters( const D2D1_COLOR_F& color, float glassOpacity, - float blurAmount + float blurAmount, + float colorizationAfterglowBalanceVal, + float colorizationBlurBalanceVal, + float colorizationColorBalanceVal, + Type type ) override; void STDMETHODCALLTYPE SetSize(const D2D1_SIZE_F& size) override; HRESULT STDMETHODCALLTYPE Invalidate( @@ -57,12 +65,20 @@ HRESULT GlassEffectManager::CGlassEffect::Initialize() void STDMETHODCALLTYPE GlassEffectManager::CGlassEffect::SetGlassRenderingParameters( const D2D1_COLOR_F& color, float glassOpacity, - float blurAmount + float blurAmount, + float colorizationAfterglowBalanceVal, + float colorizationBlurBalanceVal, + float colorizationColorBalanceVal, + Type type ) { m_color = color; m_glassOpacity = glassOpacity; m_blurAmount = blurAmount; + m_colorizationAfterglowBalanceVal = colorizationAfterglowBalanceVal; + m_colorizationBlurBalanceVal = colorizationBlurBalanceVal; + m_colorizationColorBalanceVal = colorizationColorBalanceVal; + m_type = type; } void STDMETHODCALLTYPE GlassEffectManager::CGlassEffect::SetSize(const D2D1_SIZE_F& size) { @@ -196,7 +212,11 @@ HRESULT STDMETHODCALLTYPE GlassEffectManager::CGlassEffect::Invalidate( m_blurBuffer.get(), invalidInputRect, imageBounds, - m_blurAmount + m_blurAmount, + m_colorizationAfterglowBalanceVal, + m_colorizationBlurBalanceVal, + m_colorizationColorBalanceVal, + m_type ) ); } diff --git a/OpenGlass/GlassEffectManager.hpp b/OpenGlass/GlassEffectManager.hpp index ca7951a..d3febbe 100644 --- a/OpenGlass/GlassEffectManager.hpp +++ b/OpenGlass/GlassEffectManager.hpp @@ -5,11 +5,6 @@ namespace OpenGlass::GlassEffectManager { - enum class Type : UCHAR - { - Blur, - Aero - }; // [Guid("01AA613C-2376-4B95-8A74-B94CA840D4D1")] DECLARE_INTERFACE_IID_(IGlassEffect, IUnknown, "01AA613C-2376-4B95-8A74-B94CA840D4D1") @@ -17,7 +12,11 @@ namespace OpenGlass::GlassEffectManager virtual void STDMETHODCALLTYPE SetGlassRenderingParameters( const D2D1_COLOR_F& color, float glassOpacity, - float blurAmount + float blurAmount, + float colorizationAfterglowBalanceVal, + float colorizationBlurBalanceVal, + float colorizationColorBalanceVal, + Type type ) = 0; virtual void STDMETHODCALLTYPE SetSize(const D2D1_SIZE_F& size) = 0; virtual HRESULT STDMETHODCALLTYPE Invalidate( diff --git a/OpenGlass/GlassFramework.cpp b/OpenGlass/GlassFramework.cpp index 61f5852..5bc0c24 100644 --- a/OpenGlass/GlassFramework.cpp +++ b/OpenGlass/GlassFramework.cpp @@ -332,6 +332,10 @@ void GlassFramework::UpdateConfiguration(ConfigurationFramework::UpdateType type g_roundRectRadius = static_cast(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"RoundRectRadius")); } + GlassSharedData::g_ColorizationAfterglowBalance = ((float)ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"OG_ColorizationAfterglowBalance",43) / 100); + GlassSharedData::g_ColorizationBlurBalance = ((float)ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"OG_ColorizationBlurBalance",49) / 100); + GlassSharedData::g_ColorizationColorBalance = ((float)ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"OG_ColorizationColorBalance",8) / 100); + auto lock{ wil::EnterCriticalSection(uDwm::CDesktopManager::s_csDwmInstance) }; if (!GlassSharedData::IsBackdropAllowed()) { diff --git a/OpenGlass/GlassRenderer.cpp b/OpenGlass/GlassRenderer.cpp index 845bd01..09bae2a 100644 --- a/OpenGlass/GlassRenderer.cpp +++ b/OpenGlass/GlassRenderer.cpp @@ -70,7 +70,7 @@ namespace OpenGlass::GlassRenderer dwmcore::IDrawingContext* g_drawingContextNoRef{ nullptr }; ID2D1Device* g_deviceNoRef{ nullptr }; - GlassEffectManager::Type g_type{ GlassEffectManager::Type::Blur }; + Type g_type{ Type::Blur }; float g_blurAmount{ 9.f }; float g_glassOpacity{ 0.63f }; // exclusively used by aero backdrop @@ -237,6 +237,9 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( winrt::com_ptr backdropBitmap{ backdropImage.as() }; RETURN_IF_FAILED(This->GetDrawingContext()->FlushD2D()); + //TODO: idk if this is best, prob change + bool active = false; + dwmcore::CMILMatrix matrix{}; D2D1_RECT_F shapeWorldBounds{}; RETURN_IF_FAILED(This->GetDrawingContext()->GetWorldTransform(&matrix)); @@ -244,7 +247,11 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( glassEffect->SetGlassRenderingParameters( color, g_glassOpacity, - g_blurAmount + g_blurAmount, + GlassSharedData::g_ColorizationAfterglowBalance, + active ? GlassSharedData::g_ColorizationBlurBalance : 0.4f * GlassSharedData::g_ColorizationBlurBalance + 0.6f, + GlassSharedData::g_ColorizationColorBalance, + g_type ); glassEffect->SetSize( D2D1::SizeF( @@ -344,7 +351,7 @@ void GlassRenderer::UpdateConfiguration(ConfigurationFramework::UpdateType type) } g_afterglowBalance = std::clamp(static_cast(afterglowBalance.value()) / 100.f, 0.f, 1.f); - g_type = static_cast(std::clamp(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"GlassType", 0), 0ul, 4ul)); + g_type = static_cast(std::clamp(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"GlassType", 0), 0ul, 4ul)); } } diff --git a/OpenGlass/GlassSharedData.hpp b/OpenGlass/GlassSharedData.hpp index df9aa3f..4332a9f 100644 --- a/OpenGlass/GlassSharedData.hpp +++ b/OpenGlass/GlassSharedData.hpp @@ -8,6 +8,9 @@ namespace OpenGlass::GlassSharedData inline bool g_overrideAccent{ false }; inline bool g_batteryMode{ false }; inline bool g_transparencyEnabled{ true }; + inline float g_ColorizationAfterglowBalance = 0.43f; + inline float g_ColorizationBlurBalance = 0.49f; + inline float g_ColorizationColorBalance = 0.08f; FORCEINLINE bool IsBackdropAllowed() { diff --git a/OpenGlass/framework.hpp b/OpenGlass/framework.hpp index 84c5a34..a71d242 100644 --- a/OpenGlass/framework.hpp +++ b/OpenGlass/framework.hpp @@ -63,4 +63,13 @@ #pragma comment(lib, "dwrite.lib") #pragma comment(lib, "dxguid.lib") -#pragma comment(lib, "onecore.lib") \ No newline at end of file +#pragma comment(lib, "onecore.lib") + +namespace OpenGlass +{ + enum class Type : UCHAR + { + Blur = 0, + Aero = 1 + }; +} From f0f45d1a2e59d73301c15d25b090c73b782f3826 Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Tue, 16 Jul 2024 19:00:43 +0100 Subject: [PATCH 04/17] unhardcode --- OpenGlass/CustomBlurEffect.cpp | 14 +++++++------- OpenGlass/GlassRenderer.cpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/OpenGlass/CustomBlurEffect.cpp b/OpenGlass/CustomBlurEffect.cpp index 26db720..ef03b0a 100644 --- a/OpenGlass/CustomBlurEffect.cpp +++ b/OpenGlass/CustomBlurEffect.cpp @@ -283,10 +283,10 @@ HRESULT CCustomBlurEffect::InitializeAero() // okay my conclusion is that i shouldnt tamper with whatever was already set up (no point in removing the scales or adding gaussian blur) // so since all of the blur work is done here, starting my part of it: - // hardcoded values whatever - m_colorizationAfterglowBalanceVal = 0.43f; - m_colorizationBlurBalanceVal = 0.49f; - m_colorizationColorBalanceVal = 0.08f; + // hardcoded values whatever (EDIT: Not Anymore!) + //m_colorizationAfterglowBalanceVal = 0.43f; + //m_colorizationBlurBalanceVal = 0.796f; + //m_colorizationColorBalanceVal = 0.08f; // afterglow m_saturationEffect->SetInputEffect(0, m_directionalBlurYEffect.get()); @@ -434,9 +434,9 @@ HRESULT STDMETHODCALLTYPE CCustomBlurEffect::Invalidate( Type type ) { - colorizationAfterglowBalanceVal = 0.49f; - colorizationBlurBalanceVal = 0.796f; - colorizationBlurBalanceVal = 0.08f; + //colorizationAfterglowBalanceVal = 0.49f; + //colorizationBlurBalanceVal = 0.796f; + //colorizationColorBalanceVal = 0.08f; if (!inputImage) return S_FALSE; bool recalculateParams{ false }; diff --git a/OpenGlass/GlassRenderer.cpp b/OpenGlass/GlassRenderer.cpp index 09bae2a..f87add2 100644 --- a/OpenGlass/GlassRenderer.cpp +++ b/OpenGlass/GlassRenderer.cpp @@ -238,7 +238,7 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( RETURN_IF_FAILED(This->GetDrawingContext()->FlushD2D()); //TODO: idk if this is best, prob change - bool active = false; + bool active = true; dwmcore::CMILMatrix matrix{}; D2D1_RECT_F shapeWorldBounds{}; From f887aedc33dfb2e7f52fee29e10cd52bb076122a Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Tue, 16 Jul 2024 22:00:23 +0100 Subject: [PATCH 05/17] SCUFFED ASS ACTIVE CHECKS, PLEASE FIXXXXXXXXX --- OpenGlass/CustomBlurEffect.cpp | 207 ++++++++++++++++++--------------- OpenGlass/CustomBlurEffect.hpp | 2 + OpenGlass/GlassFramework.cpp | 5 + OpenGlass/GlassRenderer.cpp | 13 ++- OpenGlass/GlassSharedData.hpp | 1 + 5 files changed, 132 insertions(+), 96 deletions(-) diff --git a/OpenGlass/CustomBlurEffect.cpp b/OpenGlass/CustomBlurEffect.cpp index ef03b0a..d8a83c5 100644 --- a/OpenGlass/CustomBlurEffect.cpp +++ b/OpenGlass/CustomBlurEffect.cpp @@ -53,71 +53,8 @@ HRESULT CCustomBlurEffect::Initialize() ) ); - /* - RETURN_IF_FAILED( - m_cropInputEffect->SetValue(D2D1_PROPERTY_CACHED, TRUE) - );*/ - RETURN_IF_FAILED( - m_cropInputEffect->SetValue( - D2D1_CROP_PROP_BORDER_MODE, - D2D1_BORDER_MODE_SOFT - ) - ); - m_scaleDownEffect->SetInputEffect(0, m_cropInputEffect.get()); - RETURN_IF_FAILED(m_scaleDownEffect->SetValue(D2D1_SCALE_PROP_SHARPNESS, 1.f)); - RETURN_IF_FAILED( - m_scaleDownEffect->SetValue( - D2D1_SCALE_PROP_BORDER_MODE, - D2D1_BORDER_MODE_HARD - ) - ); - RETURN_IF_FAILED( - m_scaleDownEffect->SetValue( - D2D1_SCALE_PROP_INTERPOLATION_MODE, - D2D1_SCALE_INTERPOLATION_MODE_LINEAR - ) - ); - m_borderEffect->SetInputEffect(0, m_scaleDownEffect.get()); - RETURN_IF_FAILED( - m_borderEffect->SetValue( - D2D1_BORDER_PROP_EDGE_MODE_X, - D2D1_BORDER_EDGE_MODE_MIRROR - ) - ); - RETURN_IF_FAILED( - m_borderEffect->SetValue( - D2D1_BORDER_PROP_EDGE_MODE_Y, - D2D1_BORDER_EDGE_MODE_MIRROR - ) - ); - m_directionalBlurXEffect->SetInputEffect(0, m_borderEffect.get()); - RETURN_IF_FAILED( - m_directionalBlurXEffect->SetValue( - D2D1_DIRECTIONALBLURKERNEL_PROP_DIRECTION, - D2D1_DIRECTIONALBLURKERNEL_DIRECTION_X - ) - ); - m_directionalBlurYEffect->SetInputEffect(0, m_directionalBlurXEffect.get()); - RETURN_IF_FAILED( - m_directionalBlurYEffect->SetValue( - D2D1_DIRECTIONALBLURKERNEL_PROP_DIRECTION, - D2D1_DIRECTIONALBLURKERNEL_DIRECTION_Y - ) - ); - m_scaleUpEffect->SetInputEffect(0, m_directionalBlurYEffect.get()); - RETURN_IF_FAILED(m_scaleUpEffect->SetValue(D2D1_SCALE_PROP_SHARPNESS, 1.f)); - RETURN_IF_FAILED( - m_scaleUpEffect->SetValue( - D2D1_SCALE_PROP_BORDER_MODE, - D2D1_BORDER_MODE_HARD - ) - ); - RETURN_IF_FAILED( - m_scaleUpEffect->SetValue( - D2D1_SCALE_PROP_INTERPOLATION_MODE, - D2D1_SCALE_INTERPOLATION_MODE_LINEAR - ) - ); + SetParams(); + m_initialized = true; return S_OK; @@ -225,7 +162,87 @@ HRESULT CCustomBlurEffect::InitializeAero() m_cropInputEffect->SetValue(D2D1_PROPERTY_CACHED, TRUE) );*/ + SetParamsAero(); + + + m_initialized = true; + + return S_OK; +} + +HRESULT CCustomBlurEffect::SetParams() +{ + /* + RETURN_IF_FAILED( + m_cropInputEffect->SetValue(D2D1_PROPERTY_CACHED, TRUE) + );*/ + RETURN_IF_FAILED( + m_cropInputEffect->SetValue( + D2D1_CROP_PROP_BORDER_MODE, + D2D1_BORDER_MODE_SOFT + ) + ); + m_scaleDownEffect->SetInputEffect(0, m_cropInputEffect.get()); + RETURN_IF_FAILED(m_scaleDownEffect->SetValue(D2D1_SCALE_PROP_SHARPNESS, 1.f)); + RETURN_IF_FAILED( + m_scaleDownEffect->SetValue( + D2D1_SCALE_PROP_BORDER_MODE, + D2D1_BORDER_MODE_HARD + ) + ); + RETURN_IF_FAILED( + m_scaleDownEffect->SetValue( + D2D1_SCALE_PROP_INTERPOLATION_MODE, + D2D1_SCALE_INTERPOLATION_MODE_LINEAR + ) + ); + m_borderEffect->SetInputEffect(0, m_scaleDownEffect.get()); + RETURN_IF_FAILED( + m_borderEffect->SetValue( + D2D1_BORDER_PROP_EDGE_MODE_X, + D2D1_BORDER_EDGE_MODE_MIRROR + ) + ); + RETURN_IF_FAILED( + m_borderEffect->SetValue( + D2D1_BORDER_PROP_EDGE_MODE_Y, + D2D1_BORDER_EDGE_MODE_MIRROR + ) + ); + m_directionalBlurXEffect->SetInputEffect(0, m_borderEffect.get()); + RETURN_IF_FAILED( + m_directionalBlurXEffect->SetValue( + D2D1_DIRECTIONALBLURKERNEL_PROP_DIRECTION, + D2D1_DIRECTIONALBLURKERNEL_DIRECTION_X + ) + ); + m_directionalBlurYEffect->SetInputEffect(0, m_directionalBlurXEffect.get()); + RETURN_IF_FAILED( + m_directionalBlurYEffect->SetValue( + D2D1_DIRECTIONALBLURKERNEL_PROP_DIRECTION, + D2D1_DIRECTIONALBLURKERNEL_DIRECTION_Y + ) + ); + m_scaleUpEffect->SetInputEffect(0, m_directionalBlurYEffect.get()); + RETURN_IF_FAILED(m_scaleUpEffect->SetValue(D2D1_SCALE_PROP_SHARPNESS, 1.f)); + RETURN_IF_FAILED( + m_scaleUpEffect->SetValue( + D2D1_SCALE_PROP_BORDER_MODE, + D2D1_BORDER_MODE_HARD + ) + ); + RETURN_IF_FAILED( + m_scaleUpEffect->SetValue( + D2D1_SCALE_PROP_INTERPOLATION_MODE, + D2D1_SCALE_INTERPOLATION_MODE_LINEAR + ) + ); + + return S_OK; +} +HRESULT CCustomBlurEffect::SetParamsAero() +{ // now here we start setting values n shit or atleast the default values // imma have to investigate later in the file whats being done but otherwise @@ -235,7 +252,7 @@ HRESULT CCustomBlurEffect::InitializeAero() m_cropInputEffect->SetValue( D2D1_CROP_PROP_BORDER_MODE, D2D1_BORDER_MODE_SOFT - ) + ) ); m_scaleDownEffect->SetInputEffect(0, m_cropInputEffect.get()); RETURN_IF_FAILED(m_scaleDownEffect->SetValue(D2D1_SCALE_PROP_SHARPNESS, 1.f)); @@ -243,40 +260,40 @@ HRESULT CCustomBlurEffect::InitializeAero() m_scaleDownEffect->SetValue( D2D1_SCALE_PROP_BORDER_MODE, D2D1_BORDER_MODE_HARD - ) + ) ); RETURN_IF_FAILED( m_scaleDownEffect->SetValue( D2D1_SCALE_PROP_INTERPOLATION_MODE, D2D1_SCALE_INTERPOLATION_MODE_ANISOTROPIC - ) + ) ); m_borderEffect->SetInputEffect(0, m_scaleDownEffect.get()); RETURN_IF_FAILED( m_borderEffect->SetValue( D2D1_BORDER_PROP_EDGE_MODE_X, D2D1_BORDER_EDGE_MODE_MIRROR - ) + ) ); RETURN_IF_FAILED( m_borderEffect->SetValue( D2D1_BORDER_PROP_EDGE_MODE_Y, D2D1_BORDER_EDGE_MODE_MIRROR - ) + ) ); m_directionalBlurXEffect->SetInputEffect(0, m_borderEffect.get()); RETURN_IF_FAILED( m_directionalBlurXEffect->SetValue( D2D1_DIRECTIONALBLURKERNEL_PROP_DIRECTION, D2D1_DIRECTIONALBLURKERNEL_DIRECTION_X - ) + ) ); m_directionalBlurYEffect->SetInputEffect(0, m_directionalBlurXEffect.get()); RETURN_IF_FAILED( m_directionalBlurYEffect->SetValue( D2D1_DIRECTIONALBLURKERNEL_PROP_DIRECTION, D2D1_DIRECTIONALBLURKERNEL_DIRECTION_Y - ) + ) ); @@ -294,7 +311,7 @@ HRESULT CCustomBlurEffect::InitializeAero() m_saturationEffect->SetValue( D2D1_SATURATION_PROP_SATURATION, 0.0f - ) + ) ); m_tintEffect->SetInputEffect(0, m_saturationEffect.get()); @@ -302,22 +319,22 @@ HRESULT CCustomBlurEffect::InitializeAero() m_tintEffect->SetValue( D2D1_TINT_PROP_COLOR, D2D1::Vector4F(116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f, 1.0f) - ) + ) ); D2D1_MATRIX_5X4_F AfterglowBalanceM = D2D1::Matrix5x4F(m_colorizationAfterglowBalanceVal, 0.f, 0.f, 0.f, - 0.f, m_colorizationAfterglowBalanceVal, 0.f, 0.f, - 0.f, 0.f, m_colorizationAfterglowBalanceVal, 0.f, - 0.f, 0.f, 0.f, 1.f, - 0.f, 0.f, 0.f, 0.f); + 0.f, m_colorizationAfterglowBalanceVal, 0.f, 0.f, + 0.f, 0.f, m_colorizationAfterglowBalanceVal, 0.f, + 0.f, 0.f, 0.f, 1.f, + 0.f, 0.f, 0.f, 0.f); m_ColorizationAfterglowBalance->SetInputEffect(0, m_tintEffect.get()); RETURN_IF_FAILED( m_ColorizationAfterglowBalance->SetValue( D2D1_COLORMATRIX_PROP_COLOR_MATRIX, AfterglowBalanceM - ) + ) ); // afterglow done @@ -326,15 +343,15 @@ HRESULT CCustomBlurEffect::InitializeAero() D2D1_MATRIX_5X4_F BlurBalanceM = D2D1::Matrix5x4F(m_colorizationBlurBalanceVal, 0.f, 0.f, 0.f, 0.f, m_colorizationBlurBalanceVal, 0.f, 0.f, 0.f, 0.f, m_colorizationBlurBalanceVal, 0.f, - 0.f, 0.f, 0.f, 1.f, - 0.f, 0.f, 0.f, 0.f); + 0.f, 0.f, 0.f, 1.f, + 0.f, 0.f, 0.f, 0.f); m_ColorizationBlurBalance->SetInputEffect(0, m_directionalBlurYEffect.get()); RETURN_IF_FAILED( m_ColorizationBlurBalance->SetValue( D2D1_COLORMATRIX_PROP_COLOR_MATRIX, BlurBalanceM - ) + ) ); // and finally ColorizationColor @@ -343,21 +360,21 @@ HRESULT CCustomBlurEffect::InitializeAero() m_ColorizationColor->SetValue( D2D1_FLOOD_PROP_COLOR, D2D1::Vector4F(116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f, 1.0f) - ) + ) ); D2D1_MATRIX_5X4_F ColorBalanceM = D2D1::Matrix5x4F(m_colorizationColorBalanceVal, 0.f, 0.f, 0.f, - 0.f, m_colorizationColorBalanceVal, 0.f, 0.f, - 0.f, 0.f, m_colorizationColorBalanceVal, 0.f, - 0.f, 0.f, 0.f, 1.f, - 0.f, 0.f, 0.f, 0.f); + 0.f, m_colorizationColorBalanceVal, 0.f, 0.f, + 0.f, 0.f, m_colorizationColorBalanceVal, 0.f, + 0.f, 0.f, 0.f, 1.f, + 0.f, 0.f, 0.f, 0.f); m_ColorizationColorBalance->SetInputEffect(0, m_ColorizationColor.get()); RETURN_IF_FAILED( m_ColorizationColorBalance->SetValue( D2D1_COLORMATRIX_PROP_COLOR_MATRIX, ColorBalanceM - ) + ) ); @@ -368,7 +385,7 @@ HRESULT CCustomBlurEffect::InitializeAero() m_compositeEffect->SetValue( D2D1_COMPOSITE_PROP_MODE, D2D1_COMPOSITE_MODE_PLUS - ) + ) ); m_compositeEffect_pass2->SetInputEffect(0, m_compositeEffect.get()); @@ -387,18 +404,16 @@ HRESULT CCustomBlurEffect::InitializeAero() m_scaleUpEffect->SetValue( D2D1_SCALE_PROP_BORDER_MODE, D2D1_BORDER_MODE_HARD - ) + ) ); RETURN_IF_FAILED( m_scaleUpEffect->SetValue( D2D1_SCALE_PROP_INTERPOLATION_MODE, D2D1_SCALE_INTERPOLATION_MODE_ANISOTROPIC - ) + ) ); - m_initialized = true; - return S_OK; } @@ -594,6 +609,12 @@ HRESULT STDMETHODCALLTYPE CCustomBlurEffect::Invalidate( (prescaleAmount.y != finalPrescaleAmount.y) ? D2D1_DIRECTIONALBLURKERNEL_OPTIMIZATION_TRANSFORM_SCALE : D2D1_DIRECTIONALBLURKERNEL_OPTIMIZATION_TRANSFORM_IDENDITY ) ); + + if (m_type == Type::Blur) + RETURN_IF_FAILED(SetParams()); + else if (m_type == Type::Aero) + RETURN_IF_FAILED(SetParamsAero()); + #ifdef _DEBUG OutputDebugStringW( std::format( diff --git a/OpenGlass/CustomBlurEffect.hpp b/OpenGlass/CustomBlurEffect.hpp index 75f618a..7b81cbe 100644 --- a/OpenGlass/CustomBlurEffect.hpp +++ b/OpenGlass/CustomBlurEffect.hpp @@ -80,6 +80,8 @@ namespace OpenGlass static float DetermineOutputScale(float size, float blurAmount); HRESULT Initialize(); HRESULT InitializeAero(); + HRESULT SetParams(); + HRESULT SetParamsAero(); public: CCustomBlurEffect(ID2D1DeviceContext* deviceContext); diff --git a/OpenGlass/GlassFramework.cpp b/OpenGlass/GlassFramework.cpp index 5bc0c24..a6ebb83 100644 --- a/OpenGlass/GlassFramework.cpp +++ b/OpenGlass/GlassFramework.cpp @@ -81,11 +81,13 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCTopLevelWindow_UpdateNCAreaBackgrou { if (!GlassSharedData::IsBackdropAllowed()) { + GlassSharedData::g_LastTopLevelWindow = 0; return g_CTopLevelWindow_UpdateNCAreaBackground_Org(This); } auto data{ This->GetData() }; if (!data) { + GlassSharedData::g_LastTopLevelWindow = 0; return g_CTopLevelWindow_UpdateNCAreaBackground_Org(This); } @@ -123,6 +125,7 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCTopLevelWindow_UpdateNCAreaBackgrou HRGN borderRegion{ GeometryRecorder::GetRegionFromGeometry(borderGeometry) }; hr = legacyVisualOverride->UpdateNCBackground(captionRegion, borderRegion); + GlassSharedData::g_LastTopLevelWindow = This; } } @@ -130,6 +133,7 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCTopLevelWindow_UpdateNCAreaBackgrou } else { + GlassSharedData::g_LastTopLevelWindow = 0; VisualManager::RemoveLegacyVisualOverrider(This); hr = g_CTopLevelWindow_UpdateNCAreaBackground_Org(This); } @@ -152,6 +156,7 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCTopLevelWindow_UpdateClientBlur(uDw g_capturedWindow = This; GeometryRecorder::BeginCapture(); + GlassSharedData::g_LastTopLevelWindow = 0; HRESULT hr{ g_CTopLevelWindow_UpdateClientBlur_Org(This) }; GeometryRecorder::EndCapture(); g_capturedWindow = nullptr; diff --git a/OpenGlass/GlassRenderer.cpp b/OpenGlass/GlassRenderer.cpp index f87add2..c48ccda 100644 --- a/OpenGlass/GlassRenderer.cpp +++ b/OpenGlass/GlassRenderer.cpp @@ -153,6 +153,9 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawSolidRectangle( g_drawColor = std::nullopt; return g_CDrawingContext_DrawSolidRectangle_Org(This, rectangle, convertedColor); } + +bool active = false; + HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( dwmcore::IDrawingContext* This, dwmcore::CLegacyMilBrush* brush, @@ -236,9 +239,12 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( This->GetDrawingContext()->GetD2DContext()->GetDeviceContext()->GetTarget(backdropImage.put()); winrt::com_ptr backdropBitmap{ backdropImage.as() }; RETURN_IF_FAILED(This->GetDrawingContext()->FlushD2D()); + //TODO: ADD PROPER TYPE CHECKED CAST + bool bactive = false; + if (GlassSharedData::g_LastTopLevelWindow) + bactive = (reinterpret_cast(GlassSharedData::g_LastTopLevelWindow)->TreatAsActiveWindow()); - //TODO: idk if this is best, prob change - bool active = true; + //bool bactive = true; dwmcore::CMILMatrix matrix{}; D2D1_RECT_F shapeWorldBounds{}; @@ -249,7 +255,7 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( g_glassOpacity, g_blurAmount, GlassSharedData::g_ColorizationAfterglowBalance, - active ? GlassSharedData::g_ColorizationBlurBalance : 0.4f * GlassSharedData::g_ColorizationBlurBalance + 0.6f, + bactive ? GlassSharedData::g_ColorizationBlurBalance : 0.4f * GlassSharedData::g_ColorizationBlurBalance + 0.6f, GlassSharedData::g_ColorizationColorBalance, g_type ); @@ -317,6 +323,7 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDirtyRegion__Add( lprc.right + extendAmount, lprc.bottom + extendAmount }; + active = unknown; return g_CDirtyRegion__Add_Org( This, visual, diff --git a/OpenGlass/GlassSharedData.hpp b/OpenGlass/GlassSharedData.hpp index 4332a9f..bdb180d 100644 --- a/OpenGlass/GlassSharedData.hpp +++ b/OpenGlass/GlassSharedData.hpp @@ -4,6 +4,7 @@ namespace OpenGlass::GlassSharedData { + inline void* g_LastTopLevelWindow = nullptr; inline bool g_disableOnBattery{ true }; inline bool g_overrideAccent{ false }; inline bool g_batteryMode{ false }; From 557f3c9abe840e04047297eb3e6d0244bb50ce11 Mon Sep 17 00:00:00 2001 From: kfh83 <85626296+kfh83@users.noreply.github.com> Date: Wed, 17 Jul 2024 03:12:00 -0300 Subject: [PATCH 06/17] Fix ColorizationColorBalance being incorrect in inactive windows The value stayed constant between active/inactive when in Windows 7 it its 40% of the active value --- OpenGlass/GlassRenderer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenGlass/GlassRenderer.cpp b/OpenGlass/GlassRenderer.cpp index c48ccda..70d4020 100644 --- a/OpenGlass/GlassRenderer.cpp +++ b/OpenGlass/GlassRenderer.cpp @@ -254,9 +254,9 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( color, g_glassOpacity, g_blurAmount, - GlassSharedData::g_ColorizationAfterglowBalance, - bactive ? GlassSharedData::g_ColorizationBlurBalance : 0.4f * GlassSharedData::g_ColorizationBlurBalance + 0.6f, - GlassSharedData::g_ColorizationColorBalance, + GlassSharedData::g_ColorizationAfterglowBalance, // stays the same + bactive ? GlassSharedData::g_ColorizationBlurBalance : 0.4f * GlassSharedData::g_ColorizationBlurBalance + 0.6f, // y = 0.4x + 60 + bactive ? GlassSharedData::g_ColorizationColorBalance : 0.4f * GlassSharedData::g_ColorizationColorBalance, //y = 0.4x g_type ); glassEffect->SetSize( @@ -410,4 +410,4 @@ void GlassRenderer::Shutdown() GlassEffectManager::Shutdown(); ReflectionRenderer::g_reflectionBitmap = nullptr; -} \ No newline at end of file +} From c66ee6297fe908bd93d8b28bafbc7c6489f5042e Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Wed, 17 Jul 2024 15:11:40 +0100 Subject: [PATCH 07/17] fix colours and active inactive checks --- OpenGlass/CustomBlurEffect.cpp | 6 ++++-- OpenGlass/CustomBlurEffect.hpp | 3 +++ OpenGlass/GlassEffectManager.cpp | 1 + OpenGlass/GlassFramework.cpp | 5 +++++ OpenGlass/GlassRenderer.cpp | 18 +++++++++++++----- OpenGlass/GlassSharedData.hpp | 1 + OpenGlass/VisualManager.cpp | 1 + OpenGlass/dwmcoreProjection.hpp | 3 ++- 8 files changed, 30 insertions(+), 8 deletions(-) diff --git a/OpenGlass/CustomBlurEffect.cpp b/OpenGlass/CustomBlurEffect.cpp index d8a83c5..e131bbe 100644 --- a/OpenGlass/CustomBlurEffect.cpp +++ b/OpenGlass/CustomBlurEffect.cpp @@ -359,7 +359,7 @@ HRESULT CCustomBlurEffect::SetParamsAero() RETURN_IF_FAILED( m_ColorizationColor->SetValue( D2D1_FLOOD_PROP_COLOR, - D2D1::Vector4F(116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f, 1.0f) + D2D1::Vector4F(m_Color.r, m_Color.g, m_Color.b, 1.0f) ) ); @@ -446,6 +446,7 @@ HRESULT STDMETHODCALLTYPE CCustomBlurEffect::Invalidate( float colorizationAfterglowBalanceVal, float colorizationBlurBalanceVal, float colorizationColorBalanceVal, + D2D1_COLOR_F color, Type type ) { @@ -457,12 +458,13 @@ HRESULT STDMETHODCALLTYPE CCustomBlurEffect::Invalidate( bool recalculateParams{ false }; if (m_blurAmount != blurAmount || m_colorizationAfterglowBalanceVal != colorizationAfterglowBalanceVal || m_colorizationBlurBalanceVal != colorizationBlurBalanceVal || - m_colorizationColorBalanceVal != colorizationColorBalanceVal) + m_colorizationColorBalanceVal != colorizationColorBalanceVal || (m_Color.r != color.r) || (m_Color.g != color.g) || (m_Color.b != color.b) || (m_Color.a != color.a) ) { m_blurAmount = blurAmount; m_colorizationAfterglowBalanceVal = colorizationAfterglowBalanceVal; m_colorizationBlurBalanceVal = colorizationBlurBalanceVal; m_colorizationColorBalanceVal = colorizationColorBalanceVal; + m_Color = color; recalculateParams = true; } diff --git a/OpenGlass/CustomBlurEffect.hpp b/OpenGlass/CustomBlurEffect.hpp index 7b81cbe..d91a5a1 100644 --- a/OpenGlass/CustomBlurEffect.hpp +++ b/OpenGlass/CustomBlurEffect.hpp @@ -35,6 +35,7 @@ namespace OpenGlass float colorizationAfterglowBalanceVal, float colorizationBlurBalanceVal, float colorizationColorBalanceVal, + D2D1_COLOR_F color, Type type ) = 0; virtual HRESULT STDMETHODCALLTYPE Draw( @@ -75,6 +76,7 @@ namespace OpenGlass float m_colorizationAfterglowBalanceVal = 0.43f; float m_colorizationBlurBalanceVal = 0.49f; float m_colorizationColorBalanceVal = 0.08f; + D2D1_COLOR_F m_Color = { 116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f,1.0f }; static const float k_optimizations[16]; static float DetermineOutputScale(float size, float blurAmount); @@ -93,6 +95,7 @@ namespace OpenGlass float colorizationAfterglowBalanceVal, float colorizationBlurBalanceVal, float colorizationColorBalanceVal, + D2D1_COLOR_F color, Type type ) override; HRESULT STDMETHODCALLTYPE Draw( diff --git a/OpenGlass/GlassEffectManager.cpp b/OpenGlass/GlassEffectManager.cpp index 9755908..3fb95ad 100644 --- a/OpenGlass/GlassEffectManager.cpp +++ b/OpenGlass/GlassEffectManager.cpp @@ -216,6 +216,7 @@ HRESULT STDMETHODCALLTYPE GlassEffectManager::CGlassEffect::Invalidate( m_colorizationAfterglowBalanceVal, m_colorizationBlurBalanceVal, m_colorizationColorBalanceVal, + m_color, m_type ) ); diff --git a/OpenGlass/GlassFramework.cpp b/OpenGlass/GlassFramework.cpp index a6ebb83..31c6376 100644 --- a/OpenGlass/GlassFramework.cpp +++ b/OpenGlass/GlassFramework.cpp @@ -67,6 +67,7 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCDrawGeometryInstruction_Create(uDwm ); auto color{ g_capturedWindow->GetTitlebarColorizationParameters()->getArgbcolor() }; color.a *= 0.99f; + color.r = g_capturedWindow->TreatAsActiveWindow(); RETURN_IF_FAILED(solidBrush->Update(1.0, color)); return g_CDrawGeometryInstruction_Create_Org(solidBrush.get(), rgnGeometry.get(), instruction); } @@ -251,6 +252,7 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCRenderDataVisual_AddInstruction(uDw } color.a = 0.99f; + color.r = 1.0f; winrt::com_ptr rgnGeometry{ nullptr }; uDwm::ResourceHelper::CreateGeometryFromHRGN(wil::unique_hrgn{ CreateRectRgn(static_cast(rectangle.left), static_cast(rectangle.top), static_cast(rectangle.right), static_cast(rectangle.bottom)) }.get(), rgnGeometry.put()); winrt::com_ptr solidBrush{ nullptr }; @@ -341,6 +343,9 @@ void GlassFramework::UpdateConfiguration(ConfigurationFramework::UpdateType type GlassSharedData::g_ColorizationBlurBalance = ((float)ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"OG_ColorizationBlurBalance",49) / 100); GlassSharedData::g_ColorizationColorBalance = ((float)ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"OG_ColorizationColorBalance",8) / 100); + DWORD hexColour = ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"AccentColor", 0xfffcb874); + GlassSharedData::g_AccentColor = Utils::FromAbgr(hexColour); + auto lock{ wil::EnterCriticalSection(uDwm::CDesktopManager::s_csDwmInstance) }; if (!GlassSharedData::IsBackdropAllowed()) { diff --git a/OpenGlass/GlassRenderer.cpp b/OpenGlass/GlassRenderer.cpp index c48ccda..a0bc44d 100644 --- a/OpenGlass/GlassRenderer.cpp +++ b/OpenGlass/GlassRenderer.cpp @@ -173,8 +173,15 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( return hr; } + bool bactive = g_drawColor.value().r == 1.0f; //HACK!!!: check if window is active using the data sent through the red channel + //bool bactive = data->GetWindow()->TreatAsActiveWindow(); + //OutputDebugStringW(std::format(L"r {}", g_drawColor.value().r).c_str()); + //g_drawColor.value() = D2D1_COLOR_F{ 116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f, g_drawColor.value().a}; + //g_drawColor.value() = D2D1_COLOR_F{ GlassSharedData::g_AccentColor.r, GlassSharedData::g_AccentColor.g, GlassSharedData::g_AccentColor.b, g_drawColor.value().a}; auto cleanUp{ wil::scope_exit([]{ g_drawColor = std::nullopt; })}; - D2D1_COLOR_F color{ dwmcore::Convert_D2D1_COLOR_F_scRGB_To_D2D1_COLOR_F_sRGB(g_drawColor.value()) }; + //D2D1_COLOR_F color{ dwmcore::Convert_D2D1_COLOR_F_scRGB_To_D2D1_COLOR_F_sRGB(g_drawColor.value()) }; + //D2D1_COLOR_F color{ g_drawColor.value()}; + D2D1_COLOR_F color{ GlassSharedData::g_AccentColor.r, GlassSharedData::g_AccentColor.g, GlassSharedData::g_AccentColor.b, g_drawColor.value().a }; dwmcore::CShapePtr geometryShape{}; if ( FAILED(geometry->GetShapeData(nullptr, &geometryShape)) || @@ -238,11 +245,12 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( winrt::com_ptr backdropImage{}; This->GetDrawingContext()->GetD2DContext()->GetDeviceContext()->GetTarget(backdropImage.put()); winrt::com_ptr backdropBitmap{ backdropImage.as() }; - RETURN_IF_FAILED(This->GetDrawingContext()->FlushD2D()); //TODO: ADD PROPER TYPE CHECKED CAST - bool bactive = false; - if (GlassSharedData::g_LastTopLevelWindow) - bactive = (reinterpret_cast(GlassSharedData::g_LastTopLevelWindow)->TreatAsActiveWindow()); + //bool bactive = false; + //if (This->GetDrawingContext()->GetCurrentVisual()) + //bactive = true; + + RETURN_IF_FAILED(This->GetDrawingContext()->FlushD2D()); //bool bactive = true; diff --git a/OpenGlass/GlassSharedData.hpp b/OpenGlass/GlassSharedData.hpp index bdb180d..c513859 100644 --- a/OpenGlass/GlassSharedData.hpp +++ b/OpenGlass/GlassSharedData.hpp @@ -12,6 +12,7 @@ namespace OpenGlass::GlassSharedData inline float g_ColorizationAfterglowBalance = 0.43f; inline float g_ColorizationBlurBalance = 0.49f; inline float g_ColorizationColorBalance = 0.08f; + inline D2D_COLOR_F g_AccentColor{ 116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f,1.0f }; FORCEINLINE bool IsBackdropAllowed() { diff --git a/OpenGlass/VisualManager.cpp b/OpenGlass/VisualManager.cpp index 7304022..efb726e 100644 --- a/OpenGlass/VisualManager.cpp +++ b/OpenGlass/VisualManager.cpp @@ -175,6 +175,7 @@ HRESULT STDMETHODCALLTYPE VisualManager::CLegacyVisualOverrider::UpdateNCBackgro auto color{ m_window->GetTitlebarColorizationParameters()->getArgbcolor() }; color.a *= 0.99f; + color.r = m_window->TreatAsActiveWindow(); //HACK!!: Send active or inactive window data through the red channel RETURN_IF_FAILED(m_brush->Update(1.0, color)); wil::unique_hrgn emptyRegion{ CreateRectRgn(0, 0, 0, 0) }; diff --git a/OpenGlass/dwmcoreProjection.hpp b/OpenGlass/dwmcoreProjection.hpp index 91dab87..d0e44e0 100644 --- a/OpenGlass/dwmcoreProjection.hpp +++ b/OpenGlass/dwmcoreProjection.hpp @@ -475,7 +475,8 @@ namespace OpenGlass::dwmcore CVisual* STDMETHODCALLTYPE GetCurrentVisual() const { DEFINE_INVOKER(CDrawingContext::GetCurrentVisual); - return INVOKE_MEMBERFUNCTION(); + //return INVOKE_MEMBERFUNCTION(); + return std::invoke(s_fn_ptr, (CDrawingContext*)(__int64(this) + 0x18) ); } bool STDMETHODCALLTYPE IsInLayer() const { From 819fc5f919aee87f6dfb8313aaec03989786de17 Mon Sep 17 00:00:00 2001 From: kfh83 <85626296+kfh83@users.noreply.github.com> Date: Wed, 17 Jul 2024 14:18:11 -0300 Subject: [PATCH 08/17] credits --- OpenGlass/CustomBlurEffect.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OpenGlass/CustomBlurEffect.cpp b/OpenGlass/CustomBlurEffect.cpp index e131bbe..50823c2 100644 --- a/OpenGlass/CustomBlurEffect.cpp +++ b/OpenGlass/CustomBlurEffect.cpp @@ -243,7 +243,7 @@ HRESULT CCustomBlurEffect::SetParams() HRESULT CCustomBlurEffect::SetParamsAero() { - // now here we start setting values n shit or atleast the default values + // now here we start setting values, or atleast the default values // imma have to investigate later in the file whats being done but otherwise @@ -297,6 +297,8 @@ HRESULT CCustomBlurEffect::SetParamsAero() ); + // CREDITS: @kfh83, @wiktorwiktor12, @TorutheRedFox and @WackyIdeas. special shoutouts to @aubymori and @kawapure for testing/help + // okay my conclusion is that i shouldnt tamper with whatever was already set up (no point in removing the scales or adding gaussian blur) // so since all of the blur work is done here, starting my part of it: @@ -671,4 +673,4 @@ HRESULT STDMETHODCALLTYPE CCustomBlurEffect::Draw( }*/ return S_OK; -} \ No newline at end of file +} From ff6f94e8f57549220390ce034854bace1715ef01 Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Thu, 18 Jul 2024 01:31:47 +0100 Subject: [PATCH 09/17] fix colour shit we are blind and didnt see this, Oopsies! --- OpenGlass/CustomBlurEffect.cpp | 2 +- OpenGlass/GlassFramework.cpp | 4 ++-- OpenGlass/GlassRenderer.cpp | 12 +++++++++--- OpenGlass/GlassSharedData.hpp | 2 +- OpenGlass/Utils.hpp | 18 ++++++++++++++++++ OpenGlass/dwmcoreProjection.hpp | 4 ++-- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/OpenGlass/CustomBlurEffect.cpp b/OpenGlass/CustomBlurEffect.cpp index 50823c2..c0b7f94 100644 --- a/OpenGlass/CustomBlurEffect.cpp +++ b/OpenGlass/CustomBlurEffect.cpp @@ -320,7 +320,7 @@ HRESULT CCustomBlurEffect::SetParamsAero() RETURN_IF_FAILED( m_tintEffect->SetValue( D2D1_TINT_PROP_COLOR, - D2D1::Vector4F(116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f, 1.0f) + D2D1::Vector4F(m_Color.r, m_Color.g, m_Color.b, 1.0f) ) ); diff --git a/OpenGlass/GlassFramework.cpp b/OpenGlass/GlassFramework.cpp index 31c6376..d217582 100644 --- a/OpenGlass/GlassFramework.cpp +++ b/OpenGlass/GlassFramework.cpp @@ -343,8 +343,8 @@ void GlassFramework::UpdateConfiguration(ConfigurationFramework::UpdateType type GlassSharedData::g_ColorizationBlurBalance = ((float)ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"OG_ColorizationBlurBalance",49) / 100); GlassSharedData::g_ColorizationColorBalance = ((float)ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"OG_ColorizationColorBalance",8) / 100); - DWORD hexColour = ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"AccentColor", 0xfffcb874); - GlassSharedData::g_AccentColor = Utils::FromAbgr(hexColour); + DWORD hexColour = ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"ColorizationColor", 0xfffcb874); + GlassSharedData::g_ColorizationColor = Utils::FromArgb(hexColour); auto lock{ wil::EnterCriticalSection(uDwm::CDesktopManager::s_csDwmInstance) }; if (!GlassSharedData::IsBackdropAllowed()) diff --git a/OpenGlass/GlassRenderer.cpp b/OpenGlass/GlassRenderer.cpp index 0b5f14c..7295658 100644 --- a/OpenGlass/GlassRenderer.cpp +++ b/OpenGlass/GlassRenderer.cpp @@ -172,16 +172,22 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( { return hr; } - + //HWND hwnd = reinterpret_cast(This->GetDrawingContext()->GetD2DContextOwner())->GetCurrentVisual()->GetTopLevelWindow(); + //uDwm::CWindowData* data{ nullptr }; + //{ + // auto lock{ wil::EnterCriticalSection(uDwm::CDesktopManager::s_csDwmInstance) }; + // uDwm::CDesktopManager::s_pDesktopManagerInstance->GetWindowList()->GetSyncedWindowDataByHwnd(hwnd, &data); + //} + //if (!data) return hr; bool bactive = g_drawColor.value().r == 1.0f; //HACK!!!: check if window is active using the data sent through the red channel //bool bactive = data->GetWindow()->TreatAsActiveWindow(); //OutputDebugStringW(std::format(L"r {}", g_drawColor.value().r).c_str()); //g_drawColor.value() = D2D1_COLOR_F{ 116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f, g_drawColor.value().a}; - //g_drawColor.value() = D2D1_COLOR_F{ GlassSharedData::g_AccentColor.r, GlassSharedData::g_AccentColor.g, GlassSharedData::g_AccentColor.b, g_drawColor.value().a}; + //g_drawColor.value() = D2D1_COLOR_F{ GlassSharedData::g_ColorizationColor.r, GlassSharedData::g_ColorizationColor.g, GlassSharedData::g_ColorizationColor.b, g_drawColor.value().a}; auto cleanUp{ wil::scope_exit([]{ g_drawColor = std::nullopt; })}; //D2D1_COLOR_F color{ dwmcore::Convert_D2D1_COLOR_F_scRGB_To_D2D1_COLOR_F_sRGB(g_drawColor.value()) }; //D2D1_COLOR_F color{ g_drawColor.value()}; - D2D1_COLOR_F color{ GlassSharedData::g_AccentColor.r, GlassSharedData::g_AccentColor.g, GlassSharedData::g_AccentColor.b, g_drawColor.value().a }; + D2D1_COLOR_F color{ GlassSharedData::g_ColorizationColor.r, GlassSharedData::g_ColorizationColor.g, GlassSharedData::g_ColorizationColor.b, g_drawColor.value().a }; dwmcore::CShapePtr geometryShape{}; if ( FAILED(geometry->GetShapeData(nullptr, &geometryShape)) || diff --git a/OpenGlass/GlassSharedData.hpp b/OpenGlass/GlassSharedData.hpp index c513859..73fde04 100644 --- a/OpenGlass/GlassSharedData.hpp +++ b/OpenGlass/GlassSharedData.hpp @@ -12,7 +12,7 @@ namespace OpenGlass::GlassSharedData inline float g_ColorizationAfterglowBalance = 0.43f; inline float g_ColorizationBlurBalance = 0.49f; inline float g_ColorizationColorBalance = 0.08f; - inline D2D_COLOR_F g_AccentColor{ 116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f,1.0f }; + inline D2D_COLOR_F g_ColorizationColor{ 116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f,1.0f }; FORCEINLINE bool IsBackdropAllowed() { diff --git a/OpenGlass/Utils.hpp b/OpenGlass/Utils.hpp index 60483e7..2cf8340 100644 --- a/OpenGlass/Utils.hpp +++ b/OpenGlass/Utils.hpp @@ -118,6 +118,24 @@ namespace OpenGlass::Utils static_cast(abgr[3]) / 255.f }; } + FORCEINLINE D2D1_COLOR_F FromArgb(DWORD color) + { + auto argb{ reinterpret_cast(&color) }; + return + { + static_cast(argb[2]) / 255.f, + static_cast(argb[1]) / 255.f, + static_cast(argb[0]) / 255.f, + static_cast(argb[3]) / 255.f + }; + + /* + float r; + float g; + float b; + float a; + */ + } } #define DEFINE_INVOKER(fn) static const auto s_fn_ptr{ Utils::cast_pointer(g_symbolMap.at(#fn)) } diff --git a/OpenGlass/dwmcoreProjection.hpp b/OpenGlass/dwmcoreProjection.hpp index d0e44e0..f8ebd2a 100644 --- a/OpenGlass/dwmcoreProjection.hpp +++ b/OpenGlass/dwmcoreProjection.hpp @@ -475,8 +475,8 @@ namespace OpenGlass::dwmcore CVisual* STDMETHODCALLTYPE GetCurrentVisual() const { DEFINE_INVOKER(CDrawingContext::GetCurrentVisual); - //return INVOKE_MEMBERFUNCTION(); - return std::invoke(s_fn_ptr, (CDrawingContext*)(__int64(this) + 0x18) ); + return INVOKE_MEMBERFUNCTION(); + //return std::invoke(s_fn_ptr, (CDrawingContext*)(__int64(this) + 0x18) ); } bool STDMETHODCALLTYPE IsInLayer() const { From 92d97253fec00243bce17a271071753f3c62371c Mon Sep 17 00:00:00 2001 From: kfh83 <85626296+kfh83@users.noreply.github.com> Date: Thu, 18 Jul 2024 00:45:51 -0300 Subject: [PATCH 10/17] Update README.md added some demo images and new balance keys in the documentation area --- README.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d770ee0..29cae0e 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,23 @@ # OpenGlass A replica of the dead software glass8, also known as the upstream project of [DWMBlurGlass](https://github.com/Maplespe/DWMBlurGlass). -This branch does not rely on `dcomp` and `Windows.UI.Composition`, so it is very limited in functionality and it is not unusual to encounter all kinds of bugs, but its performance is much better than the master branch. Currently this branch ONLY supports Windows 10 2004-22H2. +This branch does not rely on `dcomp` and `Windows.UI.Composition` and instead uses raw Direct2D to leverage better performance than the master branch, however due to it's early nature you may encounter more bugs and crashes. Currently this branch ONLY supports Windows 10 2004-22H2. > [!IMPORTANT] > This software is intended for advanced users only. If you are a beginner and you do not have deeper knowledge of Windows (such as registry editing etc.) you should not install this software. > For the average users, you should consider using [DWMBlurGlass](https://github.com/Maplespe/DWMBlurGlass). > [!WARNING] > OpenGlass does NOT support and is NOT intended to support Windows Insider Preview, so if you want to use it in these Windows versions please do it at your own risk. + +## Demonstration +![Screenshot_1](https://github.com/user-attachments/assets/87bd340e-f60f-427b-83dd-d5470af3628a) +![Dj2ZNvKO1f](https://github.com/user-attachments/assets/69cb8c6e-1232-4d6a-8661-a8291c1eb40b) +![BBNq9TdJNM](https://github.com/user-attachments/assets/f2bf46cc-0229-4952-a385-3cfca0df0c35) +![XzSxjpAIWr](https://github.com/user-attachments/assets/4be75ef3-0862-494a-a4c7-e6679ec2f790) +![paintdotnet_lRyttWoEq4](https://github.com/user-attachments/assets/9d52fb58-e6b8-438e-8801-28afc19ecdbc) +> *.msstyles theme used for screenshots: [Aero10 by vaporvance](https://www.deviantart.com/vaporvance/art/Aero10-for-Windows-10-1903-22H2-909711949)* + +> *additional software used: [Windhawk](https://windhawk.net/), [Aero Window Manager](https://github.com/Dulappy/aero-window-manager) by @Dulappy* ## How to use this software 1. Extract the files from the Release page to `C:\`, but please don't put them in `C:\Users\*`, otherwise OpenGlass won't work properly. 2. Run `install.bat` as administrator, this will create a scheduled task for you to run the OpenGlass helper process on boot, which will monitor and automatically inject its component into Dwm. @@ -26,10 +36,14 @@ The legacy branch can use most of the features of the master branch. The followi | master branch | Type | Description | legacy branch | Description | Remarks | ---- | ---- | ---- | ---- | ---- | ---- | | RoundRectRadius | DWORD | The radius of glass geometry, Win8 = 0, Win7 = 12 | | Rounded corners are not anti-aliased. | **OK** | +| og_ColorizationColorBalance | DWORD | Controls the balance of the solid color layer. Behaves the same as Windows 7. | | **NOTE FOR og_ VARIANTS:** This is done so Windows doesn't override these values with bogus ones. | **OK** | +| og_ColorizationAfterglowBalance | DWORD | Controls the balance of the multiply+blur layer. Behaves the same as Windows 7. | | | **OK** | +| og_ColorizationrBlurBalance | DWORD | Controls the balance of the blur layer. Behaves the same as Windows 7. | | | **OK** | | CustomThemeMaterial | String | **Undocumented** | | | **Not implemented** | | MaterialOpacity | DWORD | **Undocumented** | | | **Not implemented** | | GlassLuminosity | DWORD | The luminosity of Acrylic/Mica effect | | | **Not implemented** | -| GlassType | DWORD | The type of backdrop effect (0x0-0x4). 0x0=Blur. 0x01=Aero. 0x02=Acrylic. 0x03=Mica. 0x04=Solid. | | Only 0x0 is implemented. | **OK** | +| GlassOpacity | DWORD | Controls the opacity of the glass colorization | | ***TODO:** deprecate this registry key for GlassType 0x1 and introduce an inactive variant for GlassType 0x0 (Vista style) | **OK*** | +| GlassType | DWORD | The type of backdrop effect (0x0-0x4). 0x0=Blur. 0x01=Aero. 0x02=Acrylic. 0x03=Mica. 0x04=Solid. | | Only 0x0 and 0x1 are implemented. | **OK** | | GlassOverrideBorder | DWORD | Specifies that the effect should extend to the border. The default value is 0. | | The glass will override the border by default. | **Not implemented** | | GlassCrossFadeTime | DWORD | The cross fade time for backdrop switching. The default value is 87. | | | **Not supported** | | GlassOverrideAccent | DWORD | Overriding accent with the effect of OpenGlass. The default value is 0. | | Some windows are overwritten resulting in full transparency. And the behavior of the overrides makes a difference. | **OK** | @@ -70,13 +84,13 @@ PostMessage(FindWindow(TEXT("Dwm"), nullptr), WM_DWMCOLORIZATIONCHANGED, 0, 0); stop AWM In this case you are likely to get a crash of DWM or the other software working abnormally. -- OpenGlass can be used with most windhawk mods, but some may have compatibility issues, especially community or personally written mods that can't be found in the windhawk marketplace. +- OpenGlass can be used with most Windhawk mods, but some may have compatibility issues, especially community or personally written mods that can't be found in the windhawk marketplace. - This branch cannot be used with the master branch. ## Dependencies and References ### [Banner for OpenGlass](https://github.com/ALTaleX531/OpenGlass/discussions/11) Provided by [@aubymori](https://github.com/aubymori) -Wallpaper: [metalheart jawn](https://www.deviantart.com/kfh83/art/metalheart-jawn-2-1068250045) #2 by [@kfh83](https://github.com/kfh83) +Wallpaper: [metalheart jawn #2](https://www.deviantart.com/kfh83/art/metalheart-jawn-2-1068250045) by [@kfh83](https://github.com/kfh83) ### [Microsoft Research Detours Package](https://github.com/microsoft/Detours) Detours is a software package for monitoring and instrumenting API calls on Windows. ### [VC-LTL - An elegant way to compile lighter binaries.](https://github.com/Chuyu-Team/VC-LTL5) @@ -90,4 +104,4 @@ Win2D sucks! ### [AcrylicEverywhere](https://github.com/ALTaleX531/AcrylicEverywhere) The predecessor of this project. ### [Loading Visual Styles Per-Application](https://winclassic.net/thread/2178/loading-visual-styles-application) -It is possible for an application to load a style on a per-application basis using an undocumented API. \ No newline at end of file +It is possible for an application to load a style on a per-application basis using an undocumented API. From 8cec988cc3e3b3edef108a09cbcb75fb5c2a7ad0 Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Thu, 18 Jul 2024 17:05:12 +0100 Subject: [PATCH 11/17] caption glow initial initial prototype of theme, work well TODO: CLEANUP --- OpenGlass/CaptionTextHandler.cpp | 140 +++++++++++++++++++++++++++++++ OpenGlass/uDwmProjection.hpp | 12 +++ 2 files changed, 152 insertions(+) diff --git a/OpenGlass/CaptionTextHandler.cpp b/OpenGlass/CaptionTextHandler.cpp index b06e2ae..e47ccf7 100644 --- a/OpenGlass/CaptionTextHandler.cpp +++ b/OpenGlass/CaptionTextHandler.cpp @@ -262,6 +262,140 @@ void CaptionTextHandler::UpdateConfiguration(ConfigurationFramework::UpdateType } } +struct GlowPartDefinition +{ + DWORD PartID; + DWORD unk1; + DWORD unk2; + DWORD unk3; +}; + +//Remake from w7 udwm +inline __int64(__fastcall* CTopLevelWindow__CreateBitmapFromAtlas)(HTHEME hTheme, int iPartId, MARGINS* outMargins, void** outBitmapSource); + +HRESULT CTopLevelWindow__CreateButtonGlowsFromAtlas(HTHEME hTheme) +{ +#ifdef DEBUG + OutputDebugStringW(std::format(L"CTopLevelWindow__CreateButtonGlowsFromAtlas").c_str()); +#endif + MARGINS margins{}; + HRESULT hr = S_OK; + void* OutBitmapSourceBlue = nullptr; + void* OutBitmapSourceRed = nullptr; + void* OutBitmapSourceTool = nullptr; + + const int MINMAXBUTTONGLOW = 93; //16 in windows 7 + const int CLOSEBUTTONGLOW = 92; //11 in windows 7 + const int TOOLCLOSEBUTTONGLOW = 94; //47 in windows 7 + + hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, MINMAXBUTTONGLOW, &margins, &OutBitmapSourceBlue); + if (hr < 0) + return hr; + *(MARGINS*)(__int64(OutBitmapSourceBlue) + 0x30) = margins; //offset is the same as w7, so it shouldnt change + + hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, CLOSEBUTTONGLOW, &margins, &OutBitmapSourceRed); + if (hr < 0) + return hr; + *(MARGINS*)(__int64(OutBitmapSourceRed) + 0x30) = margins; + + hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, TOOLCLOSEBUTTONGLOW, &margins, &OutBitmapSourceTool); + if (hr < 0) + return hr; + *(MARGINS*)(__int64(OutBitmapSourceTool) + 0x30) = margins; + + for (int i = 0; i < 4; ++i) + { + auto frame = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[i]; + *(void**)(__int64(frame) + 0xD0) = OutBitmapSourceBlue; + *(void**)(__int64(frame) + 0xC8) = OutBitmapSourceRed; + } + for (int i = 4; i < 6; ++i) + { + auto frame = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[i]; + *(void**)(__int64(frame) + 0xD0) = OutBitmapSourceTool; + *(void**)(__int64(frame) + 0xC8) = OutBitmapSourceTool; + } + return hr; + //old attempt at remaking the function from windows 7 + /* + GlowPartDefinition partIds[3] = { {93,92,0,1},{93,92,2,3},{-1,94,4,5} }; + + GlowPartDefinition* def = &partIds[0]; + + int i = 0; + + void* OutBitmapSource = nullptr; + while (1) + { + OutputDebugStringW(std::format(L"it {}", i).c_str()); + def = &partIds[i]; + int partId = def->PartID; + if (partId != -1) + { + hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, partId, &margins, &OutBitmapSource); + OutputDebugStringW(std::format(L"1outbitmapsource: {}",OutBitmapSource).c_str()); + if (hr < 0) + return hr; + + + *(_MARGINS*)(__int64(OutBitmapSource) + 0x30) = margins; + if (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + { + OutputDebugStringW(std::format(L"def->unk2 {} def->unk3 {}", def->unk2, def->unk3).c_str()); + auto frame1 = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[def->unk2]; + auto frame2 = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[def->unk3]; + OutputDebugStringW(std::format(L"f1 {} f2 {}", frame1, frame2).c_str()); + *(void**)(__int64(frame1) + 0xD0) = OutBitmapSource; + *(void**)(__int64(frame2) + 0xD0) = OutBitmapSource; + //*(void**)((*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk2)) + 0xC8) = OutBitmapSource; + //*(void**)((*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk3)) + 0xC8) = OutBitmapSource; + + //*(uintptr_t*)(*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk2) + 0xC8i64) = (uintptr_t)OutBitmapSource; + //*(uintptr_t*)(*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk3) + 0xC8i64) = (uintptr_t)OutBitmapSource; + } + else + OutputDebugStringW(std::format(L"NULLL FRAMES").c_str()); + + } + if (partId == -1) + break; + + ++i; + if (i >= 3) + return hr; + } + def = &partIds[0]; + hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, def->unk1, &margins, &OutBitmapSource); + OutputDebugStringW(std::format(L"2outbitmapsource: {}", OutBitmapSource).c_str()); + if (hr < 0) + return hr; + *(_MARGINS*)(__int64(OutBitmapSource) + 0x30) = margins; + if (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + { + OutputDebugStringW(std::format(L"def->unk2 {} def->unk3 {}", def->unk2, def->unk3).c_str()); + auto frame1 = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[def->unk2]; + auto frame2 = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[def->unk3]; + OutputDebugStringW(std::format(L"f1 {} f2 {}", frame1, frame2).c_str()); + *(void**)(__int64(frame1) + 0xC8) = OutBitmapSource; + *(void**)(__int64(frame2) + 0xC8) = OutBitmapSource; + //*(uintptr_t*)(*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk2) + 0xC0i64) = (uintptr_t)OutBitmapSource; + //*(uintptr_t*)(*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk3) + 0xC0i64) = (uintptr_t)OutBitmapSource; + //*(void**)((*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk2)) + 0xC8) = OutBitmapSource; + //*(void**)((*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk3)) + 0xC8) = OutBitmapSource; + } + else + OutputDebugStringW(std::format(L"NULLL FRAMES").c_str()); + + return hr;*/ +} + +inline HRESULT(__fastcall* CTopLevelWindow_CreateGlyphsFromAtlas)(HTHEME); +HRESULT __fastcall CTopLevelWindow_CreateGlyphsFromAtlas_Hook(HTHEME hTheme) +{ + CTopLevelWindow__CreateButtonGlowsFromAtlas(hTheme); + return CTopLevelWindow_CreateGlyphsFromAtlas(hTheme); +} + HRESULT CaptionTextHandler::Startup() { DWORD value{ 0ul }; @@ -274,6 +408,12 @@ HRESULT CaptionTextHandler::Startup() HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ); g_disableTextHooks = (value & 1) != 0; + uDwm::GetAddressFromSymbolMap("CTopLevelWindow::CreateBitmapFromAtlas", CTopLevelWindow__CreateBitmapFromAtlas); + uDwm::GetAddressFromSymbolMap("CTopLevelWindow::CreateGlyphsFromAtlas", CTopLevelWindow_CreateGlyphsFromAtlas); + HookHelper::Detours::Write([]() + { + HookHelper::Detours::Attach(&CTopLevelWindow_CreateGlyphsFromAtlas, CTopLevelWindow_CreateGlyphsFromAtlas_Hook); + }); if (!g_disableTextHooks) { diff --git a/OpenGlass/uDwmProjection.hpp b/OpenGlass/uDwmProjection.hpp index 3f4b20b..eb0c590 100644 --- a/OpenGlass/uDwmProjection.hpp +++ b/OpenGlass/uDwmProjection.hpp @@ -604,6 +604,7 @@ namespace OpenGlass::uDwm }; struct CTopLevelWindow : CVisual { + inline static void*** s_rgpwfWindowFrames{ nullptr }; CRgnGeometryProxy* GetBorderGeometry() const { CRgnGeometryProxy* geometry{ nullptr }; @@ -1198,6 +1199,11 @@ namespace OpenGlass::uDwm return interopDevice; } + HTHEME __fastcall GetTheme(int a1) + { + DEFINE_INVOKER(CDesktopManager::GetTheme); + return INVOKE_MEMBERFUNCTION(a1); + } }; FORCEINLINE HWND GetShellWindowForCurrentDesktop() { @@ -1224,6 +1230,7 @@ namespace OpenGlass::uDwm if ( fullyUnDecoratedFunctionName.starts_with("CCompositor::") || fullyUnDecoratedFunctionName.starts_with("CText::") || + fullyUnDecoratedFunctionName.starts_with("CButton::") || fullyUnDecoratedFunctionName.starts_with("CVisual::") || fullyUnDecoratedFunctionName.starts_with("CVisualProxy::") || fullyUnDecoratedFunctionName.starts_with("CCanvasVisual::") || @@ -1260,6 +1267,11 @@ namespace OpenGlass::uDwm { offset.To(g_moduleHandle, CDesktopManager::s_csDwmInstance); } + if (fullyUnDecoratedFunctionName == "CTopLevelWindow::s_rgpwfWindowFrames") + { + uintptr_t address = (offset.value + (uintptr_t)g_moduleHandle); + CTopLevelWindow::s_rgpwfWindowFrames = (void***)(address); + } return true; } From a55d1074f5df49f937eb1f4888b17631e051b74e Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Thu, 18 Jul 2024 17:09:07 +0100 Subject: [PATCH 12/17] a bit of cleanup --- OpenGlass/CaptionTextHandler.cpp | 81 +------------------------------- 1 file changed, 2 insertions(+), 79 deletions(-) diff --git a/OpenGlass/CaptionTextHandler.cpp b/OpenGlass/CaptionTextHandler.cpp index e47ccf7..5e54d14 100644 --- a/OpenGlass/CaptionTextHandler.cpp +++ b/OpenGlass/CaptionTextHandler.cpp @@ -262,17 +262,11 @@ void CaptionTextHandler::UpdateConfiguration(ConfigurationFramework::UpdateType } } -struct GlowPartDefinition -{ - DWORD PartID; - DWORD unk1; - DWORD unk2; - DWORD unk3; -}; -//Remake from w7 udwm +//TODO: MOVE TO SEPERATE FILE!! inline __int64(__fastcall* CTopLevelWindow__CreateBitmapFromAtlas)(HTHEME hTheme, int iPartId, MARGINS* outMargins, void** outBitmapSource); +//functional remake from w7 udwm (not 1 to 1 remake, but functions the same) HRESULT CTopLevelWindow__CreateButtonGlowsFromAtlas(HTHEME hTheme) { #ifdef DEBUG @@ -316,77 +310,6 @@ HRESULT CTopLevelWindow__CreateButtonGlowsFromAtlas(HTHEME hTheme) *(void**)(__int64(frame) + 0xC8) = OutBitmapSourceTool; } return hr; - //old attempt at remaking the function from windows 7 - /* - GlowPartDefinition partIds[3] = { {93,92,0,1},{93,92,2,3},{-1,94,4,5} }; - - GlowPartDefinition* def = &partIds[0]; - - int i = 0; - - void* OutBitmapSource = nullptr; - while (1) - { - OutputDebugStringW(std::format(L"it {}", i).c_str()); - def = &partIds[i]; - int partId = def->PartID; - if (partId != -1) - { - hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, partId, &margins, &OutBitmapSource); - OutputDebugStringW(std::format(L"1outbitmapsource: {}",OutBitmapSource).c_str()); - if (hr < 0) - return hr; - - - *(_MARGINS*)(__int64(OutBitmapSource) + 0x30) = margins; - if (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames) - { - OutputDebugStringW(std::format(L"def->unk2 {} def->unk3 {}", def->unk2, def->unk3).c_str()); - auto frame1 = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[def->unk2]; - auto frame2 = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[def->unk3]; - OutputDebugStringW(std::format(L"f1 {} f2 {}", frame1, frame2).c_str()); - *(void**)(__int64(frame1) + 0xD0) = OutBitmapSource; - *(void**)(__int64(frame2) + 0xD0) = OutBitmapSource; - //*(void**)((*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk2)) + 0xC8) = OutBitmapSource; - //*(void**)((*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk3)) + 0xC8) = OutBitmapSource; - - //*(uintptr_t*)(*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk2) + 0xC8i64) = (uintptr_t)OutBitmapSource; - //*(uintptr_t*)(*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk3) + 0xC8i64) = (uintptr_t)OutBitmapSource; - } - else - OutputDebugStringW(std::format(L"NULLL FRAMES").c_str()); - - } - if (partId == -1) - break; - - ++i; - if (i >= 3) - return hr; - } - def = &partIds[0]; - hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, def->unk1, &margins, &OutBitmapSource); - OutputDebugStringW(std::format(L"2outbitmapsource: {}", OutBitmapSource).c_str()); - if (hr < 0) - return hr; - *(_MARGINS*)(__int64(OutBitmapSource) + 0x30) = margins; - if (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames) - { - OutputDebugStringW(std::format(L"def->unk2 {} def->unk3 {}", def->unk2, def->unk3).c_str()); - auto frame1 = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[def->unk2]; - auto frame2 = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[def->unk3]; - OutputDebugStringW(std::format(L"f1 {} f2 {}", frame1, frame2).c_str()); - *(void**)(__int64(frame1) + 0xC8) = OutBitmapSource; - *(void**)(__int64(frame2) + 0xC8) = OutBitmapSource; - //*(uintptr_t*)(*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk2) + 0xC0i64) = (uintptr_t)OutBitmapSource; - //*(uintptr_t*)(*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk3) + 0xC0i64) = (uintptr_t)OutBitmapSource; - //*(void**)((*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk2)) + 0xC8) = OutBitmapSource; - //*(void**)((*(uintptr_t*)(__int64(uDwm::CTopLevelWindow::s_rgpwfWindowFrames) + 8i64 * (unsigned int)def->unk3)) + 0xC8) = OutBitmapSource; - } - else - OutputDebugStringW(std::format(L"NULLL FRAMES").c_str()); - - return hr;*/ } inline HRESULT(__fastcall* CTopLevelWindow_CreateGlyphsFromAtlas)(HTHEME); From 0628669ce5233d74a6550217507a814dbd0d2601 Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Thu, 18 Jul 2024 23:39:54 +0100 Subject: [PATCH 13/17] move buttonglow to seperate file --- OpenGlass/ButtonGlowHandler.cpp | 86 ++++++++++++++++++++++++++++ OpenGlass/ButtonGlowHandler.hpp | 11 ++++ OpenGlass/CaptionTextHandler.cpp | 63 -------------------- OpenGlass/ConfigurationFramework.cpp | 2 + OpenGlass/CustomBlurEffect.hpp | 1 + OpenGlass/GlassEffectManager.cpp | 1 + OpenGlass/GlassEffectManager.hpp | 1 + OpenGlass/GlassRenderer.cpp | 1 + OpenGlass/GlassSharedStructures.hpp | 10 ++++ OpenGlass/OpenGlass.cpp | 3 + OpenGlass/OpenGlass.vcxproj | 3 + OpenGlass/framework.hpp | 9 +-- 12 files changed, 120 insertions(+), 71 deletions(-) create mode 100644 OpenGlass/ButtonGlowHandler.cpp create mode 100644 OpenGlass/ButtonGlowHandler.hpp create mode 100644 OpenGlass/GlassSharedStructures.hpp diff --git a/OpenGlass/ButtonGlowHandler.cpp b/OpenGlass/ButtonGlowHandler.cpp new file mode 100644 index 0000000..a532860 --- /dev/null +++ b/OpenGlass/ButtonGlowHandler.cpp @@ -0,0 +1,86 @@ +#include "pch.h" +#include "ButtonGlowHandler.hpp" + +using namespace OpenGlass; +namespace OpenGlass::ButtonGlowHandler +{ + static int MINMAXBUTTONGLOW = 93; //16 in windows 7 + static int CLOSEBUTTONGLOW = 92; //11 in windows 7 + static int TOOLCLOSEBUTTONGLOW = 94; //47 in windows 7 + + inline __int64(__fastcall* CTopLevelWindow__CreateBitmapFromAtlas)(HTHEME hTheme, int iPartId, MARGINS* outMargins, void** outBitmapSource); + HRESULT CTopLevelWindow__CreateButtonGlowsFromAtlas(HTHEME hTheme) + { +#ifdef DEBUG + OutputDebugStringW(std::format(L"CTopLevelWindow__CreateButtonGlowsFromAtlas").c_str()); +#endif + MARGINS margins{}; + HRESULT hr = S_OK; + void* OutBitmapSourceBlue = nullptr; + void* OutBitmapSourceRed = nullptr; + void* OutBitmapSourceTool = nullptr; + + hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, MINMAXBUTTONGLOW, &margins, &OutBitmapSourceBlue); + if (hr < 0) + return hr; + *(MARGINS*)(__int64(OutBitmapSourceBlue) + 0x30) = margins; //offset is the same as w7, so it shouldnt change + + hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, CLOSEBUTTONGLOW, &margins, &OutBitmapSourceRed); + if (hr < 0) + return hr; + *(MARGINS*)(__int64(OutBitmapSourceRed) + 0x30) = margins; + + hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, TOOLCLOSEBUTTONGLOW, &margins, &OutBitmapSourceTool); + if (hr < 0) + return hr; + *(MARGINS*)(__int64(OutBitmapSourceTool) + 0x30) = margins; + + for (int i = 0; i < 4; ++i) + { + auto frame = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[i]; + *(void**)(__int64(frame) + 0xD0) = OutBitmapSourceBlue; + *(void**)(__int64(frame) + 0xC8) = OutBitmapSourceRed; + } + for (int i = 4; i < 6; ++i) + { + auto frame = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[i]; + *(void**)(__int64(frame) + 0xD0) = OutBitmapSourceTool; + *(void**)(__int64(frame) + 0xC8) = OutBitmapSourceTool; + } + return hr; + } + + HRESULT (__fastcall* CTopLevelWindow_CreateGlyphsFromAtlas)(HTHEME hTheme); + HRESULT __fastcall CTopLevelWindow_CreateGlyphsFromAtlas_Hook(HTHEME hTheme) + { + CTopLevelWindow__CreateButtonGlowsFromAtlas(hTheme); + return CTopLevelWindow_CreateGlyphsFromAtlas(hTheme); + } + + void UpdateConfiguration(ConfigurationFramework::UpdateType type) + { + MINMAXBUTTONGLOW = ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"MINMAXBUTTONGLOWid",93); + CLOSEBUTTONGLOW = ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"CLOSEBUTTONGLOWid",92); + TOOLCLOSEBUTTONGLOW = ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"TOOLCLOSEBUTTONGLOWid",94); + } + + HRESULT Startup() + { + uDwm::GetAddressFromSymbolMap("CTopLevelWindow::CreateBitmapFromAtlas", CTopLevelWindow__CreateBitmapFromAtlas); + uDwm::GetAddressFromSymbolMap("CTopLevelWindow::CreateGlyphsFromAtlas", CTopLevelWindow_CreateGlyphsFromAtlas); + HookHelper::Detours::Write([]() + { + HookHelper::Detours::Attach(&CTopLevelWindow_CreateGlyphsFromAtlas, CTopLevelWindow_CreateGlyphsFromAtlas_Hook); + }); + + return S_OK; + } + + void Shutdown() + { + HookHelper::Detours::Write([]() + { + HookHelper::Detours::Detach(&CTopLevelWindow_CreateGlyphsFromAtlas, CTopLevelWindow_CreateGlyphsFromAtlas_Hook); + }); + } +} diff --git a/OpenGlass/ButtonGlowHandler.hpp b/OpenGlass/ButtonGlowHandler.hpp new file mode 100644 index 0000000..ed69c6f --- /dev/null +++ b/OpenGlass/ButtonGlowHandler.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "framework.hpp" +#include "ConfigurationFramework.hpp" + +namespace OpenGlass::ButtonGlowHandler +{ + void UpdateConfiguration(ConfigurationFramework::UpdateType type); + + HRESULT Startup(); + void Shutdown(); +} \ No newline at end of file diff --git a/OpenGlass/CaptionTextHandler.cpp b/OpenGlass/CaptionTextHandler.cpp index 5e54d14..b06e2ae 100644 --- a/OpenGlass/CaptionTextHandler.cpp +++ b/OpenGlass/CaptionTextHandler.cpp @@ -262,63 +262,6 @@ void CaptionTextHandler::UpdateConfiguration(ConfigurationFramework::UpdateType } } - -//TODO: MOVE TO SEPERATE FILE!! -inline __int64(__fastcall* CTopLevelWindow__CreateBitmapFromAtlas)(HTHEME hTheme, int iPartId, MARGINS* outMargins, void** outBitmapSource); - -//functional remake from w7 udwm (not 1 to 1 remake, but functions the same) -HRESULT CTopLevelWindow__CreateButtonGlowsFromAtlas(HTHEME hTheme) -{ -#ifdef DEBUG - OutputDebugStringW(std::format(L"CTopLevelWindow__CreateButtonGlowsFromAtlas").c_str()); -#endif - MARGINS margins{}; - HRESULT hr = S_OK; - void* OutBitmapSourceBlue = nullptr; - void* OutBitmapSourceRed = nullptr; - void* OutBitmapSourceTool = nullptr; - - const int MINMAXBUTTONGLOW = 93; //16 in windows 7 - const int CLOSEBUTTONGLOW = 92; //11 in windows 7 - const int TOOLCLOSEBUTTONGLOW = 94; //47 in windows 7 - - hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, MINMAXBUTTONGLOW, &margins, &OutBitmapSourceBlue); - if (hr < 0) - return hr; - *(MARGINS*)(__int64(OutBitmapSourceBlue) + 0x30) = margins; //offset is the same as w7, so it shouldnt change - - hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, CLOSEBUTTONGLOW, &margins, &OutBitmapSourceRed); - if (hr < 0) - return hr; - *(MARGINS*)(__int64(OutBitmapSourceRed) + 0x30) = margins; - - hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, TOOLCLOSEBUTTONGLOW, &margins, &OutBitmapSourceTool); - if (hr < 0) - return hr; - *(MARGINS*)(__int64(OutBitmapSourceTool) + 0x30) = margins; - - for (int i = 0; i < 4; ++i) - { - auto frame = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[i]; - *(void**)(__int64(frame) + 0xD0) = OutBitmapSourceBlue; - *(void**)(__int64(frame) + 0xC8) = OutBitmapSourceRed; - } - for (int i = 4; i < 6; ++i) - { - auto frame = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[i]; - *(void**)(__int64(frame) + 0xD0) = OutBitmapSourceTool; - *(void**)(__int64(frame) + 0xC8) = OutBitmapSourceTool; - } - return hr; -} - -inline HRESULT(__fastcall* CTopLevelWindow_CreateGlyphsFromAtlas)(HTHEME); -HRESULT __fastcall CTopLevelWindow_CreateGlyphsFromAtlas_Hook(HTHEME hTheme) -{ - CTopLevelWindow__CreateButtonGlowsFromAtlas(hTheme); - return CTopLevelWindow_CreateGlyphsFromAtlas(hTheme); -} - HRESULT CaptionTextHandler::Startup() { DWORD value{ 0ul }; @@ -331,12 +274,6 @@ HRESULT CaptionTextHandler::Startup() HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ); g_disableTextHooks = (value & 1) != 0; - uDwm::GetAddressFromSymbolMap("CTopLevelWindow::CreateBitmapFromAtlas", CTopLevelWindow__CreateBitmapFromAtlas); - uDwm::GetAddressFromSymbolMap("CTopLevelWindow::CreateGlyphsFromAtlas", CTopLevelWindow_CreateGlyphsFromAtlas); - HookHelper::Detours::Write([]() - { - HookHelper::Detours::Attach(&CTopLevelWindow_CreateGlyphsFromAtlas, CTopLevelWindow_CreateGlyphsFromAtlas_Hook); - }); if (!g_disableTextHooks) { diff --git a/OpenGlass/ConfigurationFramework.cpp b/OpenGlass/ConfigurationFramework.cpp index 49bedca..476c901 100644 --- a/OpenGlass/ConfigurationFramework.cpp +++ b/OpenGlass/ConfigurationFramework.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "ConfigurationFramework.hpp" #include "CaptionTextHandler.hpp" +#include "ButtonGlowHandler.hpp" #include "GlassFramework.hpp" #include "GlassRenderer.hpp" #include "CustomMsstyleLoader.hpp" @@ -19,6 +20,7 @@ void ConfigurationFramework::Update(UpdateType type) GlassRenderer::UpdateConfiguration(type); CaptionTextHandler::UpdateConfiguration(type); CustomMsstyleLoader::UpdateConfiguration(type); + ButtonGlowHandler::UpdateConfiguration(type); DwmFlush(); } diff --git a/OpenGlass/CustomBlurEffect.hpp b/OpenGlass/CustomBlurEffect.hpp index d91a5a1..9a72028 100644 --- a/OpenGlass/CustomBlurEffect.hpp +++ b/OpenGlass/CustomBlurEffect.hpp @@ -2,6 +2,7 @@ #include "pch.h" #include "framework.hpp" #include "cpprt.hpp" +#include "GlassSharedStructures.hpp" namespace OpenGlass { diff --git a/OpenGlass/GlassEffectManager.cpp b/OpenGlass/GlassEffectManager.cpp index 3fb95ad..3194cac 100644 --- a/OpenGlass/GlassEffectManager.cpp +++ b/OpenGlass/GlassEffectManager.cpp @@ -5,6 +5,7 @@ #include "GlassEffectManager.hpp" #include "ReflectionRenderer.hpp" #include "CustomBlurEffect.hpp" +#include "GlassSharedStructures.hpp" using namespace OpenGlass; namespace OpenGlass::GlassEffectManager diff --git a/OpenGlass/GlassEffectManager.hpp b/OpenGlass/GlassEffectManager.hpp index d3febbe..8241a0e 100644 --- a/OpenGlass/GlassEffectManager.hpp +++ b/OpenGlass/GlassEffectManager.hpp @@ -2,6 +2,7 @@ #include "framework.hpp" #include "cpprt.hpp" #include "uDwmProjection.hpp" +#include "GlassSharedStructures.hpp" namespace OpenGlass::GlassEffectManager { diff --git a/OpenGlass/GlassRenderer.cpp b/OpenGlass/GlassRenderer.cpp index 7295658..45683f7 100644 --- a/OpenGlass/GlassRenderer.cpp +++ b/OpenGlass/GlassRenderer.cpp @@ -6,6 +6,7 @@ #include "GlassEffectManager.hpp" #include "GlassSharedData.hpp" #include "ReflectionRenderer.hpp" +#include "GlassSharedStructures.hpp" using namespace OpenGlass; diff --git a/OpenGlass/GlassSharedStructures.hpp b/OpenGlass/GlassSharedStructures.hpp new file mode 100644 index 0000000..5231162 --- /dev/null +++ b/OpenGlass/GlassSharedStructures.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace OpenGlass +{ + enum class Type : unsigned char + { + Blur = 0, + Aero = 1 + }; +} \ No newline at end of file diff --git a/OpenGlass/OpenGlass.cpp b/OpenGlass/OpenGlass.cpp index a98a86b..a8433ca 100644 --- a/OpenGlass/OpenGlass.cpp +++ b/OpenGlass/OpenGlass.cpp @@ -9,6 +9,7 @@ #include "dwmcoreProjection.hpp" #include "GeometryRecorder.hpp" #include "CaptionTextHandler.hpp" +#include "ButtonGlowHandler.hpp" #include "GlassFramework.hpp" #include "GlassRenderer.hpp" #include "CustomMsstyleLoader.hpp" @@ -422,6 +423,7 @@ DWORD WINAPI OpenGlass::Initialize(PVOID) GlassFramework::Startup(); GlassRenderer::Startup(); CaptionTextHandler::Startup(); + ButtonGlowHandler::Startup(); GeometryRecorder::Startup(); CustomMsstyleLoader::Startup(); ConfigurationFramework::Load(); @@ -516,6 +518,7 @@ void OpenGlass::Shutdown() GeometryRecorder::Shutdown(); CaptionTextHandler::Shutdown(); + ButtonGlowHandler::Shutdown(); GlassRenderer::Shutdown(); GlassFramework::Shutdown(); CustomMsstyleLoader::Shutdown(); diff --git a/OpenGlass/OpenGlass.vcxproj b/OpenGlass/OpenGlass.vcxproj index d2d6ee4..e555557 100644 --- a/OpenGlass/OpenGlass.vcxproj +++ b/OpenGlass/OpenGlass.vcxproj @@ -189,10 +189,12 @@ + + @@ -215,6 +217,7 @@ + diff --git a/OpenGlass/framework.hpp b/OpenGlass/framework.hpp index a71d242..33b46fa 100644 --- a/OpenGlass/framework.hpp +++ b/OpenGlass/framework.hpp @@ -65,11 +65,4 @@ #pragma comment(lib, "onecore.lib") -namespace OpenGlass -{ - enum class Type : UCHAR - { - Blur = 0, - Aero = 1 - }; -} + From 14c998ad2d7b69123e1ed1440b3a5916e20a0a64 Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Fri, 19 Jul 2024 00:08:53 +0100 Subject: [PATCH 14/17] address comments by altalex --- OpenGlass/GlassFramework.cpp | 14 +++++++------- OpenGlass/GlassRenderer.cpp | 14 ++++++-------- OpenGlass/GlassSharedData.hpp | 3 ++- OpenGlass/VisualManager.cpp | 4 +++- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/OpenGlass/GlassFramework.cpp b/OpenGlass/GlassFramework.cpp index d217582..77554a2 100644 --- a/OpenGlass/GlassFramework.cpp +++ b/OpenGlass/GlassFramework.cpp @@ -67,7 +67,8 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCDrawGeometryInstruction_Create(uDwm ); auto color{ g_capturedWindow->GetTitlebarColorizationParameters()->getArgbcolor() }; color.a *= 0.99f; - color.r = g_capturedWindow->TreatAsActiveWindow(); + if (GlassSharedData::g_type == Type::Aero) + color.r = g_capturedWindow->TreatAsActiveWindow(); RETURN_IF_FAILED(solidBrush->Update(1.0, color)); return g_CDrawGeometryInstruction_Create_Org(solidBrush.get(), rgnGeometry.get(), instruction); } @@ -82,13 +83,11 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCTopLevelWindow_UpdateNCAreaBackgrou { if (!GlassSharedData::IsBackdropAllowed()) { - GlassSharedData::g_LastTopLevelWindow = 0; return g_CTopLevelWindow_UpdateNCAreaBackground_Org(This); } auto data{ This->GetData() }; if (!data) { - GlassSharedData::g_LastTopLevelWindow = 0; return g_CTopLevelWindow_UpdateNCAreaBackground_Org(This); } @@ -126,7 +125,6 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCTopLevelWindow_UpdateNCAreaBackgrou HRGN borderRegion{ GeometryRecorder::GetRegionFromGeometry(borderGeometry) }; hr = legacyVisualOverride->UpdateNCBackground(captionRegion, borderRegion); - GlassSharedData::g_LastTopLevelWindow = This; } } @@ -134,7 +132,6 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCTopLevelWindow_UpdateNCAreaBackgrou } else { - GlassSharedData::g_LastTopLevelWindow = 0; VisualManager::RemoveLegacyVisualOverrider(This); hr = g_CTopLevelWindow_UpdateNCAreaBackground_Org(This); } @@ -157,7 +154,6 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCTopLevelWindow_UpdateClientBlur(uDw g_capturedWindow = This; GeometryRecorder::BeginCapture(); - GlassSharedData::g_LastTopLevelWindow = 0; HRESULT hr{ g_CTopLevelWindow_UpdateClientBlur_Org(This) }; GeometryRecorder::EndCapture(); g_capturedWindow = nullptr; @@ -252,7 +248,8 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCRenderDataVisual_AddInstruction(uDw } color.a = 0.99f; - color.r = 1.0f; + if (GlassSharedData::g_type == Type::Aero) + color.r = 1.0f; winrt::com_ptr rgnGeometry{ nullptr }; uDwm::ResourceHelper::CreateGeometryFromHRGN(wil::unique_hrgn{ CreateRectRgn(static_cast(rectangle.left), static_cast(rectangle.top), static_cast(rectangle.right), static_cast(rectangle.bottom)) }.get(), rgnGeometry.put()); winrt::com_ptr solidBrush{ nullptr }; @@ -339,10 +336,13 @@ void GlassFramework::UpdateConfiguration(ConfigurationFramework::UpdateType type g_roundRectRadius = static_cast(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"RoundRectRadius")); } + //Seperate keys for now until a way to readd the code that handles setting the actual values in registry is found GlassSharedData::g_ColorizationAfterglowBalance = ((float)ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"OG_ColorizationAfterglowBalance",43) / 100); GlassSharedData::g_ColorizationBlurBalance = ((float)ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"OG_ColorizationBlurBalance",49) / 100); GlassSharedData::g_ColorizationColorBalance = ((float)ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"OG_ColorizationColorBalance",8) / 100); + //Get the colorizationColor from registry directly for aero glass type, a dwm function could be used, however mods or programs such as AWM hook into this and can + //cause issues, so the colour is taken directly from registry, which is fine for aero glass (actually better) since inactive and active have the same colour DWORD hexColour = ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"ColorizationColor", 0xfffcb874); GlassSharedData::g_ColorizationColor = Utils::FromArgb(hexColour); diff --git a/OpenGlass/GlassRenderer.cpp b/OpenGlass/GlassRenderer.cpp index 45683f7..23cbbf7 100644 --- a/OpenGlass/GlassRenderer.cpp +++ b/OpenGlass/GlassRenderer.cpp @@ -71,7 +71,6 @@ namespace OpenGlass::GlassRenderer dwmcore::IDrawingContext* g_drawingContextNoRef{ nullptr }; ID2D1Device* g_deviceNoRef{ nullptr }; - Type g_type{ Type::Blur }; float g_blurAmount{ 9.f }; float g_glassOpacity{ 0.63f }; // exclusively used by aero backdrop @@ -155,8 +154,6 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawSolidRectangle( return g_CDrawingContext_DrawSolidRectangle_Org(This, rectangle, convertedColor); } -bool active = false; - HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( dwmcore::IDrawingContext* This, dwmcore::CLegacyMilBrush* brush, @@ -186,9 +183,10 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( //g_drawColor.value() = D2D1_COLOR_F{ 116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f, g_drawColor.value().a}; //g_drawColor.value() = D2D1_COLOR_F{ GlassSharedData::g_ColorizationColor.r, GlassSharedData::g_ColorizationColor.g, GlassSharedData::g_ColorizationColor.b, g_drawColor.value().a}; auto cleanUp{ wil::scope_exit([]{ g_drawColor = std::nullopt; })}; - //D2D1_COLOR_F color{ dwmcore::Convert_D2D1_COLOR_F_scRGB_To_D2D1_COLOR_F_sRGB(g_drawColor.value()) }; - //D2D1_COLOR_F color{ g_drawColor.value()}; + D2D1_COLOR_F color{ GlassSharedData::g_ColorizationColor.r, GlassSharedData::g_ColorizationColor.g, GlassSharedData::g_ColorizationColor.b, g_drawColor.value().a }; + if (GlassSharedData::g_type == Type::Blur) + color = dwmcore::Convert_D2D1_COLOR_F_scRGB_To_D2D1_COLOR_F_sRGB(g_drawColor.value()); dwmcore::CShapePtr geometryShape{}; if ( FAILED(geometry->GetShapeData(nullptr, &geometryShape)) || @@ -272,7 +270,7 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( GlassSharedData::g_ColorizationAfterglowBalance, // stays the same bactive ? GlassSharedData::g_ColorizationBlurBalance : 0.4f * GlassSharedData::g_ColorizationBlurBalance + 0.6f, // y = 0.4x + 60 bactive ? GlassSharedData::g_ColorizationColorBalance : 0.4f * GlassSharedData::g_ColorizationColorBalance, //y = 0.4x - g_type + GlassSharedData::g_type ); glassEffect->SetSize( D2D1::SizeF( @@ -338,7 +336,7 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDirtyRegion__Add( lprc.right + extendAmount, lprc.bottom + extendAmount }; - active = unknown; + return g_CDirtyRegion__Add_Org( This, visual, @@ -373,7 +371,7 @@ void GlassRenderer::UpdateConfiguration(ConfigurationFramework::UpdateType type) } g_afterglowBalance = std::clamp(static_cast(afterglowBalance.value()) / 100.f, 0.f, 1.f); - g_type = static_cast(std::clamp(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"GlassType", 0), 0ul, 4ul)); + GlassSharedData::g_type = static_cast(std::clamp(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"GlassType", 0), 0ul, 4ul)); } } diff --git a/OpenGlass/GlassSharedData.hpp b/OpenGlass/GlassSharedData.hpp index 73fde04..e446ce0 100644 --- a/OpenGlass/GlassSharedData.hpp +++ b/OpenGlass/GlassSharedData.hpp @@ -1,10 +1,10 @@ #pragma once #include "framework.hpp" #include "cpprt.hpp" +#include "GlassSharedStructures.hpp" namespace OpenGlass::GlassSharedData { - inline void* g_LastTopLevelWindow = nullptr; inline bool g_disableOnBattery{ true }; inline bool g_overrideAccent{ false }; inline bool g_batteryMode{ false }; @@ -13,6 +13,7 @@ namespace OpenGlass::GlassSharedData inline float g_ColorizationBlurBalance = 0.49f; inline float g_ColorizationColorBalance = 0.08f; inline D2D_COLOR_F g_ColorizationColor{ 116.0f / 255.0f, 184.0f / 255.0f, 252.0f / 255.0f,1.0f }; + inline Type g_type{ Type::Blur }; FORCEINLINE bool IsBackdropAllowed() { diff --git a/OpenGlass/VisualManager.cpp b/OpenGlass/VisualManager.cpp index efb726e..48b491c 100644 --- a/OpenGlass/VisualManager.cpp +++ b/OpenGlass/VisualManager.cpp @@ -2,6 +2,7 @@ #include "GlassFramework.hpp" #include "uDwmProjection.hpp" #include "VisualManager.hpp" +#include "GlassSharedData.hpp" #include "Utils.hpp" using namespace OpenGlass; @@ -175,7 +176,8 @@ HRESULT STDMETHODCALLTYPE VisualManager::CLegacyVisualOverrider::UpdateNCBackgro auto color{ m_window->GetTitlebarColorizationParameters()->getArgbcolor() }; color.a *= 0.99f; - color.r = m_window->TreatAsActiveWindow(); //HACK!!: Send active or inactive window data through the red channel + if (GlassSharedData::g_type == Type::Aero) + color.r = m_window->TreatAsActiveWindow(); //HACK!!: Send active or inactive window data through the red channel RETURN_IF_FAILED(m_brush->Update(1.0, color)); wil::unique_hrgn emptyRegion{ CreateRectRgn(0, 0, 0, 0) }; From 744f15b34bcc5279439fa443cba9bbeb6026ace0 Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Fri, 19 Jul 2024 16:10:52 +0100 Subject: [PATCH 15/17] make glassopacity 0 for aero (its meant to be 0) --- OpenGlass/GlassRenderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenGlass/GlassRenderer.cpp b/OpenGlass/GlassRenderer.cpp index 23cbbf7..f75f73f 100644 --- a/OpenGlass/GlassRenderer.cpp +++ b/OpenGlass/GlassRenderer.cpp @@ -265,7 +265,7 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( RETURN_IF_FAILED(geometryShape->GetTightBounds(&shapeWorldBounds, &matrix)); glassEffect->SetGlassRenderingParameters( color, - g_glassOpacity, + ((GlassSharedData::g_type == Type::Aero) ? 0.0f : g_glassOpacity), g_blurAmount, GlassSharedData::g_ColorizationAfterglowBalance, // stays the same bactive ? GlassSharedData::g_ColorizationBlurBalance : 0.4f * GlassSharedData::g_ColorizationBlurBalance + 0.6f, // y = 0.4x + 60 From 85a12f03a76f1f91737348daf76aca862f0abee9 Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Sat, 20 Jul 2024 01:39:01 +0100 Subject: [PATCH 16/17] little bit of cleanup --- OpenGlass/ButtonGlowHandler.cpp | 47 ++++++++++++++++++--------------- OpenGlass/CustomBlurEffect.cpp | 5 ---- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/OpenGlass/ButtonGlowHandler.cpp b/OpenGlass/ButtonGlowHandler.cpp index a532860..9d2a540 100644 --- a/OpenGlass/ButtonGlowHandler.cpp +++ b/OpenGlass/ButtonGlowHandler.cpp @@ -4,50 +4,53 @@ using namespace OpenGlass; namespace OpenGlass::ButtonGlowHandler { + constexpr int MARGIN_OFFSET = 0x30; //offset is the same as w7, so it shouldnt change + + /* + * https://imgur.com/a/kHFLBON + * To find these offsets, look in CTopLevelWindow::UpdateButtonVisuals in uDWM.dll + * where offset can be found inside, used to get the image to pass into CButton::SetVisualStates + * there will be many calls, but they all get at the same 2 offset, which correspond to these + */ + constexpr int MINMAXBUTTONGLOWIMAGE = 0xD0; + constexpr int CLOSEBUTTONGLOWIMAGE = 0xC8; + static int MINMAXBUTTONGLOW = 93; //16 in windows 7 static int CLOSEBUTTONGLOW = 92; //11 in windows 7 static int TOOLCLOSEBUTTONGLOW = 94; //47 in windows 7 - inline __int64(__fastcall* CTopLevelWindow__CreateBitmapFromAtlas)(HTHEME hTheme, int iPartId, MARGINS* outMargins, void** outBitmapSource); + inline HRESULT(__fastcall* CTopLevelWindow__CreateBitmapFromAtlas)(HTHEME hTheme, int iPartId, MARGINS* outMargins, void** outBitmapSource); + + //not 1 to 1 to the one in windows 7 udwm, however it achieves the same outcome whilst being simpler HRESULT CTopLevelWindow__CreateButtonGlowsFromAtlas(HTHEME hTheme) { -#ifdef DEBUG - OutputDebugStringW(std::format(L"CTopLevelWindow__CreateButtonGlowsFromAtlas").c_str()); -#endif MARGINS margins{}; - HRESULT hr = S_OK; void* OutBitmapSourceBlue = nullptr; void* OutBitmapSourceRed = nullptr; void* OutBitmapSourceTool = nullptr; - hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, MINMAXBUTTONGLOW, &margins, &OutBitmapSourceBlue); - if (hr < 0) - return hr; - *(MARGINS*)(__int64(OutBitmapSourceBlue) + 0x30) = margins; //offset is the same as w7, so it shouldnt change + RETURN_IF_FAILED(CTopLevelWindow__CreateBitmapFromAtlas(hTheme, MINMAXBUTTONGLOW, &margins, &OutBitmapSourceBlue)); + *(MARGINS*)(__int64(OutBitmapSourceBlue) + MARGIN_OFFSET) = margins; - hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, CLOSEBUTTONGLOW, &margins, &OutBitmapSourceRed); - if (hr < 0) - return hr; - *(MARGINS*)(__int64(OutBitmapSourceRed) + 0x30) = margins; + RETURN_IF_FAILED(CTopLevelWindow__CreateBitmapFromAtlas(hTheme, CLOSEBUTTONGLOW, &margins, &OutBitmapSourceRed)); + *(MARGINS*)(__int64(OutBitmapSourceRed) + MARGIN_OFFSET) = margins; - hr = CTopLevelWindow__CreateBitmapFromAtlas(hTheme, TOOLCLOSEBUTTONGLOW, &margins, &OutBitmapSourceTool); - if (hr < 0) - return hr; - *(MARGINS*)(__int64(OutBitmapSourceTool) + 0x30) = margins; + RETURN_IF_FAILED(CTopLevelWindow__CreateBitmapFromAtlas(hTheme, TOOLCLOSEBUTTONGLOW, &margins, &OutBitmapSourceTool)); + *(MARGINS*)(__int64(OutBitmapSourceTool) + MARGIN_OFFSET) = margins; for (int i = 0; i < 4; ++i) { auto frame = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[i]; - *(void**)(__int64(frame) + 0xD0) = OutBitmapSourceBlue; - *(void**)(__int64(frame) + 0xC8) = OutBitmapSourceRed; + *(void**)(__int64(frame) + MINMAXBUTTONGLOWIMAGE) = OutBitmapSourceBlue; + *(void**)(__int64(frame) + CLOSEBUTTONGLOWIMAGE) = OutBitmapSourceRed; } for (int i = 4; i < 6; ++i) { auto frame = (*uDwm::CTopLevelWindow::s_rgpwfWindowFrames)[i]; - *(void**)(__int64(frame) + 0xD0) = OutBitmapSourceTool; - *(void**)(__int64(frame) + 0xC8) = OutBitmapSourceTool; + *(void**)(__int64(frame) + MINMAXBUTTONGLOWIMAGE) = OutBitmapSourceTool; + *(void**)(__int64(frame) + CLOSEBUTTONGLOWIMAGE) = OutBitmapSourceTool; } - return hr; + return S_OK; } HRESULT (__fastcall* CTopLevelWindow_CreateGlyphsFromAtlas)(HTHEME hTheme); diff --git a/OpenGlass/CustomBlurEffect.cpp b/OpenGlass/CustomBlurEffect.cpp index c0b7f94..6d86e3b 100644 --- a/OpenGlass/CustomBlurEffect.cpp +++ b/OpenGlass/CustomBlurEffect.cpp @@ -301,11 +301,6 @@ HRESULT CCustomBlurEffect::SetParamsAero() // okay my conclusion is that i shouldnt tamper with whatever was already set up (no point in removing the scales or adding gaussian blur) // so since all of the blur work is done here, starting my part of it: - - // hardcoded values whatever (EDIT: Not Anymore!) - //m_colorizationAfterglowBalanceVal = 0.43f; - //m_colorizationBlurBalanceVal = 0.796f; - //m_colorizationColorBalanceVal = 0.08f; // afterglow m_saturationEffect->SetInputEffect(0, m_directionalBlurYEffect.get()); From daff89f30a4c357b0cbd61a6dfe84056e9048703 Mon Sep 17 00:00:00 2001 From: wiktorwiktor12 Date: Sat, 20 Jul 2024 01:40:10 +0100 Subject: [PATCH 17/17] add vcxproj.user files to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index cb996ee..70bebd6 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *.user *.userosscache *.sln.docstates +*.vcxproj.user # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs