fix: adjust window size in NCCALCSIZE instead of adding insets (#19883)
This commit is contained in:
parent
080fdb3817
commit
f6c523db13
3 changed files with 28 additions and 37 deletions
|
@ -239,6 +239,15 @@ int GetAppbarAutohideEdges(HWND hwnd) {
|
||||||
return edges;
|
return edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TriggerNCCalcSize(HWND hwnd) {
|
||||||
|
RECT rcClient;
|
||||||
|
::GetWindowRect(hwnd, &rcClient);
|
||||||
|
|
||||||
|
::SetWindowPos(hwnd, NULL, rcClient.left, rcClient.top,
|
||||||
|
rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
|
||||||
|
SWP_FRAMECHANGED);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::set<NativeWindowViews*> NativeWindowViews::forwarding_windows_;
|
std::set<NativeWindowViews*> NativeWindowViews::forwarding_windows_;
|
||||||
|
@ -369,8 +378,12 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
|
||||||
// https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/
|
// https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/
|
||||||
DefWindowProcW(GetAcceleratedWidget(), WM_NCCALCSIZE, w_param, l_param);
|
DefWindowProcW(GetAcceleratedWidget(), WM_NCCALCSIZE, w_param, l_param);
|
||||||
|
|
||||||
|
if (last_window_state_ == ui::SHOW_STATE_MAXIMIZED) {
|
||||||
|
params->rgrc[0].top = 0;
|
||||||
|
} else {
|
||||||
params->rgrc[0] = PROPOSED;
|
params->rgrc[0] = PROPOSED;
|
||||||
params->rgrc[1] = BEFORE;
|
params->rgrc[1] = BEFORE;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -453,26 +466,15 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
|
||||||
// window state and notify the user accordingly.
|
// window state and notify the user accordingly.
|
||||||
switch (w_param) {
|
switch (w_param) {
|
||||||
case SIZE_MAXIMIZED: {
|
case SIZE_MAXIMIZED: {
|
||||||
// Frameless maximized windows are size compensated by Windows for a
|
|
||||||
// border that's not actually there, so we must conter-compensate.
|
|
||||||
// https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/
|
|
||||||
if (!has_frame()) {
|
|
||||||
float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(
|
|
||||||
GetAcceleratedWidget());
|
|
||||||
|
|
||||||
int border =
|
|
||||||
GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
|
|
||||||
if (!thick_frame_) {
|
|
||||||
border -= GetSystemMetrics(SM_CXBORDER);
|
|
||||||
}
|
|
||||||
root_view_->SetInsets(gfx::Insets(border).Scale(1.0f / scale_factor));
|
|
||||||
}
|
|
||||||
|
|
||||||
last_window_state_ = ui::SHOW_STATE_MAXIMIZED;
|
last_window_state_ = ui::SHOW_STATE_MAXIMIZED;
|
||||||
if (consecutive_moves_) {
|
if (consecutive_moves_) {
|
||||||
last_normal_bounds_ = last_normal_bounds_before_move_;
|
last_normal_bounds_ = last_normal_bounds_before_move_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!has_frame()) {
|
||||||
|
TriggerNCCalcSize(GetAcceleratedWidget());
|
||||||
|
}
|
||||||
|
|
||||||
NotifyWindowMaximize();
|
NotifyWindowMaximize();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -497,8 +499,12 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
|
||||||
switch (last_window_state_) {
|
switch (last_window_state_) {
|
||||||
case ui::SHOW_STATE_MAXIMIZED:
|
case ui::SHOW_STATE_MAXIMIZED:
|
||||||
last_window_state_ = ui::SHOW_STATE_NORMAL;
|
last_window_state_ = ui::SHOW_STATE_NORMAL;
|
||||||
root_view_->SetInsets(gfx::Insets(0));
|
|
||||||
NotifyWindowUnmaximize();
|
NotifyWindowUnmaximize();
|
||||||
|
|
||||||
|
if (!has_frame()) {
|
||||||
|
TriggerNCCalcSize(GetAcceleratedWidget());
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ui::SHOW_STATE_MINIMIZED:
|
case ui::SHOW_STATE_MINIMIZED:
|
||||||
if (IsFullscreen()) {
|
if (IsFullscreen()) {
|
||||||
|
|
|
@ -176,18 +176,14 @@ void RootView::Layout() {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto menu_bar_bounds =
|
const auto menu_bar_bounds =
|
||||||
menu_bar_visible_
|
menu_bar_visible_ ? gfx::Rect(0, 0, size().width(), kMenuBarHeight)
|
||||||
? gfx::Rect(insets_.left(), insets_.top(),
|
|
||||||
size().width() - insets_.width(), kMenuBarHeight)
|
|
||||||
: gfx::Rect();
|
: gfx::Rect();
|
||||||
if (menu_bar_)
|
if (menu_bar_)
|
||||||
menu_bar_->SetBoundsRect(menu_bar_bounds);
|
menu_bar_->SetBoundsRect(menu_bar_bounds);
|
||||||
|
|
||||||
window_->content_view()->SetBoundsRect(
|
window_->content_view()->SetBoundsRect(
|
||||||
gfx::Rect(insets_.left(),
|
gfx::Rect(0, menu_bar_visible_ ? menu_bar_bounds.bottom() : 0,
|
||||||
menu_bar_visible_ ? menu_bar_bounds.bottom() : insets_.top(),
|
size().width(), size().height() - menu_bar_bounds.height()));
|
||||||
size().width() - insets_.width(),
|
|
||||||
size().height() - menu_bar_bounds.height() - insets_.height()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Size RootView::GetMinimumSize() const {
|
gfx::Size RootView::GetMinimumSize() const {
|
||||||
|
@ -224,11 +220,4 @@ void RootView::UnregisterAcceleratorsWithFocusManager() {
|
||||||
focus_manager->UnregisterAccelerators(this);
|
focus_manager->UnregisterAccelerators(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RootView::SetInsets(const gfx::Insets& insets) {
|
|
||||||
if (insets != insets_) {
|
|
||||||
insets_ = insets;
|
|
||||||
Layout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
|
@ -40,8 +40,6 @@ class RootView : public views::View {
|
||||||
// Register/Unregister accelerators supported by the menu model.
|
// Register/Unregister accelerators supported by the menu model.
|
||||||
void RegisterAcceleratorsWithFocusManager(AtomMenuModel* menu_model);
|
void RegisterAcceleratorsWithFocusManager(AtomMenuModel* menu_model);
|
||||||
void UnregisterAcceleratorsWithFocusManager();
|
void UnregisterAcceleratorsWithFocusManager();
|
||||||
void SetInsets(const gfx::Insets& insets);
|
|
||||||
gfx::Insets insets() const { return insets_; }
|
|
||||||
|
|
||||||
// views::View:
|
// views::View:
|
||||||
void Layout() override;
|
void Layout() override;
|
||||||
|
@ -59,8 +57,6 @@ class RootView : public views::View {
|
||||||
bool menu_bar_visible_ = false;
|
bool menu_bar_visible_ = false;
|
||||||
bool menu_bar_alt_pressed_ = false;
|
bool menu_bar_alt_pressed_ = false;
|
||||||
|
|
||||||
gfx::Insets insets_;
|
|
||||||
|
|
||||||
// Map from accelerator to menu item's command id.
|
// Map from accelerator to menu item's command id.
|
||||||
accelerator_util::AcceleratorTable accelerator_table_;
|
accelerator_util::AcceleratorTable accelerator_table_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue