mirror of
https://github.com/RustyRaptor/plasma-keyboard.git
synced 2026-12-04 08:15:17 -07:00
This is the first step in https://invent.kde.org/plasma/plasma-keyboard/-/merge_requests/109 (please see it for context and rationale), and introduces a basic input engine and layout framework. The virtual keyboard library and engine are in /virtualkeyboard: - /virtualkeyboard/components - QML components for building keyboard layouts and the keyboard itself - /virtualkeyboard/inputbackend.h - generic input "backend" for sending events from the vkbd, currently just for input-method-v1 but could be for xdg-remote-desktop? - /virtualkeyboard/inputengine.h - internal input method "state" - /virtualkeyboard/keyboardcontroller.h - internal virtual keyboard panel "state" - /virtualkeyboard/keyboardpackageresolver.h - utilities to find and parse keyboard "layout packages" - /virtualkeyboard/textcomposers/abstracttextcomposer.h - abstract interface that implements event handling from the keyboard layout and talks to InputEngine for the final "text" (needed for CJK, text prediction) - /virtualkeyboard/textcomposers/directtextcomposer.h - directly enters text (enough for most layouts) For an example keyboard package (not included in this MR), please see https://invent.kde.org/plasma/plasma-keyboard/-/tree/e8e33ef2103c545decaed556a43907349e789fb8/layouts/en (shared layouts in https://invent.kde.org/plasma/plasma-keyboard/-/tree/e8e33ef2103c545decaed556a43907349e789fb8/layouts/defaultplugin) - Metadata is in metadata.json, which lists the locales the package is meant for, and what layouts it provides - Each keyboard layout has predefined "required" layouts: main, symbols, digits, numbers and dialpad - Each keyboard layout can define which form factors to show up for (ex. desktop ones won't show up in the mobile kcm keyboard selector by default)
53 lines
1018 B
C++
53 lines
1018 B
C++
/*
|
|
SPDX-FileCopyrightText: 2026 Devin Lin <devin@kde.org>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
*/
|
|
|
|
#include "inputbackend.h"
|
|
|
|
#include <algorithm>
|
|
|
|
InputBackend::InputBackend(QObject *parent)
|
|
: QObject(parent)
|
|
{
|
|
}
|
|
|
|
InputBackend::~InputBackend() = default;
|
|
|
|
QList<int> InputBackend::pressedKeys() const
|
|
{
|
|
return m_pressedKeys;
|
|
}
|
|
|
|
void InputBackend::clearPressedKeys()
|
|
{
|
|
const QList<int> keys = m_pressedKeys;
|
|
for (const int key : keys) {
|
|
sendKeyPressed(key, false);
|
|
}
|
|
}
|
|
|
|
void InputBackend::reset()
|
|
{
|
|
clearPressedKeys();
|
|
Q_EMIT resetRequested();
|
|
}
|
|
|
|
void InputBackend::setKeyPressed(int key, bool pressed)
|
|
{
|
|
if (pressed) {
|
|
if (m_pressedKeys.contains(key)) {
|
|
return;
|
|
}
|
|
m_pressedKeys.append(key);
|
|
std::sort(m_pressedKeys.begin(), m_pressedKeys.end());
|
|
} else {
|
|
if (!m_pressedKeys.removeAll(key)) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
Q_EMIT pressedKeysChanged();
|
|
}
|