From 0f1b47f2ab4b374a6d85dcf9dd63e1159cc7ea65 Mon Sep 17 00:00:00 2001 From: Nate Graham Date: Thu, 20 Aug 2020 12:09:05 -0600 Subject: Remember window sizes on a per-screen-arrangement basis This is done for window positions, so it should also be done for window sizes. The combination of both should substantially improve the use case of maintaining a consistent window arrangement for multiple display setups (e.g. laptop and laptop + external screen). --- src/gui/kwindowconfig.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/gui/kwindowconfig.cpp b/src/gui/kwindowconfig.cpp index fcbbf196..5785bdbc 100644 --- a/src/gui/kwindowconfig.cpp +++ b/src/gui/kwindowconfig.cpp @@ -25,15 +25,19 @@ void KWindowConfig::saveWindowSize(const QWindow *window, KConfigGroup &config, const QSize sizeToSave = window->size(); const bool isMaximized = window->windowState() & Qt::WindowMaximized; - const QString screenMaximizedString(QStringLiteral("Window-Maximized %1x%2").arg(desk.height()).arg(desk.width())); + // Prepend the names of all connected screens so that we save the size + // on a per-screen-arrangement basis, since people often like to have + // windows laid out differently depending on their screen arrangements + const QString allScreens = allConnectedScreens(); + const QString screenMaximizedString(allScreens + QStringLiteral(" Window-Maximized %1x%2").arg(desk.height()).arg(desk.width())); // Save size only if window is not maximized if (!isMaximized) { const QSize defaultSize(window->property(s_initialSizePropertyName).toSize()); const QSize defaultScreenSize(window->property(s_initialScreenSizePropertyName).toSize()); const bool sizeValid = defaultSize.isValid() && defaultScreenSize.isValid(); if (!sizeValid || (sizeValid && (defaultSize != sizeToSave || defaultScreenSize != desk.size()))) { - const QString wString(QStringLiteral("Width %1").arg(desk.width())); - const QString hString(QStringLiteral("Height %1").arg(desk.height())); + const QString wString(allScreens + QStringLiteral(" Width %1").arg(desk.width())); + const QString hString(allScreens + QStringLiteral(" Height %1").arg(desk.height())); config.writeEntry(wString, sizeToSave.width(), options); config.writeEntry(hString, sizeToSave.height(), options); } @@ -54,9 +58,15 @@ void KWindowConfig::restoreWindowSize(QWindow *window, const KConfigGroup &confi const QRect desk = window->screen()->geometry(); - const int width = config.readEntry(QStringLiteral("Width %1").arg(desk.width()), window->size().width()); - const int height = config.readEntry(QStringLiteral("Height %1").arg(desk.height()), window->size().height()); - const bool isMaximized = config.readEntry(QStringLiteral("Window-Maximized %1x%2").arg(desk.height()).arg(desk.width()), false); + // Fall back to non-per-screen-arrangement info if it's available but + // per-screen-arrangement information is not + const int fallbackWidth = config.readEntry(QStringLiteral("Width %1").arg(desk.width()), window->size().width()); + const int fallbackHeight = config.readEntry(QStringLiteral("Height %1").arg(desk.height()), window->size().height()); + + const QString allScreens = allConnectedScreens(); + const int width = config.readEntry(allScreens + QStringLiteral(" Width %1").arg(desk.width()), fallbackWidth); + const int height = config.readEntry(allScreens + QStringLiteral(" Height %1").arg(desk.height()), fallbackHeight); + const bool isMaximized = config.readEntry(allScreens + QStringLiteral(" Window-Maximized %1x%2").arg(desk.height()).arg(desk.width()), false); // Check default size const QSize defaultSize(window->property(s_initialSizePropertyName).toSize()); -- cgit v1.2.1