Skip to content

Commit

Permalink
address comments by altalex
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktorwiktor12 committed Jul 18, 2024
1 parent 0628669 commit 14c998a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
14 changes: 7 additions & 7 deletions OpenGlass/GlassFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -126,15 +125,13 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCTopLevelWindow_UpdateNCAreaBackgrou
HRGN borderRegion{ GeometryRecorder::GetRegionFromGeometry(borderGeometry) };

hr = legacyVisualOverride->UpdateNCBackground(captionRegion, borderRegion);
GlassSharedData::g_LastTopLevelWindow = This;
}
}

GeometryRecorder::EndCapture();
}
else
{
GlassSharedData::g_LastTopLevelWindow = 0;
VisualManager::RemoveLegacyVisualOverrider(This);
hr = g_CTopLevelWindow_UpdateNCAreaBackground_Org(This);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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<uDwm::CRgnGeometryProxy> rgnGeometry{ nullptr };
uDwm::ResourceHelper::CreateGeometryFromHRGN(wil::unique_hrgn{ CreateRectRgn(static_cast<LONG>(rectangle.left), static_cast<LONG>(rectangle.top), static_cast<LONG>(rectangle.right), static_cast<LONG>(rectangle.bottom)) }.get(), rgnGeometry.put());
winrt::com_ptr<uDwm::CSolidColorLegacyMilBrushProxy> solidBrush{ nullptr };
Expand Down Expand Up @@ -339,10 +336,13 @@ void GlassFramework::UpdateConfiguration(ConfigurationFramework::UpdateType type
g_roundRectRadius = static_cast<int>(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);

Expand Down
14 changes: 6 additions & 8 deletions OpenGlass/GlassRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)) ||
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -338,7 +336,7 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDirtyRegion__Add(
lprc.right + extendAmount,
lprc.bottom + extendAmount
};
active = unknown;

return g_CDirtyRegion__Add_Org(
This,
visual,
Expand Down Expand Up @@ -373,7 +371,7 @@ void GlassRenderer::UpdateConfiguration(ConfigurationFramework::UpdateType type)
}
g_afterglowBalance = std::clamp(static_cast<float>(afterglowBalance.value()) / 100.f, 0.f, 1.f);

g_type = static_cast<Type>(std::clamp(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"GlassType", 0), 0ul, 4ul));
GlassSharedData::g_type = static_cast<Type>(std::clamp(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"GlassType", 0), 0ul, 4ul));
}
}

Expand Down
3 changes: 2 additions & 1 deletion OpenGlass/GlassSharedData.hpp
Original file line number Diff line number Diff line change
@@ -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 };
Expand All @@ -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()
{
Expand Down
4 changes: 3 additions & 1 deletion OpenGlass/VisualManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "GlassFramework.hpp"
#include "uDwmProjection.hpp"
#include "VisualManager.hpp"
#include "GlassSharedData.hpp"
#include "Utils.hpp"

using namespace OpenGlass;
Expand Down Expand Up @@ -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) };
Expand Down

0 comments on commit 14c998a

Please sign in to comment.