diff --git a/src/ui/display.h b/src/ui/display.h index fe322e5c4..662ac838a 100644 --- a/src/ui/display.h +++ b/src/ui/display.h @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2019-2021 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -75,6 +75,10 @@ namespace ui { gfx::Size workareaSizeUIScale(); + void _setParentDisplay(Display* parentDisplay) { + m_parentDisplay = parentDisplay; + } + private: Display* m_parentDisplay; os::WindowRef m_nativeWindow; diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index 6958d489f..64ddc5274 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -1498,7 +1498,7 @@ void Manager::_closeWindow(Window* window, bool redraw_background) if (// The display can be nullptr if the window was not opened or // was closed before. window->ownDisplay()) { - parentDisplay = windowDisplay->parentDisplay(); + parentDisplay = (windowDisplay ? windowDisplay->parentDisplay(): nullptr); ASSERT(parentDisplay); ASSERT(windowDisplay); ASSERT(windowDisplay != this->display()); @@ -1538,6 +1538,18 @@ void Manager::_closeWindow(Window* window, bool redraw_background) // delete. _internal_set_mouse_display(parentDisplay); + // Remove the display that we're going to delete (windowDisplay) + // as parent of any other existent display. + for (auto otherChild : children()) { + if (auto otherWindow = static_cast(otherChild)) { + if (otherWindow != window && + otherWindow->display() && + otherWindow->display()->parentDisplay() == windowDisplay) { + otherWindow->display()->_setParentDisplay(parentDisplay); + } + } + } + // The ui::Display should destroy the os::Window delete windowDisplay;