2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2017-01-27 05:50:50 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016, 2017 Martin Gräßlin <mgraesslin@kde.org>
|
2017-01-27 05:50:50 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2017-01-27 05:50:50 +00:00
|
|
|
#include "keyboard_repeat.h"
|
|
|
|
#include "keyboard_input.h"
|
|
|
|
#include "input_event.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
|
2021-03-10 14:28:50 +00:00
|
|
|
#include <KWaylandServer/keyboard_interface.h>
|
2020-04-29 15:18:41 +00:00
|
|
|
#include <KWaylandServer/seat_interface.h>
|
2017-01-27 05:50:50 +00:00
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
KeyboardRepeat::KeyboardRepeat(Xkb *xkb)
|
|
|
|
: QObject()
|
2020-08-14 14:49:33 +00:00
|
|
|
, m_timer(new QTimer(this))
|
2017-01-27 05:50:50 +00:00
|
|
|
, m_xkb(xkb)
|
|
|
|
{
|
|
|
|
connect(m_timer, &QTimer::timeout, this, &KeyboardRepeat::handleKeyRepeat);
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyboardRepeat::~KeyboardRepeat() = default;
|
|
|
|
|
|
|
|
void KeyboardRepeat::handleKeyRepeat()
|
|
|
|
{
|
|
|
|
// TODO: don't depend on WaylandServer
|
2020-10-16 04:59:24 +00:00
|
|
|
if (waylandServer()->seat()->keyboard()->keyRepeatRate() != 0) {
|
|
|
|
m_timer->setInterval(1000 / waylandServer()->seat()->keyboard()->keyRepeatRate());
|
2017-01-27 05:50:50 +00:00
|
|
|
}
|
|
|
|
// TODO: better time
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT keyRepeat(m_key, m_time);
|
2017-01-27 05:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-10-16 04:59:24 +00:00
|
|
|
if (m_xkb->shouldKeyRepeat(key) && waylandServer()->seat()->keyboard()->keyRepeatDelay() != 0) {
|
|
|
|
m_timer->setInterval(waylandServer()->seat()->keyboard()->keyRepeatDelay());
|
2017-01-27 05:50:50 +00:00
|
|
|
m_key = key;
|
|
|
|
m_time = event->timestamp();
|
|
|
|
m_timer->start();
|
|
|
|
}
|
|
|
|
} else if (event->type() == QEvent::KeyRelease) {
|
|
|
|
if (key == m_key) {
|
|
|
|
m_timer->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|