Commit ca7a2cde authored by Xaver Hugl's avatar Xaver Hugl
Browse files

plugins/nightcolor: use FileDescriptor class

parent 9c4f3d44
Pipeline #217128 passed with stage
in 14 minutes and 5 seconds
......@@ -22,40 +22,33 @@ namespace KWin
LinuxClockSkewNotifierEngine *LinuxClockSkewNotifierEngine::create(QObject *parent)
{
const int fd = timerfd_create(CLOCK_REALTIME, O_CLOEXEC | O_NONBLOCK);
if (fd == -1) {
FileDescriptor fd{timerfd_create(CLOCK_REALTIME, O_CLOEXEC | O_NONBLOCK)};
if (!fd.isValid()) {
qWarning("Couldn't create clock skew notifier engine: %s", strerror(errno));
return nullptr;
}
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) {
qWarning("Couldn't create clock skew notifier engine: %s", strerror(errno));
close(fd);
return nullptr;
}
return new LinuxClockSkewNotifierEngine(fd, parent);
return new LinuxClockSkewNotifierEngine(std::move(fd), parent);
}
LinuxClockSkewNotifierEngine::LinuxClockSkewNotifierEngine(int fd, QObject *parent)
LinuxClockSkewNotifierEngine::LinuxClockSkewNotifierEngine(FileDescriptor &&fd, QObject *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);
}
LinuxClockSkewNotifierEngine::~LinuxClockSkewNotifierEngine()
{
close(m_fd);
}
void LinuxClockSkewNotifierEngine::handleTimerCancelled()
{
uint64_t expirationCount;
read(m_fd, &expirationCount, sizeof(expirationCount));
read(m_fd.get(), &expirationCount, sizeof(expirationCount));
Q_EMIT clockSkewed();
}
......
......@@ -7,6 +7,7 @@
#pragma once
#include "clockskewnotifierengine_p.h"
#include "utils/filedescriptor.h"
namespace KWin
{
......@@ -16,17 +17,15 @@ class LinuxClockSkewNotifierEngine : public ClockSkewNotifierEngine
Q_OBJECT
public:
~LinuxClockSkewNotifierEngine() override;
static LinuxClockSkewNotifierEngine *create(QObject *parent);
private Q_SLOTS:
void handleTimerCancelled();
private:
LinuxClockSkewNotifierEngine(int fd, QObject *parent);
LinuxClockSkewNotifierEngine(FileDescriptor &&fd, QObject *parent);
int m_fd;
FileDescriptor m_fd;
};
} // namespace KWin
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment