Skip to content

Commit fb82bfa

Browse files
brencackerr
authored andcommitted
fix: handle WM_GETMINMAXINFO instead of letting chromium do it (electron#19928) (electron#20001)
* fix: remove WM_GETMINMAXINFO workaround since it's no longer needed * fix: handle WM_GETMINMAXINFO ourselves * fix: remove part of the chromium WM_GETMINMAXINFO handler
1 parent 9b724dc commit fb82bfa

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

atom/browser/native_window_views_win.cc

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,24 +345,35 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
345345
return false;
346346
}
347347
case WM_GETMINMAXINFO: {
348-
WINDOWPLACEMENT wp;
349-
wp.length = sizeof(WINDOWPLACEMENT);
350-
351-
// We do this to work around a Windows bug, where the minimized Window
352-
// would report that the closest display to it is not the one that it was
353-
// previously on (but the leftmost one instead). We restore the position
354-
// of the window during the restore operation, this way chromium can
355-
// use the proper display to calculate the scale factor to use.
356-
if (!last_normal_placement_bounds_.IsEmpty() &&
357-
GetWindowPlacement(GetAcceleratedWidget(), &wp)) {
358-
last_normal_placement_bounds_.set_size(gfx::Size(0, 0));
359-
wp.rcNormalPosition = last_normal_placement_bounds_.ToRECT();
360-
SetWindowPlacement(GetAcceleratedWidget(), &wp);
361-
362-
last_normal_placement_bounds_ = gfx::Rect();
348+
// We need to handle GETMINMAXINFO ourselves because chromium tries to
349+
// get the scale factor of the window during it's version of this handler
350+
// based on the window position, which is invalid at this point. The
351+
// previous method of calling SetWindowPlacement fixed the window
352+
// position for the scale factor calculation but broke other things.
353+
MINMAXINFO* info = reinterpret_cast<MINMAXINFO*>(l_param);
354+
355+
display::Display display =
356+
display::Screen::GetScreen()->GetDisplayNearestPoint(
357+
last_normal_placement_bounds_.origin());
358+
359+
gfx::Size min_size = gfx::ScaleToCeiledSize(
360+
widget()->GetMinimumSize(), display.device_scale_factor());
361+
gfx::Size max_size = gfx::ScaleToCeiledSize(
362+
widget()->GetMaximumSize(), display.device_scale_factor());
363+
364+
info->ptMinTrackSize.x = min_size.width();
365+
info->ptMinTrackSize.y = min_size.height();
366+
if (max_size.width() || max_size.height()) {
367+
if (!max_size.width())
368+
max_size.set_width(GetSystemMetrics(SM_CXMAXTRACK));
369+
if (!max_size.height())
370+
max_size.set_height(GetSystemMetrics(SM_CYMAXTRACK));
371+
info->ptMaxTrackSize.x = max_size.width();
372+
info->ptMaxTrackSize.y = max_size.height();
363373
}
364374

365-
return false;
375+
*result = 1;
376+
return true;
366377
}
367378
case WM_NCCALCSIZE: {
368379
if (!has_frame() && w_param == TRUE) {

0 commit comments

Comments
 (0)