diff --git a/crates/gpui/src/platform/windows/events.rs b/crates/gpui/src/platform/windows/events.rs index 5e0888e82524910d39ea516c86dcaf28f9a6f4ee..4ac573766b3f1f00822066b48a537ff2450777e9 100644 --- a/crates/gpui/src/platform/windows/events.rs +++ b/crates/gpui/src/platform/windows/events.rs @@ -89,7 +89,7 @@ pub(crate) fn handle_msg( WM_IME_COMPOSITION => handle_ime_composition(handle, lparam, state_ptr), WM_SETCURSOR => handle_set_cursor(lparam, state_ptr), WM_SETTINGCHANGE => handle_system_settings_changed(handle, state_ptr), - WM_DWMCOLORIZATIONCOLORCHANGED => handle_system_theme_changed(state_ptr), + WM_DWMCOLORIZATIONCOLORCHANGED => handle_system_theme_changed(handle, state_ptr), WM_GPUI_CURSOR_STYLE_CHANGED => handle_cursor_changed(lparam, state_ptr), _ => None, }; @@ -1215,7 +1215,10 @@ fn handle_system_command(wparam: WPARAM, state_ptr: Rc) - None } -fn handle_system_theme_changed(state_ptr: Rc) -> Option { +fn handle_system_theme_changed( + handle: HWND, + state_ptr: Rc, +) -> Option { let mut callback = state_ptr .state .borrow_mut() @@ -1224,6 +1227,7 @@ fn handle_system_theme_changed(state_ptr: Rc) -> Option HCURSOR { })) } +pub(crate) fn set_dwm_window_appearance(hwnd: HWND) { + let dark_mode_enabled: BOOL = match system_appearance().log_err().unwrap_or_default() { + WindowAppearance::Dark | WindowAppearance::VibrantDark => true.into(), + WindowAppearance::Light | WindowAppearance::VibrantLight => false.into(), + }; + unsafe { + DwmSetWindowAttribute( + hwnd, + DWMWA_USE_IMMERSIVE_DARK_MODE, + &dark_mode_enabled as *const _ as _, + std::mem::size_of::() as u32, + ) + .log_err(); + } +} + #[inline] pub(crate) fn logical_point(x: f32, y: f32, scale_factor: f32) -> Point { Point { diff --git a/crates/gpui/src/platform/windows/window.rs b/crates/gpui/src/platform/windows/window.rs index 2d873d23bc3fabd2bde3a7f0f991a5c7994ad49f..9dec526d444b85063ab9435d8ff4871aa0cd61eb 100644 --- a/crates/gpui/src/platform/windows/window.rs +++ b/crates/gpui/src/platform/windows/window.rs @@ -443,7 +443,7 @@ impl WindowsWindow { let state_ptr = context.inner.take().unwrap()?; let hwnd = creation_result?; register_drag_drop(state_ptr.clone())?; - + set_dwm_window_appearance(hwnd); state_ptr.state.borrow_mut().border_offset.update(hwnd)?; let placement = retrieve_window_placement( hwnd,