feat(slock): add user facing SessionLock and SessionLockSurface

This commit is contained in:
outfoxxed 2024-02-28 19:55:49 -08:00
parent 1fa87b7c5a
commit 48bdcf4db2
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
10 changed files with 458 additions and 14 deletions

View file

@ -17,10 +17,10 @@ QSWaylandSessionLock::~QSWaylandSessionLock() { this->unlock(); }
void QSWaylandSessionLock::unlock() {
if (this->isInitialized()) {
if (this->locked) this->unlock_and_destroy();
else this->destroy();
if (this->finished) this->destroy();
else this->unlock_and_destroy();
this->locked = false;
this->secure = false;
this->manager->active = nullptr;
emit this->unlocked();
@ -29,14 +29,15 @@ void QSWaylandSessionLock::unlock() {
bool QSWaylandSessionLock::active() const { return this->isInitialized(); }
bool QSWaylandSessionLock::hasCompositorLock() const { return this->locked; }
bool QSWaylandSessionLock::hasCompositorLock() const { return this->secure; }
void QSWaylandSessionLock::ext_session_lock_v1_locked() {
this->locked = true;
this->secure = true;
emit this->compositorLocked();
}
void QSWaylandSessionLock::ext_session_lock_v1_finished() {
this->locked = false;
this->secure = false;
this->finished = true;
this->unlock();
}

View file

@ -34,5 +34,6 @@ private:
QSWaylandSessionLockManager* manager; // static and not dealloc'd
// true when the compositor determines the session is locked
bool locked = false;
bool secure = false;
bool finished = false;
};

View file

@ -21,7 +21,7 @@ static QSWaylandSessionLockManager* manager() {
}
bool SessionLockManager::lock() {
if (SessionLockManager::sessionLocked()) return false;
if (this->isLocked() || SessionLockManager::sessionLocked()) return false;
this->mLock = manager()->acquireLock();
this->mLock->setParent(this);

View file

@ -13,7 +13,7 @@ class SessionLockManager: public QObject {
Q_OBJECT;
public:
SessionLockManager(QObject* parent = nullptr): QObject(parent) {}
explicit SessionLockManager(QObject* parent = nullptr): QObject(parent) {}
Q_DISABLE_COPY_MOVE(SessionLockManager);
// Returns true if a lock was acquired.
@ -57,7 +57,7 @@ class LockWindowExtension: public QObject {
Q_OBJECT;
public:
LockWindowExtension(QObject* parent = nullptr): QObject(parent) {}
explicit LockWindowExtension(QObject* parent = nullptr): QObject(parent) {}
~LockWindowExtension() override;
// Attach this lock extension to the given window.

View file

@ -40,7 +40,10 @@ QSWaylandSessionLockSurface::QSWaylandSessionLockSurface(QtWaylandClient::QWayla
this->init(this->ext->lock->get_lock_surface(window->waylandSurface()->object(), output));
}
QSWaylandSessionLockSurface::~QSWaylandSessionLockSurface() { this->destroy(); }
QSWaylandSessionLockSurface::~QSWaylandSessionLockSurface() {
if (this->ext != nullptr) this->ext->surface = nullptr;
this->destroy();
}
bool QSWaylandSessionLockSurface::isExposed() const { return this->configured; }
@ -60,7 +63,7 @@ bool QSWaylandSessionLockSurface::handleExpose(const QRegion& region) {
void QSWaylandSessionLockSurface::setExtension(LockWindowExtension* ext) {
if (ext == nullptr) {
this->window()->window()->close();
if (this->window() != nullptr) this->window()->window()->close();
} else {
if (this->ext != nullptr) {
this->ext->surface = nullptr;