Skip to content

Commit

Permalink
fix: windows, window size, fullscree & maximized (#477)
Browse files Browse the repository at this point in the history
Signed-off-by: fufesou <[email protected]>
  • Loading branch information
fufesou authored Aug 8, 2024
1 parent 35f3e18 commit fa2a963
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions windows/window_manager_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ class WindowManagerPlugin : public flutter::Plugin {
void HandleMethodCall(
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;
sz->rgrc[0].left -= l;
sz->rgrc[0].top -= t;
sz->rgrc[0].right += l;
sz->rgrc[0].bottom += t;
}
};

// static
Expand Down Expand Up @@ -119,43 +128,30 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd,
if (window_manager->IsFullScreen() &&
window_manager->title_bar_style_ != "normal") {
if (window_manager->is_frameless_) {
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
sz->rgrc[0].left += 8;
sz->rgrc[0].top += 8;
sz->rgrc[0].right -= 8;
sz->rgrc[0].bottom -= 8;
adjustNCCALCSIZE(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_) {
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
if (window_manager->IsMaximized()) {
// Add borders when maximized so app doesn't get cut off.
sz->rgrc[0].left += 8;
sz->rgrc[0].top += 8;
sz->rgrc[0].right -= 8;
sz->rgrc[0].bottom -= 9;
adjustNCCALCSIZE(reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam));
}
return 0;
}

// This must always be last.
if (wParam && window_manager->title_bar_style_ == "hidden") {
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);

// Add 8 pixel to the top border when maximized so the app isn't cut off
if (window_manager->IsMaximized()) {
sz->rgrc[0].top += 8;
// Adjust the borders when maximized so the app isn't cut off
adjustNCCALCSIZE(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
// of the app and I've yet to find a way to remove that.
sz->rgrc[0].top += IsWindows11OrGreater() ? 0 : 1;
}
sz->rgrc[0].right -= 8;
sz->rgrc[0].bottom -= 8;
sz->rgrc[0].left -= -8;

// Previously (WVR_HREDRAW | WVR_VREDRAW), but returning 0 or 1 doesn't
// actually break anything so I've set it to 0. Unless someone pointed a
Expand Down

0 comments on commit fa2a963

Please sign in to comment.