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