| 1 | // Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QWAYLANDTEXTINPUT_P_H |
| 5 | #define QWAYLANDTEXTINPUT_P_H |
| 6 | |
| 7 | #include <QtWaylandCompositor/private/qwaylandcompositorextension_p.h> |
| 8 | #include <QtWaylandCompositor/private/qwayland-server-text-input-unstable-v2.h> |
| 9 | #include <QtWaylandCompositor/QWaylandDestroyListener> |
| 10 | |
| 11 | #include <QtCore/QObject> |
| 12 | #include <QtCore/QMap> |
| 13 | #include <QtCore/QHash> |
| 14 | #include <QtCore/QRect> |
| 15 | #include <QtGui/QInputMethod> |
| 16 | #include <QtWaylandCompositor/QWaylandSurface> |
| 17 | |
| 18 | // |
| 19 | // W A R N I N G |
| 20 | // ------------- |
| 21 | // |
| 22 | // This file is not part of the Qt API. It exists purely as an |
| 23 | // implementation detail. This header file may change from version to |
| 24 | // version without notice, or even be removed. |
| 25 | // |
| 26 | // We mean it. |
| 27 | // |
| 28 | |
| 29 | QT_BEGIN_NAMESPACE |
| 30 | |
| 31 | class QInputMethodEvent; |
| 32 | class QKeyEvent; |
| 33 | class QWaylandCompositor; |
| 34 | class QWaylandView; |
| 35 | |
| 36 | class QWaylandTextInputClientState { |
| 37 | public: |
| 38 | QWaylandTextInputClientState(); |
| 39 | |
| 40 | Qt::InputMethodQueries updatedQueries(const QWaylandTextInputClientState &other) const; |
| 41 | Qt::InputMethodQueries mergeChanged(const QWaylandTextInputClientState &other); |
| 42 | |
| 43 | Qt::InputMethodHints hints = Qt::ImhNone; |
| 44 | QRect cursorRectangle; |
| 45 | QString surroundingText; |
| 46 | int cursorPosition = 0; |
| 47 | int anchorPosition = 0; |
| 48 | QString preferredLanguage; |
| 49 | |
| 50 | Qt::InputMethodQueries changedState; |
| 51 | }; |
| 52 | |
| 53 | class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandTextInputPrivate : public QWaylandCompositorExtensionPrivate, public QtWaylandServer::zwp_text_input_v2 |
| 54 | { |
| 55 | Q_DECLARE_PUBLIC(QWaylandTextInput) |
| 56 | public: |
| 57 | explicit QWaylandTextInputPrivate(QWaylandCompositor *compositor); |
| 58 | |
| 59 | void sendInputMethodEvent(QInputMethodEvent *event); |
| 60 | void sendKeyEvent(QKeyEvent *event); |
| 61 | void sendInputPanelState(); |
| 62 | void sendTextDirection(); |
| 63 | void sendLocale(); |
| 64 | void sendModifiersMap(const QByteArray &modifiersMap); |
| 65 | |
| 66 | QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const; |
| 67 | |
| 68 | void setFocus(QWaylandSurface *surface); |
| 69 | |
| 70 | QWaylandCompositor *compositor = nullptr; |
| 71 | |
| 72 | QWaylandSurface *focus = nullptr; |
| 73 | Resource *focusResource = nullptr; |
| 74 | QWaylandDestroyListener focusDestroyListener; |
| 75 | |
| 76 | bool inputPanelVisible = false; |
| 77 | |
| 78 | std::unique_ptr<QWaylandTextInputClientState> currentState; |
| 79 | std::unique_ptr<QWaylandTextInputClientState> pendingState; |
| 80 | |
| 81 | uint32_t serial = 0; |
| 82 | |
| 83 | QHash<Resource *, QWaylandSurface*> enabledSurfaces; |
| 84 | |
| 85 | protected: |
| 86 | void zwp_text_input_v2_bind_resource(Resource *resource) override; |
| 87 | void zwp_text_input_v2_destroy_resource(Resource *resource) override; |
| 88 | |
| 89 | void zwp_text_input_v2_destroy(Resource *resource) override; |
| 90 | void zwp_text_input_v2_enable(Resource *resource, wl_resource *surface) override; |
| 91 | void zwp_text_input_v2_disable(Resource *resource, wl_resource *surface) override; |
| 92 | void zwp_text_input_v2_show_input_panel(Resource *resource) override; |
| 93 | void zwp_text_input_v2_hide_input_panel(Resource *resource) override; |
| 94 | void zwp_text_input_v2_set_surrounding_text(Resource *resource, const QString &text, int32_t cursor, int32_t anchor) override; |
| 95 | void zwp_text_input_v2_set_content_type(Resource *resource, uint32_t hint, uint32_t purpose) override; |
| 96 | void zwp_text_input_v2_set_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override; |
| 97 | void zwp_text_input_v2_set_preferred_language(Resource *resource, const QString &language) override; |
| 98 | void zwp_text_input_v2_update_state(Resource *resource, uint32_t serial, uint32_t flags) override; |
| 99 | |
| 100 | private: |
| 101 | quint32 shiftModifierMask = 1; |
| 102 | quint32 controlModifierMask = 2; |
| 103 | quint32 altModifierMask = 4; |
| 104 | quint32 metaModifierMask = 8; |
| 105 | }; |
| 106 | |
| 107 | QT_END_NAMESPACE |
| 108 | |
| 109 | #endif // QWAYLANDTEXTINPUT_P_H |
| 110 | |