--- ./src/MainWindow.h.orig 2021-08-04 16:48:59.000000000 -0500 +++ ./src/MainWindow.h 2021-08-19 19:24:14.000000000 -0500 @@ -200,6 +200,7 @@ bool _menuBarInitialVisibility; bool _menuBarInitialVisibilityApplied; bool _blurEnabled = false; + bool _isSavedUiState = false; }; } --- ./src/MainWindow.cpp.orig 2021-08-04 16:48:59.000000000 -0500 +++ ./src/MainWindow.cpp 2021-08-19 19:24:14.000000000 -0500 @@ -11,12 +11,12 @@ #include #include #include -#include // KDE #include #include #include +#include #include #include #include @@ -56,6 +56,8 @@ #include "terminalDisplay/TerminalDisplay.h" #include "widgets/ViewContainer.h" +#include + using namespace Konsole; MainWindow::MainWindow() : @@ -68,13 +70,22 @@ _menuBarInitialVisibility(true), _menuBarInitialVisibilityApplied(false) { - if (!KonsoleSettings::saveGeometryOnExit()) { + 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 - KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig(QStringLiteral("konsolerc")); - KConfigGroup group = konsoleConfig->group("MainWindow"); - QMap configEntries = group.entryMap(); + QMap configEntries = cg.entryMap(); QMapIterator i(configEntries); while (i.hasNext()) { @@ -91,7 +102,7 @@ || i.key().contains(QLatin1String(" YPosition")) #endif ) { - group.deleteEntry(i.key()); + cg.deleteEntry(i.key()); } } } @@ -103,7 +114,7 @@ // create view manager _viewManager = new ViewManager(this, actionCollection()); - connect(_viewManager, &Konsole::ViewManager::empty, this, &Konsole::MainWindow::close); + connect(_viewManager, &Konsole::ViewManager::empty, this, &QWidget::close); connect(_viewManager, &Konsole::ViewManager::activeViewChanged, this, &Konsole::MainWindow::activeViewChanged); connect(_viewManager, &Konsole::ViewManager::unplugController, this, @@ -129,8 +140,10 @@ // in terminal applications KAcceleratorManager::setNoAccel(menuBar()); - // create menus - createGUI(); + constexpr KXmlGuiWindow::StandardWindowOptions guiOpts = ToolBar | Keys | Save | Create; + const QString xmlFile = componentName() + QLatin1String("ui.rc"); // Typically "konsoleui.rc" + // The "Create" flag will make it call createGUI() + setupGUI(guiOpts, xmlFile); // remember the original menu accelerators for later use rememberMenuAccelerators(); @@ -146,11 +159,7 @@ connect(KonsoleSettings::self(), &Konsole::KonsoleSettings::configChanged, this, &Konsole::MainWindow::applyKonsoleSettings); - - // KXMLGui is making the status bar always visible, we need to fix in a proper way. - if (statusBar() != nullptr) { - statusBar()->installEventFilter(this); - } + KCrash::initialize(); } void MainWindow::updateUseTransparency() @@ -889,7 +898,15 @@ #if KWINDOWSYSTEM_VERSION < QT_VERSION_CHECK(5,82,0) KWindowEffects::enableBlurBehind(winId(), blur); #else - KWindowEffects::enableBlurBehind(windowHandle(), blur); + // Set the WA_NativeWindow attribute to force the creation of the QWindow. + // Without this QWidget::windowHandle() returns 0. + // See https://phabricator.kde.org/D23108 + setAttribute(Qt::WA_NativeWindow); + if (QWindow *window = windowHandle()) { + KWindowEffects::enableBlurBehind(window, blur); + } else { + qCWarning(KonsoleDebug) << "Blur effect couldn't be enabled."; + } #endif } } @@ -935,9 +952,14 @@ menuBar()->setVisible(_menuBarInitialVisibility); _toggleMenuBarAction->setChecked(_menuBarInitialVisibility); _menuBarInitialVisibilityApplied = true; - if (!KonsoleSettings::saveGeometryOnExit()) { - resize(sizeHint()); - } + } + + if (!_isSavedUiState || !KonsoleSettings::saveGeometryOnExit()) { + // Delay resizing to here, so that the other parts of the UI + // (ViewManager, TabbedViewContainer, TerminalDisplay ... etc) + // have been created and TabbedViewContainer::sizeHint() returns + // a usuable size. + resize(sizeHint()); } // Call parent method @@ -971,13 +993,7 @@ default: ; } } - if (qobject_cast(obj) != nullptr) { - switch(event->type()) { - case QEvent::Show: statusBar()->hide(); break; - default: return true; - } - return true; - } + return KXmlGuiWindow::eventFilter(obj, event); }