Skip to content

Commit 9a4a61e

Browse files
dristicxarvic
authored andcommitted
Add dark mode support for Windows. (linebender#2196)
1 parent 5bcf594 commit 9a4a61e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

CHANGELOG.md

+3
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

@@ -554,6 +555,7 @@ Last release without a changelog :(
554555
[@superfell]: https://github.com/superfell
555556
[@GoldsteinE]: https://github.com/GoldsteinE
556557
[@twitchyliquid64]: https://github.com/twitchyliquid64
558+
[@dristic]: https://github.com/dristic
557559

558560
[#599]: https://github.com/linebender/druid/pull/599
559561
[#611]: https://github.com/linebender/druid/pull/611
@@ -847,6 +849,7 @@ Last release without a changelog :(
847849
[#2157]: https://github.com/linebender/druid/pull/2157
848850
[#2158]: https://github.com/linebender/druid/pull/2158
849851
[#2172]: https://github.com/linebender/druid/pull/2172
852+
[#2196]: https://github.com/linebender/druid/pull/2196
850853

851854
[Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master
852855
[0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0

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)