From 352614d40a7397f836ef2e3ca992b8d4a41a602a Mon Sep 17 00:00:00 2001 From: fufesou Date: Mon, 12 Aug 2024 23:48:01 +0800 Subject: [PATCH] fix: win, adjustNCCALCSIZE with monitor coords Signed-off-by: fufesou --- windows/window_manager_plugin.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/windows/window_manager_plugin.cpp b/windows/window_manager_plugin.cpp index d83e52bd..4ba6e668 100644 --- a/windows/window_manager_plugin.cpp +++ b/windows/window_manager_plugin.cpp @@ -62,9 +62,24 @@ class WindowManagerPlugin : public flutter::Plugin { const flutter::MethodCall& method_call, std::unique_ptr> result); - void adjustNCCALCSIZE(NCCALCSIZE_PARAMS* sz) { - LONG l = sz->rgrc[0].left; - LONG t = sz->rgrc[0].top; + void adjustNCCALCSIZE(HWND hwnd, NCCALCSIZE_PARAMS* sz) { + LONG l = 8; + LONG t = 8; + + HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); + if (monitor != NULL) { + MONITORINFO monitorInfo; + monitorInfo.cbSize = sizeof(MONITORINFO); + if (TRUE == GetMonitorInfo(monitor, &monitorInfo)) { + l = sz->rgrc[0].left - monitorInfo.rcWork.left; + t = sz->rgrc[0].top - monitorInfo.rcWork.top; + } else { + // GetMonitorInfo failed, use (8, 8) as default value + } + } else { + // unreachable code + } + sz->rgrc[0].left -= l; sz->rgrc[0].top -= t; sz->rgrc[0].right += l; @@ -128,7 +143,7 @@ std::optional WindowManagerPlugin::HandleWindowProc(HWND hWnd, if (window_manager->IsFullScreen() && window_manager->title_bar_style_ != "normal") { if (window_manager->is_frameless_) { - adjustNCCALCSIZE(reinterpret_cast(lParam)); + adjustNCCALCSIZE(hWnd, reinterpret_cast(lParam)); } return 0; } @@ -136,7 +151,7 @@ std::optional WindowManagerPlugin::HandleWindowProc(HWND hWnd, // the `if TitleBarStyle.hidden` doesn't get executed. if (window_manager->is_frameless_) { if (window_manager->IsMaximized()) { - adjustNCCALCSIZE(reinterpret_cast(lParam)); + adjustNCCALCSIZE(hWnd, reinterpret_cast(lParam)); } return 0; } @@ -145,7 +160,7 @@ std::optional WindowManagerPlugin::HandleWindowProc(HWND hWnd, if (wParam && window_manager->title_bar_style_ == "hidden") { if (window_manager->IsMaximized()) { // Adjust the borders when maximized so the app isn't cut off - adjustNCCALCSIZE(reinterpret_cast(lParam)); + adjustNCCALCSIZE(hWnd, reinterpret_cast(lParam)); } else { NCCALCSIZE_PARAMS* sz = reinterpret_cast(lParam); // on windows 10, if set to 0, there's a white line at the top