diff --git a/shell/scripting/scriptengine.cpp b/shell/scripting/scriptengine.cpp --- a/shell/scripting/scriptengine.cpp +++ b/shell/scripting/scriptengine.cpp @@ -383,7 +383,14 @@ //that relies on it //NOTE: if we'll allow setting a panel screen from JS, it will have to use the following lines as well KConfigGroup cg=c->config(); - cg.writeEntry(QStringLiteral("lastScreen"), 0); + + // Only force lastScreen to 0 if the newly created containment doesn't have one, yet. + // Otherwise newly created panels would always be created on screen 0. + int lastScreen = cg.readEntry(QStringLiteral("lastScreen"), -1); + if (lastScreen < 0) { + cg.writeEntry(QStringLiteral("lastScreen"), 0); + } + c->restore(cg); } c->updateConstraints(Plasma::Types::AllConstraints | Plasma::Types::StartupCompletedConstraint); diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -1812,11 +1812,23 @@ Plasma::Containment *ShellCorona::addPanel(const QString &plugin) { - Plasma::Containment *panel = createContainment(plugin); + // find out current screen to create new panels on + const QPoint cursorPos(QCursor::pos()); + int screenNum = -1; + foreach (QScreen *screen, QGuiApplication::screens()) { + if (screen->geometry().contains(cursorPos)) { + screenNum = m_screenPool->id(screen->name()); + break; + } + } + + Plasma::Containment *panel = createContainmentForScreen(screenNum, plugin); if (!panel) { return 0; } + panel->setLastScreen(screenNum); + QList availableLocations; availableLocations << Plasma::Types::LeftEdge << Plasma::Types::TopEdge << Plasma::Types::RightEdge << Plasma::Types::BottomEdge; @@ -1850,7 +1862,6 @@ //made al lthe full representations be loaded. m_waitingPanelsTimer.start(); - const QPoint cursorPos(QCursor::pos()); foreach (QScreen *screen, QGuiApplication::screens()) { //m_panelViews.contains(panel) == false iff addPanel is executed in a startup script if (screen->geometry().contains(cursorPos) && m_panelViews.contains(panel)) {