diff options
| author | Nate Graham <nate@kde.org> | 2020-08-20 12:09:05 -0600 | 
|---|---|---|
| committer | Nate Graham <nate@kde.org> | 2020-08-25 15:39:23 +0000 | 
| commit | 0f1b47f2ab4b374a6d85dcf9dd63e1159cc7ea65 (patch) | |
| tree | 8744d33c044d4584517eebd3a40f958914dd32fd | |
| parent | 803b9f16e0b9133ddfef40dd16a368c39fa1b0a6 (diff) | |
| download | kconfig-0f1b47f2ab4b374a6d85dcf9dd63e1159cc7ea65.tar.gz kconfig-0f1b47f2ab4b374a6d85dcf9dd63e1159cc7ea65.tar.bz2 | |
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).
| -rw-r--r-- | src/gui/kwindowconfig.cpp | 22 | 
1 files changed, 16 insertions, 6 deletions
| 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()); | 
