Added clang-format/tidy for additional rules. Adjusted inbranch cpp files.
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 15s
Python / lint-format (pull_request) Successful in 37s
Python / test (pull_request) Successful in 59s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m20s

This commit is contained in:
2026-06-03 02:05:18 +02:00
parent 45f36ce71c
commit 896e5e520d
5 changed files with 125 additions and 23 deletions
+23 -14
View File
@@ -12,12 +12,10 @@ namespace ZShell {
static constexpr auto kLogin1Service = "org.freedesktop.login1";
static constexpr auto kLogin1Path = "/org/freedesktop/login1";
static constexpr auto kLogin1Interface = "org.freedesktop.login1.Manager";
static constexpr auto kDBusPropertiesInterface = "org.freedesktop.DBus.Properties";
static constexpr auto kDBusPropertiesInterface =
"org.freedesktop.DBus.Properties";
LidWatcher::LidWatcher(QObject* parent)
: QObject(parent)
, m_available(false)
, m_state(Opened) {
LidWatcher::LidWatcher(QObject* parent) : QObject(parent), m_available(false) {
QDBusConnection bus = QDBusConnection::systemBus();
m_available = bus.isConnected();
@@ -27,8 +25,13 @@ LidWatcher::LidWatcher(QObject* parent)
return;
}
const auto ok = bus.connect(kLogin1Service, kLogin1Path, kDBusPropertiesInterface, "PropertiesChanged",
this, SLOT(onPropertiesChanged(QString,QVariantMap,QStringList)));
const auto ok = bus.connect(
kLogin1Service,
kLogin1Path,
kDBusPropertiesInterface,
"PropertiesChanged",
this,
SLOT(onPropertiesChanged(QString, QVariantMap, QStringList)));
m_available = ok;
emit availableChanged();
@@ -49,24 +52,30 @@ LidWatcher::LidState LidWatcher::state() const {
}
void LidWatcher::queryInitialState() {
auto msg = QDBusMessage::createMethodCall(
kLogin1Service, kLogin1Path,
kDBusPropertiesInterface, "Get");
auto msg = QDBusMessage::createMethodCall(kLogin1Service,
kLogin1Path,
kDBusPropertiesInterface,
"Get");
msg << kLogin1Interface << "LidClosed";
const QDBusReply<QVariant> reply = QDBusConnection::systemBus().call(msg);
if (!reply.isValid()) {
qCWarning(lcLidWatcher) << "cannot query LidClosed:" << reply.error().message();
qCWarning(lcLidWatcher)
<< "cannot query LidClosed:" << reply.error().message();
return;
}
m_state = reply.value().toBool() ? Closed : Opened;
emit stateChanged();
}
void LidWatcher::onPropertiesChanged(const QString& interface, const QVariantMap& changed, const QStringList& /*invalidated*/) {
if (interface != kLogin1Interface)
void LidWatcher::onPropertiesChanged(const QString& interface,
const QVariantMap& changed,
const QStringList& ) {
if (interface != kLogin1Interface) {
return;
if (!changed.contains("LidClosed"))
}
if (!changed.contains("LidClosed")) {
return;
}
m_state = changed.value("LidClosed").toBool() ? Closed : Opened;
emit stateChanged();
}
+10 -9
View File
@@ -3,6 +3,7 @@
#include <QObject>
#include <QStringList>
#include <QVariantMap>
#include <cstdint>
#include <qqmlintegration.h>
namespace ZShell {
@@ -15,11 +16,8 @@ class LidWatcher : public QObject {
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
Q_PROPERTY(LidState state READ state NOTIFY stateChanged)
public:
enum LidState {
Opened,
Closed
};
public:
enum LidState : std::uint8_t{ Opened, Closed };
Q_ENUM(LidState)
explicit LidWatcher(QObject* parent = nullptr);
@@ -27,16 +25,19 @@ public:
[[nodiscard]] bool available() const;
[[nodiscard]] LidState state() const;
private:
private:
void queryInitialState();
bool m_available;
LidState m_state = Opened;
private Q_SLOTS:
void onPropertiesChanged(const QString& interface, const QVariantMap& changed, const QStringList& invalidated);
Q_SIGNALS:
void extracted();
void onPropertiesChanged(const QString& interface,
const QVariantMap& changed,
const QStringList& invalidated);
Q_SIGNALS:
void availableChanged();
void stateChanged();
};