Registers as KWin's virtual keyboard (input-method-unstable-v1), shows a non-focusable layer-shell overlay, and commits Unicode text. Verified in a nested headless KWin with the textprobe tool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.2 KiB
C++
34 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
|
|
// Delivers text produced by the keyboard to the focused application.
|
|
// Implementations hide the transport (KWin input method, uinput, XTest, ...).
|
|
// Keys are identified by XKB keysyms so every backend speaks the same language.
|
|
class TextBackend : public QObject
|
|
{
|
|
Q_OBJECT
|
|
Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
|
|
Q_PROPERTY(QString surroundingText READ surroundingText NOTIFY surroundingChanged)
|
|
Q_PROPERTY(int cursorPosition READ cursorPosition NOTIFY surroundingChanged)
|
|
|
|
public:
|
|
using QObject::QObject;
|
|
|
|
// True while a text field is focused and accepts input.
|
|
virtual bool isActive() const = 0;
|
|
|
|
// Text around the cursor, if the backend knows it (empty otherwise).
|
|
virtual QString surroundingText() const { return {}; }
|
|
virtual int cursorPosition() const { return -1; }
|
|
|
|
Q_INVOKABLE virtual void commitText(const QString &text) = 0;
|
|
Q_INVOKABLE virtual void setPreedit(const QString &text) = 0;
|
|
Q_INVOKABLE virtual void sendKeysym(quint32 keysym, Qt::KeyboardModifiers modifiers = Qt::NoModifier) = 0;
|
|
|
|
Q_SIGNALS:
|
|
void activeChanged();
|
|
void surroundingChanged();
|
|
};
|