lid behavior watcher to lock session #115
@@ -45,11 +45,13 @@ qml_module(ZShell
|
|||||||
requests.hpp requests.cpp
|
requests.hpp requests.cpp
|
||||||
toaster.hpp toaster.cpp
|
toaster.hpp toaster.cpp
|
||||||
qalculator.hpp qalculator.cpp
|
qalculator.hpp qalculator.cpp
|
||||||
|
lidwatcher.hpp lidwatcher.cpp
|
||||||
LIBRARIES
|
LIBRARIES
|
||||||
Qt::Gui
|
Qt::Gui
|
||||||
Qt::Quick
|
Qt::Quick
|
||||||
Qt::Concurrent
|
Qt::Concurrent
|
||||||
Qt::Sql
|
Qt::Sql
|
||||||
|
Qt::DBus
|
||||||
PkgConfig::Qalculate
|
PkgConfig::Qalculate
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#include "lidwatcher.hpp"
|
||||||
|
|
||||||
|
#include <QtDBus/QDBusConnection>
|
||||||
|
#include <QLoggingCategory>
|
||||||
|
|
||||||
|
Q_LOGGING_CATEGORY(lcLidWatcher, "ZShell.lidwatcher", QtInfoMsg)
|
||||||
|
|
||||||
|
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 kPrepareForSleep = "PrepareForSleep";
|
||||||
|
|
||||||
|
LidWatcher::LidWatcher(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_available(false) {
|
||||||
|
QDBusConnection bus = QDBusConnection::systemBus();
|
||||||
|
m_available = bus.isConnected();
|
||||||
|
|
||||||
|
if (!m_available) {
|
||||||
|
qCWarning(lcLidWatcher) << "system bus unavailable";
|
||||||
|
emit availableChanged();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto ok = bus.connect(kLogin1Service, kLogin1Path, kLogin1Interface, kPrepareForSleep, this,
|
||||||
|
SLOT(onPrepareForSleep(bool)));
|
||||||
|
|
||||||
|
m_available = ok;
|
||||||
|
emit availableChanged();
|
||||||
|
if (!m_available) {
|
||||||
|
qCWarning(lcLidWatcher) << "login1 lid signal unavailable";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LidWatcher::available() const {
|
||||||
|
return m_available;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LidWatcher::onPrepareForSleep(bool goingDown) {
|
||||||
|
AramJonghu marked this conversation as resolved
Outdated
|
|||||||
|
if (goingDown) {
|
||||||
|
emit lidClosing();
|
||||||
|
} else {
|
||||||
|
emit lidOpened();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ZShell
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <qqmlintegration.h>
|
||||||
|
|
||||||
|
namespace ZShell {
|
||||||
|
|
||||||
|
class LidWatcher : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
QML_ELEMENT
|
||||||
|
QML_SINGLETON
|
||||||
|
|
||||||
|
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit LidWatcher(QObject* parent = nullptr);
|
||||||
|
|
||||||
|
[[nodiscard]] bool available() const;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void onPrepareForSleep(bool goingDown);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void availableChanged();
|
||||||
|
void lidClosing();
|
||||||
|
void lidOpened();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_available;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ZShell
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
//@ pragma DropExpensiveFonts
|
//@ pragma DropExpensiveFonts
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Services.UPower
|
import Quickshell.Services.UPower
|
||||||
|
import ZShell
|
||||||
import qs.Modules
|
import qs.Modules
|
||||||
import qs.Modules.Wallpaper
|
import qs.Modules.Wallpaper
|
||||||
import qs.Modules.Lock
|
import qs.Modules.Lock
|
||||||
@@ -35,6 +36,14 @@ ShellRoot {
|
|||||||
id: lock
|
id: lock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
function onLidClosing(): void {
|
||||||
|
lock.locked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
target: LidWatcher
|
||||||
|
}
|
||||||
|
|
||||||
Shortcuts {
|
Shortcuts {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user
Doesn't this trigger only when the system is about to suspend/hibernate? There should be a way to query the lid state directly.
Correct. And in retrospect, not every distro has defaults where the system suspends when laptop is on AC. The idea was that it should only trigger when the system suspends or hibernates to cover it more broadly for desktops (if wished). Could be a separate plugin or addition to current implementation if that is a wish separate from laptop lid behavior.