Skip to content

Commit

Permalink
Fix restoring window geometry with multiple screens
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Jun 5, 2017
1 parent 72ac4a9 commit 69dabbb
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,29 @@ QString getGeometryConfigurationFilePath()
return getConfigurationFilePath("_geometry.ini");
}

QString resolutionTag(const QWidget &widget, GeometryAction geometryAction)
QString resolutionTagForScreen(int i)
{
const int n = screenNumber(widget, geometryAction);
const QRect screenGeometry = QApplication::desktop()->screenGeometry(n);
const QRect screenGeometry = QApplication::desktop()->screenGeometry(i);
return QString("_%1x%2")
.arg(screenGeometry.width())
.arg(screenGeometry.height());
}

QString resolutionTag(const QWidget &widget, GeometryAction geometryAction, bool openOnCurrentScreen)
{
if (openOnCurrentScreen) {
const int i = screenNumber(widget, geometryAction);
return resolutionTagForScreen(i);
}

QString tag;
const auto desktop = QApplication::desktop();
for ( int i = 0; i < desktop->screenCount(); ++i )
tag.append( resolutionTagForScreen(i) );

return tag;
}

} // namespace

QString getConfigurationFilePath(const QString &suffix)
Expand Down Expand Up @@ -106,7 +120,7 @@ void setGeometryOptionValue(const QString &optionName, const QVariant &value)
void restoreWindowGeometry(QWidget *w, bool openOnCurrentScreen)
{
const QString optionName = geometryOptionName(*w, GeometryAction::Restore, openOnCurrentScreen);
const QString tag = resolutionTag(*w, GeometryAction::Restore);
const QString tag = resolutionTag(*w, GeometryAction::Restore, openOnCurrentScreen);
QByteArray geometry = geometryOptionValue(optionName + tag).toByteArray();

// If geometry for screen resolution doesn't exist, use last saved one.
Expand Down Expand Up @@ -145,7 +159,7 @@ void restoreWindowGeometry(QWidget *w, bool openOnCurrentScreen)
void saveWindowGeometry(QWidget *w, bool openOnCurrentScreen)
{
const QString optionName = geometryOptionName(*w, GeometryAction::Save, openOnCurrentScreen);
const QString tag = resolutionTag(*w, GeometryAction::Save);
const QString tag = resolutionTag(*w, GeometryAction::Save, openOnCurrentScreen);
QSettings geometrySettings( getGeometryConfigurationFilePath(), QSettings::IniFormat );
geometrySettings.setValue( optionName + tag, w->saveGeometry() );
geometrySettings.setValue( optionName, w->saveGeometry() );
Expand Down

0 comments on commit 69dabbb

Please sign in to comment.