KWin
Loading...
Searching...
No Matches
src
plugins
nightcolor
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
7
#include "
clockskewnotifierengine_linux.h
"
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
20
namespace
KWin
21
{
22
23
LinuxClockSkewNotifierEngine
*
LinuxClockSkewNotifierEngine::create
(QObject *parent)
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
40
LinuxClockSkewNotifierEngine::LinuxClockSkewNotifierEngine(
FileDescriptor
&&fd, QObject *parent)
41
:
ClockSkewNotifierEngine
(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
48
void
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"
KWin::ClockSkewNotifierEngine
Definition
clockskewnotifierengine_p.h:15
KWin::ClockSkewNotifierEngine::clockSkewed
void clockSkewed()
KWin::FileDescriptor
Definition
filedescriptor.h:17
KWin::FileDescriptor::get
int get() const
Definition
filedescriptor.cpp:50
KWin::LinuxClockSkewNotifierEngine
Definition
clockskewnotifierengine_linux.h:16
KWin::LinuxClockSkewNotifierEngine::create
static LinuxClockSkewNotifierEngine * create(QObject *parent)
Definition
clockskewnotifierengine_linux.cpp:23
TFD_TIMER_CANCEL_ON_SET
#define TFD_TIMER_CANCEL_ON_SET
Definition
clockskewnotifierengine_linux.cpp:17
clockskewnotifierengine_linux.h
KWin
Definition
activation_test.cpp:20
Generated on Sat Feb 17 2024 01:42:10 for KWin by
1.10.0