Fix saving/loading correct frame position (mainly on macOS)

We have to save the frame position before we close the native
window.
This commit is contained in:
David Capello 2021-05-10 11:52:38 -03:00
parent 69a7faefa2
commit d2c6abf5a7
2 changed files with 7 additions and 8 deletions

View File

@ -409,19 +409,19 @@ void load_window_pos(Window* window, const char* section,
}
}
void save_window_pos(Window* window, const char *section)
void save_window_pos(Window* window, const char* section)
{
gfx::Rect rc;
if (!window->lastNativeFrame().isEmpty()) {
os::Window* mainNativeWindow = manager->display()->nativeWindow();
int scale = mainNativeWindow->scale();
const os::Window* mainNativeWindow = manager->display()->nativeWindow();
rc = window->lastNativeFrame();
set_config_rect(section, "WindowFrame", rc);
rc.offset(-mainNativeWindow->frame().origin());
rc /= scale;
rc /= mainNativeWindow->scale();
}
else {
del_config_value(section, "WindowFrame");
rc = window->bounds();
}

View File

@ -149,11 +149,8 @@ Display* Window::display() const
void Window::setDisplay(Display* display, const bool own)
{
if (m_display) {
if (m_ownDisplay)
m_lastFrame = m_display->nativeWindow()->frame();
if (m_display)
m_display->removeWindow(this);
}
m_display = display;
m_ownDisplay = own;
@ -405,6 +402,8 @@ void Window::openWindowInForeground()
void Window::closeWindow(Widget* closer)
{
m_closer = closer;
if (m_ownDisplay)
m_lastFrame = m_display->nativeWindow()->frame();
manager()->_closeWindow(this, true);