[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client area

未关闭 适合新手
#53 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@lijy91 已经在做这个了。

开始于 2026年11月23日。

  • #54 来自 @lijy91 —— 未关闭
  • #101 来自 @lijy91 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
67/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp, dart, flutter
领域
desktop

调研方向

从 src/platform/windows/window_windows.cpp 开始,在 HandleHiddenTitleBarFrame 内 WM_NCCALCSIZE 的最大化分支处;阅读紧挨其上方 proposed 是如何保存的,以及 GetMonitorInfoW 如何通过 MonitorFromWindow 获取其监视器。用隐藏标题栏复现:在辅助监视器上最大化,最小化再还原,然后检查 client rect 和 WM_NCHITTEST。当还原后的客户区是辅助监视器的工作区,且主监视器和最大化移动这些情况保持不变时,即完成。

由索引模型根据 Issue 内容生成。

描述

Environment
  • window_manager 0.7.1 (also 0.7.0), nativeapi / cnativeapi / nativeapi_flutter 0.6.2 (also 0.6.1)
  • Flutter 3.50.0, Windows 11 (build 26300), x64
  • Two 1920×1080 monitors at 100 %, the secondary one to the right of the primary one
Steps to reproduce
final window = WindowManager.instance.getCurrent()!;
window.titleBarStyle = TitleBarStyle.hidden;
window.maximize();
  1. Put the maximized window on the secondary monitor.
  2. Minimize it (caption button, window.minimize() or SC_MINIMIZE).
  3. Restore it (taskbar button or SC_RESTORE).
Expected

Client area = work area of the secondary monitor, as before minimizing.

Actual

Measured right after the restore:

before minimize after restore
window rect (1912,-8)-(3848,1040) (1912,-8)-(3848,1040)
client rect (screen coordinates) (1920,0)-(3840,1032) (0,0)-(1920,1032), the primary monitor's work area, outside the window
WM_NCHITTEST, middle of the window HTCLIENT HTNOWHERE
WM_NCHITTEST, top band HTCLIENT HTCAPTION
Flutter view (child HWND) (1920,0)-(3840,1032) (0,0)-(1920,1032)

The app looks frozen: clicks no longer reach the Flutter view, and the top band behaves like the native caption. On the primary monitor the same steps work.

Moving a maximized window from one monitor to another without minimizing it (SetWindowPos while zoomed) is not affected.

Cause

HandleHiddenTitleBarFrame, maximized branch of WM_NCCALCSIZE (src/platform/windows/window_windows.cpp, nativeapi-core main):

MONITORINFO monitor = {sizeof(monitor)};
if (GetMonitorInfoW(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &monitor))
  params->rgrc[0] = monitor.rcWork;

During WM_NCCALCSIZE the window still has its previous rect. When it leaves the minimized state that rect is the placeholder at (-32000, -32000), so MonitorFromWindow answers the monitor nearest to that point rather than the one the window is restored to.

Suggested fix

proposed (the incoming rgrc[0], saved a few lines above) is the rect the window is moving to:

     // The maximized frame extends beyond the work area by its resize borders.
     // Fit the captionless client to the work area, excluding those borders.
+    // The window still has its previous rect here, the minimized placeholder at
+    // (-32000, -32000) when it leaves the minimized state: take the monitor of the
+    // rect it is moving to.
     MONITORINFO monitor = {sizeof(monitor)};
-    if (GetMonitorInfoW(MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST), &monitor))
+    if (GetMonitorInfoW(MonitorFromRect(&proposed, MONITOR_DEFAULTTONEAREST), &monitor))
       params->rgrc[0] = monitor.rcWork;

Tested with a patched cnativeapi 0.6.2 (dependency_overrides) and an unmodified Flutter runner: the client rect is (1920,0)-(3840,1032) as soon as the window is restored, hit testing and the Flutter view are back on the secondary monitor, and the primary monitor and the maximized move case are unchanged.

Workaround until a release

In the runner's FlutterWindow::MessageHandler, on WM_WINDOWPOSCHANGED: if IsZoomed(hwnd) and the client rect (mapped to screen) is not inside GetWindowRect, call SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED). The window has its final rect by then, so the next WM_NCCALCSIZE picks the right monitor.

主要语言
TypeScript
星标
190
派生
18
平均合并
8 小时 17 分钟
30 天内合并 PR
11

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。