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: make 'setParentWindow' compatible under Windows #15775

Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


Just for now

fix: make 'setParentWindow' compatible under Windows

  • Loading branch information...
neo291 committed Nov 20, 2018
commit 195d9b264afe0aa550c0dccbd6607a3e86664676
@@ -671,6 +671,7 @@ void TopLevelWindow::SetParentWindow(v8::Local<v8::Value> value,
} else if (mate::ConvertFromV8(isolate(), value, &parent)) {
parent_window_.Reset(isolate(), value);
parent->child_windows_.Set(isolate(), weak_map_id(), GetWrapper());
@@ -1061,9 +1062,7 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setContentProtection", &TopLevelWindow::SetContentProtection)
.SetMethod("setFocusable", &TopLevelWindow::SetFocusable)
.SetMethod("setMenu", &TopLevelWindow::SetMenu)
#if !defined(OS_WIN)
.SetMethod("setParentWindow", &TopLevelWindow::SetParentWindow)
.SetMethod("setBrowserView", &TopLevelWindow::SetBrowserView)
@@ -989,20 +989,27 @@ void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
xdisplay, GetAcceleratedWidget(),
parent ? parent->GetAcceleratedWidget() : DefaultRootWindow(xdisplay));
#elif defined(OS_WIN) && defined(DEBUG)
// Should work, but does not, it seems that the views toolkit doesn't support
// reparenting on desktop.
if (parent) {
::SetParent(GetAcceleratedWidget(), parent->GetAcceleratedWidget());
wm::AddTransientChild(parent->GetNativeWindow(), GetNativeWindow());
} else {
if (!GetNativeWindow()->parent())
::SetParent(GetAcceleratedWidget(), NULL);
views::Widget::ReparentNativeView(GetNativeWindow(), nullptr);
wm::RemoveTransientChild(GetNativeWindow()->parent(), GetNativeWindow());
#elif defined(OS_WIN)
// To set parentship between windows into Windows is better to play with the
// owner instead of the parent, as Windows natively seems to do if a parent
// is specified at window creation time.
// For do this we must NOT use the ::SetParent function, instead we must use
// the ::GetWindowLongPtr or ::SetWindowLongPtr functions with "nIndex" set
// to "GWLP_HWNDPARENT" which actually means the window owner.
HWND hwndParent = parent ? parent->GetAcceleratedWidget() : NULL;
if (hwndParent ==
(HWND)::GetWindowLongPtr(GetAcceleratedWidget(), GWLP_HWNDPARENT))
::SetWindowLongPtr(GetAcceleratedWidget(), GWLP_HWNDPARENT,
// Ensures the visibility
if (IsVisible()) {
wp.length = sizeof(WINDOWPLACEMENT);
::GetWindowPlacement(GetAcceleratedWidget(), &wp);
::ShowWindow(GetAcceleratedWidget(), SW_HIDE);
::ShowWindow(GetAcceleratedWidget(), wp.showCmd);
@@ -122,7 +122,6 @@ state is `hidden` in order to minimize power consumption.
* On macOS the child windows will keep the relative position to parent window
when parent window moves, while on Windows and Linux child windows will not
* On Windows it is not supported to change parent window dynamically.
* On Linux the type of modal windows will be changed to `dialog`.
* On Linux many desktop environments do not support hiding a modal window.

@@ -1529,7 +1528,7 @@ On Windows it calls SetWindowDisplayAffinity with `WDA_MONITOR`.

Changes whether the window can be focused.

#### `win.setParentWindow(parent)` _Linux_ _macOS_
#### `win.setParentWindow(parent)`

* `parent` BrowserWindow

@@ -2957,12 +2957,6 @@ describe('BrowserWindow module', () => {

describe('win.setParentWindow(parent)', () => {
before(function () {
if (process.platform === 'win32') {

beforeEach(() => {
if (c != null) c.destroy()
c = new BrowserWindow({ show: false })
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.