Skip to content

Commit

Permalink
#5401: Remove the code trying to fix the bottom left window coordinat…
Browse files Browse the repository at this point in the history
…e if it's supposedly off-screen, we only care about the upper left corner.

Use GetScreenPosition to read the actual window position after moving, the wxMoveEvent delivers some offsets. The values returned by GetScreenPosition can be negative (on my Win10) machine, but this obviously is not a problem when trying to restore these values.
  • Loading branch information
codereader committed Nov 14, 2020
1 parent 161deef commit 9537e9e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions libs/wxutil/WindowPosition.cpp
Expand Up @@ -108,19 +108,18 @@ void WindowPosition::loadFromPath(const std::string& path)

void WindowPosition::applyPosition()
{
if (_window == NULL) return;
if (_window == nullptr) return;

// On multi-monitor setups, wxWidgets offers a virtual big screen with
// coordinates going from 0,0 to whatever lower-rightmost point there is

// Sanity check the window position
wxRect targetPos = wxRect(_position[0], _position[1], _size[0], _size[1]);

const int TOL = 30;
const int TOL = 8;

// Employ a few pixels tolerance to allow for placement very near the borders
if (wxDisplay::GetFromPoint(targetPos.GetTopLeft() + wxPoint(TOL, TOL)) == wxNOT_FOUND ||
wxDisplay::GetFromPoint(targetPos.GetBottomRight() - wxPoint(TOL, TOL)) == wxNOT_FOUND)
if (wxDisplay::GetFromPoint(targetPos.GetTopLeft() + wxPoint(TOL, TOL)) == wxNOT_FOUND)
{
// Window probably ends up invisible, refuse these coords
_window->CenterOnParent();
Expand Down Expand Up @@ -170,7 +169,14 @@ void WindowPosition::onResize(wxSizeEvent& ev)

void WindowPosition::onMove(wxMoveEvent& ev)
{
setPosition(ev.GetPosition().x, ev.GetPosition().y);
if (_window == nullptr) return;

// The position passed in the wxMoveEvent seems (on my Win10 system)
// to be off by about x=8,y=51
// Call GetScreenPosition to get the real coordinates
//setPosition(ev.GetPosition().x, ev.GetPosition().y);
_window->GetScreenPosition(&_position[0], &_position[1]);

ev.Skip();
}

Expand Down

0 comments on commit 9537e9e

Please sign in to comment.