File indexing completed on 2024-12-08 13:21:54
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2016, 2017 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "keyboard_repeat.h" 0010 #include "input_event.h" 0011 #include "keyboard_input.h" 0012 #include "wayland/keyboard_interface.h" 0013 #include "wayland/seat_interface.h" 0014 #include "wayland_server.h" 0015 #include "xkb.h" 0016 0017 #include <QTimer> 0018 0019 namespace KWin 0020 { 0021 0022 KeyboardRepeat::KeyboardRepeat(Xkb *xkb) 0023 : QObject() 0024 , m_timer(new QTimer(this)) 0025 , m_xkb(xkb) 0026 { 0027 connect(m_timer, &QTimer::timeout, this, &KeyboardRepeat::handleKeyRepeat); 0028 } 0029 0030 KeyboardRepeat::~KeyboardRepeat() = default; 0031 0032 void KeyboardRepeat::handleKeyRepeat() 0033 { 0034 // TODO: don't depend on WaylandServer 0035 if (waylandServer()->seat()->keyboard()->keyRepeatRate() != 0) { 0036 m_timer->setInterval(1000 / waylandServer()->seat()->keyboard()->keyRepeatRate()); 0037 } 0038 // TODO: better time 0039 Q_EMIT keyRepeat(m_key, m_time); 0040 } 0041 0042 void KeyboardRepeat::keyEvent(KeyEvent *event) 0043 { 0044 if (event->isAutoRepeat()) { 0045 return; 0046 } 0047 const quint32 key = event->nativeScanCode(); 0048 if (event->type() == QEvent::KeyPress) { 0049 // TODO: don't get these values from WaylandServer 0050 if (m_xkb->shouldKeyRepeat(key) && waylandServer()->seat()->keyboard()->keyRepeatDelay() != 0) { 0051 m_timer->setInterval(waylandServer()->seat()->keyboard()->keyRepeatDelay()); 0052 m_key = key; 0053 m_time = event->timestamp(); 0054 m_timer->start(); 0055 } 0056 } else if (event->type() == QEvent::KeyRelease) { 0057 if (key == m_key) { 0058 m_timer->stop(); 0059 } 0060 } 0061 } 0062 0063 }