Skip to content

Commit fa2a963

Browse files
authored
fix: windows, window size, fullscree & maximized (#477)
Signed-off-by: fufesou <linlong1266@gmail.com>
1 parent 35f3e18 commit fa2a963

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

windows/window_manager_plugin.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ class WindowManagerPlugin : public flutter::Plugin {
6161
void HandleMethodCall(
6262
const flutter::MethodCall<flutter::EncodableValue>& method_call,
6363
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
64+
65+
void adjustNCCALCSIZE(NCCALCSIZE_PARAMS* sz) {
66+
LONG l = sz->rgrc[0].left;
67+
LONG t = sz->rgrc[0].top;
68+
sz->rgrc[0].left -= l;
69+
sz->rgrc[0].top -= t;
70+
sz->rgrc[0].right += l;
71+
sz->rgrc[0].bottom += t;
72+
}
6473
};
6574

6675
// static
@@ -119,43 +128,30 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd,
119128
if (window_manager->IsFullScreen() &&
120129
window_manager->title_bar_style_ != "normal") {
121130
if (window_manager->is_frameless_) {
122-
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
123-
sz->rgrc[0].left += 8;
124-
sz->rgrc[0].top += 8;
125-
sz->rgrc[0].right -= 8;
126-
sz->rgrc[0].bottom -= 8;
131+
adjustNCCALCSIZE(reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam));
127132
}
128133
return 0;
129134
}
130135
// This must always be before handling title_bar_style_ == "hidden" so
131136
// the `if TitleBarStyle.hidden` doesn't get executed.
132137
if (window_manager->is_frameless_) {
133-
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
134138
if (window_manager->IsMaximized()) {
135-
// Add borders when maximized so app doesn't get cut off.
136-
sz->rgrc[0].left += 8;
137-
sz->rgrc[0].top += 8;
138-
sz->rgrc[0].right -= 8;
139-
sz->rgrc[0].bottom -= 9;
139+
adjustNCCALCSIZE(reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam));
140140
}
141141
return 0;
142142
}
143143

144144
// This must always be last.
145145
if (wParam && window_manager->title_bar_style_ == "hidden") {
146-
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
147-
148-
// Add 8 pixel to the top border when maximized so the app isn't cut off
149146
if (window_manager->IsMaximized()) {
150-
sz->rgrc[0].top += 8;
147+
// Adjust the borders when maximized so the app isn't cut off
148+
adjustNCCALCSIZE(reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam));
151149
} else {
150+
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
152151
// on windows 10, if set to 0, there's a white line at the top
153152
// of the app and I've yet to find a way to remove that.
154153
sz->rgrc[0].top += IsWindows11OrGreater() ? 0 : 1;
155154
}
156-
sz->rgrc[0].right -= 8;
157-
sz->rgrc[0].bottom -= 8;
158-
sz->rgrc[0].left -= -8;
159155

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

0 commit comments

Comments
 (0)