Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dark mode support for Windows. #2196

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion druid-shell/src/backend/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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::<BOOL>() as u32,
);

self.app.add_window(hwnd);

if let Some(accels) = accels {
Expand Down