mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-20 22:30:05 +02:00
Bug 1314 - Audacity always launches in middle of first monitor after quit on any part of second monitor.
Splash screen still always appears on first screen (intentional). Also I fixed issue where new project windows would appear on first screen, even if Audacity on second.
This commit is contained in:
parent
9787bf7978
commit
8d55ab9afd
@ -636,16 +636,21 @@ void GetDefaultWindowRect(wxRect *defRect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// true iff we have enough of the top bar to be able to reposition the window.
|
||||||
bool IsWindowAccessible(wxRect *requestedRect)
|
bool IsWindowAccessible(wxRect *requestedRect)
|
||||||
{
|
{
|
||||||
wxDisplay display;
|
wxDisplay display;
|
||||||
wxRect targetTitleRect(requestedRect->GetLeftTop(), requestedRect->GetBottomRight());
|
wxRect targetTitleRect(requestedRect->GetLeftTop(), requestedRect->GetBottomRight());
|
||||||
|
// Hackery to approximate a window top bar size from a window size.
|
||||||
|
// and exclude the open/close and borders.
|
||||||
targetTitleRect.x += 15;
|
targetTitleRect.x += 15;
|
||||||
targetTitleRect.width -= 100;
|
targetTitleRect.width -= 100;
|
||||||
if (targetTitleRect.width < 165) targetTitleRect.width = 165;
|
if (targetTitleRect.width < 165) targetTitleRect.width = 165;
|
||||||
targetTitleRect.height = 15;
|
targetTitleRect.height = 15;
|
||||||
int targetBottom = targetTitleRect.GetBottom();
|
int targetBottom = targetTitleRect.GetBottom();
|
||||||
int targetRight = targetTitleRect.GetRight();
|
int targetRight = targetTitleRect.GetRight();
|
||||||
|
// This looks like overkill to check each and every pixel in the ranges.
|
||||||
|
// and decide that if any is visible on screen we are OK.
|
||||||
for (int i = targetTitleRect.GetLeft(); i < targetRight; i++) {
|
for (int i = targetTitleRect.GetLeft(); i < targetRight; i++) {
|
||||||
for (int j = targetTitleRect.GetTop(); j < targetBottom; j++) {
|
for (int j = targetTitleRect.GetTop(); j < targetBottom; j++) {
|
||||||
int monitor = display.GetFromPoint(wxPoint(i, j));
|
int monitor = display.GetFromPoint(wxPoint(i, j));
|
||||||
@ -657,6 +662,18 @@ bool IsWindowAccessible(wxRect *requestedRect)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the screen containing a rectangle, or -1 if none does.
|
||||||
|
int ScreenContaining( wxRect & r ){
|
||||||
|
unsigned int n = wxDisplay::GetCount();
|
||||||
|
for(unsigned int i = 0;i<n;i++){
|
||||||
|
wxDisplay d(i);
|
||||||
|
wxRect scr = d.GetClientArea();
|
||||||
|
if( scr.Contains( r ) )
|
||||||
|
return (int)i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// BG: Calculate where to place the next window (could be the first window)
|
// 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.
|
// BG: Does not store X and Y in prefs. This is intentional.
|
||||||
//
|
//
|
||||||
@ -692,8 +709,6 @@ void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
|
|||||||
windowRect = defaultRect;
|
windowRect = defaultRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The 'screen' is the area minus the task bar.
|
|
||||||
wxRect screenRect = wxGetClientDisplayRect();
|
|
||||||
|
|
||||||
#if defined(__WXMAC__)
|
#if defined(__WXMAC__)
|
||||||
// On OSX, the top of the window should never be less than the menu height,
|
// On OSX, the top of the window should never be less than the menu height,
|
||||||
@ -712,10 +727,10 @@ void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
|
|||||||
// contributing to bug 1243.
|
// contributing to bug 1243.
|
||||||
// Now instead if the window significantly doesn't fit the screen, we use the default
|
// Now instead if the window significantly doesn't fit the screen, we use the default
|
||||||
// window instead, which we know does.
|
// window instead, which we know does.
|
||||||
if (!screenRect.Contains( wxRect(normalRect).Deflate( 32, 32 ))) {
|
if (ScreenContaining( wxRect(normalRect).Deflate( 32, 32 ))<0) {
|
||||||
normalRect = defaultRect;
|
normalRect = defaultRect;
|
||||||
}
|
}
|
||||||
if (!screenRect.Contains( wxRect(windowRect).Deflate( 32, 32 ) )) {
|
if (ScreenContaining( wxRect(windowRect).Deflate( 32, 32 ) )<0) {
|
||||||
windowRect = defaultRect;
|
windowRect = defaultRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,6 +770,11 @@ void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
|
|||||||
nextRect->y += 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.
|
||||||
|
// windowRect is a saved rectangle size.
|
||||||
|
// normalRect seems to be a substitute for windowRect when iconized or maximised.
|
||||||
|
|
||||||
// Windows can say that we are off screen when actually we are not.
|
// Windows can say that we are off screen when actually we are not.
|
||||||
// On Windows 10 I am seeing miscalculation by about 6 pixels.
|
// On Windows 10 I am seeing miscalculation by about 6 pixels.
|
||||||
// To fix this we allow some sloppiness on the edge being counted as off screen.
|
// To fix this we allow some sloppiness on the edge being counted as off screen.
|
||||||
@ -762,7 +782,15 @@ void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
|
|||||||
// in one dimension (height or width) but not both.
|
// in one dimension (height or width) but not both.
|
||||||
const int edgeSlop = 10;
|
const int edgeSlop = 10;
|
||||||
|
|
||||||
//Have we hit the right side of the screen?
|
// Next four lines are getting the rectangle for the screen that contains the
|
||||||
|
// top left corner of nextRect (and defaulting to rect of screen 0 otherwise).
|
||||||
|
wxPoint p = nextRect->GetLeftTop();
|
||||||
|
int scr = std::max( 0, wxDisplay::GetFromPoint( p ));
|
||||||
|
wxDisplay d( scr );
|
||||||
|
wxRect screenRect = d.GetClientArea();
|
||||||
|
|
||||||
|
// Now we (possibly) start trimming our rectangle down.
|
||||||
|
// Have we hit the right side of the screen?
|
||||||
wxPoint bottomRight = nextRect->GetBottomRight();
|
wxPoint bottomRight = nextRect->GetBottomRight();
|
||||||
if (bottomRight.x > (screenRect.GetRight()+edgeSlop)) {
|
if (bottomRight.x > (screenRect.GetRight()+edgeSlop)) {
|
||||||
int newWidth = screenRect.GetWidth() - nextRect->GetLeft();
|
int newWidth = screenRect.GetWidth() - nextRect->GetLeft();
|
||||||
@ -776,7 +804,7 @@ void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Have we hit the bottom of the screen?
|
// Have we hit the bottom of the screen?
|
||||||
bottomRight = nextRect->GetBottomRight();
|
bottomRight = nextRect->GetBottomRight();
|
||||||
if (bottomRight.y > (screenRect.GetBottom()+edgeSlop)) {
|
if (bottomRight.y > (screenRect.GetBottom()+edgeSlop)) {
|
||||||
nextRect->y -= inc;
|
nextRect->y -= inc;
|
||||||
@ -786,6 +814,9 @@ void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// After all that we could have a window that does not have a visible
|
||||||
|
// top bar. [It is unlikely, but something might have gone wrong]
|
||||||
|
// If so, use the safe fallback size.
|
||||||
if (!IsWindowAccessible(nextRect)) {
|
if (!IsWindowAccessible(nextRect)) {
|
||||||
*nextRect = defaultRect;
|
*nextRect = defaultRect;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user