Skip to content

Commit 94e85eb

Browse files
committed
2.3.2b3
1 parent 323d38d commit 94e85eb

23 files changed

Lines changed: 201 additions & 21 deletions

Common/Common.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ namespace MDWMBlurGlass
206206
cfgData.effectType = effectType::Acrylic;
207207
});
208208

209+
GetCfgValueInternal(L"blurQuality",
210+
{
211+
cfgData.blurQuality = (MDWMBlurGlass::blurQuality)std::clamp(_wtoi(value.data()), 0, 1);
212+
});
213+
209214
GetCfgValueInternal(L"crossfadeTime",
210215
{
211216
cfgData.crossfadeTime = (UINT)std::clamp(_wtoi(value.data()), 0, 500);

Common/Common.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ namespace MDWMBlurGlass
4040
Mica
4141
};
4242

43+
enum class blurQuality
44+
{
45+
Speed = 0,
46+
Quality = 1
47+
};
48+
4349
struct ConfigData
4450
{
4551
bool applyglobal = false;
@@ -66,12 +72,14 @@ namespace MDWMBlurGlass
6672

6773
//Options without GUI
6874
int extendRound = 10;
75+
int clipRound = 0;
6976
int titlebtnOffsetX = -1;
77+
//
78+
7079
int customCloseBtnW = 49;
7180
int customMaxBtnW = 27;
7281
int customMinBtnW = 29;
7382
int customBtnFrameH = 20;
74-
//
7583

7684
float blurAmount = 20.f;
7785
float customBlurAmount = 20.f;
@@ -99,6 +107,7 @@ namespace MDWMBlurGlass
99107

100108
blurMethod blurmethod = blurMethod::CustomBlur;
101109
effectType effectType = effectType::Blur;
110+
blurQuality blurQuality = blurQuality::Speed;
102111

103112
std::wstring customAeroTexturePath;
104113

Common/VersionHelper.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ namespace MDWMBlurGlass
3131
const ULONG buildNumber = Utils::get_kernel_shared_info()->NtBuildNumber;
3232
const ULONG minorVersion = Utils::get_kernel_shared_info()->NtMinorVersion;
3333
const ULONG majorVersion = Utils::get_kernel_shared_info()->NtMajorVersion;
34+
const ULONG ubrNumber = []() -> ULONG {
35+
ULONG value = 0;
36+
HKEY hKey = nullptr;
37+
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
38+
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
39+
0, KEY_READ, &hKey) == ERROR_SUCCESS)
40+
{
41+
DWORD size = sizeof(DWORD);
42+
RegQueryValueExW(hKey, L"UBR", nullptr, nullptr,
43+
reinterpret_cast<LPBYTE>(&value), &size);
44+
RegCloseKey(hKey);
45+
}
46+
return value;
47+
}();
3448
const NT_PRODUCT_TYPE productType = Utils::get_kernel_shared_info()->NtProductType;
3549
}
3650
}

Common/VersionHelper.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,8 @@ namespace MDWMBlurGlass
195195
extern const ULONG buildNumber;
196196
extern const ULONG minorVersion;
197197
extern const ULONG majorVersion;
198-
extern const NT_PRODUCT_TYPE productType;
198+
extern const ULONG ubrNumber;
199199

200-
auto constexpr w10_2004 = 19041;
201200
auto constexpr w10_20h2 = 19042;
202201
auto constexpr w10_21h1 = 19043;
203202
auto constexpr w10_21h2 = 19044;

DWMBlurGlassExt/Backdrops/AeroBackdrop.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "../Effects/SaturationEffect.hpp"
77
#include "../Effects/TintEffect.hpp"
88
#include "../Effects/BlendEffect.hpp"
9+
#include "../Common/CommonDef.h"
910

