diff --git a/crates/gpui/src/platform/windows/events.rs b/crates/gpui/src/platform/windows/events.rs index aa550109e00b7497a9bcf152f19b7860b51a75a1..7c5a9736146f8c83bef3fade0566262942e68fc5 100644 --- a/crates/gpui/src/platform/windows/events.rs +++ b/crates/gpui/src/platform/windows/events.rs @@ -1259,7 +1259,7 @@ fn is_modifier(virtual_key: VIRTUAL_KEY) -> bool { } #[inline] -fn current_modifiers() -> Modifiers { +pub(crate) fn current_modifiers() -> Modifiers { Modifiers { control: is_virtual_key_pressed(VK_CONTROL), alt: is_virtual_key_pressed(VK_MENU), diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index 4edd807b8b8d1813d0410be0b36522edf1669793..f46b325cd76e17a9a1adf611f9f8818bed2cc7f8 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -27,10 +27,7 @@ use windows::{ System::{Com::*, LibraryLoader::*, Ole::*, SystemInformation::*, Threading::*, Time::*}, UI::{Input::KeyboardAndMouse::*, Shell::*, WindowsAndMessaging::*}, }, - UI::{ - Color, - ViewManagement::{UIColorType, UISettings}, - }, + UI::ViewManagement::UISettings, }; use crate::*; @@ -678,25 +675,6 @@ fn load_icon() -> Result { Ok(HICON(handle.0)) } -// https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes -#[inline] -fn system_appearance() -> Result { - let ui_settings = UISettings::new()?; - let foreground_color = ui_settings.GetColorValue(UIColorType::Foreground)?; - // If the foreground is light, then is_color_light will evaluate to true, - // meaning Dark mode is enabled. - if is_color_light(&foreground_color) { - Ok(WindowAppearance::Dark) - } else { - Ok(WindowAppearance::Light) - } -} - -#[inline(always)] -fn is_color_light(color: &Color) -> bool { - ((5 * color.G as u32) + (2 * color.R as u32) + color.B as u32) > (8 * 128) -} - #[inline] fn should_auto_hide_scrollbars() -> Result { let ui_settings = UISettings::new()?; diff --git a/crates/gpui/src/platform/windows/util.rs b/crates/gpui/src/platform/windows/util.rs index ba2d9ff7b2382f98781ef938dbb31179b560bcd4..e39390056e0d52835fa25018140721d18529defa 100644 --- a/crates/gpui/src/platform/windows/util.rs +++ b/crates/gpui/src/platform/windows/util.rs @@ -1,7 +1,13 @@ use std::sync::OnceLock; use ::util::ResultExt; -use windows::Win32::{Foundation::*, UI::WindowsAndMessaging::*}; +use windows::{ + Win32::{Foundation::*, UI::WindowsAndMessaging::*}, + UI::{ + Color, + ViewManagement::{UIColorType, UISettings}, + }, +}; use crate::*; @@ -118,3 +124,22 @@ pub(crate) fn logical_point(x: f32, y: f32, scale_factor: f32) -> Point y: px(y / scale_factor), } } + +// https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes +#[inline] +pub(crate) fn system_appearance() -> Result { + let ui_settings = UISettings::new()?; + let foreground_color = ui_settings.GetColorValue(UIColorType::Foreground)?; + // If the foreground is light, then is_color_light will evaluate to true, + // meaning Dark mode is enabled. + if is_color_light(&foreground_color) { + Ok(WindowAppearance::Dark) + } else { + Ok(WindowAppearance::Light) + } +} + +#[inline(always)] +fn is_color_light(color: &Color) -> bool { + ((5 * color.G as u32) + (2 * color.R as u32) + color.B as u32) > (8 * 128) +} diff --git a/crates/gpui/src/platform/windows/window.rs b/crates/gpui/src/platform/windows/window.rs index 8c648661cafea8d517b7dec7d119012047800d02..46a2a4e6b3b4ea22bd2556e47973759e4e023a9b 100644 --- a/crates/gpui/src/platform/windows/window.rs +++ b/crates/gpui/src/platform/windows/window.rs @@ -383,9 +383,8 @@ impl PlatformWindow for WindowsWindow { self.0.state.borrow().scale_factor } - // todo(windows) fn appearance(&self) -> WindowAppearance { - WindowAppearance::Dark + system_appearance().log_err().unwrap_or_default() } fn display(&self) -> Option> { @@ -405,9 +404,8 @@ impl PlatformWindow for WindowsWindow { logical_point(point.x as f32, point.y as f32, scale_factor) } - // todo(windows) fn modifiers(&self) -> Modifiers { - Modifiers::none() + current_modifiers() } fn set_input_handler(&mut self, input_handler: PlatformInputHandler) {