diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui/kwindowconfig.cpp | 27 | ||||
| -rw-r--r-- | src/gui/kwindowconfig.h | 8 | 
2 files changed, 20 insertions, 15 deletions
| diff --git a/src/gui/kwindowconfig.cpp b/src/gui/kwindowconfig.cpp index 07f1a307..fcbbf196 100644 --- a/src/gui/kwindowconfig.cpp +++ b/src/gui/kwindowconfig.cpp @@ -84,13 +84,7 @@ void KWindowConfig::saveWindowPosition(const QWindow *window, KConfigGroup &conf      // Prepend the names of all connected screens so that we save the position      // on a per-screen-arrangement basis, since people often like to have      // windows positioned differently depending on their screen arrangements -    QStringList names; -    const auto screens = QGuiApplication::screens(); -    names.reserve(screens.length()); -    for (auto screen : screens) { -        names << screen->name(); -    } -    const QString allScreens = names.join(QStringLiteral(" ")); +    const QString allScreens = allConnectedScreens();      config.writeEntry(allScreens + QStringLiteral(" XPosition"), window->x(), options);      config.writeEntry(allScreens + QStringLiteral(" YPosition"), window->y(), options);  } @@ -112,13 +106,7 @@ void KWindowConfig::restoreWindowPosition(QWindow *window, const KConfigGroup &c          return;      } -    QStringList names; -    const auto screens = QGuiApplication::screens(); -    names.reserve(screens.length()); -    for (auto screen : screens) { -        names << screen->name(); -    } -    const QString allScreens = names.join(QStringLiteral(" ")); +    const QString allScreens = allConnectedScreens();      const int xPos = config.readEntry(allScreens + QStringLiteral(" XPosition"), -1);      const int yPos = config.readEntry(allScreens + QStringLiteral(" YPosition"), -1); @@ -129,3 +117,14 @@ void KWindowConfig::restoreWindowPosition(QWindow *window, const KConfigGroup &c      window->setX(xPos);      window->setY(yPos);  } + +QString KWindowConfig::allConnectedScreens() +{ +    QStringList names; +    const auto screens = QGuiApplication::screens(); +    names.reserve(screens.length()); +    for (auto screen : screens) { +        names << screen->name(); +    } +    return names.join(QStringLiteral(" ")); +} diff --git a/src/gui/kwindowconfig.h b/src/gui/kwindowconfig.h index 04af27d1..0d36fa48 100644 --- a/src/gui/kwindowconfig.h +++ b/src/gui/kwindowconfig.h @@ -82,6 +82,12 @@ KCONFIGGUI_EXPORT void saveWindowPosition(const QWindow *window, KConfigGroup &c   * @since 5.74   */  KCONFIGGUI_EXPORT void restoreWindowPosition(QWindow *window,  const KConfigGroup &config); -} +/** + * Convenience function to get a space-separated list of all connected screens. + * + * @since 5.75 + */ +QString allConnectedScreens(); +}  #endif // KWINDOWCONFIG_H | 
