diff --git a/src/interfaces/declarative/qtshellintegrationplugin.cpp b/src/interfaces/declarative/qtshellintegrationplugin.cpp index 872b12d..eaa7f2f 100644 --- a/src/interfaces/declarative/qtshellintegrationplugin.cpp +++ b/src/interfaces/declarative/qtshellintegrationplugin.cpp @@ -4,10 +4,11 @@ #include #include -#include "../sessionlocksurface.h" #include "../layersurface.h" +#include "../sessionlocksurface.h" QML_DECLARE_TYPEINFO(Liri::QtShellIntegration::LayerSurface, QML_HAS_ATTACHED_PROPERTIES) +QML_DECLARE_TYPEINFO(Liri::QtShellIntegration::SessionLockSurface, QML_HAS_ATTACHED_PROPERTIES) class Plugin : public QQmlExtensionPlugin { @@ -17,8 +18,8 @@ class Plugin : public QQmlExtensionPlugin void registerTypes(const char *uri) override { Q_ASSERT(QLatin1String(uri) == QLatin1String("Liri.QtShellIntegration")); - qmlRegisterType(uri, 1, 0, "SessionLockSurface"); qmlRegisterType(uri, 1, 0, "LayerSurface"); + qmlRegisterType(uri, 1, 0, "SessionLockSurface"); } }; diff --git a/src/interfaces/sessionlocksurface.cpp b/src/interfaces/sessionlocksurface.cpp index 8855ff5..80a2029 100644 --- a/src/interfaces/sessionlocksurface.cpp +++ b/src/interfaces/sessionlocksurface.cpp @@ -14,10 +14,13 @@ namespace QtShellIntegration { typedef QHash SessionLockSurfaceMap; Q_GLOBAL_STATIC(SessionLockSurfaceMap, globalLockSurfaces) -SessionLockSurface::SessionLockSurface(QObject *parent) +SessionLockSurface::SessionLockSurface(QWindow *window, QObject *parent) : QObject(parent) , d_ptr(new SessionLockSurfacePrivate()) { + Q_D(SessionLockSurface); + d->window = window; + globalLockSurfaces->insert(window, this); } SessionLockSurface::~SessionLockSurface() @@ -26,55 +29,43 @@ SessionLockSurface::~SessionLockSurface() globalLockSurfaces->remove(d->window); } -bool SessionLockSurface::isInitialized() const +QWindow *SessionLockSurface::window() const { Q_D(const SessionLockSurface); - return d->initialized; -} - -void SessionLockSurface::initialize() -{ - Q_D(SessionLockSurface); - - if (d->initialized) - return; - - if (!d->window) { - qCWarning(lcQtShellIntegration, "Window not assigned to SessionLockSurface, failed to initialize"); - return; - } - - d->initialized = true; + return d->window; } -QWindow *SessionLockSurface::window() const +bool SessionLockSurface::isEnabled() const { Q_D(const SessionLockSurface); - return d->window; + return d->enabled; } -void SessionLockSurface::setWindow(QWindow *window) +void SessionLockSurface::setEnabled(bool enabled) { Q_D(SessionLockSurface); - - if (d->window == window) - return; - - if (d->initialized) { - qCWarning(lcQtShellIntegration, "Unable to change SessionLockSurface::window after initialization"); - return; + + if (!d->initialized) { + if (d->enabled == enabled) + return; + + d->initialized = true; + d->enabled = enabled; + Q_EMIT enabledChanged(enabled); } - - d->window = window; - Q_EMIT windowChanged(d->window); - - if (!globalLockSurfaces->contains(d->window)) - globalLockSurfaces->insert(d->window, this); } SessionLockSurface *SessionLockSurface::get(QWindow *window) { - return globalLockSurfaces->value(window, nullptr); + if (globalLockSurfaces->contains(window)) + return globalLockSurfaces->value(window); + else + return new SessionLockSurface(window); +} + +SessionLockSurface *SessionLockSurface::qmlAttachedProperties(QObject *object) +{ + return get(qobject_cast(object)); } } // QtShellIntegration diff --git a/src/interfaces/sessionlocksurface.h b/src/interfaces/sessionlocksurface.h index 73f4ad0..7499d33 100644 --- a/src/interfaces/sessionlocksurface.h +++ b/src/interfaces/sessionlocksurface.h @@ -19,25 +19,30 @@ class LIRIQTSHELLINTEGRATION_EXPORT SessionLockSurface : public QObject { Q_OBJECT QML_ELEMENT + QML_UNCREATABLE("Cannot instantiate SessionLockSurface") + QML_ATTACHED(SessionLockSurface) Q_DECLARE_PRIVATE(SessionLockSurface) - Q_PROPERTY(QWindow *window READ window WRITE setWindow NOTIFY windowChanged) + Q_PROPERTY(QWindow *window READ window CONSTANT) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) public: - SessionLockSurface(QObject *parent = nullptr); ~SessionLockSurface(); - bool isInitialized() const; - - void initialize(); - QWindow *window() const; - void setWindow(QWindow *window); + + bool isEnabled() const; + void setEnabled(bool enabled); static SessionLockSurface *get(QWindow *window); + static SessionLockSurface *qmlAttachedProperties(QObject *object); + Q_SIGNALS: - void windowChanged(QWindow *window); + void enabledChanged(bool enabled); void unlockRequested(); +protected: + SessionLockSurface(QWindow *window, QObject *parent = nullptr); + private: QScopedPointer const d_ptr; }; diff --git a/src/interfaces/sessionlocksurface_p.h b/src/interfaces/sessionlocksurface_p.h index 2410764..3a9445f 100644 --- a/src/interfaces/sessionlocksurface_p.h +++ b/src/interfaces/sessionlocksurface_p.h @@ -27,6 +27,7 @@ class SessionLockSurfacePrivate bool initialized = false; QWindow *window = nullptr; + bool enabled = false; }; } // namespace QtShellIntegration diff --git a/src/shell-integrations/ext-session-lock/qwaylandextsessionlock.cpp b/src/shell-integrations/ext-session-lock/qwaylandextsessionlock.cpp index 659f78f..4d6c3a4 100644 --- a/src/shell-integrations/ext-session-lock/qwaylandextsessionlock.cpp +++ b/src/shell-integrations/ext-session-lock/qwaylandextsessionlock.cpp @@ -26,6 +26,10 @@ QWaylandExtSessionLockSurface::QWaylandExtSessionLockSurface(QWaylandExtSessionL qCWarning(lcQpaWayland) << "Cannot find LockSurface interface on window" << window->window(); return; } + if (!interface->isEnabled()) { + qCWarning(lcQpaWayland) << "LockSurface is disabled on window" << window->window(); + return; + } init(lock->get_lock_surface(window->wlSurface(), window->waylandScreen()->output()));