Skip to content

Commit

Permalink
fix: win, adjustNCCALCSIZE with monitor coords
Browse files Browse the repository at this point in the history
Signed-off-by: fufesou <linlong1266@gmail.com>
  • Loading branch information
fufesou committed Aug 12, 2024
1 parent 85fc90f commit 352614d
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions windows/window_manager_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,24 @@ class WindowManagerPlugin : public flutter::Plugin {
const flutter::MethodCall<flutter::EncodableValue>& method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> 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;
Expand Down Expand Up @@ -128,15 +143,15 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd,
if (window_manager->IsFullScreen() &&
window_manager->title_bar_style_ != "normal") {
if (window_manager->is_frameless_) {
adjustNCCALCSIZE(reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam));
adjustNCCALCSIZE(hWnd, reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam));
}
return 0;
}
// This must always be before handling title_bar_style_ == "hidden" so
// the `if TitleBarStyle.hidden` doesn't get executed.
if (window_manager->is_frameless_) {
if (window_manager->IsMaximized()) {
adjustNCCALCSIZE(reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam));
adjustNCCALCSIZE(hWnd, reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam));
}
return 0;
}
Expand All @@ -145,7 +160,7 @@ std::optional<LRESULT> 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<NCCALCSIZE_PARAMS*>(lParam));
adjustNCCALCSIZE(hWnd, reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam));
} else {
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
// on windows 10, if set to 0, there's a white line at the top
Expand Down

0 comments on commit 352614d

Please sign in to comment.