mirror of
https://git.outfoxxed.me/quickshell/quickshell.git
synced 2025-11-06 19:14:57 +11:00
wayland/idle-notify: add idle notify
This commit is contained in:
parent
b8fa424f85
commit
6eb12551ba
8 changed files with 329 additions and 0 deletions
52
src/wayland/idle_notify/monitor.cpp
Normal file
52
src/wayland/idle_notify/monitor.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include "monitor.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
#include <qlogging.h>
|
||||
#include <qscopeguard.h>
|
||||
#include <qtypes.h>
|
||||
|
||||
#include "proto.hpp"
|
||||
|
||||
namespace qs::wayland::idle_notify {
|
||||
|
||||
IdleMonitor::~IdleMonitor() { delete this->bNotification.value(); }
|
||||
|
||||
void IdleMonitor::onPostReload() {
|
||||
this->bParams.setBinding([this] {
|
||||
return Params {
|
||||
.enabled = this->bEnabled.value(),
|
||||
.timeout = this->bTimeout.value(),
|
||||
.respectInhibitors = this->bRespectInhibitors.value()
|
||||
};
|
||||
});
|
||||
|
||||
this->bIsIdle.setBinding([this] {
|
||||
auto* notification = this->bNotification.value();
|
||||
return notification ? notification->bIsIdle.value() : false;
|
||||
});
|
||||
}
|
||||
|
||||
void IdleMonitor::updateNotification() {
|
||||
auto* notification = this->bNotification.value();
|
||||
delete notification;
|
||||
notification = nullptr;
|
||||
|
||||
auto guard = qScopeGuard([&] { this->bNotification = notification; });
|
||||
|
||||
auto params = this->bParams.value();
|
||||
|
||||
if (params.enabled) {
|
||||
auto* manager = impl::IdleNotificationManager::instance();
|
||||
|
||||
if (!manager) {
|
||||
qWarning() << "Cannot create idle monitor as ext-idle-notify-v1 is not supported by the "
|
||||
"current compositor.";
|
||||
return;
|
||||
}
|
||||
|
||||
auto timeout = static_cast<quint32>(std::max(0, static_cast<int>(params.timeout * 1000)));
|
||||
notification = manager->createIdleNotification(timeout, params.respectInhibitors);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace qs::wayland::idle_notify
|
||||
Loading…
Add table
Add a link
Reference in a new issue