Windows: fix enabling dark mode

This got broken by a recentish windows update.
This commit is contained in:
Wez Furlong committed 2020-10-17 19:48:43 -07:00
1 parent b7e303f39c
commit cac02b3bbb
3 files changed
+31 -1

No files matched your search

Generated
+1
View File
@@ -4245,6 +4245,7 @@ dependencies = [
"pretty_env_logger",
"promise",
"resize",
"shared_library",
"smithay-client-toolkit",
"thiserror",
"wayland-client",
+1
View File
@@ -47,6 +47,7 @@ winapi = { version = "0.3", features = [
]}
winreg = "0.6"
clipboard-win = "2.2"
shared_library = "0.1"
[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
filedescriptor = { version="0.7", path = "../filedescriptor" }
+29 -1
View File
@@ -11,6 +11,7 @@ use crate::{
use anyhow::{bail, Context};
use lazy_static::lazy_static;
use promise::Future;
use shared_library::shared_library;
use std::any::Any;
use std::cell::RefCell;
use std::collections::HashMap;
@@ -567,6 +568,22 @@ fn enable_dark_mode(hwnd: HWND) {
use winapi::um::dwmapi::DwmSetWindowAttribute;
use winapi::um::uxtheme::SetWindowTheme;
#[allow(non_snake_case)]
type WINDOWCOMPOSITIONATTRIB = u32;
const WCA_USEDARKMODECOLORS: WINDOWCOMPOSITIONATTRIB = 26;
#[allow(non_snake_case)]
#[repr(C)]
pub struct WINDOWCOMPOSITIONATTRIBDATA {
Attrib: WINDOWCOMPOSITIONATTRIB,
pvData: PVOID,
cbData: winapi::shared::basetsd::SIZE_T,
}
shared_library!(User32,
pub fn SetWindowCompositionAttribute(hwnd: HWND, attrib: *mut WINDOWCOMPOSITIONATTRIBDATA) -> BOOL,
);
const DWMWA_USE_IMMERSIVE_DARK_MODE: DWORD = 19;
unsafe {
SetWindowTheme(
@@ -575,13 +592,24 @@ fn enable_dark_mode(hwnd: HWND) {
std::ptr::null_mut(),
);
let enabled: BOOL = 1;
let mut enabled: BOOL = 1;
DwmSetWindowAttribute(
hwnd as _,
DWMWA_USE_IMMERSIVE_DARK_MODE,
&enabled as *const _ as *const _,
std::mem::size_of_val(&enabled) as u32,
);
if let Ok(user) = User32::open(std::path::Path::new("user32.dll")) {
(user.SetWindowCompositionAttribute)(
hwnd,
&mut WINDOWCOMPOSITIONATTRIBDATA {
Attrib: WCA_USEDARKMODECOLORS,
pvData: &mut enabled as *mut _ as _,
cbData: std::mem::size_of_val(&enabled) as _,
},
);
}
}
}