#pragma once #include #include // 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(); };