From 01d5bda05b9b78ebe1a290518b96dc849dd90db4 Mon Sep 17 00:00:00 2001 From: Dan Ristic Date: Sat, 4 Jun 2022 10:41:13 -0700 Subject: [PATCH] Add dark mode support for Windows. --- CHANGELOG.md | 3 +++ druid-shell/src/backend/windows/window.rs | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94ea1a8bb3..59bd732506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ You can find its changes [documented below](#070---2021-01-01). - `WidgetPod::requested_layout` ([#2145] by [@xarvic]) - Make `Parse` work better with floats and similar types ([#2148] by [@superfell]) - Added `compute_max_intrinsic` method to the `Widget` trait, which determines the maximum useful dimension of the widget ([#2172] by [@sjoshid]) +- Windows: Dark mode support for the title bar ([#2196] by [@dristic]) ### Changed @@ -554,6 +555,7 @@ Last release without a changelog :( [@superfell]: https://github.com/superfell [@GoldsteinE]: https://github.com/GoldsteinE [@twitchyliquid64]: https://github.com/twitchyliquid64 +[@dristic]: https://github.com/dristic [#599]: https://github.com/linebender/druid/pull/599 [#611]: https://github.com/linebender/druid/pull/611 @@ -847,6 +849,7 @@ Last release without a changelog :( [#2157]: https://github.com/linebender/druid/pull/2157 [#2158]: https://github.com/linebender/druid/pull/2158 [#2172]: https://github.com/linebender/druid/pull/2172 +[#2196]: https://github.com/linebender/druid/pull/2196 [Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master [0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0 diff --git a/druid-shell/src/backend/windows/window.rs b/druid-shell/src/backend/windows/window.rs index e580325ce6..04597dd5ff 100644 --- a/druid-shell/src/backend/windows/window.rs +++ b/druid-shell/src/backend/windows/window.rs @@ -35,7 +35,7 @@ use winapi::shared::minwindef::*; use winapi::shared::windef::*; use winapi::shared::winerror::*; use winapi::um::dcomp::{IDCompositionDevice, IDCompositionTarget, IDCompositionVisual}; -use winapi::um::dwmapi::DwmExtendFrameIntoClientArea; +use winapi::um::dwmapi::{DwmExtendFrameIntoClientArea, DwmSetWindowAttribute}; use winapi::um::errhandlingapi::GetLastError; use winapi::um::shellscalingapi::MDT_EFFECTIVE_DPI; use winapi::um::unknwnbase::*; @@ -1516,6 +1516,18 @@ impl WindowBuilder { } } + // Dark mode support + // https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes + const DWMWA_USE_IMMERSIVE_DARK_MODE: u32 = 20; + let value: BOOL = 1; + let value_ptr = &value as *const _ as *const c_void; + DwmSetWindowAttribute( + hwnd, + DWMWA_USE_IMMERSIVE_DARK_MODE, + value_ptr, + std::mem::size_of::() as u32, + ); + self.app.add_window(hwnd); if let Some(accels) = accels {