parent
ce7074c883
commit
8203b6875b
4 changed files with 30 additions and 29 deletions
|
@ -1259,7 +1259,7 @@ fn is_modifier(virtual_key: VIRTUAL_KEY) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn current_modifiers() -> Modifiers {
|
pub(crate) fn current_modifiers() -> Modifiers {
|
||||||
Modifiers {
|
Modifiers {
|
||||||
control: is_virtual_key_pressed(VK_CONTROL),
|
control: is_virtual_key_pressed(VK_CONTROL),
|
||||||
alt: is_virtual_key_pressed(VK_MENU),
|
alt: is_virtual_key_pressed(VK_MENU),
|
||||||
|
|
|
@ -27,10 +27,7 @@ use windows::{
|
||||||
System::{Com::*, LibraryLoader::*, Ole::*, SystemInformation::*, Threading::*, Time::*},
|
System::{Com::*, LibraryLoader::*, Ole::*, SystemInformation::*, Threading::*, Time::*},
|
||||||
UI::{Input::KeyboardAndMouse::*, Shell::*, WindowsAndMessaging::*},
|
UI::{Input::KeyboardAndMouse::*, Shell::*, WindowsAndMessaging::*},
|
||||||
},
|
},
|
||||||
UI::{
|
UI::ViewManagement::UISettings,
|
||||||
Color,
|
|
||||||
ViewManagement::{UIColorType, UISettings},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
@ -678,25 +675,6 @@ fn load_icon() -> Result<HICON> {
|
||||||
Ok(HICON(handle.0))
|
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]
|
#[inline]
|
||||||
fn should_auto_hide_scrollbars() -> Result<bool> {
|
fn should_auto_hide_scrollbars() -> Result<bool> {
|
||||||
let ui_settings = UISettings::new()?;
|
let ui_settings = UISettings::new()?;
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
use ::util::ResultExt;
|
use ::util::ResultExt;
|
||||||
use windows::Win32::{Foundation::*, UI::WindowsAndMessaging::*};
|
use windows::{
|
||||||
|
Win32::{Foundation::*, UI::WindowsAndMessaging::*},
|
||||||
|
UI::{
|
||||||
|
Color,
|
||||||
|
ViewManagement::{UIColorType, UISettings},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::*;
|
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),
|
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
|
self.0.state.borrow().scale_factor
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo(windows)
|
|
||||||
fn appearance(&self) -> WindowAppearance {
|
fn appearance(&self) -> WindowAppearance {
|
||||||
WindowAppearance::Dark
|
system_appearance().log_err().unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display(&self) -> Option<Rc<dyn PlatformDisplay>> {
|
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)
|
logical_point(point.x as f32, point.y as f32, scale_factor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo(windows)
|
|
||||||
fn modifiers(&self) -> Modifiers {
|
fn modifiers(&self) -> Modifiers {
|
||||||
Modifiers::none()
|
current_modifiers()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_input_handler(&mut self, input_handler: PlatformInputHandler) {
|
fn set_input_handler(&mut self, input_handler: PlatformInputHandler) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue