Commit 50fc20dc authored by Devin Lin's avatar Devin Lin 🎨
Browse files

Fix wallpaper not loading (leaving the background black)

We need to apply the wallpaper anchors after the lockscreen theme is loaded, otherwise they won't be set properly and we end up with a black background.

This issue was triggered by !84

The reason why this wasn't noticed on Plasma Desktop, was that its lockscreen theme draws a FastBlur above the wallpaper in the background which will still correctly display the wallpaper item.

I had forgotten about that I used that as a workaround in Plasma Mobile for months... oops
parent 63b07109
......@@ -258,12 +258,12 @@ QWindow *UnlockApp::getActiveScreen()
return activeScreen;
}
void UnlockApp::loadWallpaperPlugin(KQuickAddons::QuickViewSharedEngine *view)
KDeclarative::QmlObjectSharedEngine *UnlockApp::loadWallpaperPlugin(KQuickAddons::QuickViewSharedEngine *view)
{
auto package = m_wallpaperIntegration->package();
if (!package.isValid()) {
qCWarning(KSCREENLOCKER_GREET) << "Error loading the wallpaper, no valid package loaded";
return;
return nullptr;
}
auto qmlObject = new KDeclarative::QmlObjectSharedEngine(view);
......@@ -288,6 +288,27 @@ void UnlockApp::loadWallpaperPlugin(KQuickAddons::QuickViewSharedEngine *view)
view->rootContext()->setContextProperty(QStringLiteral("wallpaper"), item);
view->rootContext()->setContextProperty(QStringLiteral("wallpaperIntegration"), m_wallpaperIntegration);
});
return qmlObject;
}
void setWallpaperItemProperties(KDeclarative::QmlObjectSharedEngine *wallpaperObject, KQuickAddons::QuickViewSharedEngine *view)
{
if (!wallpaperObject) {
return;
}
auto item = qobject_cast<QQuickItem *>(wallpaperObject->rootObject());
if (!item) {
qCWarning(KSCREENLOCKER_GREET) << "Wallpaper needs to be a QtQuick Item";
// return;
}
item->setParentItem(view->rootObject());
item->setZ(-1000);
// set anchors
QQmlExpression expr(wallpaperObject->engine()->rootContext(), item, QStringLiteral("parent"));
QQmlProperty prop(item, QStringLiteral("anchors.fill"));
prop.write(expr.evaluate());
}
void UnlockApp::initialViewSetup()
......@@ -365,7 +386,7 @@ KQuickAddons::QuickViewSharedEngine *UnlockApp::createViewForScreen(QScreen *scr
context->setContextProperty(QStringLiteral("defaultToSwitchUser"), m_defaultToSwitchUser);
context->setContextProperty(QStringLiteral("config"), m_lnfIntegration->configuration());
loadWallpaperPlugin(view);
auto wallpaperObj = loadWallpaperPlugin(view);
if (auto object = view->property("wallpaperGraphicsObject").value<KDeclarative::QmlObjectSharedEngine *>()) {
// initialize with our size to avoid as much resize events as possible
object->completeInitialization({
......@@ -386,6 +407,10 @@ KQuickAddons::QuickViewSharedEngine *UnlockApp::createViewForScreen(QScreen *scr
}
view->setResizeMode(KQuickAddons::QuickViewSharedEngine::SizeRootObjectToView);
// we need to set this wallpaper properties separately after the lockscreen QML is loaded
// this is because we need to anchor to the view that gets loaded
setWallpaperItemProperties(wallpaperObj, view);
QQmlProperty lockProperty(view->rootObject(), QStringLiteral("locked"));
lockProperty.write(m_immediateLock || (!m_noLock && !m_delayedLockTimer));
......
......@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef SCREENLOCKER_GREETERAPP_H
#define SCREENLOCKER_GREETERAPP_H
#include <KDeclarative/QmlObjectSharedEngine>
#include <KPackage/PackageStructure>
#include <QGuiApplication>
#include <QUrl>
......@@ -90,7 +91,8 @@ private Q_SLOTS:
private:
void initialize();
void shareEvent(QEvent *e, KQuickAddons::QuickViewSharedEngine *from);
void loadWallpaperPlugin(KQuickAddons::QuickViewSharedEngine *view);
KDeclarative::QmlObjectSharedEngine *loadWallpaperPlugin(KQuickAddons::QuickViewSharedEngine *view);
void setWallpaperItemProperties(KDeclarative::QmlObjectSharedEngine *wallpaperObject, KQuickAddons::QuickViewSharedEngine *view);
void screenGeometryChanged(QScreen *screen, const QRect &geo);
QWindow *getActiveScreen();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment