Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: win, adjustNCCALCSIZE with monitor coords #482

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 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 @@ -105,7 +120,8 @@ WindowManagerPlugin::~WindowManagerPlugin() {
}

void WindowManagerPlugin::_EmitEvent(std::string eventName) {
if (channel == nullptr) return;
if (channel == nullptr)
return;
flutter::EncodableMap args = flutter::EncodableMap();
args[flutter::EncodableValue("eventName")] =
flutter::EncodableValue(eventName);
Expand All @@ -128,15 +144,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,12 +161,17 @@ 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
// of the app and I've yet to find a way to remove that.
sz->rgrc[0].top += IsWindows11OrGreater() ? 0 : 1;
// The following lines are required for resizing the window.
// https://github.com/leanflutter/window_manager/issues/483
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
Expand Down