KWin
Loading...
Searching...
No Matches
clockskewnotifierengine_linux.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
8
9#include <QSocketNotifier>
10
11#include <cerrno>
12#include <fcntl.h>
13#include <sys/timerfd.h>
14#include <unistd.h>
15
16#ifndef TFD_TIMER_CANCEL_ON_SET // only available in newer glib
17#define TFD_TIMER_CANCEL_ON_SET (1 << 1)
18#endif
19
20namespace KWin
21{
22
24{
25 FileDescriptor fd{timerfd_create(CLOCK_REALTIME, O_CLOEXEC | O_NONBLOCK)};
26 if (!fd.isValid()) {
27 qWarning("Couldn't create clock skew notifier engine: %s", strerror(errno));
28 return nullptr;
29 }
30
31 const itimerspec spec = {};
32 const int ret = timerfd_settime(fd.get(), TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &spec, nullptr);
33 if (ret == -1) {
34 qWarning("Couldn't create clock skew notifier engine: %s", strerror(errno));
35 return nullptr;
36 }
37 return new LinuxClockSkewNotifierEngine(std::move(fd), parent);
38}
39
40LinuxClockSkewNotifierEngine::LinuxClockSkewNotifierEngine(FileDescriptor &&fd, QObject *parent)
42 , m_fd(std::move(fd))
43{
44 const QSocketNotifier *notifier = new QSocketNotifier(m_fd.get(), QSocketNotifier::Read, this);
45 connect(notifier, &QSocketNotifier::activated, this, &LinuxClockSkewNotifierEngine::handleTimerCancelled);
46}
47
48void LinuxClockSkewNotifierEngine::handleTimerCancelled()
49{
50 uint64_t expirationCount;
51 read(m_fd.get(), &expirationCount, sizeof(expirationCount));
52
53 Q_EMIT clockSkewed();
54}
55
56} // namespace KWin
57
58#include "moc_clockskewnotifierengine_linux.cpp"
static LinuxClockSkewNotifierEngine * create(QObject *parent)
#define TFD_TIMER_CANCEL_ON_SET