KWin
Loading...
Searching...
No Matches
src
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
19
namespace
KWin
20
{
21
22
KeyboardRepeat::KeyboardRepeat
(
Xkb
*xkb)
23
: QObject()
24
, m_timer(new QTimer(this))
25
, m_xkb(xkb)
26
{
27
connect(m_timer, &QTimer::timeout,
this
, &KeyboardRepeat::handleKeyRepeat);
28
}
29
30
KeyboardRepeat::~KeyboardRepeat
() =
default
;
31
32
void
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
42
void
KeyboardRepeat::keyEvent
(
KeyEvent
*event)
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"
KWin::KeyEvent
Definition
input_event.h:133
KWin::KeyboardRepeat::keyEvent
void keyEvent(KeyEvent *event) override
Definition
keyboard_repeat.cpp:42
KWin::KeyboardRepeat::KeyboardRepeat
KeyboardRepeat(Xkb *xkb)
Definition
keyboard_repeat.cpp:22
KWin::KeyboardRepeat::keyRepeat
void keyRepeat(quint32 key, std::chrono::microseconds time)
KWin::KeyboardRepeat::~KeyboardRepeat
~KeyboardRepeat() override
KWin::Xkb
Definition
xkb.h:39
KWin::Xkb::shouldKeyRepeat
bool shouldKeyRepeat(quint32 key) const
Definition
xkb.cpp:602
input_event.h
keyboard.h
keyboard_input.h
keyboard_repeat.h
KWin
Definition
activation_test.cpp:20
KWin::waylandServer
WaylandServer * waylandServer()
Definition
wayland_server.h:297
seat.h
wayland_server.h
xkb.h
Generated on Sat Feb 17 2024 01:42:09 for KWin by
1.10.0