From b3909f56007b19d3e80c3ad25d37aab1dae68fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Montes?= Date: Tue, 21 Apr 2020 21:58:38 +0200 Subject: [PATCH] fix: moveAbove not working on Windows (#23161) * fix moveAbove on Windows systems The documentation for [setWindowPos](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos) second argument `hWndInsertAfter` is a bit confusing... > A handle to the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values. Since Windows refers to the Z order from low to high it means that the window provided as reference will always _precede_ the electron window, which is the opposite of what we want in this function, since the electron window is displayed behind the referenced window. The change is simply to ask `SetWindowPos` to position our window *behind* the window that's *above* the reference window, effectively making our window sit just above the reference one. * lint --- shell/browser/native_window_views.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index a4169343d025..2dd79ef41ea6 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -654,10 +654,8 @@ bool NativeWindowViews::MoveAbove(const std::string& sourceId) { if (!::IsWindow(otherWindow)) return false; - gfx::Point pos = GetPosition(); - gfx::Size size = GetSize(); - ::SetWindowPos(GetAcceleratedWidget(), otherWindow, pos.x(), pos.y(), - size.width(), size.height(), + ::SetWindowPos(GetAcceleratedWidget(), GetWindow(otherWindow, GW_HWNDPREV), 0, + 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); #elif defined(USE_X11) if (!IsWindowValid(id.id))