36void QWaylandQtTextInputMethodPrivate::text_input_method_v1_disable(Resource *resource,
struct ::wl_resource *surface)
38 Q_Q(QWaylandQtTextInputMethod);
39 if (
this->resource == resource) {
40 QWaylandSurface *waylandSurface = QWaylandSurface::fromResource(surface);
41 QWaylandSurface *enabledSurface = enabledSurfaces.take(resource);
43 if (Q_UNLIKELY(enabledSurface != waylandSurface))
44 qCWarning(qLcWaylandCompositorInputMethods) <<
"Disabled surface does not match the one currently enabled";
46 emit q->surfaceEnabled(waylandSurface);
153 : QWaylandCompositorExtensionTemplate(container, *
new QWaylandQtTextInputMethodPrivate(compositor))
155 connect(&d_func()->focusDestroyListener, &QWaylandDestroyListener::fired,
158 connect(qGuiApp->inputMethod(), &QInputMethod::visibleChanged,
this, &QWaylandQtTextInputMethod::sendVisibleChanged);
159 connect(qGuiApp->inputMethod(), &QInputMethod::keyboardRectangleChanged,
this, &
QWaylandQtTextInputMethod::sendKeyboardRectangleChanged);
160 connect(qGuiApp->inputMethod(), &QInputMethod::inputDirectionChanged,
this, &
QWaylandQtTextInputMethod::sendInputDirectionChanged);
186 Q_D(
const QWaylandQtTextInputMethod);
189 return int(d->hints);
190 case Qt::ImCursorRectangle:
191 return d->cursorRectangle;
192 case Qt::ImCursorPosition:
193 return d->cursorPosition;
194 case Qt::ImSurroundingText:
195 return d->surroundingText;
196 case Qt::ImAbsolutePosition:
197 return d->absolutePosition;
198 case Qt::ImCurrentSelection:
199 return d->surroundingText.mid(qMin(d->cursorPosition, d->anchorPosition),
200 qAbs(d->anchorPosition - d->cursorPosition));
201 case Qt::ImAnchorPosition:
202 return d->anchorPosition;
203 case Qt::ImTextAfterCursor:
204 if (argument.isValid())
205 return d->surroundingText.mid(d->cursorPosition, argument.toInt());
206 return d->surroundingText.mid(d->cursorPosition);
207 case Qt::ImTextBeforeCursor:
208 if (argument.isValid())
209 return d->surroundingText.left(d->cursorPosition).right(argument.toInt());
210 return d->surroundingText.left(d->cursorPosition);
211 case Qt::ImPreferredLanguage:
212 return d->preferredLanguage;
239 Q_D(QWaylandQtTextInputMethod);
240 if (d->resource ==
nullptr || d->resource->handle ==
nullptr || d->compositor ==
nullptr)
243 if (d->updatingQueries != 0) {
244 qCWarning(qLcWaylandCompositorInputMethods) <<
"Input method event sent while client is updating. Ignored.";
248 Q_ASSERT(!d->waitingForSync);
250 QString oldSurroundText = d->surroundingText;
251 int oldCursorPosition = d->cursorPosition;
252 int oldAnchorPosition = d->anchorPosition;
253 int oldAbsolutePosition = d->absolutePosition;
254 QRect oldCursorRectangle = d->cursorRectangle;
255 QString oldPreferredLanguage = d->preferredLanguage;
256 Qt::InputMethodHints oldHints = d->hints;
258 uint serial = d->compositor->nextSerial();
259 d->send_start_input_method_event(d->resource->handle, serial, d->surroundingTextOffset);
260 for (
const QInputMethodEvent::Attribute &attribute : event->attributes()) {
261 switch (attribute.type) {
262 case QInputMethodEvent::TextFormat:
264 auto properties = attribute.value.value<QTextFormat>().properties();
265 if (properties.size() != 2 || properties.firstKey() != QTextFormat::FontUnderline || properties.lastKey() != QTextFormat::TextUnderlineStyle) {
266 qCWarning(qLcWaylandCompositorInputMethods()) <<
"Only underline text formats currently supported";
269 d->send_input_method_event_attribute(d->resource->handle,
277 case QInputMethodEvent::Cursor:
278 d->cursorPosition = attribute.start;
279 d->send_input_method_event_attribute(d->resource->handle,
284 attribute.value.typeId() == QMetaType::QColor ? attribute.value.value<QColor>().name() : QString());
286 case QInputMethodEvent::Language:
288 case QInputMethodEvent::Ruby:
289 d->send_input_method_event_attribute(d->resource->handle,
294 attribute.value.toString());
296 case QInputMethodEvent::Selection:
297 d->send_input_method_event_attribute(d->resource->handle,
304 case QInputMethodEvent::MimeData:
305 qCWarning(qLcWaylandCompositorInputMethods())
306 <<
"Ignoring QInputMethodEvent::MimeData";
311 d->waitingForSync =
true;
312 d->send_end_input_method_event(d->resource->handle,
314 event->commitString(),
315 event->preeditString(),
316 event->replacementStart(),
317 event->replacementLength());
319 while (d->waitingForSync) {
320 d->compositor->processWaylandEvents();
324 QCoreApplication::processEvents();
327 Qt::InputMethodQueries queries;
328 if (d->surroundingText != oldSurroundText)
329 queries |= Qt::ImSurroundingText;
330 if (d->cursorPosition != oldCursorPosition)
331 queries |= Qt::ImCursorPosition;
332 if (d->anchorPosition != oldAnchorPosition)
333 queries |= Qt::ImAnchorPosition;
334 if (d->absolutePosition != oldAbsolutePosition)
335 queries |= Qt::ImAbsolutePosition;
336 if (d->cursorRectangle != oldCursorRectangle)
337 queries |= Qt::ImCursorRectangle;
338 if (d->preferredLanguage != oldPreferredLanguage)
339 queries |= Qt::ImPreferredLanguage;
340 if (d->hints != oldHints)
341 queries |= Qt::ImHints;
343 emit updateInputMethod(queries);
354 Q_D(QWaylandQtTextInputMethod);
356 QWaylandQtTextInputMethodPrivate::Resource *resource = surface !=
nullptr ? d->resourceMap().value(surface->waylandClient()) :
nullptr;
357 if (d->resource == resource && d->focusedSurface == surface)
360 if (d->resource !=
nullptr && d->focusedSurface !=
nullptr) {
361 d->send_leave(d->resource->handle, d->focusedSurface->resource());
362 d->focusDestroyListener.reset();
365 d->resource = resource;
366 d->focusedSurface = surface;
368 if (d->resource !=
nullptr && d->focusedSurface !=
nullptr) {
369 d->surroundingText.clear();
370 d->cursorPosition = 0;
371 d->anchorPosition = 0;
372 d->absolutePosition = 0;
373 d->cursorRectangle = QRect();
374 d->preferredLanguage.clear();
375 d->hints = Qt::InputMethodHints();
376 d->send_enter(d->resource->handle, d->focusedSurface->resource());
377 sendInputDirectionChanged();
379 sendInputDirectionChanged();
380 d->focusDestroyListener.listenForDestruction(surface->resource());
381 if (d->inputPanelVisible && d->enabledSurfaces.values().contains(surface))
382 qGuiApp->inputMethod()->show();