From 9ad845b40a1403db4bcceb1ceb4fb8c4ddc176fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Thu, 29 Aug 2024 11:05:19 +0800 Subject: [PATCH] windows: Implement theme changed events (#16207) Closes [#16198](https://github.com/zed-industries/zed/issues/16198) AFAIK, when the system's theme mode or accent color changes, there are typically two types of broadcast messages: 1. A `WM_SETTINGCHANGE` message, where `lParam` points to the string "ImmersiveColorSet". 2. A `WM_DWMCOLORIZATIONCOLORCHANGED` message. I use `WM_DWMCOLORIZATIONCOLORCHANGED` here for simplicity. https://github.com/user-attachments/assets/422f8e4e-c698-4e7c-8d2d-01f453b9a7b3 Release Notes: - N/A --- crates/gpui/src/platform/windows/events.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/gpui/src/platform/windows/events.rs b/crates/gpui/src/platform/windows/events.rs index 62fd9a4270d7663751eb964a36874da1ca27e2ed..5d0fd2069674dfe9368b8b1b50a66aea337c719f 100644 --- a/crates/gpui/src/platform/windows/events.rs +++ b/crates/gpui/src/platform/windows/events.rs @@ -84,6 +84,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), CURSOR_STYLE_CHANGED => handle_cursor_changed(lparam, state_ptr), _ => None, }; @@ -1118,6 +1119,18 @@ fn handle_system_command(wparam: WPARAM, state_ptr: Rc) - None } +fn handle_system_theme_changed(state_ptr: Rc) -> Option { + let mut callback = state_ptr + .state + .borrow_mut() + .callbacks + .appearance_changed + .take()?; + callback(); + state_ptr.state.borrow_mut().callbacks.appearance_changed = Some(callback); + Some(0) +} + fn parse_syskeydown_msg_keystroke(wparam: WPARAM) -> Option { let modifiers = current_modifiers(); if !modifiers.alt {