1// Copyright (C) 2021 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
5#ifndef QWAYLANDTEXTINPUTV1_H
6#define QWAYLANDTEXTINPUTV1_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "qwaylandtextinputinterface_p.h"
20#include <QtWaylandClient/private/qwayland-text-input-unstable-v1.h>
21#include <qwaylandinputmethodeventbuilder_p.h>
22
23struct wl_callback;
24struct wl_callback_listener;
25
26QT_BEGIN_NAMESPACE
27
28namespace QtWaylandClient {
29
30class QWaylandDisplay;
31
32class QWaylandTextInputv1 : public QtWayland::zwp_text_input_v1, public QWaylandTextInputInterface
33{
34public:
35 QWaylandTextInputv1(QWaylandDisplay *display, struct ::zwp_text_input_v1 *text_input);
36 ~QWaylandTextInputv1() override;
37
38 void setSeat(struct ::wl_seat *seat) { m_seat = seat; }
39
40 void reset() override;
41 void commit() override;
42 void updateState(Qt::InputMethodQueries queries, uint32_t flags) override;
43
44 void setCursorInsidePreedit(int cursor) override;
45
46 bool isInputPanelVisible() const override;
47 QRectF keyboardRect() const override;
48
49 QLocale locale() const override;
50 Qt::LayoutDirection inputDirection() const override;
51
52 void showInputPanel() override
53 {
54 show_input_panel();
55 }
56 void hideInputPanel() override
57 {
58 hide_input_panel();
59 }
60 void enableSurface(::wl_surface *surface) override
61 {
62 activate(m_seat, surface);
63 }
64 void disableSurface(::wl_surface *surface) override
65 {
66 Q_UNUSED(surface);
67 deactivate(m_seat);
68 }
69
70protected:
71 void zwp_text_input_v1_enter(struct ::wl_surface *surface) override;
72 void zwp_text_input_v1_leave() override;
73 void zwp_text_input_v1_modifiers_map(wl_array *map) override;
74 void zwp_text_input_v1_input_panel_state(uint32_t state) override;
75 void zwp_text_input_v1_preedit_string(uint32_t serial, const QString &text, const QString &commit) override;
76 void zwp_text_input_v1_preedit_styling(uint32_t index, uint32_t length, uint32_t style) override;
77 void zwp_text_input_v1_preedit_cursor(int32_t index) override;
78 void zwp_text_input_v1_commit_string(uint32_t serial, const QString &text) override;
79 void zwp_text_input_v1_cursor_position(int32_t index, int32_t anchor) override;
80 void zwp_text_input_v1_delete_surrounding_text(int32_t before_length, uint32_t after_length) override;
81 void zwp_text_input_v1_keysym(uint32_t serial, uint32_t time, uint32_t sym, uint32_t state, uint32_t modifiers) override;
82 void zwp_text_input_v1_language(uint32_t serial, const QString &language) override;
83 void zwp_text_input_v1_text_direction(uint32_t serial, uint32_t direction) override;
84
85private:
86 Qt::KeyboardModifiers modifiersToQtModifiers(uint32_t modifiers);
87
88 QWaylandInputMethodEventBuilder m_builder;
89
90 QList<Qt::KeyboardModifier> m_modifiersMap;
91
92 uint32_t m_serial = 0;
93 struct ::wl_surface *m_surface = nullptr;
94 struct ::wl_seat *m_seat = nullptr;
95
96 QString m_preeditCommit;
97
98 bool m_inputPanelVisible = false;
99 QRectF m_keyboardRectangle;
100 QLocale m_locale;
101 Qt::LayoutDirection m_inputDirection = Qt::LayoutDirectionAuto;
102
103 struct ::wl_callback *m_resetCallback = nullptr;
104 static const wl_callback_listener callbackListener;
105 static void resetCallback(void *data, struct wl_callback *wl_callback, uint32_t time);
106};
107
108}
109
110QT_END_NAMESPACE
111#endif // QWAYLANDTEXTINPUTV1_H
112
113

source code of qtwayland/src/client/qwaylandtextinputv1_p.h