parent
4465f1e01c
commit
d4dde2c02d
5 changed files with 75 additions and 36 deletions
|
|
@ -27,11 +27,13 @@ Scope {
|
||||||
Quickshell.execDetached(action);
|
Quickshell.execDetached(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
SleepNotifier {
|
LogindManager {
|
||||||
onAboutToSleep: {
|
onAboutToSleep: {
|
||||||
if (Config.general.idle.lockBeforeSleep)
|
if (Config.general.idle.lockBeforeSleep)
|
||||||
root.lock.lock.locked = true;
|
root.lock.lock.locked = true;
|
||||||
}
|
}
|
||||||
|
onLockRequested: root.lock.lock.locked = true
|
||||||
|
onUnlockRequested: root.lock.lock.unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
Variants {
|
Variants {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ qml_module(caelestia-internal
|
||||||
circularindicatormanager.hpp circularindicatormanager.cpp
|
circularindicatormanager.hpp circularindicatormanager.cpp
|
||||||
hyprdevices.hpp hyprdevices.cpp
|
hyprdevices.hpp hyprdevices.cpp
|
||||||
hyprextras.hpp hyprextras.cpp
|
hyprextras.hpp hyprextras.cpp
|
||||||
sleepnotifier.hpp sleepnotifier.cpp
|
logindmanager.hpp logindmanager.cpp
|
||||||
LIBRARIES
|
LIBRARIES
|
||||||
Qt::Gui
|
Qt::Gui
|
||||||
Qt::Quick
|
Qt::Quick
|
||||||
|
|
|
||||||
65
plugin/src/Caelestia/Internal/logindmanager.cpp
Normal file
65
plugin/src/Caelestia/Internal/logindmanager.cpp
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
#include "logindmanager.hpp"
|
||||||
|
|
||||||
|
#include <QtDBus/qdbusconnection.h>
|
||||||
|
#include <QtDBus/qdbuserror.h>
|
||||||
|
#include <QtDBus/qdbusinterface.h>
|
||||||
|
#include <QtDBus/qdbusreply.h>
|
||||||
|
|
||||||
|
namespace caelestia::internal {
|
||||||
|
|
||||||
|
LogindManager::LogindManager(QObject* parent)
|
||||||
|
: QObject(parent) {
|
||||||
|
auto bus = QDBusConnection::systemBus();
|
||||||
|
if (!bus.isConnected()) {
|
||||||
|
qWarning() << "LogindManager::LogindManager: failed to connect to system bus:" << bus.lastError().message();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ok = bus.connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager",
|
||||||
|
"PrepareForSleep", this, SLOT(handlePrepareForSleep(bool)));
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
qWarning() << "LogindManager::LogindManager: failed to connect to PrepareForSleep signal:"
|
||||||
|
<< bus.lastError().message();
|
||||||
|
}
|
||||||
|
|
||||||
|
QDBusInterface login1("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", bus);
|
||||||
|
const QDBusReply<QDBusObjectPath> reply = login1.call("GetSession", "auto");
|
||||||
|
if (!reply.isValid()) {
|
||||||
|
qWarning() << "LogindManager::LogindManager: failed to get session path";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto sessionPath = reply.value().path();
|
||||||
|
|
||||||
|
ok = bus.connect("org.freedesktop.login1", sessionPath, "org.freedesktop.login1.Session", "Lock", this,
|
||||||
|
SLOT(handleLockRequested()));
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
qWarning() << "LogindManager::LogindManager: failed to connect to Lock signal:" << bus.lastError().message();
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = bus.connect("org.freedesktop.login1", sessionPath, "org.freedesktop.login1.Session", "Unlock", this,
|
||||||
|
SLOT(handleUnlockRequested()));
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
qWarning() << "LogindManager::LogindManager: failed to connect to Unlock signal:" << bus.lastError().message();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogindManager::handlePrepareForSleep(bool sleep) {
|
||||||
|
if (sleep) {
|
||||||
|
emit aboutToSleep();
|
||||||
|
} else {
|
||||||
|
emit resumed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogindManager::handleLockRequested() {
|
||||||
|
emit lockRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogindManager::handleUnlockRequested() {
|
||||||
|
emit unlockRequested();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace caelestia::internal
|
||||||
|
|
@ -5,19 +5,23 @@
|
||||||
|
|
||||||
namespace caelestia::internal {
|
namespace caelestia::internal {
|
||||||
|
|
||||||
class SleepNotifier : public QObject {
|
class LogindManager : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SleepNotifier(QObject* parent = nullptr);
|
explicit LogindManager(QObject* parent = nullptr);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void aboutToSleep();
|
void aboutToSleep();
|
||||||
void resumed();
|
void resumed();
|
||||||
|
void lockRequested();
|
||||||
|
void unlockRequested();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handlePrepareForSleep(bool sleep);
|
void handlePrepareForSleep(bool sleep);
|
||||||
|
void handleLockRequested();
|
||||||
|
void handleUnlockRequested();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace caelestia::internal
|
} // namespace caelestia::internal
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
#include "sleepnotifier.hpp"
|
|
||||||
|
|
||||||
#include <QtDBus/qdbusconnection.h>
|
|
||||||
#include <QtDBus/qdbuserror.h>
|
|
||||||
|
|
||||||
namespace caelestia::internal {
|
|
||||||
|
|
||||||
SleepNotifier::SleepNotifier(QObject* parent)
|
|
||||||
: QObject(parent) {
|
|
||||||
auto bus = QDBusConnection::systemBus();
|
|
||||||
if (!bus.isConnected()) {
|
|
||||||
qWarning() << "SleepNotifier::SleepNotifier: failed to connect to system bus:" << bus.lastError().message();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool ok = bus.connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager",
|
|
||||||
"PrepareForSleep", this, SLOT(handlePrepareForSleep(bool)));
|
|
||||||
|
|
||||||
if (!ok) {
|
|
||||||
qWarning() << "SleepNotifier::SleepNotifier: failed to connect to dbus:" << bus.lastError().message();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SleepNotifier::handlePrepareForSleep(bool sleep) {
|
|
||||||
if (sleep) {
|
|
||||||
emit aboutToSleep();
|
|
||||||
} else {
|
|
||||||
emit resumed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace caelestia::internal
|
|
||||||
Loading…
Add table
Reference in a new issue