1011
namespace MDWMBlurGlassExt::AeroBackdrop
1112
{
@@ -32,7 +33,11 @@ namespace MDWMBlurGlassExt::AeroBackdrop
3233
gaussianBlurEffect->SetName(L"Blur");
3334
gaussianBlurEffect->SetBorderMode(D2D1_BORDER_MODE_HARD);
3435
gaussianBlurEffect->SetBlurAmount(blurAmount);
35-
gaussianBlurEffect->SetOptimizationMode(D2D1_GAUSSIANBLUR_OPTIMIZATION_SPEED);
36+
gaussianBlurEffect->SetOptimizationMode(
37+
CommonDef::g_configData.blurQuality == blurQuality::Speed ?
38+
D2D1_GAUSSIANBLUR_OPTIMIZATION_SPEED :
39+
D2D1_GAUSSIANBLUR_OPTIMIZATION_QUALITY
40+
);
3641
gaussianBlurEffect->SetInput(wuc::CompositionEffectSourceParameter{ L"Backdrop" });
3742

3843
auto blurredBackdropBrush{ compositor.CreateEffectFactory(*gaussianBlurEffect).CreateBrush() };

DWMBlurGlassExt/Backdrops/BlurBackdrop.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../Effects/GaussianBlurEffect.hpp"
44
#include "../Effects/ColorSourceEffect.hpp"
55
#include "../Effects/OpacityEffect.hpp"
6+
#include "../Common/CommonDef.h"
67

78
namespace MDWMBlurGlassExt::BlurBackdrop
89
{
@@ -27,7 +28,11 @@ namespace MDWMBlurGlassExt::BlurBackdrop
2728
gaussianBlurEffect->SetName(L"Blur");
2829
gaussianBlurEffect->SetBorderMode(D2D1_BORDER_MODE_HARD);
2930
gaussianBlurEffect->SetBlurAmount(blurAmount);
30-
gaussianBlurEffect->SetOptimizationMode(D2D1_GAUSSIANBLUR_OPTIMIZATION_SPEED);
31+
gaussianBlurEffect->SetOptimizationMode(
32+
CommonDef::g_configData.blurQuality == blurQuality::Speed ?
33+
D2D1_GAUSSIANBLUR_OPTIMIZATION_SPEED :
34+
D2D1_GAUSSIANBLUR_OPTIMIZATION_QUALITY
35+
);
3136
gaussianBlurEffect->SetInput(wuc::CompositionEffectSourceParameter{ L"Backdrop" });
3237
if (static_cast<float>(tintColor.A) * tintOpacity == 0.f)
3338
{

DWMBlurGlassExt/Backdrops/DCompBackdrop.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ namespace MDWMBlurGlassExt
3636
gaussianBlurEffect->SetName(L"Blur");
3737
gaussianBlurEffect->SetBorderMode(D2D1_BORDER_MODE_HARD);
3838
gaussianBlurEffect->SetBlurAmount(blurAmount);
39-
gaussianBlurEffect->SetOptimizationMode(D2D1_GAUSSIANBLUR_OPTIMIZATION_SPEED);
39+
gaussianBlurEffect->SetOptimizationMode(
40+
CommonDef::g_configData.blurQuality == blurQuality::Speed ?
41+
D2D1_GAUSSIANBLUR_OPTIMIZATION_SPEED :
42+
D2D1_GAUSSIANBLUR_OPTIMIZATION_QUALITY
43+
);
4044
gaussianBlurEffect->SetInput(wuc::CompositionEffectSourceParameter{ L"Backdrop" });
4145
return *gaussianBlurEffect;
4246
}

DWMBlurGlassExt/Common/DWMStruct.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ namespace MDWMBlurGlassExt::DWM
220220
{
221221
darkMode = (reinterpret_cast<BYTE const*>(this)[669] & 4) != 0;
222222
}
223-
else if (os::buildNumber < os::w11_25h2)
223+
else if (os::buildNumber < os::w11_25h2 && os::ubrNumber < 7171)
224224
{
225225
darkMode = (reinterpret_cast<BYTE const*>(this)[677] & 4) != 0; // ok with build 26020
226226
}
@@ -242,7 +242,7 @@ namespace MDWMBlurGlassExt::DWM
242242
{
243243
attribute = *reinterpret_cast<const DWORD*>(reinterpret_cast<BYTE const*>(this) + 664);
244244
}
245-
else if (os::buildNumber < os::w11_25h2)
245+
else if (os::buildNumber < os::w11_25h2 && os::ubrNumber < 7171)
246246
{
247247
attribute = *reinterpret_cast<const DWORD*>(reinterpret_cast<BYTE const*>(this) + 672); // ok with build 26020
248248
}

DWMBlurGlassExt/Section/CompositedBackdrop.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ namespace MDWMBlurGlassExt
129129
{
130130
clipApplied = true;
131131
}
132+
// If clipRound is configured, always apply clipping
133+
if (g_configData.clipRound > 0)
134+
{
135+
clipApplied = true;
136+
}
132137
if (m_clipApplied2 != clipApplied)
133138
{
134139
m_rootVisual.Clip(clipApplied ? m_dcompDevice.as<wuc::Compositor>().CreateGeometricClip(m_pathGeometry) : nullptr);
@@ -149,7 +154,43 @@ namespace MDWMBlurGlassExt
149154
m_compositedRgn.get()
150155
)
151156
};
152-
m_pathGeometry.Path(wuc::CompositionPath{ canvasGeometry.as<wg::IGeometrySource2D>() });
157+
158+
// Apply rounded rectangle clipping
159+
if (g_configData.clipRound > 0)
160+
{
161+
winrt::com_ptr<ID2D1RoundedRectangleGeometry> roundedRectGeometry{ nullptr };
162+
D2D1_ROUNDED_RECT roundedRect = D2D1::RoundedRect(
163+
D2D1::RectF(0.f, 0.f, static_cast<float>(wil::rect_width(regionBox)), static_cast<float>(wil::rect_height(regionBox))),
164+
static_cast<float>(g_configData.clipRound),
165+
static_cast<float>(g_configData.clipRound)
166+
);
167+
THROW_IF_FAILED(factory->CreateRoundedRectangleGeometry(roundedRect, roundedRectGeometry.put()));
168+
169+
winrt::com_ptr<ID2D1PathGeometry> clippedGeometry{ nullptr };
170+
THROW_IF_FAILED(factory->CreatePathGeometry(clippedGeometry.put()));
171+
winrt::com_ptr<ID2D1GeometrySink> sink{ nullptr };
172+
THROW_IF_FAILED(clippedGeometry->Open(sink.put()));
173+
174+
winrt::com_ptr<ID2D1Geometry> baseGeometry{ nullptr };
175+
canvasGeometry->GetGeometry(baseGeometry.put());
176+
THROW_IF_FAILED(
177+
baseGeometry->CombineWithGeometry(
178+
roundedRectGeometry.get(),
179+
D2D1_COMBINE_MODE_INTERSECT,
180+
nullptr,
181+
sink.get()
182+
)
183+
);
184+
THROW_IF_FAILED(sink->Close());
185+
186+
auto clippedCanvasGeometry{ winrt::make_self<Geometry::CanvasGeometry>() };
187+
clippedCanvasGeometry->SetGeometry(clippedGeometry.get());
188+
m_pathGeometry.Path(wuc::CompositionPath{ clippedCanvasGeometry.as<wg::IGeometrySource2D>() });
189+
}
190+
else
191+
{
192+
m_pathGeometry.Path(wuc::CompositionPath{ canvasGeometry.as<wg::IGeometrySource2D>() });
193+
}
153194
}
154195

