kwin/src/keyboard_repeat.cpp
Laurent Montel b823747c3b Add explicit moc includes to sources for moc-covered headers
* speeds up incremental builds as changes to a header will not always
  need the full mocs_compilation.cpp for all the target's headers rebuild,
  while having a moc file sourced into a source file only adds minor
  extra costs, due to small own code and the used headers usually
  already covered by the source file, being for the same class/struct
* seems to not slow down clean builds, due to empty mocs_compilation.cpp
  resulting in those quickly processed, while the minor extra cost of the
  sourced moc files does not outweigh that in summary.
  Measured times actually improved by some percent points.
  (ideally CMake would just skip empty mocs_compilation.cpp & its object
  file one day)
* enables compiler to see all methods of a class in same compilation unit
  to do some sanity checks
* potentially more inlining in general, due to more in the compilation unit
* allows to keep using more forward declarations in the header, as with the
  moc code being sourced into the cpp file there definitions can be ensured
  and often are already for the needs of the normal class methods
2023-07-15 08:40:49 +00:00

65 lines
1.7 KiB
C++

/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2016, 2017 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "keyboard_repeat.h"
#include "input_event.h"
#include "keyboard_input.h"
#include "wayland/keyboard_interface.h"
#include "wayland/seat_interface.h"
#include "wayland_server.h"
#include "xkb.h"
#include <QTimer>
namespace KWin
{
KeyboardRepeat::KeyboardRepeat(Xkb *xkb)
: QObject()
, m_timer(new QTimer(this))
, m_xkb(xkb)
{
connect(m_timer, &QTimer::timeout, this, &KeyboardRepeat::handleKeyRepeat);
}
KeyboardRepeat::~KeyboardRepeat() = default;
void KeyboardRepeat::handleKeyRepeat()
{
// TODO: don't depend on WaylandServer
if (waylandServer()->seat()->keyboard()->keyRepeatRate() != 0) {
m_timer->setInterval(1000 / waylandServer()->seat()->keyboard()->keyRepeatRate());
}
// TODO: better time
Q_EMIT keyRepeat(m_key, m_time);
}
void KeyboardRepeat::keyEvent(KeyEvent *event)
{
if (event->isAutoRepeat()) {
return;
}
const quint32 key = event->nativeScanCode();
if (event->type() == QEvent::KeyPress) {
// TODO: don't get these values from WaylandServer
if (m_xkb->shouldKeyRepeat(key) && waylandServer()->seat()->keyboard()->keyRepeatDelay() != 0) {
m_timer->setInterval(waylandServer()->seat()->keyboard()->keyRepeatDelay());
m_key = key;
m_time = event->timestamp();
m_timer->start();
}
} else if (event->type() == QEvent::KeyRelease) {
if (key == m_key) {
m_timer->stop();
}
}
}
}
#include "moc_keyboard_repeat.cpp"