Skip to content

Commit

Permalink
Issue #4583: Improve handling on multi-monitor setups. Try to restore…
Browse files Browse the repository at this point in the history
… stored window coordinates unless they go are more than 30 pixels off screen.

Bump pre-release version
  • Loading branch information
codereader committed May 6, 2018
1 parent 6166182 commit 4cfd853
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion include/version.h
Expand Up @@ -2,7 +2,7 @@
#include <config.h>
#define RADIANT_VERSION PACKAGE_VERSION
#else
#define RADIANT_VERSION "2.6.0pre4"
#define RADIANT_VERSION "2.6.0pre5"
#endif

#define RADIANT_APPNAME "DarkRadiant"
Expand Down
35 changes: 19 additions & 16 deletions libs/wxutil/WindowPosition.cpp
Expand Up @@ -20,7 +20,7 @@ namespace wxutil
WindowPosition::WindowPosition() :
_position(DEFAULT_POSITION_X, DEFAULT_POSITION_Y),
_size(DEFAULT_SIZE_X, DEFAULT_SIZE_Y),
_window(NULL)
_window(nullptr)
{}

void WindowPosition::initialise(wxTopLevelWindow* window,
Expand All @@ -47,24 +47,24 @@ void WindowPosition::initialise(wxTopLevelWindow* window,
// Connect the passed window to this object
void WindowPosition::connect(wxTopLevelWindow* window)
{
if (_window != NULL)
if (_window != nullptr)
{
disconnect(_window);
}

_window = window;
applyPosition();

window->Connect(wxEVT_SIZE, wxSizeEventHandler(WindowPosition::onResize), NULL, this);
window->Connect(wxEVT_MOVE, wxMoveEventHandler(WindowPosition::onMove), NULL, this);
window->Connect(wxEVT_SIZE, wxSizeEventHandler(WindowPosition::onResize), nullptr, this);
window->Connect(wxEVT_MOVE, wxMoveEventHandler(WindowPosition::onMove), nullptr, this);
}

void WindowPosition::disconnect(wxTopLevelWindow* window)
{
_window = NULL;
_window = nullptr;

window->Disconnect(wxEVT_SIZE, wxSizeEventHandler(WindowPosition::onResize), NULL, this);
window->Disconnect(wxEVT_MOVE, wxMoveEventHandler(WindowPosition::onMove), NULL, this);
window->Disconnect(wxEVT_SIZE, wxSizeEventHandler(WindowPosition::onResize), nullptr, this);
window->Disconnect(wxEVT_MOVE, wxMoveEventHandler(WindowPosition::onMove), nullptr, this);
}

const WindowPosition::Position& WindowPosition::getPosition() const
Expand Down Expand Up @@ -106,20 +106,23 @@ void WindowPosition::loadFromPath(const std::string& path)
_size[1] = string::convert<int>(GlobalRegistry().getAttribute(path, "height"));
}

// Applies the internally stored size/position info to the GtkWindow
// The algorithm was adapted from original GtkRadiant code (window.h)
void WindowPosition::applyPosition()
{
if (_window == NULL) return;

// TODO: What about multi-monitor setups with overlapping windows?
wxDisplay display(wxDisplay::GetFromWindow(_window));
// 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;

// Sanity check of the window position
if (_position[0] < 0 || _position[1] < 0 ||
_position[0] > display.GetGeometry().GetWidth() ||
_position[1] > display.GetGeometry().GetHeight())
// 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)
{
// Window probably ends up invisible, refuse these coords
_window->CenterOnParent();
}
else
Expand All @@ -142,7 +145,7 @@ void WindowPosition::readPosition()

void WindowPosition::fitToScreen(float xfraction, float yfraction)
{
if (_window == NULL) return;
if (_window == nullptr) return;

wxDisplay display(wxDisplay::GetFromWindow(_window));

Expand Down
6 changes: 3 additions & 3 deletions tools/innosetup/darkradiant.iss
Expand Up @@ -3,15 +3,15 @@

[Setup]
AppName=DarkRadiant
AppVerName=DarkRadiant 2.6.0pre4 x86
AppVerName=DarkRadiant 2.6.0pre5 x86
AppPublisher=The Dark Mod
AppPublisherURL=http://www.darkradiant.net
AppSupportURL=http://www.darkradiant.net
AppUpdatesURL=http://www.darkradiant.net
DefaultDirName={pf}\DarkRadiant
DefaultGroupName=DarkRadiant 2.6.0pre4 x86
DefaultGroupName=DarkRadiant 2.6.0pre5 x86
OutputDir=.
OutputBaseFilename=darkradiant-2.6.0pre4-x86
OutputBaseFilename=darkradiant-2.6.0pre5-x86
Compression=lzma
SolidCompression=yes
;ArchitecturesAllowed=x64
Expand Down
6 changes: 3 additions & 3 deletions tools/innosetup/darkradiant.x64.iss
Expand Up @@ -3,15 +3,15 @@

[Setup]
AppName=DarkRadiant
AppVerName=DarkRadiant 2.6.0pre4 x64
AppVerName=DarkRadiant 2.6.0pre5 x64
AppPublisher=The Dark Mod
AppPublisherURL=http://www.darkradiant.net
AppSupportURL=http://www.darkradiant.net
AppUpdatesURL=http://www.darkradiant.net
DefaultDirName={pf}\DarkRadiant
DefaultGroupName=DarkRadiant 2.6.0pre4 x64
DefaultGroupName=DarkRadiant 2.6.0pre5 x64
OutputDir=.
OutputBaseFilename=darkradiant-2.6.0pre4-x64
OutputBaseFilename=darkradiant-2.6.0pre5-x64
Compression=lzma
SolidCompression=yes
ArchitecturesAllowed=x64
Expand Down

0 comments on commit 4cfd853

Please sign in to comment.