1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-13 15:17:42 +02:00

Bug1314 - Residual. Allow projects to straddle screens.

Opening Audacity can give a project window that straddles screens (if that is what the user wants and had last time they closed).
New windows created from menu item new will still start out initially all on one screen.
This commit is contained in:
James Crook 2016-12-27 22:58:59 +00:00
parent 694b13bd3d
commit 32a33bf0e4

View File

@ -524,9 +524,9 @@ bool ImportXMLTagHandler::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
AudacityProject *CreateNewAudacityProject()
{
bool bMaximized;
wxRect wndRect;
bool bIconized;
bool bMaximized = false;
bool bIconized = false;
GetNextWindowPlacement(&wndRect, &bMaximized, &bIconized);
// Create and show a NEW project
@ -677,6 +677,16 @@ int ScreenContaining( wxRect & r ){
return -1;
}
// true IFF TL and BR corners are on a connected display.
// Does not need to check all four. We just need to check that
// the window probably is straddling screens in a sensible way.
// If the user wants to use mixed landscape and portrait, they can.
bool CornersOnScreen( wxRect & r ){
if( wxDisplay::GetFromPoint( r.GetTopLeft() ) == wxNOT_FOUND) return false;
if( wxDisplay::GetFromPoint( r.GetBottomRight() ) == wxNOT_FOUND) return false;
return true;
}
// BG: Calculate where to place the next window (could be the first window)
// BG: Does not store X and Y in prefs. This is intentional.
//
@ -726,6 +736,31 @@ void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
}
#endif
// IF projects empty, THEN it's the first window.
// It lands where the config says it should, and can straddle screen.
if (gAudacityProjects.empty()) {
if (*pMaximized || *pIconized) {
*nextRect = normalRect;
}
else {
*nextRect = windowRect;
}
// Resize, for example if one monitor that was on is now off.
if (!CornersOnScreen( wxRect(*nextRect).Deflate( 32, 32 ))) {
*nextRect = defaultRect;
}
if (!IsWindowAccessible(nextRect)) {
*nextRect = defaultRect;
}
// Do not trim the first project window down.
// All corners are on screen (or almost so), and
// the rect may straddle screens.
return;
}
// ELSE a subsequent new window. It will NOT straddle screens.
// We don't mind being 32 pixels off the screen in any direction.
// Make sure initial sizes (pretty much) fit within the display bounds
// We used to trim the sizes which could result in ridiculously small windows.
@ -739,18 +774,6 @@ void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
windowRect = defaultRect;
}
if (gAudacityProjects.empty()) {
if (*pMaximized || *pIconized) {
*nextRect = normalRect;
}
else {
*nextRect = windowRect;
}
if (!IsWindowAccessible(nextRect)) {
*nextRect = defaultRect;
}
}
else {
bool validWindowSize = false;
AudacityProject * validProject = NULL;
size_t numProjects = gAudacityProjects.size();
@ -765,6 +788,10 @@ void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
*nextRect = validProject->GetRect();
*pMaximized = validProject->IsMaximized();
*pIconized = validProject->IsIconized();
// Do not straddle screens.
if (ScreenContaining( wxRect(*nextRect).Deflate( 32, 32 ) )<0) {
*nextRect = defaultRect;
}
}
else {
*nextRect = normalRect;
@ -773,7 +800,6 @@ void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
//Placement depends on the increments
nextRect->x += inc;
nextRect->y += inc;
}
// defaultrect is a rectangle on the first screen. It's the right fallback to
// use most of the time if things are not working out right with sizing.