Use the new KConfig WindowStateSaver
This removes some NeoChat-specific code we have for saving/restoring the window.
This commit is contained in:
@@ -304,7 +304,6 @@ int main(int argc, char *argv[])
|
||||
QWindow *window = windowFromEngine(&engine);
|
||||
|
||||
WindowController::instance().setWindow(window);
|
||||
WindowController::instance().restoreGeometry();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import QtQuick
|
||||
import QtQuick.Controls as QQC2
|
||||
|
||||
import org.kde.kirigami as Kirigami
|
||||
import org.kde.config as KConfig
|
||||
|
||||
import org.kde.neochat
|
||||
import org.kde.neochat.login
|
||||
@@ -68,36 +69,8 @@ Kirigami.ApplicationWindow {
|
||||
}
|
||||
}
|
||||
|
||||
// This timer allows to batch update the window size change to reduce
|
||||
// the io load and also work around the fact that x/y/width/height are
|
||||
// changed when loading the page and overwrite the saved geometry from
|
||||
// the previous session.
|
||||
Timer {
|
||||
id: saveWindowGeometryTimer
|
||||
interval: 1000
|
||||
onTriggered: WindowController.saveGeometry()
|
||||
}
|
||||
|
||||
Connections {
|
||||
id: saveWindowGeometryConnections
|
||||
enabled: false // Disable on startup to avoid writing wrong values if the window is hidden
|
||||
target: root
|
||||
|
||||
function onClosing() {
|
||||
WindowController.saveGeometry();
|
||||
}
|
||||
function onWidthChanged() {
|
||||
saveWindowGeometryTimer.restart();
|
||||
}
|
||||
function onHeightChanged() {
|
||||
saveWindowGeometryTimer.restart();
|
||||
}
|
||||
function onXChanged() {
|
||||
saveWindowGeometryTimer.restart();
|
||||
}
|
||||
function onYChanged() {
|
||||
saveWindowGeometryTimer.restart();
|
||||
}
|
||||
KConfig.WindowStateSaver {
|
||||
configGroupName: "Window"
|
||||
}
|
||||
|
||||
QuickSwitcher {
|
||||
|
||||
@@ -40,26 +40,6 @@ QWindow *WindowController::window() const
|
||||
return m_window;
|
||||
}
|
||||
|
||||
void WindowController::restoreGeometry()
|
||||
{
|
||||
const auto stateConfig = KSharedConfig::openStateConfig();
|
||||
const KConfigGroup windowGroup = stateConfig->group(QStringLiteral("Window"));
|
||||
|
||||
KWindowConfig::restoreWindowSize(m_window, windowGroup);
|
||||
KWindowConfig::restoreWindowPosition(m_window, windowGroup);
|
||||
}
|
||||
|
||||
void WindowController::saveGeometry()
|
||||
{
|
||||
const auto stateConfig = KSharedConfig::openStateConfig();
|
||||
KConfigGroup windowGroup = stateConfig->group(QStringLiteral("Window"));
|
||||
|
||||
KWindowConfig::saveWindowPosition(m_window, windowGroup);
|
||||
KWindowConfig::saveWindowSize(m_window, windowGroup);
|
||||
|
||||
stateConfig->sync();
|
||||
}
|
||||
|
||||
void WindowController::showAndRaiseWindow(const QString &startupId)
|
||||
{
|
||||
if (m_window == nullptr) {
|
||||
@@ -67,7 +47,6 @@ void WindowController::showAndRaiseWindow(const QString &startupId)
|
||||
}
|
||||
if (!m_window->isVisible()) {
|
||||
m_window->show();
|
||||
restoreGeometry();
|
||||
}
|
||||
|
||||
#ifdef HAVE_WINDOWSYSTEM
|
||||
|
||||
@@ -41,16 +41,6 @@ public:
|
||||
*/
|
||||
QWindow *window() const;
|
||||
|
||||
/**
|
||||
* @brief Restore any saved window geometry if available.
|
||||
*/
|
||||
void restoreGeometry();
|
||||
|
||||
/**
|
||||
* @brief Save the current window geometry.
|
||||
*/
|
||||
Q_INVOKABLE void saveGeometry();
|
||||
|
||||
/**
|
||||
* @brief Show the window and raise to the top.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user