7#include <QtGui/qevent.h>
8#include <QtGui/qguiapplication.h>
9#include <QtGui/qinputmethod.h>
10#include <QtGui/qcolor.h>
11#include <QtGui/qtextformat.h>
13#include <QtWaylandCompositor/qwaylandcompositor.h>
14#include <QtWaylandCompositor/qwaylandsurface.h>
28 if (surface !=
nullptr) {
30 emit q->surfaceEnabled(waylandSurface);
42 if (
Q_UNLIKELY(enabledSurface != waylandSurface))
43 qCWarning(qLcWaylandCompositorInputMethods) <<
"Disabled surface does not match the one currently enabled";
45 emit q->surfaceEnabled(waylandSurface);
52 wl_resource_destroy(
resource->handle);
58 qApp->inputMethod()->reset();
64 qApp->inputMethod()->commit();
70 qApp->inputMethod()->show();
76 qApp->inputMethod()->hide();
100 this->hints = Qt::InputMethodHints(
hints);
141 emit q->updateInputMethod(queries);
155 this, &QWaylandQtTextInputMethod::focusSurfaceDestroyed);
168void QWaylandQtTextInputMethod::focusSurfaceDestroyed()
171 d->focusDestroyListener.reset();
172 d->waitingForSync =
false;
173 d->resource =
nullptr;
174 d->focusedSurface =
nullptr;
180 return d->focusedSurface;
188 return int(
d->hints);
190 return d->cursorRectangle;
192 return d->cursorPosition;
194 return d->surroundingText;
196 return d->absolutePosition;
198 return d->surroundingText.mid(
qMin(
d->cursorPosition,
d->anchorPosition),
199 qAbs(
d->anchorPosition -
d->cursorPosition));
201 return d->anchorPosition;
204 return d->surroundingText.mid(
d->cursorPosition,
argument.toInt());
205 return d->surroundingText.mid(
d->cursorPosition);
208 return d->surroundingText.left(
d->cursorPosition).right(
argument.toInt());
209 return d->surroundingText.left(
d->cursorPosition);
211 return d->preferredLanguage;
221 if (
d->resource ==
nullptr ||
d->resource->handle ==
nullptr)
224 d->send_key(
d->resource->handle,
228 event->isAutoRepeat(),
230 event->nativeScanCode(),
231 event->nativeVirtualKey(),
232 event->nativeModifiers(),
239 if (
d->resource ==
nullptr ||
d->resource->handle ==
nullptr ||
d->compositor ==
nullptr)
242 if (
d->updatingQueries != 0) {
243 qCWarning(qLcWaylandCompositorInputMethods) <<
"Input method event sent while client is updating. Ignored.";
249 QString oldSurroundText =
d->surroundingText;
250 int oldCursorPosition =
d->cursorPosition;
251 int oldAnchorPosition =
d->anchorPosition;
252 int oldAbsolutePosition =
d->absolutePosition;
253 QRect oldCursorRectangle =
d->cursorRectangle;
254 QString oldPreferredLanguage =
d->preferredLanguage;
255 Qt::InputMethodHints oldHints =
d->hints;
257 uint serial =
d->compositor->nextSerial();
258 d->send_start_input_method_event(
d->resource->handle, serial,
d->surroundingTextOffset);
265 qCWarning(qLcWaylandCompositorInputMethods()) <<
"Only underline text formats currently supported";
268 d->send_input_method_event_attribute(
d->resource->handle,
278 d->send_input_method_event_attribute(
d->resource->handle,
288 d->send_input_method_event_attribute(
d->resource->handle,
296 d->send_input_method_event_attribute(
d->resource->handle,
306 d->waitingForSync =
true;
307 d->send_end_input_method_event(
d->resource->handle,
309 event->commitString(),
310 event->preeditString(),
311 event->replacementStart(),
312 event->replacementLength());
314 while (
d->waitingForSync)
315 d->compositor->processWaylandEvents();
317 Qt::InputMethodQueries queries;
318 if (
d->surroundingText != oldSurroundText)
320 if (
d->cursorPosition != oldCursorPosition)
322 if (
d->anchorPosition != oldAnchorPosition)
324 if (
d->absolutePosition != oldAbsolutePosition)
326 if (
d->cursorRectangle != oldCursorRectangle)
328 if (
d->preferredLanguage != oldPreferredLanguage)
330 if (
d->hints != oldHints)
339 return d->enabledSurfaces.values().contains(surface);
346 QWaylandQtTextInputMethodPrivate::Resource *resource = surface !=
nullptr ?
d->resourceMap().value(surface->
waylandClient()) :
nullptr;
347 if (
d->resource == resource)
350 if (
d->resource !=
nullptr &&
d->focusedSurface !=
nullptr) {
351 d->send_leave(
d->resource->handle,
d->focusedSurface->resource());
352 d->focusDestroyListener.reset();
355 d->resource = resource;
356 d->focusedSurface = surface;
358 if (
d->resource !=
nullptr &&
d->focusedSurface !=
nullptr) {
359 d->surroundingText.clear();
360 d->cursorPosition = 0;
361 d->anchorPosition = 0;
362 d->absolutePosition = 0;
363 d->cursorRectangle =
QRect();
364 d->preferredLanguage.clear();
365 d->hints = Qt::InputMethodHints();
366 d->send_enter(
d->resource->handle,
d->focusedSurface->resource());
367 sendInputDirectionChanged();
369 sendInputDirectionChanged();
370 d->focusDestroyListener.listenForDestruction(surface->
resource());
371 if (
d->inputPanelVisible &&
d->enabledSurfaces.values().contains(surface))
372 qGuiApp->inputMethod()->show();
376void QWaylandQtTextInputMethod::sendLocaleChanged()
379 if (
d->resource ==
nullptr ||
d->resource->handle ==
nullptr)
382 d->send_locale_changed(
d->resource->handle,
qGuiApp->inputMethod()->locale().bcp47Name());
385void QWaylandQtTextInputMethod::sendInputDirectionChanged()
388 if (
d->resource ==
nullptr ||
d->resource->handle ==
nullptr)
391 d->send_input_direction_changed(
d->resource->handle,
int(
qGuiApp->inputMethod()->inputDirection()));
394void QWaylandQtTextInputMethod::sendKeyboardRectangleChanged()
397 if (
d->resource ==
nullptr ||
d->resource->handle ==
nullptr)
400 QRectF keyboardRectangle =
qGuiApp->inputMethod()->keyboardRectangle();
401 d->send_keyboard_rectangle_changed(
d->resource->handle,
402 wl_fixed_from_double(keyboardRectangle.
x()),
403 wl_fixed_from_double(keyboardRectangle.
y()),
404 wl_fixed_from_double(keyboardRectangle.
width()),
405 wl_fixed_from_double(keyboardRectangle.
height()));
408void QWaylandQtTextInputMethod::sendVisibleChanged()
411 if (
d->resource ==
nullptr ||
d->resource->handle ==
nullptr)
414 d->send_visible_changed(
d->resource->handle,
int(
qGuiApp->inputMethod()->isVisible()));
420 d->add(client,
id, version);
425 return QWaylandQtTextInputMethodPrivate::interface();
430 return QWaylandQtTextInputMethodPrivate::interfaceName();
435#include "moc_qwaylandqttextinputmethod.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
QString name(NameFormat format=HexRgb) const
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it.
The QKeyEvent class describes a key event.
\inmodule QtCore\reentrant
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
\inmodule QtCore\reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
\inmodule QtWaylandCompositor
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
\inmodule QtWaylandCompositor
void text_input_method_v1_invoke_action(Resource *resource, int32_t type, int32_t cursorPosition) override
QHash< Resource *, QWaylandSurface * > enabledSurfaces
void text_input_method_v1_commit(Resource *resource) override
void text_input_method_v1_update_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override
void text_input_method_v1_update_anchor_position(Resource *resource, int32_t anchorPosition) override
void text_input_method_v1_hide_input_panel(Resource *resource) override
Qt::InputMethodHints hints
int surroundingTextOffset
void text_input_method_v1_update_hints(Resource *resource, int32_t hints) override
void text_input_method_v1_update_surrounding_text(Resource *resource, const QString &surroundingText, int32_t surroundingTextOffset) override
Qt::InputMethodQueries updatingQueries
void text_input_method_v1_reset(Resource *resource) override
QString preferredLanguage
void text_input_method_v1_disable(Resource *resource, struct ::wl_resource *surface) override
void text_input_method_v1_update_absolute_position(Resource *resource, int32_t absolutePosition) override
void text_input_method_v1_update_cursor_position(Resource *resource, int32_t cursorPosition) override
void text_input_method_v1_destroy(Resource *resource) override
void text_input_method_v1_end_update(Resource *resource) override
QWaylandQtTextInputMethodPrivate(QWaylandCompositor *compositor)
void text_input_method_v1_enable(Resource *resource, struct ::wl_resource *surface) override
void text_input_method_v1_start_update(Resource *resource, int32_t queries) override
void text_input_method_v1_update_preferred_language(Resource *resource, const QString &preferredLanguage) override
void text_input_method_v1_acknowledge_input_method(Resource *resource) override
void text_input_method_v1_show_input_panel(Resource *resource) override
~QWaylandQtTextInputMethod() override
static const struct wl_interface * interface()
void updateInputMethod(Qt::InputMethodQueries queries)
bool isSurfaceEnabled(QWaylandSurface *surface) const
void setFocus(QWaylandSurface *surface)
void add(::wl_client *client, uint32_t id, int version)
static QByteArray interfaceName()
void sendKeyEvent(QKeyEvent *event)
QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const
QWaylandSurface * focusedSurface() const
void sendInputMethodEvent(QInputMethodEvent *event)
QWaylandQtTextInputMethod(QWaylandObject *container, QWaylandCompositor *compositor)
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
struct wl_resource * resource() const
Returns the Wayland resource corresponding to this QWaylandSurface.
::wl_client * waylandClient() const
Holds the wl_client using this QWaylandSurface.
static QWaylandSurface * fromResource(::wl_resource *resource)
Returns the QWaylandSurface corresponding to the Wayland resource resource.
Combined button and popup list for selecting options.
static const QCssKnownValue properties[NumProperties - 1]
EGLOutputLayerEXT EGLint attribute
#define qCWarning(category,...)
constexpr const T & qMin(const T &a, const T &b)
constexpr T qAbs(const T &t)
static QOpenGLCompositor * compositor
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLdouble GLdouble GLdouble GLdouble q
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)