KWin
Loading...
Searching...
No Matches
keyboard_repeat.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016, 2017 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "keyboard_repeat.h"
10#include "input_event.h"
11#include "keyboard_input.h"
12#include "wayland/keyboard.h"
13#include "wayland/seat.h"
14#include "wayland_server.h"
15#include "xkb.h"
16
17#include <QTimer>
18
19namespace KWin
20{
21
23 : QObject()
24 , m_timer(new QTimer(this))
25 , m_xkb(xkb)
26{
27 connect(m_timer, &QTimer::timeout, this, &KeyboardRepeat::handleKeyRepeat);
28}
29
31
32void KeyboardRepeat::handleKeyRepeat()
33{
34 // TODO: don't depend on WaylandServer
35 if (waylandServer()->seat()->keyboard()->keyRepeatRate() != 0) {
36 m_timer->setInterval(1000 / waylandServer()->seat()->keyboard()->keyRepeatRate());
37 }
38 // TODO: better time
39 Q_EMIT keyRepeat(m_key, m_time);
40}
41
43{
44 if (event->isAutoRepeat()) {
45 return;
46 }
47 const quint32 key = event->nativeScanCode();
48 if (event->type() == QEvent::KeyPress) {
49 // TODO: don't get these values from WaylandServer
50 if (m_xkb->shouldKeyRepeat(key) && waylandServer()->seat()->keyboard()->keyRepeatDelay() != 0) {
51 m_timer->setInterval(waylandServer()->seat()->keyboard()->keyRepeatDelay());
52 m_key = key;
53 m_time = event->timestamp();
54 m_timer->start();
55 }
56 } else if (event->type() == QEvent::KeyRelease) {
57 if (key == m_key) {
58 m_timer->stop();
59 }
60 }
61}
62
63}
64
65#include "moc_keyboard_repeat.cpp"
void keyEvent(KeyEvent *event) override
void keyRepeat(quint32 key, std::chrono::microseconds time)
~KeyboardRepeat() override
bool shouldKeyRepeat(quint32 key) const
Definition xkb.cpp:602
WaylandServer * waylandServer()