Commit cc9073ab authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Fix geometry restoration check

MainWindow::wasWindowGeometrySaved() doesn't take into account the currently connected outputs. So
when Konsole starts after hotplugging a new output, wasWindowGeometrySaved() will erroneously return
true and resize(sizeHint()) in MainWindow::showEvent() won't be called thus resulting in Konsole
starting with wrong size.

This change makes Konsole take the current output layout into account when deciding whether the
geometry has been restored (logic was copied from KWindowConfig), however it indicates that we have
some fundamental issues in KMainWindow or KWindowConfig as it's a really messy way to determine
whether the previous state has been properly restored.

BUG: 460428


(cherry picked from commit 05892060)
parent 92383fe5
Pipeline #268216 canceled with stage
in 38 seconds
......@@ -12,6 +12,7 @@
#include <QMenu>
#include <QMenuBar>
#include <QMouseEvent>
#include <QScreen>
#include <QWindow>
// KDE
......@@ -122,6 +123,35 @@ MainWindow::MainWindow()
KCrash::initialize();
}
// Convenience function to get a space-separated list of all connected screens, copied from KWindowConfig
static QString allConnectedScreens()
{
QStringList names;
const auto screens = QGuiApplication::screens();
names.reserve(screens.length());
for (auto screen : screens) {
#ifdef Q_OS_WIN
// QScreen::name() returns garbage on Windows; see https://bugreports.qt.io/browse/QTBUG-74317
// So we use the screens' serial numbers to identify them instead
names << screen->serialNumber();
#else
names << screen->name();
#endif
}
return names.join(QLatin1Char(' '));
}
// Convenience function to get an appropriate config file key under which to
// save window size, position, or maximization information, copied from KWindowConfig.
static QString configFileString(const QScreen *screen, const QString &key)
{
// We include resolution data to also save data on a per-resolution basis
const QString returnString =
QStringLiteral("%1 %2 %3x%4 %5")
.arg(allConnectedScreens(), key, QString::number(screen->geometry().width()), QString::number(screen->geometry().height()), screen->name());
return returnString;
}
bool MainWindow::wasWindowGeometrySaved() const
{
KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig(QStringLiteral("konsolerc"));
......@@ -133,8 +163,8 @@ bool MainWindow::wasWindowGeometrySaved() const
const QMap<QString, QString> entries = cg.entryMap();
for (auto it = entries.cbegin(), itEnd = entries.cend(); it != itEnd; ++it) {
const QString configKey = it.key();
if (configKey.contains(QLatin1String(" Width")) || configKey.contains(QLatin1String(" Height")) || configKey.contains(QLatin1String(" XPosition"))
|| configKey.contains(QLatin1String(" YPosition"))) {
if (configKey == configFileString(screen(), QStringLiteral("Width")) || configKey == configFileString(screen(), QStringLiteral("Height"))
|| configKey == configFileString(screen(), QStringLiteral("XPosition")) || configKey == configFileString(screen(), QStringLiteral("YPosition"))) {
return true;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment