Skip to content

Commit

Permalink
ensure windows 10 for dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Feb 8, 2025
1 parent d96f338 commit 5654824
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/platform_impl/windows/dark_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use windows_sys::Win32::UI::Accessibility::{HCF_HIGHCONTRASTON, HIGHCONTRASTA};
use windows_sys::Win32::UI::Controls::SetWindowTheme;
use windows_sys::Win32::UI::WindowsAndMessaging::{SystemParametersInfoA, SPI_GETHIGHCONTRAST};

use super::util::{self, WIN_BUILD_VERSION};
use super::util::{self, WIN_VERSION};
use crate::utils::Lazy;
use crate::window::Theme;

static DARK_MODE_SUPPORTED: Lazy<bool> = Lazy::new(|| {
// We won't try to do anything for windows versions < 17763
// (Windows 10 October 2018 update)
match *WIN_BUILD_VERSION {
Some(v) => v >= 17763,
match *WIN_VERSION {
Some(v) => v.dwMajorVersion == 10 && v.dwMinorVersion == 0 && v.dwBuildNumber >= 17763,
None => false,
}
});
Expand Down
10 changes: 6 additions & 4 deletions src/platform_impl/windows/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub(crate) static GET_POINTER_DEVICE_RECTS: Lazy<Option<GetPointerDeviceRects>>
pub(crate) static GET_POINTER_TOUCH_INFO: Lazy<Option<GetPointerTouchInfo>> =
Lazy::new(|| get_function!("user32.dll", GetPointerTouchInfo));

pub(crate) static WIN_BUILD_VERSION: Lazy<Option<u32>> = Lazy::new(|| {
pub(crate) static WIN_VERSION: Lazy<Option<OSVERSIONINFOW>> = Lazy::new(|| {
type RtlGetVersion = unsafe extern "system" fn(*mut OSVERSIONINFOW) -> NTSTATUS;
let handle = get_function!("ntdll.dll", RtlGetVersion);

Expand All @@ -286,7 +286,7 @@ pub(crate) static WIN_BUILD_VERSION: Lazy<Option<u32>> = Lazy::new(|| {
let status = (rtl_get_version)(&mut vi);

if status >= 0 {
Some(vi.dwBuildNumber)
Some(vi)
} else {
None
}
Expand Down Expand Up @@ -319,8 +319,10 @@ pub fn calculate_window_insets(window: HWND) -> RECT {

let frame_thickness = get_frame_thickness(dpi);

let top_inset = match *WIN_BUILD_VERSION {
Some(v) if v >= 2200 => (dpi as f32 / USER_DEFAULT_SCREEN_DPI as f32).round() as i32,
let top_inset = match *WIN_VERSION {
Some(v) if v.dwBuildNumber >= 2200 => {
(dpi as f32 / USER_DEFAULT_SCREEN_DPI as f32).round() as i32
},
_ => 0,
};

Expand Down

0 comments on commit 5654824

Please sign in to comment.