| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | #ifndef QIBUSPLATFORMINPUTCONTEXT_H |
| 4 | #define QIBUSPLATFORMINPUTCONTEXT_H |
| 5 | |
| 6 | #include <qpa/qplatforminputcontext.h> |
| 7 | |
| 8 | #include <QtCore/qpointer.h> |
| 9 | #include <QtCore/QLocale> |
| 10 | #include <QtCore/QLoggingCategory> |
| 11 | #include <QtDBus/qdbuspendingreply.h> |
| 12 | #if QT_CONFIG(filesystemwatcher) |
| 13 | #include <QFileSystemWatcher> |
| 14 | #endif |
| 15 | #include <QTimer> |
| 16 | #include <QWindow> |
| 17 | |
| 18 | #include "qibustypes.h" |
| 19 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | Q_DECLARE_LOGGING_CATEGORY(lcQpaInputMethods); |
| 23 | |
| 24 | class QIBusPlatformInputContextPrivate; |
| 25 | class QDBusVariant; |
| 26 | |
| 27 | class QIBusFilterEventWatcher: public QDBusPendingCallWatcher |
| 28 | { |
| 29 | public: |
| 30 | explicit QIBusFilterEventWatcher(const QDBusPendingCall &call, |
| 31 | QObject *parent = nullptr, |
| 32 | QWindow *window = nullptr, |
| 33 | const Qt::KeyboardModifiers modifiers = { }, |
| 34 | const QVariantList arguments = QVariantList()) |
| 35 | : QDBusPendingCallWatcher(call, parent) |
| 36 | , m_window(window) |
| 37 | , m_modifiers(modifiers) |
| 38 | , m_arguments(arguments) |
| 39 | {} |
| 40 | ~QIBusFilterEventWatcher() |
| 41 | {} |
| 42 | |
| 43 | inline QWindow *window() const { return m_window; } |
| 44 | inline const Qt::KeyboardModifiers modifiers() const { return m_modifiers; } |
| 45 | inline const QVariantList arguments() const { return m_arguments; } |
| 46 | |
| 47 | private: |
| 48 | QPointer<QWindow> m_window; |
| 49 | const Qt::KeyboardModifiers m_modifiers; |
| 50 | const QVariantList m_arguments; |
| 51 | }; |
| 52 | |
| 53 | class QIBusPlatformInputContext : public QPlatformInputContext |
| 54 | { |
| 55 | Q_OBJECT |
| 56 | public: |
| 57 | QIBusPlatformInputContext(); |
| 58 | ~QIBusPlatformInputContext(); |
| 59 | |
| 60 | bool isValid() const override; |
| 61 | void setFocusObject(QObject *object) override; |
| 62 | |
| 63 | void invokeAction(QInputMethod::Action a, int x) override; |
| 64 | void reset() override; |
| 65 | void commit() override; |
| 66 | void update(Qt::InputMethodQueries) override; |
| 67 | bool filterEvent(const QEvent *event) override; |
| 68 | QLocale locale() const override; |
| 69 | bool hasCapability(Capability capability) const override; |
| 70 | |
| 71 | public Q_SLOTS: |
| 72 | void commitText(const QDBusVariant &text); |
| 73 | void updatePreeditText(const QDBusVariant &text, uint cursor_pos, bool visible); |
| 74 | void updatePreeditTextWithMode(const QDBusVariant &text, uint cursor_pos, bool visible, uint mode); |
| 75 | void forwardKeyEvent(uint keyval, uint keycode, uint state); |
| 76 | void cursorRectChanged(); |
| 77 | void deleteSurroundingText(int offset, uint n_chars); |
| 78 | void surroundingTextRequired(); |
| 79 | void hidePreeditText(); |
| 80 | void showPreeditText(); |
| 81 | void filterEventFinished(QDBusPendingCallWatcher *call); |
| 82 | void socketChanged(const QString &str); |
| 83 | void busRegistered(const QString &str); |
| 84 | void busUnregistered(const QString &str); |
| 85 | void connectToBus(); |
| 86 | void globalEngineChanged(const QString &engine_name); |
| 87 | |
| 88 | private: |
| 89 | QIBusPlatformInputContextPrivate *d; |
| 90 | bool m_eventFilterUseSynchronousMode; |
| 91 | #if QT_CONFIG(filesystemwatcher) |
| 92 | QFileSystemWatcher m_socketWatcher; |
| 93 | #endif |
| 94 | QTimer m_timer; |
| 95 | |
| 96 | void connectToContextSignals(); |
| 97 | }; |
| 98 | |
| 99 | QT_END_NAMESPACE |
| 100 | |
| 101 | #endif |
| 102 | |