Detailed changes
@@ -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),
@@ -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<HICON> {
Ok(HICON(handle.0))
}
-// https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes
-#[inline]
-fn system_appearance() -> Result<WindowAppearance> {
- 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<bool> {
let ui_settings = UISettings::new()?;
@@ -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<Pixels>
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<WindowAppearance> {
+ 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)
+}
@@ -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<Rc<dyn PlatformDisplay>> {
@@ -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) {