plugins/nightcolor: use FileDescriptor class
This commit is contained in:
parent
9c4f3d447f
commit
ca7a2cdef6
2 changed files with 11 additions and 19 deletions
|
@ -22,40 +22,33 @@ namespace KWin
|
||||||
|
|
||||||
LinuxClockSkewNotifierEngine *LinuxClockSkewNotifierEngine::create(QObject *parent)
|
LinuxClockSkewNotifierEngine *LinuxClockSkewNotifierEngine::create(QObject *parent)
|
||||||
{
|
{
|
||||||
const int fd = timerfd_create(CLOCK_REALTIME, O_CLOEXEC | O_NONBLOCK);
|
FileDescriptor fd{timerfd_create(CLOCK_REALTIME, O_CLOEXEC | O_NONBLOCK)};
|
||||||
if (fd == -1) {
|
if (!fd.isValid()) {
|
||||||
qWarning("Couldn't create clock skew notifier engine: %s", strerror(errno));
|
qWarning("Couldn't create clock skew notifier engine: %s", strerror(errno));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const itimerspec spec = {};
|
const itimerspec spec = {};
|
||||||
const int ret = timerfd_settime(fd, TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &spec, nullptr);
|
const int ret = timerfd_settime(fd.get(), TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &spec, nullptr);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
qWarning("Couldn't create clock skew notifier engine: %s", strerror(errno));
|
qWarning("Couldn't create clock skew notifier engine: %s", strerror(errno));
|
||||||
close(fd);
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
return new LinuxClockSkewNotifierEngine(std::move(fd), parent);
|
||||||
return new LinuxClockSkewNotifierEngine(fd, parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LinuxClockSkewNotifierEngine::LinuxClockSkewNotifierEngine(int fd, QObject *parent)
|
LinuxClockSkewNotifierEngine::LinuxClockSkewNotifierEngine(FileDescriptor &&fd, QObject *parent)
|
||||||
: ClockSkewNotifierEngine(parent)
|
: ClockSkewNotifierEngine(parent)
|
||||||
, m_fd(fd)
|
, m_fd(std::move(fd))
|
||||||
{
|
{
|
||||||
const QSocketNotifier *notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
|
const QSocketNotifier *notifier = new QSocketNotifier(m_fd.get(), QSocketNotifier::Read, this);
|
||||||
connect(notifier, &QSocketNotifier::activated, this, &LinuxClockSkewNotifierEngine::handleTimerCancelled);
|
connect(notifier, &QSocketNotifier::activated, this, &LinuxClockSkewNotifierEngine::handleTimerCancelled);
|
||||||
}
|
}
|
||||||
|
|
||||||
LinuxClockSkewNotifierEngine::~LinuxClockSkewNotifierEngine()
|
|
||||||
{
|
|
||||||
close(m_fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LinuxClockSkewNotifierEngine::handleTimerCancelled()
|
void LinuxClockSkewNotifierEngine::handleTimerCancelled()
|
||||||
{
|
{
|
||||||
uint64_t expirationCount;
|
uint64_t expirationCount;
|
||||||
read(m_fd, &expirationCount, sizeof(expirationCount));
|
read(m_fd.get(), &expirationCount, sizeof(expirationCount));
|
||||||
|
|
||||||
Q_EMIT clockSkewed();
|
Q_EMIT clockSkewed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "clockskewnotifierengine_p.h"
|
#include "clockskewnotifierengine_p.h"
|
||||||
|
#include "utils/filedescriptor.h"
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
@ -16,17 +17,15 @@ class LinuxClockSkewNotifierEngine : public ClockSkewNotifierEngine
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~LinuxClockSkewNotifierEngine() override;
|
|
||||||
|
|
||||||
static LinuxClockSkewNotifierEngine *create(QObject *parent);
|
static LinuxClockSkewNotifierEngine *create(QObject *parent);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void handleTimerCancelled();
|
void handleTimerCancelled();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LinuxClockSkewNotifierEngine(int fd, QObject *parent);
|
LinuxClockSkewNotifierEngine(FileDescriptor &&fd, QObject *parent);
|
||||||
|
|
||||||
int m_fd;
|
FileDescriptor m_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace KWin
|
} // namespace KWin
|
||||||
|
|
Loading…
Reference in a new issue