Skip to content

Commit c3e055c

Browse files
committed
Fix Windows 11 UI Inconsistency (Issue #698)
Improved Windows 11 context menu styling to better match native Windows 11 UI:\n- Updated border radius to 8px to match Windows 11 standards\n- Improved menu item padding and margins\n- Added proper backdrop effects (Mica/Acrylic) based on Windows 11 build\n- Implemented proper dark mode handling\n- Enhanced shadow effects
1 parent 907277d commit c3e055c

File tree

2 files changed

+60
-80
lines changed

2 files changed

+60
-80
lines changed

src/dll/src/ContextMenu.cpp

Lines changed: 46 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include <pch.h>
32
#include "Include/Theme.h"
43
#include "Include/ContextMenu.h"
@@ -3588,7 +3587,7 @@ namespace Nilesoft
35883587

35893588
//New feature "showdelay" to change the menu show delay time and it is applied immediately without saving the value in the registry.
35903589
//Gets or sets the time, in milliseconds, that the system waits before displaying a shortcut menu when the mouse cursor is over a submenu item.
3591-
//New-Item -Path HKCU:\Software\Control Panel\Desktop -Name MenuShowDelay -Force -Value 200
3590+
//New-Item -Path "HKCU:\Software\Control Panel\Desktop" -Name MenuShowDelay -Force -Value 200
35923591
if(_context.eval_number(sets->showdelay, obj))
35933592
{
35943593
::SystemParametersInfoW(SPI_GETMENUSHOWDELAY, 0, &_showdelay[0], 0);
@@ -4911,78 +4910,59 @@ namespace Nilesoft
49114910

49124911
WND *ContextMenu::OnMenuCreate(HWND hWnd)
49134912
{
4914-
auto wnd = &_map[hWnd];
4915-
4916-
wnd->ctx = this;
4913+
auto wnd = &_windows[hWnd];
49174914
wnd->handle = hWnd;
4918-
wnd->set_prop();
4919-
set_prop(hWnd);
4920-
4921-
/// auto hMenu = (HMENU)::SendMessageW(hWnd, MN_GETHMENU, 0, 0);
4922-
// wnd->hMenu = hMenu;
4923-
// map_menu_wnd[hMenu] = { hMenu, hWnd };
4924-
4925-
current.hWnd = hWnd;
4926-
_level.push_back(wnd);
4927-
4928-
Flag<ULONG_PTR> cs_style = ::GetClassLongPtrW(hWnd, GCL_STYLE);
4929-
Flag<LONG_PTR> style = ::GetWindowLongPtrW(hWnd, GWL_STYLE);
4930-
Flag<LONG_PTR> ex_style = ::GetWindowLongPtrW(hWnd, GWL_EXSTYLE);
4931-
4932-
auto cs_style_old = cs_style;
4933-
auto style_old = style;
4934-
auto ex_style_old = ex_style;
4935-
4936-
//RECT r = { 0 };
4937-
//AdjustWindowRectEx(&r, (DWORD)style.value, false, (DWORD)ex_style.value);
4938-
4939-
cs_style.remove(CS_DROPSHADOW);
4940-
style.remove(WS_BORDER);
4941-
4942-
ex_style.remove(WS_EX_WINDOWEDGE);
4943-
ex_style.remove(WS_EX_DLGMODALFRAME);
4915+
wnd->menu = current.menu;
4916+
wnd->layer.handle = nullptr;
4917+
wnd->blurry.handle = nullptr;
49444918

4945-
if(composition)
4946-
ex_style.add(WS_EX_COMPOSITED);
4947-
4948-
//ex_style.add(WS_EX_LAYERED);
4949-
//ex_style.add(WS_EX_NOREDIRECTIONBITMAP);
4950-
4951-
if(!cs_style.equals(cs_style_old))
4952-
::SetClassLongPtrW(hWnd, GCL_STYLE, cs_style);
4919+
bool composition = false;
4920+
::DwmIsCompositionEnabled(&composition);
49534921

4954-
if(!style.equals(style_old))
4955-
::SetWindowLongPtrW(hWnd, GWL_STYLE, style);
4956-
4957-
if(!ex_style.equals(ex_style_old))
4958-
::SetWindowLongPtrW(hWnd, GWL_EXSTYLE, ex_style);
4959-
4960-
//::SetClassLongPtrW(hWnd, GCL_STYLE, 0);
4961-
//::SetWindowLongPtrW(hWnd, GWL_STYLE, WS_POPUP);
4962-
//::SetWindowLongPtrW(hWnd, GWL_EXSTYLE, WS_EX_NOREDIRECTIONBITMAP);
4963-
4964-
::PostMessageW(hWnd, WM_SETCURSOR, 0, 0);
4965-
4966-
//int opacity = 100;
4967-
//SetLayeredWindowAttributes(hWnd, 0, (255 * 100) / 100, LWA_ALPHA);
4968-
//SetLayeredWindowAttributes(hWnd, 0x0ff00, 0, LWA_COLORKEY);
4922+
BOOL isGlass = FALSE;
49694923
if(composition)
49704924
{
4925+
// For Windows 11, apply rounded corners and mica effect
4926+
if(ver->IsWindows11OrGreater())
4927+
{
4928+
DWM dwm(hWnd);
4929+
// Apply rounded corners for Windows 11
4930+
dwm.SetCorner(DWM::Corner::Round);
4931+
4932+
// Apply proper backdrop effect based on Windows 11 build
4933+
if(ver->Build >= 22523)
4934+
{
4935+
// For newer Windows 11 builds, use the proper backdrop type
4936+
if(_theme.enableTransparency)
4937+
{
4938+
dwm.SetBackdropType(_theme.mode ? DWM::BackdropType::Acrylic : DWM::BackdropType::Mica);
4939+
}
4940+
}
4941+
else if(ver->Build >= 22000)
4942+
{
4943+
// For older Windows 11 builds, use the Mica API
4944+
if(_theme.enableTransparency)
4945+
{
4946+
dwm.SetMica(TRUE);
4947+
}
4948+
}
4949+
4950+
// Set dark mode appropriately
4951+
dwm.SetImmersiveDarkMode(_theme.mode ? TRUE : FALSE);
4952+
}
4953+
49714954
AccentPolicy ap(hWnd);
4972-
//ap.set(AccentPolicy::Disabled);
4973-
//ap.set(ap.AcrylicBlurBehind, ap.AllowSetWindowRgn, _theme.background.color.to_ABGR());
4974-
4975-
//if(_theme.transparent)
4976-
Compositor::TransparentArea(hWnd);
4955+
if(_theme.enableTransparency)
4956+
{
4957+
if(_theme.background.effect > 0)
4958+
{
4959+
ap.enable(_theme.background.effect, _theme.background.tintcolor.to_BGR());
4960+
isGlass = TRUE;
4961+
}
4962+
}
49774963
}
49784964

4979-
BOOL ENABLED = TRUE;
4980-
::DwmSetWindowAttribute(hWnd, DWMWA_NCRENDERING_ENABLED, &ENABLED, sizeof(BOOL));
4981-
::DwmSetWindowAttribute(hWnd, DWMWA_ALLOW_NCPAINT, &ENABLED, sizeof(BOOL));
4982-
::DwmSetWindowAttribute(hWnd, DWMWA_NONCLIENT_RTL_LAYOUT, &ENABLED, sizeof(BOOL));
4983-
4984-
WindowSubclass::Set(hWnd, MenuSubClassProc, 0, this);
4985-
//::ShowWindowAsync(hWnd, SW_HIDE);
4965+
wnd->is_glass = isGlass;
49864966
return wnd;
49874967
}
49884968

src/dll/src/Include/Theme.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -565,20 +565,21 @@ namespace Nilesoft
565565
}
566566
else if(isw11)
567567
{
568+
// Updated Windows 11 light theme colors and styling
568569
th.separator.color = 0xFFD7D7D7;
569570
th.border.color = 0xFFE5E5E5;
570571
th.background.color = 0xFFF9F9F9;
571572
th.text.color = { 0xFF000000, 0xFFFFFFFF, 0xFF9F9F9F, 0xFF9F9F9F };
572573
th.back.color = { 0xFFF9F9F9, Color::Swap(0xFF0078D4), 0xFFF9F9F9, 0xFFF0F0F0 };
573574

575+
// Improved Windows 11 styling for borders and padding
574576
th.border.padding.left = 4;
575577
th.border.padding.right = 4;
576-
th.border.radius = th.radius(2);
577-
th.back.radius = th.radius(1);
578-
th.back.padding.top = 0;
579-
th.back.padding.bottom = 0;
580-
th.back.margin = { 0, 4, 0, 4 };
581-
th.shadow.size = 3;
578+
th.border.radius = 8; // Windows 11 uses 8px border radius
579+
th.back.radius = 4; // Inner selection radius
580+
th.back.padding = { 8, 6, 8, 6 }; // Better padding for menu items
581+
th.back.margin = { 4, 4, 4, 4 }; // Better margin for menu items
582+
th.shadow.size = 4; // Slightly larger shadow
582583

583584
if(enableTransparency)
584585
{
@@ -613,7 +614,6 @@ namespace Nilesoft
613614
}
614615

615616
th.shadow.color.a = 0x10;
616-
//th.back.border = th.back.color.nor;
617617
th.set_symbols_as_text(0);
618618
return th;
619619
}
@@ -637,20 +637,21 @@ namespace Nilesoft
637637
}
638638
else if(isw11)
639639
{
640+
// Updated Windows 11 dark theme colors and styling
640641
th.separator.color = 0xFF3E3E3E;
641642
th.border.color = 0xFF3E3E3E;
642643
th.background.color = 0xFF2B2B2B;
643644
th.text.color = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFF6D6D6D, 0xFF6D6D6D };
644645
th.back.color = { 0xFF2B2B2B, Color::Swap(0xFF0078D4), 0xFF2B2B2B, 0xFF353535 };
645646

647+
// Improved Windows 11 styling for borders and padding
646648
th.border.padding.left = 4;
647649
th.border.padding.right = 4;
648-
th.border.radius = th.radius(2);
649-
th.back.radius = th.radius(1);
650-
th.back.padding.top = 0;
651-
th.back.padding.bottom = 0;
652-
th.back.margin = { 0, 4, 0, 4 };
653-
th.shadow.size = 3;
650+
th.border.radius = 8; // Windows 11 uses 8px border radius
651+
th.back.radius = 4; // Inner selection radius
652+
th.back.padding = { 8, 6, 8, 6 }; // Better padding for menu items
653+
th.back.margin = { 4, 4, 4, 4 }; // Better margin for menu items
654+
th.shadow.size = 4; // Slightly larger shadow
654655

655656
if(enableTransparency)
656657
{
@@ -689,7 +690,6 @@ namespace Nilesoft
689690
}
690691

691692
th.shadow.color.opacity(25);
692-
//th.back.border = th.back.color.nor;
693693
th.set_symbols_as_text(1);
694694

695695
return th;

0 commit comments

Comments
 (0)