Add support for Windows Dark Mode (#1217)
* Add support for Windows Dark Mode * Add is_dark_mode() getter to WindowExtWindows * Add WindowEvent::DarkModeChanged * Add support for dark mode in Windows 10 builds > 18362 * Change strategy for querying windows 10 build version * Drop window state before sending event Co-Authored-By: daxpedda <daxpedda@gmail.com> * Change implementation of windows dark mode support * Expand supported range of windows 10 versions with dark mode * Use get_function! macro where possible * Minor style fixes * Improve documentation for ThemeChanged * Use `as` conversion for `BOOL` * Correct CHANGELOG entry for dark mode Co-authored-by: daxpedda <daxpedda@gmail.com> Co-authored-by: Osspial <osspial@gmail.com>
This commit is contained in:
parent
25e018d1ce
commit
d59eec4633
10 changed files with 287 additions and 2 deletions
|
|
@ -48,6 +48,7 @@ use crate::{
|
|||
event::{DeviceEvent, Event, Force, KeyboardInput, Touch, TouchPhase, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootELW},
|
||||
platform_impl::platform::{
|
||||
dark_mode::try_dark_mode,
|
||||
dpi::{
|
||||
become_dpi_aware, dpi_to_scale_factor, enable_non_client_dpi_scaling, hwnd_scale_factor,
|
||||
},
|
||||
|
|
@ -1540,6 +1541,28 @@ unsafe extern "system" fn public_window_callback<T>(
|
|||
0
|
||||
}
|
||||
|
||||
winuser::WM_SETTINGCHANGE => {
|
||||
use crate::event::WindowEvent::ThemeChanged;
|
||||
|
||||
let is_dark_mode = try_dark_mode(window);
|
||||
let mut window_state = subclass_input.window_state.lock();
|
||||
let changed = window_state.is_dark_mode != is_dark_mode;
|
||||
|
||||
if changed {
|
||||
use crate::window::Theme::*;
|
||||
let theme = if is_dark_mode { Dark } else { Light };
|
||||
|
||||
window_state.is_dark_mode = is_dark_mode;
|
||||
mem::drop(window_state);
|
||||
subclass_input.send_event(Event::WindowEvent {
|
||||
window_id: RootWindowId(WindowId(window)),
|
||||
event: ThemeChanged(theme),
|
||||
});
|
||||
}
|
||||
|
||||
commctrl::DefSubclassProc(window, msg, wparam, lparam)
|
||||
}
|
||||
|
||||
_ => {
|
||||
if msg == *DESTROY_MSG_ID {
|
||||
winuser::DestroyWindow(window);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue