mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
windows: Implement window_appearance()
and should_auto_hide_scrollbars()
(#12527)
Release Notes: - N/A
This commit is contained in:
parent
da281d6d8f
commit
599102573a
@ -416,6 +416,7 @@ features = [
|
|||||||
"Foundation_Numerics",
|
"Foundation_Numerics",
|
||||||
"System",
|
"System",
|
||||||
"System_Threading",
|
"System_Threading",
|
||||||
|
"UI_ViewManagement",
|
||||||
"Wdk_System_SystemServices",
|
"Wdk_System_SystemServices",
|
||||||
"Win32_Globalization",
|
"Win32_Globalization",
|
||||||
"Win32_Graphics_Direct2D",
|
"Win32_Graphics_Direct2D",
|
||||||
|
@ -27,6 +27,10 @@ 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::{
|
||||||
|
Color,
|
||||||
|
ViewManagement::{UIColorType, UISettings},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
@ -300,9 +304,8 @@ impl Platform for WindowsPlatform {
|
|||||||
Ok(Box::new(window))
|
Ok(Box::new(window))
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo(windows)
|
|
||||||
fn window_appearance(&self) -> WindowAppearance {
|
fn window_appearance(&self) -> WindowAppearance {
|
||||||
WindowAppearance::Dark
|
system_appearance().log_err().unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_url(&self, url: &str) {
|
fn open_url(&self, url: &str) {
|
||||||
@ -498,9 +501,8 @@ impl Platform for WindowsPlatform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo(windows)
|
|
||||||
fn should_auto_hide_scrollbars(&self) -> bool {
|
fn should_auto_hide_scrollbars(&self) -> bool {
|
||||||
false
|
should_auto_hide_scrollbars().log_err().unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_to_clipboard(&self, item: ClipboardItem) {
|
fn write_to_clipboard(&self, item: ClipboardItem) {
|
||||||
@ -682,3 +684,28 @@ 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]
|
||||||
|
fn should_auto_hide_scrollbars() -> Result<bool> {
|
||||||
|
let ui_settings = UISettings::new()?;
|
||||||
|
Ok(ui_settings.AutoHideScrollBars()?)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user