| 1 |
m |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#ifndef QWAYLANDINPUTCONTEXT_H |
| 6 |
#define QWAYLANDINPUTCONTEXT_H |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <qpa/qplatforminputcontext.h> |
| 20 |
|
| 21 |
#include <QLoggingCategory> |
| 22 |
#include <QPointer> |
| 23 |
#include <QRectF> |
| 24 |
#include <QVector> |
| 25 |
|
| 26 |
#include <QtWaylandClient/private/qwayland-text-input-unstable-v2.h> |
| 27 |
#include <qwaylandinputmethodeventbuilder_p.h> |
| 28 |
|
| 29 |
QT_BEGIN_NAMESPACE |
| 30 |
|
| 31 |
Q_DECLARE_LOGGING_CATEGORY(qLcQpaInputMethods) |
| 32 |
|
| 33 |
namespace QtWaylandClient { |
| 34 |
|
| 35 |
class QWaylandDisplay; |
| 36 |
|
| 37 |
class QWaylandTextInput : public QtWayland::zwp_text_input_v2 |
| 38 |
{ |
| 39 |
public: |
| 40 |
QWaylandTextInput(QWaylandDisplay *display, struct ::zwp_text_input_v2 *text_input); |
| 41 |
~QWaylandTextInput() override; |
| 42 |
|
| 43 |
void reset(); |
| 44 |
void commit(); |
| 45 |
void updateState(Qt::InputMethodQueries queries, uint32_t flags); |
| 46 |
|
| 47 |
void setCursorInsidePreedit(int cursor); |
| 48 |
|
| 49 |
bool isInputPanelVisible() const; |
| 50 |
QRectF keyboardRect() const; |
| 51 |
|
| 52 |
QLocale locale() const; |
| 53 |
Qt::LayoutDirection inputDirection() const; |
| 54 |
|
| 55 |
protected: |
| 56 |
void zwp_text_input_v2_enter(uint32_t serial, struct ::wl_surface *surface) override; |
| 57 |
void zwp_text_input_v2_leave(uint32_t serial, struct ::wl_surface *surface) override; |
| 58 |
void zwp_text_input_v2_modifiers_map(wl_array *map) override; |
| 59 |
void zwp_text_input_v2_input_panel_state(uint32_t state, int32_t x, int32_t y, int32_t width, int32_t height) override; |
| 60 |
void zwp_text_input_v2_preedit_string(const QString &text, const QString &commit) override; |
| 61 |
void zwp_text_input_v2_preedit_styling(uint32_t index, uint32_t length, uint32_t style) override; |
| 62 |
void zwp_text_input_v2_preedit_cursor(int32_t index) override; |
| 63 |
void zwp_text_input_v2_commit_string(const QString &text) override; |
| 64 |
void zwp_text_input_v2_cursor_position(int32_t index, int32_t anchor) override; |
| 65 |
void zwp_text_input_v2_delete_surrounding_text(uint32_t before_length, uint32_t after_length) override; |
| 66 |
void zwp_text_input_v2_keysym(uint32_t time, uint32_t sym, uint32_t state, uint32_t modifiers) override; |
| 67 |
void zwp_text_input_v2_language(const QString &language) override; |
| 68 |
void zwp_text_input_v2_text_direction(uint32_t direction) override; |
| 69 |
void zwp_text_input_v2_input_method_changed(uint32_t serial, uint32_t flags) override; |
| 70 |
|
| 71 |
private: |
| 72 |
Qt::KeyboardModifiers modifiersToQtModifiers(uint32_t modifiers); |
| 73 |
|
| 74 |
QWaylandDisplay *m_display = nullptr; |
| 75 |
QWaylandInputMethodEventBuilder m_builder; |
| 76 |
|
| 77 |
QVector<Qt::KeyboardModifier> m_modifiersMap; |
| 78 |
|
| 79 |
uint32_t m_serial = 0; |
| 80 |
struct ::wl_surface *m_surface = nullptr; |
| 81 |
|
| 82 |
QString m_preeditCommit; |
| 83 |
|
| 84 |
bool m_inputPanelVisible = false; |
| 85 |
QRectF m_keyboardRectangle; |
| 86 |
QLocale m_locale; |
| 87 |
Qt::LayoutDirection m_inputDirection = Qt::LayoutDirectionAuto; |
| 88 |
|
| 89 |
struct ::wl_callback *m_resetCallback = nullptr; |
| 90 |
static const wl_callback_listener callbackListener; |
| 91 |
static void resetCallback(void *data, struct wl_callback *wl_callback, uint32_t time); |
| 92 |
}; |
| 93 |
|
| 94 |
class QWaylandInputContext : public QPlatformInputContext |
| 95 |
{ |
| 96 |
Q_OBJECT |
| 97 |
public: |
| 98 |
explicit QWaylandInputContext(QWaylandDisplay *display); |
| 99 |
~QWaylandInputContext() override; |
| 100 |
|
| 101 |
bool isValid() const override; |
| 102 |
|
| 103 |
void reset() override; |
| 104 |
void commit() override; |
| 105 |
void update(Qt::InputMethodQueries) override; |
| 106 |
|
| 107 |
void invokeAction(QInputMethod::Action, int cursorPosition) override; |
| 108 |
|
| 109 |
void showInputPanel() override; |
| 110 |
void hideInputPanel() override; |
| 111 |
bool isInputPanelVisible() const override; |
| 112 |
QRectF keyboardRect() const override; |
| 113 |
|
| 114 |
QLocale locale() const override; |
| 115 |
Qt::LayoutDirection inputDirection() const override; |
| 116 |
|
| 117 |
void setFocusObject(QObject *object) override; |
| 118 |
|
| 119 |
private: |
| 120 |
QWaylandTextInput *textInput() const; |
| 121 |
|
| 122 |
QWaylandDisplay *mDisplay = nullptr; |
| 123 |
QPointer<QWindow> mCurrentWindow; |
| 124 |
}; |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
QT_END_NAMESPACE |
| 129 |
|
| 130 |
#endif |