Skip to content

Commit 00d047d

Browse files
committed
Add dark mode support for Windows.
1 parent 0656497 commit 00d047d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ You can find its changes [documented below](#070---2021-01-01).
7272
- `WidgetPod::requested_layout` ([#2145] by [@xarvic])
7373
- Make `Parse` work better with floats and similar types ([#2148] by [@superfell])
7474
- Added `compute_max_intrinsic` method to the `Widget` trait, which determines the maximum useful dimension of the widget ([#2172] by [@sjoshid])
75+
- Windows: Dark mode support for the title bar ([#2196] by [@dristic])
7576

7677
### Changed
7778

druid-shell/src/backend/windows/window.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use winapi::shared::minwindef::*;
3535
use winapi::shared::windef::*;
3636
use winapi::shared::winerror::*;
3737
use winapi::um::dcomp::{IDCompositionDevice, IDCompositionTarget, IDCompositionVisual};
38-
use winapi::um::dwmapi::DwmExtendFrameIntoClientArea;
38+
use winapi::um::dwmapi::{DwmExtendFrameIntoClientArea, DwmSetWindowAttribute};
3939
use winapi::um::errhandlingapi::GetLastError;
4040
use winapi::um::shellscalingapi::MDT_EFFECTIVE_DPI;
4141
use winapi::um::unknwnbase::*;
@@ -1516,6 +1516,18 @@ impl WindowBuilder {
15161516
}
15171517
}
15181518

1519+
// Dark mode support
1520+
// https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes
1521+
const DWMWA_USE_IMMERSIVE_DARK_MODE: u32 = 20;
1522+
let value: BOOL = 1;
1523+
let value_ptr = &value as *const _ as *const c_void;
1524+
DwmSetWindowAttribute(
1525+
hwnd,
1526+
DWMWA_USE_IMMERSIVE_DARK_MODE,
1527+
value_ptr,
1528+
std::mem::size_of::<BOOL>() as u32,
1529+
);
1530+
15191531
self.app.add_window(hwnd);
15201532

15211533
if let Some(accels) = accels {

0 commit comments

Comments
 (0)