Skip to content

Commit c17ea54

Browse files
committed
wayland/lock: check for protocol availability before use
Fixes #66
1 parent 362c8e1 commit c17ea54

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/wayland/session_lock.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ void WlSessionLock::updateSurfaces(bool show, WlSessionLock* old) {
109109

110110
void WlSessionLock::realizeLockTarget(WlSessionLock* old) {
111111
if (this->lockTarget) {
112+
if (!SessionLockManager::lockAvailable()) {
113+
qCritical() << "Cannot start session lock: The current compositor does not support the "
114+
"ext-session-lock-v1 protocol.";
115+
this->unlock();
116+
return;
117+
}
118+
112119
if (this->mSurfaceComponent == nullptr) {
113120
qWarning() << "WlSessionLock.surface is null. Aborting lock.";
114121
this->unlock();

src/wayland/session_lock/session_lock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ QSWaylandSessionLockManager* manager() {
2222
}
2323
} // namespace
2424

25+
bool SessionLockManager::lockAvailable() { return manager()->isActive(); }
26+
2527
bool SessionLockManager::lock() {
2628
if (this->isLocked() || SessionLockManager::sessionLocked()) return false;
2729
this->mLock = manager()->acquireLock();

src/wayland/session_lock/session_lock.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class SessionLockManager: public QObject {
1515
public:
1616
explicit SessionLockManager(QObject* parent = nullptr): QObject(parent) {}
1717

18+
[[nodiscard]] static bool lockAvailable();
19+
1820
// Returns true if a lock was acquired.
1921
// If true is returned the caller must watch the global screen list and create/destroy
2022
// windows with an attached LockWindowExtension to match it.

0 commit comments

Comments
 (0)