| 1 | // Copyright (C) 2022 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 | |
| 4 | #ifndef QWAYLANDINPUTMETHODCONTEXT_P_H |
| 5 | #define QWAYLANDINPUTMETHODCONTEXT_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtGui/qpa/qplatforminputcontext.h> |
| 19 | #include <QtGui/qevent.h> |
| 20 | #include <QtCore/qlocale.h> |
| 21 | #include <QtCore/qpointer.h> |
| 22 | #include <QtCore/qlist.h> |
| 23 | #include <QtCore/qhash.h> |
| 24 | |
| 25 | #include <QtWaylandClient/private/qwayland-qt-text-input-method-unstable-v1.h> |
| 26 | #include <QtCore/private/qglobal_p.h> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | namespace QtWaylandClient { |
| 31 | class QWaylandDisplay; |
| 32 | |
| 33 | class QWaylandTextInputMethod : public QtWayland::qt_text_input_method_v1 |
| 34 | { |
| 35 | public: |
| 36 | QWaylandTextInputMethod(QWaylandDisplay *display, struct ::qt_text_input_method_v1 *textInputMethod); |
| 37 | ~QWaylandTextInputMethod() override; |
| 38 | |
| 39 | void text_input_method_v1_visible_changed(int32_t visible) override; |
| 40 | void text_input_method_v1_enter(struct ::wl_surface *surface) override; |
| 41 | void text_input_method_v1_leave(struct ::wl_surface *surface) override; |
| 42 | void text_input_method_v1_locale_changed(const QString &localeName) override; |
| 43 | void text_input_method_v1_input_direction_changed(int32_t inputDirection) override; |
| 44 | void text_input_method_v1_keyboard_rectangle_changed(wl_fixed_t x, wl_fixed_t y, wl_fixed_t width, wl_fixed_t height) override; |
| 45 | void text_input_method_v1_key(int32_t type, int32_t key, int32_t modifiers, int32_t autoRepeat, int32_t count, int32_t nativeScanCode, int32_t nativeVirtualKey, int32_t nativeModifiers, const QString &text) override; |
| 46 | void text_input_method_v1_start_input_method_event(uint32_t serial, int32_t surrounding_text_offset) override; |
| 47 | void text_input_method_v1_end_input_method_event(uint32_t serial, const QString &commitString, const QString &preeditString, int32_t replacementStart, int32_t replacementLength) override; |
| 48 | void text_input_method_v1_input_method_event_attribute(uint32_t serial, int32_t type, int32_t start, int32_t length, const QString &value) override; |
| 49 | |
| 50 | inline bool isVisible() const |
| 51 | { |
| 52 | return m_isVisible; |
| 53 | } |
| 54 | |
| 55 | inline QRectF keyboardRect() const |
| 56 | { |
| 57 | return m_keyboardRect; |
| 58 | } |
| 59 | |
| 60 | inline QLocale locale() const |
| 61 | { |
| 62 | return m_locale; |
| 63 | } |
| 64 | |
| 65 | inline Qt::LayoutDirection inputDirection() const |
| 66 | { |
| 67 | return m_layoutDirection; |
| 68 | } |
| 69 | |
| 70 | void sendInputState(QInputMethodQueryEvent *state, Qt::InputMethodQueries queries = Qt::ImQueryInput); |
| 71 | |
| 72 | private: |
| 73 | QHash<int, QList<QInputMethodEvent::Attribute> > m_pendingInputMethodEvents; |
| 74 | QHash<int,int> m_offsetFromCompositor; |
| 75 | |
| 76 | struct ::wl_surface *m_surface; |
| 77 | |
| 78 | // Cached state |
| 79 | bool m_isVisible = false; |
| 80 | QRectF m_keyboardRect; |
| 81 | QLocale m_locale; |
| 82 | Qt::LayoutDirection m_layoutDirection; |
| 83 | }; |
| 84 | |
| 85 | class QWaylandInputMethodContext : public QPlatformInputContext |
| 86 | { |
| 87 | Q_OBJECT |
| 88 | public: |
| 89 | QWaylandInputMethodContext(QWaylandDisplay *display); |
| 90 | ~QWaylandInputMethodContext() override; |
| 91 | |
| 92 | bool isValid() const override; |
| 93 | void reset() override; |
| 94 | void commit() override; |
| 95 | void update(Qt::InputMethodQueries) override; |
| 96 | void invokeAction(QInputMethod::Action, int cursorPosition) override; |
| 97 | void showInputPanel() override; |
| 98 | void hideInputPanel() override; |
| 99 | |
| 100 | bool isInputPanelVisible() const override; |
| 101 | QRectF keyboardRect() const override; |
| 102 | QLocale locale() const override; |
| 103 | Qt::LayoutDirection inputDirection() const override; |
| 104 | |
| 105 | void setFocusObject(QObject *object) override; |
| 106 | |
| 107 | private: |
| 108 | QWaylandTextInputMethod *textInputMethod() const; |
| 109 | |
| 110 | QWaylandDisplay *m_display; |
| 111 | QPointer<QWindow> m_currentWindow; |
| 112 | }; |
| 113 | |
| 114 | } // QtWaylandClient |
| 115 | |
| 116 | QT_END_NAMESPACE |
| 117 | |
| 118 | #endif // QWAYLANDINPUTMETHODCONTEXT_P_H |
| 119 | |