-
Notifications
You must be signed in to change notification settings - Fork 18
/
keyboard_repeat.cpp
73 lines (61 loc) · 2.21 KB
/
keyboard_repeat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2016, 2017 Martin Gräßlin <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "keyboard_repeat.h"
#include "keyboard_input.h"
#include "input_event.h"
#include "wayland_server.h"
#include <KWayland/Server/seat_interface.h>
#include <QTimer>
namespace KWin
{
KeyboardRepeat::KeyboardRepeat(Xkb *xkb)
: QObject()
, m_timer(new QTimer)
, 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()->keyRepeatRate() != 0) {
m_timer->setInterval(1000 / waylandServer()->seat()->keyRepeatRate());
}
// TODO: better time
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()->keyRepeatDelay() != 0) {
m_timer->setInterval(waylandServer()->seat()->keyRepeatDelay());
m_key = key;
m_time = event->timestamp();
m_timer->start();
}
} else if (event->type() == QEvent::KeyRelease) {
if (key == m_key) {
m_timer->stop();
}
}
}
}