Skip to content

Commit c4efd55

Browse files
committed
refactor: moved from using ScreenSaver to using custom dbus channel org.quickshell.SessionLock
1 parent 7277846 commit c4efd55

File tree

9 files changed

+164
-142
lines changed

9 files changed

+164
-142
lines changed

src/dbus/CMakeLists.txt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
11
set_source_files_properties(org.freedesktop.DBus.Properties.xml PROPERTIES
22
CLASSNAME DBusPropertiesInterface
33
)
4+
45
set_source_files_properties(org.freedesktop.DBus.ObjectManager.xml PROPERTIES
56
CLASSNAME DBusObjectManagerInterface
67
INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/dbus_objectmanager_types.hpp
78
)
8-
set_source_files_properties(org.freedesktop.ScreenSaver.xml PROPERTIES
9-
CLASSNAME ScreenSaverAdaptor
10-
INCLUDE screensaver_dbus.hpp
9+
10+
set_source_files_properties(org.quickshell.SessionLock.xml PROPERTIES
11+
CLASSNAME SessionLockAdaptor
12+
INCLUDE session_lock_dbus.hpp
1113
)
14+
1215
qt_add_dbus_interface(DBUS_INTERFACES
1316
org.freedesktop.DBus.Properties.xml
1417
dbus_properties
1518
)
19+
1620
qt_add_dbus_interface(DBUS_INTERFACES
1721
org.freedesktop.DBus.ObjectManager.xml
1822
dbus_objectmanager
1923
)
24+
2025
qt_add_dbus_adaptor(DBUS_INTERFACES
21-
org.freedesktop.ScreenSaver.xml
22-
${CMAKE_CURRENT_SOURCE_DIR}/screensaver_dbus.hpp
23-
qs::dbus::ScreenSaverAdaptor
26+
org.quickshell.SessionLock.xml
27+
${CMAKE_CURRENT_SOURCE_DIR}/session_lock_dbus.hpp
28+
qs::dbus::SessionLockAdaptor
2429
)
30+
2531
qt_add_library(quickshell-dbus STATIC
2632
properties.cpp
2733
objectmanager.cpp
2834
bus.cpp
29-
screensaver_dbus.cpp
35+
session_lock_dbus.cpp
3036
${DBUS_INTERFACES}
3137
)
38+
3239
# dbus headers
3340
target_include_directories(quickshell-dbus PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
3441
target_link_libraries(quickshell-dbus PRIVATE Qt::Core Qt::DBus)
42+
3543
# todo: link dbus to quickshell here instead of in modules that use it directly
3644
# linker does not like this as is
3745
qs_add_pchset(dbus
@@ -41,5 +49,7 @@ qs_add_pchset(dbus
4149
<qdebug.h>
4250
<qdbusargument.h>
4351
)
52+
4453
qs_pch(quickshell-dbus SET dbus)
54+
4555
add_subdirectory(dbusmenu)

src/dbus/org.freedesktop.ScreenSaver.xml

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<node>
2+
<interface name="org.quickshell.SessionLock">
3+
<!-- Get the current lock state -->
4+
<method name="GetLocked">
5+
<arg name="locked" direction="out" type="b"/>
6+
</method>
7+
8+
<!-- Signal emitted when lock state changes -->
9+
<signal name="LockedChanged">
10+
<arg name="locked" type="b"/>
11+
</signal>
12+
13+
<!-- Get whether the compositor has confirmed the lock (secure state) -->
14+
<method name="GetSecure">
15+
<arg name="secure" direction="out" type="b"/>
16+
</method>
17+
18+
<!-- Signal emitted when secure state changes -->
19+
<signal name="SecureChanged">
20+
<arg name="secure" type="b"/>
21+
</signal>
22+
</interface>
23+
</node>

src/dbus/screensaver_dbus.cpp

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/dbus/screensaver_dbus.hpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/dbus/session_lock_dbus.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include "session_lock_dbus.hpp"
2+
3+
#include <qdbusabstractadaptor.h>
4+
#include <qdbusconnection.h>
5+
#include <qdbuserror.h>
6+
#include <qlogging.h>
7+
#include <qloggingcategory.h>
8+
#include <qobject.h>
9+
#include <qtmetamacros.h>
10+
11+
#include "../core/logcat.hpp"
12+
13+
namespace {
14+
QS_LOGGING_CATEGORY(logDbusSessionLock, "quickshell.dbus.sessionlock", QtWarningMsg);
15+
}
16+
17+
namespace qs::dbus {
18+
19+
SessionLockAdaptor::SessionLockAdaptor(QObject* parent): QDBusAbstractAdaptor(parent) {
20+
// Register on session bus
21+
auto connection = QDBusConnection::sessionBus();
22+
23+
if (!connection.registerService("org.quickshell.SessionLock")) {
24+
qCWarning(logDbusSessionLock) << "Failed to register DBus service org.quickshell.SessionLock:"
25+
<< connection.lastError().message();
26+
} else {
27+
qCInfo(logDbusSessionLock) << "Registered DBus service org.quickshell.SessionLock";
28+
}
29+
30+
if (!connection
31+
.registerObject("/org/quickshell/SessionLock", parent, QDBusConnection::ExportAdaptors))
32+
{
33+
qCWarning(logDbusSessionLock) << "Failed to register DBus object /org/quickshell/SessionLock:"
34+
<< connection.lastError().message();
35+
} else {
36+
qCInfo(logDbusSessionLock) << "Registered DBus object /org/quickshell/SessionLock";
37+
}
38+
}
39+
40+
void SessionLockAdaptor::setLocked(bool locked) {
41+
if (this->mLocked != locked) {
42+
this->mLocked = locked;
43+
qCDebug(logDbusSessionLock) << "Lock state changed to:" << locked;
44+
emit this->LockedChanged(locked);
45+
}
46+
}
47+
48+
void SessionLockAdaptor::setSecure(bool secure) {
49+
if (this->mSecure != secure) {
50+
this->mSecure = secure;
51+
qCDebug(logDbusSessionLock) << "Secure state changed to:" << secure;
52+
emit this->SecureChanged(secure);
53+
}
54+
}
55+
56+
bool SessionLockAdaptor::GetLocked() const {
57+
qCDebug(logDbusSessionLock) << "GetLocked called, returning:" << this->mLocked;
58+
return this->mLocked;
59+
}
60+
61+
bool SessionLockAdaptor::GetSecure() const {
62+
qCDebug(logDbusSessionLock) << "GetSecure called, returning:" << this->mSecure;
63+
return this->mSecure;
64+
}
65+
66+
} // namespace qs::dbus

src/dbus/session_lock_dbus.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
#include <qdbusabstractadaptor.h>
3+
#include <qobject.h>
4+
#include <qtmetamacros.h>
5+
6+
namespace qs::dbus {
7+
8+
class SessionLockAdaptor: public QDBusAbstractAdaptor {
9+
Q_OBJECT;
10+
Q_CLASSINFO("D-Bus Interface", "org.quickshell.SessionLock")
11+
12+
public:
13+
explicit SessionLockAdaptor(QObject* parent);
14+
~SessionLockAdaptor() override = default;
15+
Q_DISABLE_COPY_MOVE(SessionLockAdaptor);
16+
17+
void setLocked(bool locked);
18+
void setSecure(bool secure);
19+
20+
public slots:
21+
[[nodiscard]] bool GetLocked() const; // NOLINT(readability-identifier-naming)
22+
[[nodiscard]] bool GetSecure() const; // NOLINT(readability-identifier-naming)
23+
24+
signals:
25+
void LockedChanged(bool locked); // NOLINT(readability-identifier-naming)
26+
void SecureChanged(bool secure); // NOLINT(readability-identifier-naming)
27+
28+
private:
29+
bool mLocked = false;
30+
bool mSecure = false;
31+
};
32+
33+
} // namespace qs::dbus

src/wayland/session_lock/session_lock.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <qtmetamacros.h>
77
#include <qwindow.h>
88

9-
#include "../../dbus/screensaver_dbus.hpp"
9+
#include "../../dbus/session_lock_dbus.hpp"
1010
#include "lock.hpp"
1111
#include "manager.hpp"
1212
#include "shell_integration.hpp"
@@ -16,14 +16,22 @@ namespace {
1616

1717
QSWaylandSessionLockManager* manager() {
1818
static QSWaylandSessionLockManager* manager = nullptr; // NOLINT
19+
1920
if (manager == nullptr) {
2021
manager = new QSWaylandSessionLockManager();
2122
}
23+
2224
return manager;
2325
}
2426

2527
} // namespace
2628

29+
SessionLockManager::SessionLockManager(QObject* parent)
30+
: QObject(parent)
31+
, mDbusAdaptor(new qs::dbus::SessionLockAdaptor(this)) {
32+
// DBus adaptor initialized in member initializer list so the service is always available
33+
}
34+
2735
bool SessionLockManager::lockAvailable() { return manager()->isActive(); }
2836

2937
bool SessionLockManager::lock() {
@@ -32,23 +40,18 @@ bool SessionLockManager::lock() {
3240
this->mLock = manager()->acquireLock();
3341
this->mLock->setParent(this);
3442

35-
// Initialize DBus adaptor if not already created
36-
if (this->mDbusAdaptor == nullptr) {
37-
this->mDbusAdaptor = new qs::dbus::ScreenSaverAdaptor(this);
38-
}
39-
4043
// Notify DBus that we're attempting to lock (not yet secure)
41-
this->mDbusAdaptor->setActive(true);
44+
this->mDbusAdaptor->setLocked(true);
4245
this->mDbusAdaptor->setSecure(false);
4346

4447
// clang-format off
4548
QObject::connect(this->mLock, &QSWaylandSessionLock::compositorLocked, this, [this]() {
4649
this->mDbusAdaptor->setSecure(true);
4750
emit this->locked();
4851
});
49-
52+
5053
QObject::connect(this->mLock, &QSWaylandSessionLock::unlocked, this, [this]() {
51-
this->mDbusAdaptor->setActive(false);
54+
this->mDbusAdaptor->setLocked(false);
5255
this->mDbusAdaptor->setSecure(false);
5356
emit this->unlocked();
5457
});
@@ -61,6 +64,7 @@ bool SessionLockManager::unlock() {
6164
if (!this->isLocked()) return false;
6265

6366
this->mLock->unlock();
67+
6468
auto* lock = this->mLock;
6569
this->mLock = nullptr;
6670
delete lock;
@@ -82,6 +86,7 @@ LockWindowExtension::~LockWindowExtension() {
8286

8387
LockWindowExtension* LockWindowExtension::get(QWindow* window) {
8488
auto v = window->property("sessionlock_ext");
89+
8590
if (v.canConvert<LockWindowExtension*>()) {
8691
return v.value<LockWindowExtension*>();
8792
} else {
@@ -107,14 +112,17 @@ bool LockWindowExtension::attach(QWindow* window, SessionLockManager* manager) {
107112
window->setScreen(screen);
108113

109114
waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow*>(window->handle());
115+
110116
if (waylandWindow == nullptr) {
111117
qWarning() << window << "is not a wayland window. Cannot create lock surface.";
112118
return false;
113119
}
114120

115121
static QSWaylandSessionLockIntegration* lockIntegration = nullptr; // NOLINT
122+
116123
if (lockIntegration == nullptr) {
117124
lockIntegration = new QSWaylandSessionLockIntegration();
125+
118126
if (!lockIntegration->initialize(waylandWindow->display())) {
119127
delete lockIntegration;
120128
lockIntegration = nullptr;

0 commit comments

Comments
 (0)