Commit 3177c9ef authored by Ahmad Samir's avatar Ahmad Samir Committed by Kurt Hindenburg
Browse files

Always save the window state and geometry

This includes the toolbar/menubar/dockwidget states (i.e. the State= config
key), and the window geometry. I was wrong to think the State= key included
the window geometry.

Depending on the "remeber window size" setting, we can apply the size saved
in the config file or the size from the profile settings (lines x columns),
which is included in MainWindow::sizeHint().

BUG: 442252
FIXED-IN: 21.12
parent 217ed276
......@@ -68,40 +68,6 @@ MainWindow::MainWindow()
, _pluggedController(nullptr)
, _menuBarInitialVisibility(true)
{
KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig(QStringLiteral("konsolerc"));
KConfigGroup cg = konsoleConfig->group(QStringLiteral("MainWindow"));
const bool isGroup = cg.exists();
if (isGroup) {
const QString stateConfig = cg.readEntry(QStringLiteral("State"));
// If "stateConfig" is empty then this is the very first run,
// i.e. no konsolerc file in $HOME
_isSavedUiState = !stateConfig.isEmpty();
}
if (isGroup && !KonsoleSettings::saveGeometryOnExit()) {
// If we are not using the global Konsole save geometry on exit,
// remove all geometry data from [MainWindow] in Konsolerc, so KWin will
// manage it directly
QMap<QString, QString> configEntries = cg.entryMap();
QMapIterator<QString, QString> i(configEntries);
while (i.hasNext()) {
i.next();
// After https://bugs.kde.org/show_bug.cgi?id=415150 was fixed in 5.74,
// the config file keys changed
#if KIO_VERSION < QT_VERSION_CHECK(5, 75, 0)
if (i.key().startsWith(QLatin1String("Width")) || i.key().startsWith(QLatin1String("Height"))
#else
if (i.key().contains(QLatin1String(" Width")) || i.key().contains(QLatin1String(" Height")) || i.key().contains(QLatin1String(" XPosition"))
|| i.key().contains(QLatin1String(" YPosition"))
#endif
) {
cg.deleteEntry(i.key());
}
}
}
updateUseTransparency();
// create actions for menus
......@@ -148,6 +114,26 @@ MainWindow::MainWindow()
KCrash::initialize();
}
bool MainWindow::wasWindowGeometrySaved() const
{
KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig(QStringLiteral("konsolerc"));
KConfigGroup cg = konsoleConfig->group(QStringLiteral("MainWindow"));
if (!cg.exists()) { // First run, no existing konsolerc?
return false;
}
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"))) {
return true;
}
}
return false;
}
void MainWindow::updateUseTransparency()
{
if (!WindowSystemInfo::HAVE_TRANSPARENCY) {
......@@ -797,9 +783,10 @@ void MainWindow::applyKonsoleSettings()
}
_viewManager->activeContainer()->setNavigationBehavior(KonsoleSettings::newTabBehavior());
if (KonsoleSettings::saveGeometryOnExit() != autoSaveSettings()) {
setAutoSaveSettings(QStringLiteral("MainWindow"), KonsoleSettings::saveGeometryOnExit());
}
// Save the toolbar/menu/dockwidget states and the window geometry
setAutoSaveSettings();
updateWindowCaption();
}
......@@ -900,7 +887,7 @@ void MainWindow::showEvent(QShowEvent *event)
menuBar()->setVisible(_menuBarInitialVisibility);
_toggleMenuBarAction->setChecked(_menuBarInitialVisibility);
if (!_isSavedUiState || !KonsoleSettings::saveGeometryOnExit()) {
if (!KonsoleSettings::saveGeometryOnExit() || !wasWindowGeometrySaved()) {
// Delay resizing to here, so that the other parts of the UI
// (ViewManager, TabbedViewContainer, TerminalDisplay ... etc)
// have been created and TabbedViewContainer::sizeHint() returns
......
......@@ -172,6 +172,12 @@ public Q_SLOTS:
void viewFullScreen(bool fullScreen);
private:
/**
* Returns true if the window geometry was previously saved to the
* config file, false otherwise.
*/
bool wasWindowGeometrySaved() const;
void correctStandardShortcuts();
void rememberMenuAccelerators();
void removeMenuAccelerators();
......@@ -200,7 +206,6 @@ private:
bool _menuBarInitialVisibility;
bool _firstShowEvent = true;
bool _blurEnabled = false;
bool _isSavedUiState = false;
};
}
......
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