155196
void CCompositedBackdropVisual::OnBackdropBrushUpdated()

DWMBlurGlassExt/Section/CustomButton.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,14 @@ namespace MDWMBlurGlassExt::CustomButton
168168
{
169169
if (auto button = GetButtonPtr(index))
170170
{
171+
if (isToolWindow)
172+
{
173+
width = height = -1;
174+
}
171175
g_cbuttonList[This].buttonList[button] = std::make_pair(index, RECT{ x, 0, width, height });
172176

173-
if (!g_configData.oldBtnHeight) return true;
177+
// 不要修改工具栏窗口的按钮 它应该是固定大小和偏移
178+
if (!g_configData.oldBtnHeight || isToolWindow) return true;
174179

175180
if (os::buildNumber < 22000 || os::buildNumber >= 26100)
176181
{
@@ -328,6 +333,12 @@ namespace MDWMBlurGlassExt::CustomButton
328333
return g_funCButton_UpdateLayout.call_org(This);
329334

330335
auto& data = iter->second.buttonList[This].second;
336+
337+
// 如果宽高为 -1 则表示使用默认尺寸(工具窗口按钮) 不进行修改
338+
if ((data.right == -1 && data.bottom == -1))
339+
{
340+
return g_funCButton_UpdateLayout.call_org(This);
341+
}
331342
size->cx = data.right;
332343
size->cy = data.bottom;
333344

@@ -371,7 +382,7 @@ namespace MDWMBlurGlassExt::CustomButton
371382

372383
//OutputDebugStringW((L"state:" + std::to_wstring(state) + L"\n").c_str());
373384
SIZE size = { data.second.right, data.second.bottom };
374-
if (!g_configData.oldBtnHeight)
385+
if (!g_configData.oldBtnHeight || (size.cx == -1 && size.cy == -1))
375386
size = *This->GetSize();
376387
backdrop->Update(data.first, *This->GetPoint(), size, scale, state == 2 || state == 1);
377388
}

0 commit comments

Comments
 (0)