Fix initial window size again; also always set Qt::WA_NativeWindow

The Qt::WA_NativeWindow attribute is need so that windowHandle() doesn't
return 0, since windowHandle() is used in two places now in the code, just
always set it.

When rememberWindowSize() is false, override the Window-Maximized config
key, which maximizes the window initially.

To test:
- unset "remember window size"
- close the window and make sure the config has been saved to konsolerc
- open konsole, keep the window unmaximized, close, open -> size is restored
- open konsole, maximize the window, close, open, the window is maximized
  even when rememberWindowSize() is false
wilder
Ahmad Samir 5 years ago committed by Kurt Hindenburg
parent 897435e5fb
commit fb7ff04d15
  1. 17
      src/MainWindow.cpp

@ -11,6 +11,7 @@
#include <QMenu>
#include <QMenuBar>
#include <QMouseEvent>
#include <QWindow>
// KDE
#include <KAcceleratorManager>
@ -67,6 +68,11 @@ MainWindow::MainWindow()
, _newTabMenuAction(nullptr)
, _pluggedController(nullptr)
{
// 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);
updateUseTransparency();
// create actions for menus
@ -842,10 +848,6 @@ void MainWindow::setBlur(bool blur)
#if KWINDOWSYSTEM_VERSION < QT_VERSION_CHECK(5, 82, 0)
KWindowEffects::enableBlurBehind(winId(), blur);
#else
// 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 {
@ -897,6 +899,13 @@ void MainWindow::showEvent(QShowEvent *event)
// (ViewManager, TabbedViewContainer, TerminalDisplay ... etc)
// have been created and TabbedViewContainer::sizeHint() returns
// a usuable size.
// Remove the WindowMaximized state to override the Window-Maximized
// config key
if (QWindow *window = windowHandle()) {
window->setWindowStates(window->windowStates() & ~Qt::WindowMaximized);
}
resize(sizeHint());
}
}

Loading…
Cancel
Save