Rework window size and position fixing code

Fixes #2624
Fixes #3888
This commit is contained in:
Jon Evans 2020-02-21 15:52:30 -05:00
parent 8c19b4b6ae
commit 96da45f12f
1 changed files with 35 additions and 14 deletions

View File

@ -453,23 +453,39 @@ void EDA_BASE_FRAME::LoadWindowSettings( WINDOW_SETTINGS* aCfg )
m_FrameSize.y = GetMinHeight();
}
// Ensure window isn't bigger than can be displayed
int displayIndex = wxDisplay::GetFromPoint( m_FramePos );
if( displayIndex == wxNOT_FOUND )
displayIndex = 0;
wxDisplay display( displayIndex );
wxRect clientSize = display.GetClientArea();
// The window may have been saved on a display that is no longer present.
// First, check the window origin and move it if it's off the chosen display
if( m_FramePos.x >= clientSize.x + clientSize.width ||
m_FramePos.y >= clientSize.y + clientSize.height )
m_FramePos = wxDefaultPosition;
// Now, fix up the size if needed
if( m_FrameSize.x + m_FramePos.x > clientSize.x + clientSize.width )
{
m_FrameSize.x = clientSize.width;
m_FramePos.x = 0;
}
if( m_FrameSize.y + m_FramePos.y > clientSize.y + clientSize.height )
{
m_FrameSize.y = clientSize.height;
m_FramePos.y = 0;
}
if( m_hasAutoSave )
m_autoSaveInterval = Pgm().GetCommonSettings()->m_System.autosave_interval;
// Ensure the window is on a connected display, and is visible.
// (at least a corner of the frame must be visible on screen)
// Sometimes, if a window was moved on an auxiliary display, and when this
// display is no more available, it is not the case.
wxRect rect( m_FramePos, m_FrameSize );
if( wxDisplay::GetFromPoint( rect.GetTopLeft() ) == wxNOT_FOUND &&
wxDisplay::GetFromPoint( rect.GetTopRight() ) == wxNOT_FOUND &&
wxDisplay::GetFromPoint( rect.GetBottomLeft() ) == wxNOT_FOUND &&
wxDisplay::GetFromPoint( rect.GetBottomRight() ) == wxNOT_FOUND )
{
m_FramePos = wxDefaultPosition;
}
// Ensure Window title bar is visible
#if defined( __WXMAC__ )
// for macOSX, the window must be below system (macOSX) toolbar
@ -479,7 +495,12 @@ void EDA_BASE_FRAME::LoadWindowSettings( WINDOW_SETTINGS* aCfg )
int Ypos_min = 0;
#endif
if( m_FramePos.y < Ypos_min )
{
if( m_FrameSize.y + ( Ypos_min - m_FramePos.y ) > clientSize.height)
m_FrameSize.y = clientSize.height - Ypos_min;
m_FramePos.y = Ypos_min;
}
if( aCfg->maximized )
Maximize();