33#include < private/qwaylanddisplay_p.h>
44#include < qlogging.h>
55#include < qobject.h>
6+ #include < qtmetamacros.h>
67#include < qwindow.h>
78
89#include " ../../dbus/screensaver_dbus.hpp"
910#include " lock.hpp"
1011#include " manager.hpp"
1112#include " shell_integration.hpp"
1213#include " surface.hpp"
14+
1315namespace {
16+
1417QSWaylandSessionLockManager* manager () {
1518 static QSWaylandSessionLockManager* manager = nullptr ; // NOLINT
1619 if (manager == nullptr ) {
1720 manager = new QSWaylandSessionLockManager ();
1821 }
1922 return manager;
2023}
24+
2125} // namespace
26+
2227bool SessionLockManager::lockAvailable () { return manager ()->isActive (); }
28+
2329bool SessionLockManager::lock () {
2430 if (this ->isLocked () || SessionLockManager::sessionLocked ()) return false ;
31+
2532 this ->mLock = manager ()->acquireLock ();
2633 this ->mLock ->setParent (this );
2734
@@ -39,30 +46,40 @@ bool SessionLockManager::lock() {
3946 this ->mDbusAdaptor ->setSecure (true );
4047 emit this ->locked ();
4148 });
49+
4250 QObject::connect (this ->mLock , &QSWaylandSessionLock::unlocked, this , [this ]() {
4351 this ->mDbusAdaptor ->setActive (false );
4452 this ->mDbusAdaptor ->setSecure (false );
4553 emit this ->unlocked ();
4654 });
4755 // clang-format on
56+
4857 return true ;
4958}
59+
5060bool SessionLockManager::unlock () {
5161 if (!this ->isLocked ()) return false ;
62+
5263 this ->mLock ->unlock ();
5364 auto * lock = this ->mLock ;
5465 this ->mLock = nullptr ;
5566 delete lock;
67+
5668 return true ;
5769}
70+
5871bool SessionLockManager::isLocked () const { return this ->mLock != nullptr ; }
72+
5973bool SessionLockManager::sessionLocked () { return manager ()->isLocked (); }
74+
6075bool SessionLockManager::isSecure () { return manager ()->isSecure (); }
76+
6177LockWindowExtension::~LockWindowExtension () {
6278 if (this ->surface != nullptr ) {
6379 this ->surface ->setExtension (nullptr );
6480 }
6581}
82+
6683LockWindowExtension* LockWindowExtension::get (QWindow* window) {
6784 auto v = window->property (" sessionlock_ext" );
6885 if (v.canConvert <LockWindowExtension*>()) {
@@ -71,24 +88,30 @@ LockWindowExtension* LockWindowExtension::get(QWindow* window) {
7188 return nullptr ;
7289 }
7390}
91+
7492bool LockWindowExtension::isAttached () const { return this ->surface != nullptr ; }
93+
7594bool LockWindowExtension::attach (QWindow* window, SessionLockManager* manager) {
7695 if (this ->surface != nullptr )
7796 qFatal () << " Cannot change the attached window of a LockWindowExtension" ;
97+
7898 auto * current = LockWindowExtension::get (window);
7999 QtWaylandClient::QWaylandWindow* waylandWindow = nullptr ;
100+
80101 if (current != nullptr ) {
81102 current->surface ->setExtension (this );
82103 } else {
83104 // Qt appears to be resetting the window's screen on creation on some systems. This works around it.
84105 auto * screen = window->screen ();
85106 window->create ();
86107 window->setScreen (screen);
108+
87109 waylandWindow = dynamic_cast <QtWaylandClient::QWaylandWindow*>(window->handle ());
88110 if (waylandWindow == nullptr ) {
89111 qWarning () << window << " is not a wayland window. Cannot create lock surface." ;
90112 return false ;
91113 }
114+
92115 static QSWaylandSessionLockIntegration* lockIntegration = nullptr ; // NOLINT
93116 if (lockIntegration == nullptr ) {
94117 lockIntegration = new QSWaylandSessionLockIntegration ();
@@ -98,17 +121,23 @@ bool LockWindowExtension::attach(QWindow* window, SessionLockManager* manager) {
98121 qWarning () << " Failed to initialize lockscreen integration" ;
99122 }
100123 }
124+
101125 waylandWindow->setShellIntegration (lockIntegration);
102126 }
127+
103128 this ->setParent (window);
104129 window->setProperty (" sessionlock_ext" , QVariant::fromValue (this ));
130+
105131 this ->lock = manager->mLock ;
132+
106133 if (waylandWindow != nullptr ) {
107134 this ->surface = new QSWaylandSessionLockSurface (waylandWindow);
108135 if (this ->immediatelyVisible ) this ->surface ->setVisible ();
109136 }
137+
110138 return true ;
111139}
140+
112141void LockWindowExtension::setVisible () {
113142 if (this ->surface == nullptr ) this ->immediatelyVisible = true ;
114143 else this ->surface ->setVisible ();
0 commit comments