Skip to content

Commit 64026de

Browse files
brencacodebytere
authored andcommitted
fix: adjust window size in NCCALCSIZE instead of adding insets (electron#19944)
1 parent e6178f8 commit 64026de

File tree

3 files changed

+28
-37
lines changed

3 files changed

+28
-37
lines changed

atom/browser/native_window_views_win.cc

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ int GetAppbarAutohideEdges(HWND hwnd) {
239239
return edges;
240240
}
241241

242+
void TriggerNCCalcSize(HWND hwnd) {
243+
RECT rcClient;
244+
::GetWindowRect(hwnd, &rcClient);
245+
246+
::SetWindowPos(hwnd, NULL, rcClient.left, rcClient.top,
247+
rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
248+
SWP_FRAMECHANGED);
249+
}
250+
242251
} // namespace
243252

244253
std::set<NativeWindowViews*> NativeWindowViews::forwarding_windows_;
@@ -369,8 +378,12 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
369378
// https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/
370379
DefWindowProcW(GetAcceleratedWidget(), WM_NCCALCSIZE, w_param, l_param);
371380

372-
params->rgrc[0] = PROPOSED;
373-
params->rgrc[1] = BEFORE;
381+
if (last_window_state_ == ui::SHOW_STATE_MAXIMIZED) {
382+
params->rgrc[0].top = 0;
383+
} else {
384+
params->rgrc[0] = PROPOSED;
385+
params->rgrc[1] = BEFORE;
386+
}
374387

375388
return true;
376389
} else {
@@ -453,26 +466,15 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
453466
// window state and notify the user accordingly.
454467
switch (w_param) {
455468
case SIZE_MAXIMIZED: {
456-
// Frameless maximized windows are size compensated by Windows for a
457-
// border that's not actually there, so we must conter-compensate.
458-
// https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/
459-
if (!has_frame()) {
460-
float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(
461-
GetAcceleratedWidget());
462-
463-
int border =
464-
GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
465-
if (!thick_frame_) {
466-
border -= GetSystemMetrics(SM_CXBORDER);
467-
}
468-
root_view_->SetInsets(gfx::Insets(border).Scale(1.0f / scale_factor));
469-
}
470-
471469
last_window_state_ = ui::SHOW_STATE_MAXIMIZED;
472470
if (consecutive_moves_) {
473471
last_normal_bounds_ = last_normal_bounds_before_move_;
474472
}
475473

474+
if (!has_frame()) {
475+
TriggerNCCalcSize(GetAcceleratedWidget());
476+
}
477+
476478
NotifyWindowMaximize();
477479
break;
478480
}
@@ -497,8 +499,12 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
497499
switch (last_window_state_) {
498500
case ui::SHOW_STATE_MAXIMIZED:
499501
last_window_state_ = ui::SHOW_STATE_NORMAL;
500-
root_view_->SetInsets(gfx::Insets(0));
501502
NotifyWindowUnmaximize();
503+
504+
if (!has_frame()) {
505+
TriggerNCCalcSize(GetAcceleratedWidget());
506+
}
507+
502508
break;
503509
case ui::SHOW_STATE_MINIMIZED:
504510
if (IsFullscreen()) {

atom/browser/ui/views/root_view.cc

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,14 @@ void RootView::Layout() {
175175
return;
176176

177177
const auto menu_bar_bounds =
178-
menu_bar_visible_
179-
? gfx::Rect(insets_.left(), insets_.top(),
180-
size().width() - insets_.width(), kMenuBarHeight)
181-
: gfx::Rect();
178+
menu_bar_visible_ ? gfx::Rect(0, 0, size().width(), kMenuBarHeight)
179+
: gfx::Rect();
182180
if (menu_bar_)
183181
menu_bar_->SetBoundsRect(menu_bar_bounds);
184182

185183
window_->content_view()->SetBoundsRect(
186-
gfx::Rect(insets_.left(),
187-
menu_bar_visible_ ? menu_bar_bounds.bottom() : insets_.top(),
188-
size().width() - insets_.width(),
189-
size().height() - menu_bar_bounds.height() - insets_.height()));
184+
gfx::Rect(0, menu_bar_visible_ ? menu_bar_bounds.bottom() : 0,
185+
size().width(), size().height() - menu_bar_bounds.height()));
190186
}
191187

192188
gfx::Size RootView::GetMinimumSize() const {
@@ -223,11 +219,4 @@ void RootView::UnregisterAcceleratorsWithFocusManager() {
223219
focus_manager->UnregisterAccelerators(this);
224220
}
225221

226-
void RootView::SetInsets(const gfx::Insets& insets) {
227-
if (insets != insets_) {
228-
insets_ = insets;
229-
Layout();
230-
}
231-
}
232-
233222
} // namespace atom

atom/browser/ui/views/root_view.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class RootView : public views::View {
4040
// Register/Unregister accelerators supported by the menu model.
4141
void RegisterAcceleratorsWithFocusManager(AtomMenuModel* menu_model);
4242
void UnregisterAcceleratorsWithFocusManager();
43-
void SetInsets(const gfx::Insets& insets);
44-
gfx::Insets insets() const { return insets_; }
4543

4644
// views::View:
4745
void Layout() override;
@@ -59,8 +57,6 @@ class RootView : public views::View {
5957
bool menu_bar_visible_ = false;
6058
bool menu_bar_alt_pressed_ = false;
6159

62-
gfx::Insets insets_;
63-
6460
// Map from accelerator to menu item's command id.
6561
accelerator_util::AcceleratorTable accelerator_table_;
6662

0 commit comments

Comments
 (0)