Skip to content

feat: Windows system title bar theme follows the theme#1961

Merged
Predidit merged 13 commits into
Predidit:mainfrom
ChouChiu:title-bar-theme
Apr 11, 2026
Merged

feat: Windows system title bar theme follows the theme#1961
Predidit merged 13 commits into
Predidit:mainfrom
ChouChiu:title-bar-theme

Conversation

@ChouChiu
Copy link
Copy Markdown
Contributor

@ChouChiu ChouChiu commented Apr 10, 2026

What's Changed:

  1. 系统标题栏颜色跟随主题
Before After
image image

close #1757

由 LLM 修改

Copilot's Summary This pull request adds support for synchronizing the Windows title bar theme (light/dark mode) with the app's selected theme. It introduces a platform channel to communicate theme changes from Flutter to native Windows code, and updates the window frame appearance accordingly. The changes ensure that when users toggle the app's theme, the Windows title bar updates in real time, provided the system title bar is used.

Windows Title Bar Theme Sync:

  • Added a new setWindowTitleBarDarkMode method in Utils (lib/utils/utils.dart) to invoke a native platform channel and update the Windows title bar theme based on the app's theme.
  • Integrated calls to setWindowTitleBarDarkMode in both app initialization (lib/app_widget.dart) and theme settings changes (lib/pages/settings/theme_settings_page.dart), so the title bar theme updates whenever the app theme changes. [1] [2]

Platform Channel and Native Windows Implementation:

  • Added a new "theme" MethodChannel on the Windows side (windows/runner/flutter_window.cpp and windows/runner/flutter_window.h) to handle requests from Flutter for updating the title bar theme. [1] [2] [3]
  • Updated the Win32Window::UpdateTheme method (windows/runner/win32_window.cpp and windows/runner/win32_window.h) to accept an optional dark mode parameter, allowing explicit control or fallback to system theme. [1] [2] [3] [4]

These changes provide a seamless, platform-consistent look for Windows users when toggling between light and dark themes in the app.

@ChouChiu ChouChiu changed the title Title bar theme 系统标题栏主题跟随应用主题 Apr 10, 2026
@ChouChiu ChouChiu changed the title 系统标题栏主题跟随应用主题 feat: Windows system title bar theme follows the app theme Apr 10, 2026
@Predidit
Copy link
Copy Markdown
Owner

这个问题很麻烦,因为 windows 实际上并不只一个深色模式

windows 可以为系统和应用独立设置深色和浅色模式

并且很多 OEM 厂商的默认主题是系统为深色模式,应用为浅色模式以提供高级感

总之一团糟,我不知道这里怎么做才是对的

@ChouChiu
Copy link
Copy Markdown
Contributor Author

ChouChiu commented Apr 10, 2026

图片1 图片2
图片3 图片4

总之一团糟,我不知道这里怎么做才是对的

跟随文件资源管理器的行为?

@Predidit
Copy link
Copy Markdown
Owner

直觉上这个PR的切入点不是很好,我们应该考虑在 window_manager 包中或者 main.cpp 中做一些修改,为我们的窗体设定特定的属性,让其跟随默认应用模式,这样应该改动最小且可靠

当前的方案像是某种 hack ,并且看上去当我们在系统设置中调整应用模式时,应用的行为存在不确定性

@ChouChiu

This comment was marked as resolved.

@Predidit
Copy link
Copy Markdown
Owner

关于在 main.cpp 中的窗体属性中添加特定值来简单适配的做法有可行性吗

如果没有的话,我注意到我们本身在使用的 window_manager 包已经提供了设定窗体深色模式的API,也就是 windowManager.setBrightness() ,用它取代我们的自定义实现可能好一点

@ChouChiu ChouChiu changed the title feat: Windows system title bar theme follows the app theme feat: Windows system title bar theme follows the theme Apr 10, 2026
Comment thread windows/runner/win32_window.cpp
Comment thread lib/bean/settings/theme_provider.dart Outdated
Comment thread windows/runner/win32_window.cpp Outdated
@Predidit
Copy link
Copy Markdown
Owner

感谢你的贡献,在我看来已经没有问题了

但是我个人现在对 glm5 的输出现在有些缺乏信任,我需要去查看一下文档,看看 WM_DWMCOLORIZATIONCOLORCHANGED 的修改是否合理与准确

我尽量在明天晚上之前合并这个pr

@ChouChiu
Copy link
Copy Markdown
Contributor Author

感谢你的贡献,在我看来已经没有问题了

但是我个人现在对 glm5 的输出现在有些缺乏信任,我需要去查看一下文档,看看 WM_DWMCOLORIZATIONCOLORCHANGED 的修改是否合理与准确

我尽量在明天晚上之前合并这个pr

https://learn.microsoft.com/zh-cn/windows/win32/dwm/wm-dwmcolorizationcolorchanged
https://learn.microsoft.com/zh-cn/windows/win32/winmsg/wm-settingchange
https://learn.microsoft.com/en-us/answers/questions/1338061/windows-color-theme-aware-app
sandboxie-plus/Sandboxie#1270
https://learn.microsoft.com/en-us/windows/win32/dwm/dwm-messages
lepoco/wpfui#1677

搜集了一下,希望有用

Comment thread windows/runner/win32_window.cpp Outdated
@Predidit
Copy link
Copy Markdown
Owner

此实现仍然有问题,让人头痛的同步问题

当应用中强制设置为浅色模式时,系统更改色彩模式为深色仍然会改变标题栏,不会改变应用内容

@ChouChiu
Copy link
Copy Markdown
Contributor Author

此实现仍然有问题,让人头痛的同步问题

当应用中强制设置为浅色模式时,系统更改色彩模式为深色仍然会改变标题栏,不会改变应用内容

解决

image

Comment thread lib/app_widget.dart Outdated
Comment thread windows/runner/win32_window.cpp Outdated
@Predidit Predidit merged commit d7a1648 into Predidit:main Apr 11, 2026
6 checks passed
ErBWs pushed a commit to ErBWs/Kazumi that referenced this pull request Apr 25, 2026
* feat: add Windows title bar theme support based on app theme

* feat: refine Windows title bar theme handling based on system settings

* feat: update Windows title bar theme handling and method channel setup

* feat: simplify theme update handling by removing redundant message case and using SetTitleBarDarkMode

* feat: enhance Windows title bar theme handling by simplifying logic and adding isEffectiveDark method

* ref: use windowManager.setBrightness method

* fix: remove unnecessary newline

* imp by review

* revert

* fix: update theme handling in MessageHandler to use correct window handle

* feat: update title bar theme handling based on platform brightness changes

* imp by review

* remove llm slop

(cherry picked from commit d7a1648)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

开启系统标签栏,颜色和主题相差过大

2 participants