KWin
Loading...
Searching...
No Matches
bouncekeys.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2023 Nicolas Fella <nicolas.fella@gmx.de>
3
4 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5*/
6
7#include "bouncekeys.h"
8#include "keyboard_input.h"
9
11 : m_configWatcher(KConfigWatcher::create(KSharedConfig::openConfig("kaccessrc")))
12{
13 const QLatin1String groupName("Keyboard");
14 connect(m_configWatcher.get(), &KConfigWatcher::configChanged, this, [this, groupName](const KConfigGroup &group) {
15 if (group.name() == groupName) {
16 loadConfig(group);
17 }
18 });
19 loadConfig(m_configWatcher->config()->group(groupName));
20}
21
22void BounceKeysFilter::loadConfig(const KConfigGroup &group)
23{
25
26 if (group.readEntry<bool>("BounceKeys", false)) {
28
29 m_delay = std::chrono::milliseconds(group.readEntry<int>("BounceKeysDelay", 500));
30 } else {
31 m_lastEvent.clear();
32 }
33}
34
36{
37 if (event->type() != KWin::KeyEvent::KeyPress) {
38 return false;
39 }
40
41 auto it = m_lastEvent.find(event->key());
42
43 if (it == m_lastEvent.end()) {
44 // first time is always good
45 m_lastEvent[event->key()] = event->timestamp();
46 return false;
47 }
48
49 auto last = *it;
50 *it = event->timestamp();
51
52 return event->timestamp() - last < m_delay;
53}
54
55#include "moc_bouncekeys.cpp"
bool keyEvent(KWin::KeyEvent *event) override
void uninstallInputEventFilter(InputEventFilter *filter)
Definition input.cpp:2684
void prependInputEventFilter(InputEventFilter *filter)
Definition input.cpp:2678
InputRedirection * input()
Definition input.h:549