aboutsummaryrefslogtreecommitdiff
path: root/src/gui/kwindowconfig.cpp
diff options
context:
space:
mode:
authorNate Graham <nate@kde.org>2020-08-20 12:04:34 -0600
committerNate Graham <nate@kde.org>2020-08-25 15:39:23 +0000
commit803b9f16e0b9133ddfef40dd16a368c39fa1b0a6 (patch)
tree0166968082ee609218f7589dd67cdb84e9c53e6b /src/gui/kwindowconfig.cpp
parenta3d55917068c99fc343ad4163be2ed52d25fc691 (diff)
downloadkconfig-803b9f16e0b9133ddfef40dd16a368c39fa1b0a6.tar.gz
kconfig-803b9f16e0b9133ddfef40dd16a368c39fa1b0a6.tar.bz2
Extract code to get list of connected screens into a re-usable function
Right now it's duplicated twice, and once we add per-screen-arrangement memory for window sizes as well, it will be duplicated four times unless we put it into a function.
Diffstat (limited to 'src/gui/kwindowconfig.cpp')
-rw-r--r--src/gui/kwindowconfig.cpp27
1 files changed, 13 insertions, 14 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(" "));
+}