Skip to content

Commit e3a160c

Browse files
authored
Merge pull request #684 from nuloperrito/myfix
Fix: Missing glow and misalignment in text title area
2 parents dfdee4f + ad49556 commit e3a160c

2 files changed

Lines changed: 55 additions & 23 deletions

File tree

DWMBlurGlassExt/DWMBlurGlass.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ namespace MDWMBlurGlassExt
162162
if(os::buildNumber < 22000)
163163
WriteIAT(udwmModule, "gdi32.dll", { { "CreateRoundRectRgn", g_funCreateRoundRgn } });
164164

165+
// By using EnumWindows, all top-level windows are forced to trigger border recalculation (SWP_FRAMECHANGED),
166+
// ensuring that when a window is woken up (SC_RESTORE), DWM is forced to completely rebuild visual nodes
167+
// in the non-working area, preventing remnants and misalignments.
168+
EnumWindows([](HWND hwnd, LPARAM) -> BOOL {
169+
if (IsWindowVisible(hwnd) || IsIconic(hwnd)) {
170+
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0,
171+
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE);
172+
}
173+
return TRUE;
174+
}, 0);
175+
165176
if (g_oldExceptionFilter)
166177
{
167178
SetUnhandledExceptionFilter(g_oldExceptionFilter);

DWMBlurGlassExt/Section/TitleTextTweaker.cpp

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "CommonDef.h"
2020
#include "wil.h"
2121
#include <shellscalingapi.h>
22+
#include "../Helper/Helper.h" // For DrawTextWithGlow
2223
#pragma comment(lib, "shcore.lib")
2324

2425
namespace MDWMBlurGlassExt::TitleTextTweaker
@@ -173,34 +174,53 @@ namespace MDWMBlurGlassExt::TitleTextTweaker
173174
lprc->right -= g_textGlowSize;
174175
lprc->bottom -= g_textGlowSize;
175176

176-
DTTOPTS options
177-
{
178-
sizeof(DTTOPTS),
179-
DTT_TEXTCOLOR | DTT_COMPOSITED | DTT_CALLBACK | DTT_GLOWSIZE,
180-
GetTextColor(hdc),
181-
0,
182-
0,
183-
0,
184-
{},
185-
0,
186-
0,
187-
0,
188-
0,
189-
FALSE,
177+
// Get the current text color and calculate the brightness using YIQ formula
178+
COLORREF textColor = GetTextColor(hdc);
179+
int luminance = (GetRValue(textColor) * 299 + GetGValue(textColor) * 587 + GetBValue(textColor) * 114) / 1000;
180+
181+
UINT crGlow = (luminance > 128) ? RGB(128, 128, 128) : RGB(255, 255, 255);
182+
UINT nGlowIntensity = 255;
183+
184+
// Prioritize calling uxtheme's inner function number 126 to render realistic glow.
185+
HRESULT hr = MDWMBlurGlassExt::DrawTextWithGlow(
186+
hdc,
187+
lpchText,
188+
cchText,
189+
lprc,
190+
format,
191+
textColor,
192+
crGlow,
190193
g_textGlowSize,
194+
nGlowIntensity,
195+
TRUE,
191196
drawTextCallback,
192197
(LPARAM)&result
193-
};
194-
wil::unique_htheme hTheme{ OpenThemeData(nullptr, L"Composited::Window") };
198+
);
195199

196-
if (hTheme)
200+
// If the extraction of the undocumented function fails, revert to the original DrawThemeTextEx as a fallback rendering method.
201+
if (FAILED(hr))
197202
{
198-
LOG_IF_FAILED(DrawThemeTextEx(hTheme.get(), hdc, 0, 0, lpchText, cchText, format, lprc, &options));
199-
}
200-
else
201-
{
202-
LOG_HR_IF_NULL(E_FAIL, hTheme);
203-
result = g_funDrawTextW(hdc, lpchText, cchText, lprc, format);
203+
DTTOPTS options
204+
{
205+
sizeof(DTTOPTS),
206+
DTT_TEXTCOLOR | DTT_COMPOSITED | DTT_CALLBACK | DTT_GLOWSIZE,
207+
textColor,
208+
0, 0, 0, {}, 0, 0, 0, 0, FALSE,
209+
g_textGlowSize,
210+
drawTextCallback,
211+
(LPARAM)&result
212+
};
213+
wil::unique_htheme hTheme{ OpenThemeData(nullptr, L"Composited::Window") };
214+
215+
if (hTheme)
216+
{
217+
LOG_IF_FAILED(DrawThemeTextEx(hTheme.get(), hdc, 0, 0, lpchText, cchText, format, lprc, &options));
218+
}
219+
else
220+
{
221+
LOG_HR_IF_NULL(E_FAIL, hTheme);
222+
result = g_funDrawTextW(hdc, lpchText, cchText, lprc, format);
223+
}
204224
}
205225

206226
lprc->left -= g_textGlowSize;
@@ -211,6 +231,7 @@ namespace MDWMBlurGlassExt::TitleTextTweaker
211231
return result;
212232
}
213233

234+
214235
HRESULT MyCreateBitmapFromHBITMAP(IWICImagingFactory2* This, HBITMAP hBitmap, HPALETTE hPalette,
215236
WICBitmapAlphaChannelOption options, IWICBitmap** ppIBitmap)
216237
{

0 commit comments

Comments
 (0)