diff options
Diffstat (limited to 'src/compositor/extensions')
16 files changed, 893 insertions, 1209 deletions
diff --git a/src/compositor/extensions/extensions.pri b/src/compositor/extensions/extensions.pri index 03be3905e..1d34803f0 100644 --- a/src/compositor/extensions/extensions.pri +++ b/src/compositor/extensions/extensions.pri @@ -4,8 +4,7 @@ WAYLANDSERVERSOURCES += \ ../extensions/touch-extension.xml \ ../extensions/qtkey-extension.xml \ ../extensions/windowmanager.xml \ - ../3rdparty/protocol/input-method.xml \ - ../3rdparty/protocol/text.xml \ + ../3rdparty/protocol/text-input-unstable-v2.xml \ ../3rdparty/protocol/xdg-shell.xml \ HEADERS += \ @@ -14,14 +13,12 @@ HEADERS += \ extensions/qwlqtkey_p.h \ extensions/qwaylandwlshell.h \ extensions/qwaylandwlshell_p.h \ + extensions/qwaylandtextinput.h \ + extensions/qwaylandtextinput_p.h \ + extensions/qwaylandtextinputmanager.h \ + extensions/qwaylandtextinputmanager_p.h \ extensions/qwaylandwindowmanagerextension.h \ extensions/qwaylandwindowmanagerextension_p.h \ - extensions/qwltextinput_p.h \ - extensions/qwltextinputmanager_p.h \ - extensions/qwlinputpanel_p.h \ - extensions/qwlinputpanelsurface_p.h \ - extensions/qwlinputmethod_p.h \ - extensions/qwlinputmethodcontext_p.h \ extensions/qwaylandxdgshell.h \ extensions/qwaylandxdgshell_p.h \ @@ -30,13 +27,9 @@ SOURCES += \ extensions/qwlqttouch.cpp \ extensions/qwlqtkey.cpp \ extensions/qwaylandwlshell.cpp \ + extensions/qwaylandtextinput.cpp \ + extensions/qwaylandtextinputmanager.cpp \ extensions/qwaylandwindowmanagerextension.cpp \ - extensions/qwltextinput.cpp \ - extensions/qwltextinputmanager.cpp \ - extensions/qwlinputpanel.cpp \ - extensions/qwlinputpanelsurface.cpp \ - extensions/qwlinputmethod.cpp \ - extensions/qwlinputmethodcontext.cpp \ extensions/qwaylandxdgshell.cpp \ qtHaveModule(quick) { diff --git a/src/compositor/extensions/qwaylandtextinput.cpp b/src/compositor/extensions/qwaylandtextinput.cpp new file mode 100644 index 000000000..31166ddb2 --- /dev/null +++ b/src/compositor/extensions/qwaylandtextinput.cpp @@ -0,0 +1,591 @@ +/**************************************************************************** +** +** Copyright (C) 2013-2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWaylandCompositor module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandtextinput.h" +#include "qwaylandtextinput_p.h" + +#include <QtWaylandCompositor/QWaylandCompositor> +#include <QtWaylandCompositor/private/qwaylandinput_p.h> + +#include "qwaylandsurface.h" +#include "qwaylandview.h" +#include "qwaylandxkb.h" +#include "qwaylandinputmethodeventbuilder.h" + +#include <QGuiApplication> +#include <QInputMethodEvent> + +QT_BEGIN_NAMESPACE + +QWaylandTextInputClientState::QWaylandTextInputClientState() + : hints(0) + , cursorRectangle() + , surroundingText() + , cursorPosition(0) + , anchorPosition(0) + , preferredLanguage() + , changedState() +{ +} + +Qt::InputMethodQueries QWaylandTextInputClientState::updatedQueries(const QWaylandTextInputClientState &other) const +{ + Qt::InputMethodQueries queries; + + if (hints != other.hints) + queries |= Qt::ImHints; + if (cursorRectangle != other.cursorRectangle) + queries |= Qt::ImCursorRectangle; + if (surroundingText != other.surroundingText) + queries |= Qt::ImSurroundingText | Qt::ImCurrentSelection; + if (cursorPosition != other.cursorPosition) + queries |= Qt::ImCursorPosition | Qt::ImCurrentSelection; + if (anchorPosition != other.anchorPosition) + queries |= Qt::ImAnchorPosition | Qt::ImCurrentSelection; + if (preferredLanguage != other.preferredLanguage) + queries |= Qt::ImPreferredLanguage; + + return queries; +} + +Qt::InputMethodQueries QWaylandTextInputClientState::mergeChanged(const QWaylandTextInputClientState &other) { + Qt::InputMethodQueries queries; + + if ((other.changedState & Qt::ImHints) && hints != other.hints) { + hints = other.hints; + queries |= Qt::ImHints; + } + + if ((other.changedState & Qt::ImCursorRectangle) && cursorRectangle != other.cursorRectangle) { + cursorRectangle = other.cursorRectangle; + queries |= Qt::ImCursorRectangle; + } + + if ((other.changedState & Qt::ImSurroundingText) && surroundingText != other.surroundingText) { + surroundingText = other.surroundingText; + queries |= Qt::ImSurroundingText | Qt::ImCurrentSelection; + } + + if ((other.changedState & Qt::ImCursorPosition) && cursorPosition != other.cursorPosition) { + cursorPosition = other.cursorPosition; + queries |= Qt::ImCursorPosition | Qt::ImCurrentSelection; + } + + if ((other.changedState & Qt::ImAnchorPosition) && anchorPosition != other.anchorPosition) { + anchorPosition = other.anchorPosition; + queries |= Qt::ImAnchorPosition | Qt::ImCurrentSelection; + } + + if ((other.changedState & Qt::ImPreferredLanguage) && preferredLanguage != other.preferredLanguage) { + preferredLanguage = other.preferredLanguage; + queries |= Qt::ImPreferredLanguage; + } + + return queries; +} + +QWaylandTextInputPrivate::QWaylandTextInputPrivate(QWaylandCompositor *compositor) + : QWaylandExtensionTemplatePrivate() + , QtWaylandServer::zwp_text_input_v2() + , compositor(compositor) + , focus(nullptr) + , focusResource(nullptr) + , focusDestroyListener() + , inputPanelVisible(false) + , currentState(new QWaylandTextInputClientState) + , pendingState(new QWaylandTextInputClientState) + , serial(0) + , enabledSurfaces() +{ +} + +void QWaylandTextInputPrivate::sendInputMethodEvent(QInputMethodEvent *event) +{ + if (!focusResource || !focusResource->handle) + return; + + if (event->replacementLength() > 0 || event->replacementStart() != 0) { + if (event->replacementStart() <= 0 && (event->replacementLength() >= -event->replacementStart())) { + const int selectionStart = qMin(currentState->cursorPosition, currentState->anchorPosition); + const int selectionEnd = qMax(currentState->cursorPosition, currentState->anchorPosition); + const int before = currentState->surroundingText.midRef(selectionStart + event->replacementStart(), -event->replacementStart()).toUtf8().size(); + const int after = currentState->surroundingText.midRef(selectionEnd, event->replacementLength() + event->replacementStart()).toUtf8().size(); + send_delete_surrounding_text(focusResource->handle, before, after); + } else { + // TODO: Implement this case + qWarning() << "Not yet supported case of replacement. Start:" << event->replacementStart() << "length:" << event->replacementLength(); + } + } + foreach (const QInputMethodEvent::Attribute &attribute, event->attributes()) { + if (attribute.type == QInputMethodEvent::Selection) { + const int cursorAfterCommit = qMin(currentState->cursorPosition, currentState->anchorPosition) + event->replacementStart() + event->commitString().length(); + QString textAfterCommit = currentState->surroundingText; + textAfterCommit.remove(qMin(currentState->cursorPosition, currentState->anchorPosition), + qAbs(currentState->cursorPosition - currentState->anchorPosition)); + textAfterCommit.replace(qMin(currentState->cursorPosition, currentState->anchorPosition) + event->replacementStart(), + event->replacementLength(), event->commitString()); + + int cursor = textAfterCommit.midRef(qMin(attribute.start, cursorAfterCommit), qAbs(attribute.start - cursorAfterCommit)).toUtf8().size(); + int anchor = textAfterCommit.midRef(qMin(attribute.length, cursorAfterCommit), qAbs(attribute.length - cursorAfterCommit)).toUtf8().size(); + send_cursor_position(focusResource->handle, + attribute.start < cursorAfterCommit ? -cursor : cursor, + attribute.start < cursorAfterCommit ? -anchor : anchor); + } + } + send_commit_string(focusResource->handle, event->commitString()); + foreach (const QInputMethodEvent::Attribute &attribute, event->attributes()) { + if (attribute.type == QInputMethodEvent::Cursor) { + int index = event->preeditString().leftRef(attribute.start).toUtf8().size(); + send_preedit_cursor(focusResource->handle, index); + } else if (attribute.type == QInputMethodEvent::TextFormat) { + int start = currentState->surroundingText.leftRef(attribute.start).toUtf8().size(); + int end = currentState->surroundingText.leftRef(attribute.start + attribute.length).toUtf8().size(); + // TODO add support for different stylesQWaylandTextInput + send_preedit_styling(focusResource->handle, start, end - start, preedit_style_default); + } + } + send_preedit_string(focusResource->handle, event->preeditString(), event->preeditString()); +} + +void QWaylandTextInputPrivate::sendKeyEvent(QKeyEvent *event) +{ + if (!focusResource || !focusResource->handle) + return; + + // TODO add support for modifiers + + foreach (xkb_keysym_t keysym, QWaylandXkb::toKeysym(event)) { + send_keysym(focusResource->handle, event->timestamp(), keysym, + event->type() == QEvent::KeyPress ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED, + 0); + } +} + +void QWaylandTextInputPrivate::sendInputPanelState() +{ + if (!focusResource || !focusResource->handle) + return; + + QInputMethod *inputMethod = qApp->inputMethod(); + const QRectF& keyboardRect = inputMethod->keyboardRectangle(); + const QRectF& sceneInputRect = inputMethod->inputItemTransform().mapRect(inputMethod->inputItemRectangle()); + const QRectF& localRect = sceneInputRect.intersected(keyboardRect).translated(-sceneInputRect.topLeft()); + + send_input_panel_state(focusResource->handle, + inputMethod->isVisible() ? input_panel_visibility_visible : input_panel_visibility_hidden, + localRect.x(), localRect.y(), localRect.width(), localRect.height()); +} + +void QWaylandTextInputPrivate::sendTextDirection() +{ + if (!focusResource || !focusResource->handle) + return; + + const Qt::LayoutDirection direction = qApp->inputMethod()->inputDirection(); + send_text_direction(focusResource->handle, + (direction == Qt::LeftToRight) ? text_direction_ltr : + (direction == Qt::RightToLeft) ? text_direction_rtl : text_direction_auto); +} + +void QWaylandTextInputPrivate::sendLocale() +{ + if (!focusResource || !focusResource->handle) + return; + + const QLocale locale = qApp->inputMethod()->locale(); + send_language(focusResource->handle, locale.bcp47Name()); +} + +QVariant QWaylandTextInputPrivate::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const +{ + switch (property) { + case Qt::ImHints: + return QVariant(static_cast<int>(currentState->hints)); + case Qt::ImCursorRectangle: + return currentState->cursorRectangle; + case Qt::ImFont: + // Not supported + return QVariant(); + case Qt::ImCursorPosition: + return currentState->cursorPosition; + case Qt::ImSurroundingText: + return currentState->surroundingText; + case Qt::ImCurrentSelection: + return currentState->surroundingText.mid(qMin(currentState->cursorPosition, currentState->anchorPosition), + qAbs(currentState->anchorPosition - currentState->cursorPosition)); + case Qt::ImMaximumTextLength: + // Not supported + return QVariant(); + case Qt::ImAnchorPosition: + return currentState->anchorPosition; + case Qt::ImAbsolutePosition: + // We assume the surrounding text is our whole document for now + return currentState->cursorPosition; + case Qt::ImTextAfterCursor: + if (argument.isValid()) + return currentState->surroundingText.mid(currentState->cursorPosition, argument.toInt()); + return currentState->surroundingText.mid(currentState->cursorPosition); + case Qt::ImTextBeforeCursor: + if (argument.isValid()) + return currentState->surroundingText.left(currentState->cursorPosition).right(argument.toInt()); + return currentState->surroundingText.left(currentState->cursorPosition); + case Qt::ImPreferredLanguage: + return currentState->preferredLanguage; + + default: + return QVariant(); + } +} + +void QWaylandTextInputPrivate::setFocus(QWaylandSurface *surface) +{ + Q_Q(QWaylandTextInput); + + if (focusResource && focus != surface) { + uint32_t serial = compositor->nextSerial(); + send_leave(focusResource->handle, serial, focus->resource()); + focusDestroyListener.reset(); + } + + Resource *resource = surface ? resourceMap().value(surface->waylandClient()) : 0; + + if (resource && (focus != surface || focusResource != resource)) { + uint32_t serial = compositor->nextSerial(); + currentState.reset(new QWaylandTextInputClientState); + pendingState.reset(new QWaylandTextInputClientState); + send_enter(resource->handle, serial, surface->resource()); + focusResource = resource; + sendInputPanelState(); + sendLocale(); + sendTextDirection(); + focusDestroyListener.listenForDestruction(surface->resource()); + if (inputPanelVisible && q->isSurfaceEnabled(surface)) + qApp->inputMethod()->show(); + } + + focusResource = resource; + focus = surface; +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_bind_resource(Resource *resource) +{ + send_modifiers_map(resource->handle, QByteArray("")); +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_destroy_resource(Resource *resource) +{ + if (focusResource == resource) + focusResource = 0; +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_destroy(Resource *resource) +{ + wl_resource_destroy(resource->handle); +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_enable(Resource *resource, wl_resource *surface) +{ + Q_Q(QWaylandTextInput); + + QWaylandSurface *s = QWaylandSurface::fromResource(surface); + enabledSurfaces.insert(resource, s); + emit q->surfaceEnabled(s); +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_disable(QtWaylandServer::zwp_text_input_v2::Resource *resource, wl_resource *) +{ + Q_Q(QWaylandTextInput); + + QWaylandSurface *s = enabledSurfaces.take(resource); + emit q->surfaceDisabled(s); +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_show_input_panel(Resource *) +{ + inputPanelVisible = true; + + qApp->inputMethod()->show(); +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_hide_input_panel(Resource *) +{ + inputPanelVisible = false; + + qApp->inputMethod()->hide(); +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_set_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) +{ + if (resource != focusResource) + return; + + pendingState->cursorRectangle = QRect(x, y, width, height); + + pendingState->changedState |= Qt::ImCursorRectangle; +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_update_state(Resource *resource, uint32_t serial, uint32_t flags) +{ + Q_Q(QWaylandTextInput); + + qCDebug(qLcCompositorInputMethods) << "update_state" << serial << flags; + + if (resource != focusResource) + return; + + if (flags == update_state_reset || flags == update_state_enter) { + qCDebug(qLcCompositorInputMethods) << "QInputMethod::reset()"; + qApp->inputMethod()->reset(); + } + + this->serial = serial; + + Qt::InputMethodQueries queries; + if (flags == update_state_change) { + queries = currentState->mergeChanged(*pendingState.data()); + } else { + queries = pendingState->updatedQueries(*currentState.data()); + currentState.swap(pendingState); + } + + pendingState.reset(new QWaylandTextInputClientState); + + if (queries) { + qCDebug(qLcCompositorInputMethods) << "QInputMethod::update()" << queries; + + emit q->updateInputMethod(queries); + } +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_set_content_type(Resource *resource, uint32_t hint, uint32_t purpose) +{ + if (resource != focusResource) + return; + + pendingState->hints = 0; + + if ((hint & content_hint_auto_completion) == 0 + && (hint & content_hint_auto_correction) == 0) + pendingState->hints |= Qt::ImhNoPredictiveText; + if ((hint & content_hint_auto_capitalization) == 0) + pendingState->hints |= Qt::ImhNoAutoUppercase; + if ((hint & content_hint_lowercase) != 0) + pendingState->hints |= Qt::ImhPreferLowercase; + if ((hint & content_hint_uppercase) != 0) + pendingState->hints |= Qt::ImhPreferUppercase; + if ((hint & content_hint_hidden_text) != 0) + pendingState->hints |= Qt::ImhHiddenText; + if ((hint & content_hint_sensitive_data) != 0) + pendingState->hints |= Qt::ImhSensitiveData; + if ((hint & content_hint_latin) != 0) + pendingState->hints |= Qt::ImhLatinOnly; + if ((hint & content_hint_multiline) != 0) + pendingState->hints |= Qt::ImhMultiLine; + + switch (purpose) { + case content_purpose_normal: + break; + case content_purpose_alpha: + pendingState->hints |= Qt::ImhUppercaseOnly | Qt::ImhLowercaseOnly; + break; + case content_purpose_digits: + pendingState->hints |= Qt::ImhDigitsOnly; + break; + case content_purpose_number: + pendingState->hints |= Qt::ImhFormattedNumbersOnly; + break; + case content_purpose_phone: + pendingState->hints |= Qt::ImhDialableCharactersOnly; + break; + case content_purpose_url: + pendingState->hints |= Qt::ImhUrlCharactersOnly; + break; + case content_purpose_email: + pendingState->hints |= Qt::ImhEmailCharactersOnly; + break; + case content_purpose_name: + case content_purpose_password: + break; + case content_purpose_date: + pendingState->hints |= Qt::ImhDate; + break; + case content_purpose_time: + pendingState->hints |= Qt::ImhTime; + break; + case content_purpose_datetime: + pendingState->hints |= Qt::ImhDate | Qt::ImhTime; + break; + case content_purpose_terminal: + default: + break; + } + + pendingState->changedState |= Qt::ImHints; +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_set_preferred_language(Resource *resource, const QString &language) +{ + if (resource != focusResource) + return; + + pendingState->preferredLanguage = language; + + pendingState->changedState |= Qt::ImPreferredLanguage; +} + +void QWaylandTextInputPrivate::zwp_text_input_v2_set_surrounding_text(Resource *resource, const QString &text, int32_t cursor, int32_t anchor) +{ + if (resource != focusResource) + return; + + pendingState->surroundingText = text; + pendingState->cursorPosition = QWaylandInputMethodEventBuilder::indexFromWayland(text, cursor); + pendingState->anchorPosition = QWaylandInputMethodEventBuilder::indexFromWayland(text, anchor); + + pendingState->changedState |= Qt::ImSurroundingText | Qt::ImCursorPosition | Qt::ImAnchorPosition; +} + +QWaylandTextInput::QWaylandTextInput(QWaylandObject *container, QWaylandCompositor *compositor) + : QWaylandExtensionTemplate(container, *new QWaylandTextInputPrivate(compositor)) +{ + connect(&d_func()->focusDestroyListener, &QWaylandDestroyListener::fired, + this, &QWaylandTextInput::focusSurfaceDestroyed); + + connect(qApp->inputMethod(), &QInputMethod::visibleChanged, + this, &QWaylandTextInput::sendInputPanelState); + connect(qApp->inputMethod(), &QInputMethod::keyboardRectangleChanged, + this, &QWaylandTextInput::sendInputPanelState); + connect(qApp->inputMethod(), &QInputMethod::inputDirectionChanged, + this, &QWaylandTextInput::sendTextDirection); + connect(qApp->inputMethod(), &QInputMethod::localeChanged, + this, &QWaylandTextInput::sendLocale); +} + +QWaylandTextInput::~QWaylandTextInput() +{ +} + +void QWaylandTextInput::sendInputMethodEvent(QInputMethodEvent *event) +{ + Q_D(QWaylandTextInput); + + d->sendInputMethodEvent(event); +} + +void QWaylandTextInput::sendKeyEvent(QKeyEvent *event) +{ + Q_D(QWaylandTextInput); + + d->sendKeyEvent(event); +} + +void QWaylandTextInput::sendInputPanelState() +{ + Q_D(QWaylandTextInput); + + d->sendInputPanelState(); +} + +void QWaylandTextInput::sendTextDirection() +{ + Q_D(QWaylandTextInput); + + d->sendTextDirection(); +} + +void QWaylandTextInput::sendLocale() +{ + Q_D(QWaylandTextInput); + + d->sendLocale(); +} + +QVariant QWaylandTextInput::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const +{ + const Q_D(QWaylandTextInput); + + return d->inputMethodQuery(property, argument); +} + +QWaylandSurface *QWaylandTextInput::focus() const +{ + const Q_D(QWaylandTextInput); + + return d->focus; +} + +void QWaylandTextInput::setFocus(QWaylandSurface *surface) +{ + Q_D(QWaylandTextInput); + + d->setFocus(surface); +} + +void QWaylandTextInput::focusSurfaceDestroyed(void *) +{ + Q_D(QWaylandTextInput); + + d->focusDestroyListener.reset(); + + d->focus = nullptr; + d->focusResource = nullptr; +} + +bool QWaylandTextInput::isSurfaceEnabled(QWaylandSurface *surface) const +{ + const Q_D(QWaylandTextInput); + + return d->enabledSurfaces.values().contains(surface); +} + +void QWaylandTextInput::add(::wl_client *client, uint32_t id, int version) +{ + Q_D(QWaylandTextInput); + + d->add(client, id, version); +} + +const wl_interface *QWaylandTextInput::interface() +{ + return QWaylandTextInputPrivate::interface(); +} + +QByteArray QWaylandTextInput::interfaceName() +{ + return QWaylandTextInputPrivate::interfaceName(); +} + +QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwlinputpanelsurface_p.h b/src/compositor/extensions/qwaylandtextinput.h index e11923bd0..100384e76 100644 --- a/src/compositor/extensions/qwlinputpanelsurface_p.h +++ b/src/compositor/extensions/qwaylandtextinput.h @@ -1,7 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2014 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). +** Copyright (C) 2013-2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWaylandCompositor module of the Qt Toolkit. @@ -35,61 +34,53 @@ ** ****************************************************************************/ -#ifndef QTWAYLAND_QWLINPUTPANELSURFACE_P_H -#define QTWAYLAND_QWLINPUTPANELSURFACE_P_H +#ifndef QWAYLANDTEXTINPUT_H +#define QWAYLANDTEXTINPUT_H -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtWaylandCompositor/private/qwayland-server-input-method.h> - -#include <QWaylandSurface> +#include <QtWaylandCompositor/QWaylandExtension> QT_BEGIN_NAMESPACE -class QWaylandOutput; +class QWaylandTextInputPrivate; -namespace QtWayland { +class QInputMethodEvent; +class QKeyEvent; +class QWaylandSurface; -class InputPanelSurface : public QtWaylandServer::wl_input_panel_surface +class QWaylandTextInput : public QWaylandExtensionTemplate<QWaylandTextInput> { + Q_OBJECT + Q_DECLARE_PRIVATE(QWaylandTextInput) public: - enum Type { - Invalid, - Toplevel, - OverlayPanel - }; + explicit QWaylandTextInput(QWaylandObject *container, QWaylandCompositor *compositor); + ~QWaylandTextInput(); - InputPanelSurface(struct ::wl_client *client, int id, QWaylandSurface *surface); + void sendInputMethodEvent(QInputMethodEvent *event); + void sendKeyEvent(QKeyEvent *event); - Type type() const; + QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const; - QWaylandOutput *output() const; - wl_input_panel_surface::position position() const; + QWaylandSurface *focus() const; + void setFocus(QWaylandSurface *surface); -protected: - void input_panel_surface_set_overlay_panel(Resource *resource) Q_DECL_OVERRIDE; - void input_panel_surface_set_toplevel(Resource *resource, wl_resource *output_resource, uint32_t position) Q_DECL_OVERRIDE; + bool isSurfaceEnabled(QWaylandSurface *surface) const; -private: - QWaylandSurface *m_surface; + void add(::wl_client *client, uint32_t id, int version); + static const struct wl_interface *interface(); + static QByteArray interfaceName(); - Type m_type; +Q_SIGNALS: + void updateInputMethod(Qt::InputMethodQueries queries); + void surfaceEnabled(QWaylandSurface *surface); + void surfaceDisabled(QWaylandSurface *surface); - QWaylandOutput *m_output; - wl_input_panel_surface::position m_position; +private: + void focusSurfaceDestroyed(void *); + void sendInputPanelState(); + void sendTextDirection(); + void sendLocale(); }; -} // namespace QtWayland - QT_END_NAMESPACE -#endif // QTWAYLAND_QWLINPUTPANELSURFACE_P_H +#endif // QWAYLANDTEXTINPUT_H diff --git a/src/compositor/extensions/qwaylandtextinput_p.h b/src/compositor/extensions/qwaylandtextinput_p.h new file mode 100644 index 000000000..79706a7e2 --- /dev/null +++ b/src/compositor/extensions/qwaylandtextinput_p.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWaylandCompositor module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDTEXTINPUT_P_H +#define QWAYLANDTEXTINPUT_P_H + +#include <QtWaylandCompositor/private/qwaylandextension_p.h> +#include <QtWaylandCompositor/private/qwayland-server-text-input-unstable-v2.h> +#include <QtWaylandCompositor/QWaylandDestroyListener> + +#include <QtCore/QObject> +#include <QtCore/QMap> +#include <QtCore/QRect> +#include <QtCore/QVector> +#include <QtGui/QInputMethod> +#include <QtWaylandCompositor/QWaylandSurface> + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class QInputMethodEvent; +class QKeyEvent; +class QWaylandCompositor; +class QWaylandView; + +class QWaylandTextInputClientState { +public: + QWaylandTextInputClientState(); + + Qt::InputMethodQueries updatedQueries(const QWaylandTextInputClientState &other) const; + Qt::InputMethodQueries mergeChanged(const QWaylandTextInputClientState &other); + + Qt::InputMethodHints hints; + QRect cursorRectangle; + QString surroundingText; + int cursorPosition; + int anchorPosition; + QString preferredLanguage; + + Qt::InputMethodQueries changedState; +}; + +class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandTextInputPrivate : public QWaylandExtensionTemplatePrivate, public QtWaylandServer::zwp_text_input_v2 +{ + Q_DECLARE_PUBLIC(QWaylandTextInput) +public: + explicit QWaylandTextInputPrivate(QWaylandCompositor *compositor); + + void sendInputMethodEvent(QInputMethodEvent *event); + void sendKeyEvent(QKeyEvent *event); + void sendInputPanelState(); + void sendTextDirection(); + void sendLocale(); + + QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const; + + void setFocus(QWaylandSurface *surface); + + QWaylandCompositor *compositor; + + QWaylandSurface *focus; + Resource *focusResource; + QWaylandDestroyListener focusDestroyListener; + + bool inputPanelVisible; + + QScopedPointer<QWaylandTextInputClientState> currentState; + QScopedPointer<QWaylandTextInputClientState> pendingState; + + uint32_t serial; + + QHash<Resource *, QWaylandSurface*> enabledSurfaces; + +protected: + void zwp_text_input_v2_bind_resource(Resource *resource) Q_DECL_OVERRIDE; + void zwp_text_input_v2_destroy_resource(Resource *resource) Q_DECL_OVERRIDE; + + void zwp_text_input_v2_destroy(Resource *resource) Q_DECL_OVERRIDE; + void zwp_text_input_v2_enable(Resource *resource, wl_resource *surface) Q_DECL_OVERRIDE; + void zwp_text_input_v2_disable(Resource *resource, wl_resource *surface) Q_DECL_OVERRIDE; + void zwp_text_input_v2_show_input_panel(Resource *resource) Q_DECL_OVERRIDE; + void zwp_text_input_v2_hide_input_panel(Resource *resource) Q_DECL_OVERRIDE; + void zwp_text_input_v2_set_surrounding_text(Resource *resource, const QString &text, int32_t cursor, int32_t anchor) Q_DECL_OVERRIDE; + void zwp_text_input_v2_set_content_type(Resource *resource, uint32_t hint, uint32_t purpose) Q_DECL_OVERRIDE; + void zwp_text_input_v2_set_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) Q_DECL_OVERRIDE; + void zwp_text_input_v2_set_preferred_language(Resource *resource, const QString &language) Q_DECL_OVERRIDE; + void zwp_text_input_v2_update_state(Resource *resource, uint32_t serial, uint32_t flags) Q_DECL_OVERRIDE; +}; + +QT_END_NAMESPACE + +#endif // QWAYLANDTEXTINPUT_P_H diff --git a/src/compositor/extensions/qwaylandtextinputmanager.cpp b/src/compositor/extensions/qwaylandtextinputmanager.cpp new file mode 100644 index 000000000..62e8ac88c --- /dev/null +++ b/src/compositor/extensions/qwaylandtextinputmanager.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2013-2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWaylandCompositor module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandtextinputmanager.h" +#include "qwaylandtextinputmanager_p.h" + +#include <QtWaylandCompositor/QWaylandCompositor> +#include <QtWaylandCompositor/QWaylandInputDevice> + +#include "qwaylandtextinput.h" + +QT_BEGIN_NAMESPACE + +QWaylandTextInputManagerPrivate::QWaylandTextInputManagerPrivate() + : QWaylandExtensionTemplatePrivate() + , QtWaylandServer::zwp_text_input_manager_v2() +{ +} + +void QWaylandTextInputManagerPrivate::zwp_text_input_manager_v2_get_text_input(Resource *resource, uint32_t id, struct ::wl_resource *seat) +{ + Q_Q(QWaylandTextInputManager); + QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(q->extensionContainer()); + QWaylandInputDevice *inputDevice = QWaylandInputDevice::fromSeatResource(seat); + QWaylandTextInput *textInput = QWaylandTextInput::findIn(inputDevice); + if (!textInput) { + textInput = new QWaylandTextInput(inputDevice, compositor); + } + textInput->add(resource->client(), id, wl_resource_get_version(resource->handle)); +} + +QWaylandTextInputManager::QWaylandTextInputManager() + : QWaylandExtensionTemplate<QWaylandTextInputManager>(*new QWaylandTextInputManagerPrivate) +{ +} + +QWaylandTextInputManager::QWaylandTextInputManager(QWaylandCompositor *compositor) + : QWaylandExtensionTemplate<QWaylandTextInputManager>(compositor, *new QWaylandTextInputManagerPrivate) +{ +} + +void QWaylandTextInputManager::initialize() +{ + Q_D(QWaylandTextInputManager); + + QWaylandExtensionTemplate::initialize(); + QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer()); + if (!compositor) { + qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandTextInputManager"; + return; + } + d->init(compositor->display(), 1); +} + +const wl_interface *QWaylandTextInputManager::interface() +{ + return QWaylandTextInputManagerPrivate::interface(); +} + +QByteArray QWaylandTextInputManager::interfaceName() +{ + return QWaylandTextInputManagerPrivate::interfaceName(); +} + +QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwltextinputmanager.cpp b/src/compositor/extensions/qwaylandtextinputmanager.h index 9c7dd72f4..6c250d58c 100644 --- a/src/compositor/extensions/qwltextinputmanager.cpp +++ b/src/compositor/extensions/qwaylandtextinputmanager.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). +** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWaylandCompositor module of the Qt Toolkit. @@ -34,31 +34,31 @@ ** ****************************************************************************/ -#include "qwltextinputmanager_p.h" +#ifndef QWAYLANDTEXTINPUTMANAGER_H +#define QWAYLANDTEXTINPUTMANAGER_H -#include <QtWaylandCompositor/QWaylandCompositor> -#include "qwltextinput_p.h" +#include <QtWaylandCompositor/QWaylandExtension> + +#include <QtCore/QSize> QT_BEGIN_NAMESPACE -namespace QtWayland { +class QWaylandTextInputManagerPrivate; -TextInputManager::TextInputManager(QWaylandCompositor *compositor) - : QWaylandExtensionTemplate(compositor) - , QtWaylandServer::wl_text_input_manager(compositor->display(), 1) - , m_compositor(compositor) +class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandTextInputManager : public QWaylandExtensionTemplate<QWaylandTextInputManager> { -} + Q_OBJECT + Q_DECLARE_PRIVATE(QWaylandTextInputManager) +public: + QWaylandTextInputManager(); + QWaylandTextInputManager(QWaylandCompositor *compositor); -TextInputManager::~TextInputManager() -{ -} + void initialize() Q_DECL_OVERRIDE; -void TextInputManager::text_input_manager_create_text_input(Resource *resource, uint32_t id) -{ - new TextInput(this, m_compositor, resource->client(), id); -} - -} // namespace QtWayland + static const struct wl_interface *interface(); + static QByteArray interfaceName(); +}; QT_END_NAMESPACE + +#endif // QWAYLANDTEXTINPUTMANAGER_H diff --git a/src/compositor/extensions/qwltextinputmanager_p.h b/src/compositor/extensions/qwaylandtextinputmanager_p.h index 0125bdcae..8052301c9 100644 --- a/src/compositor/extensions/qwltextinputmanager_p.h +++ b/src/compositor/extensions/qwaylandtextinputmanager_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). +** Copyright (C) 2013-2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWaylandCompositor module of the Qt Toolkit. @@ -34,11 +34,12 @@ ** ****************************************************************************/ -#ifndef QTWAYLAND_QWLTEXTINPUTMANAGER_P_H -#define QTWAYLAND_QWLTEXTINPUTMANAGER_P_H +#ifndef QWAYLANDTEXTINPUTMANAGER_P_H +#define QWAYLANDTEXTINPUTMANAGER_P_H -#include <QtWaylandCompositor/QWaylandExtension> -#include <QtWaylandCompositor/private/qwayland-server-text.h> +#include <QtWaylandCompositor/private/qwaylandextension_p.h> + +#include <QtWaylandCompositor/private/qwayland-server-text-input-unstable-v2.h> // // W A R N I N G @@ -53,26 +54,16 @@ QT_BEGIN_NAMESPACE -class QWaylandCompositor; - -namespace QtWayland { - -class TextInputManager : public QWaylandExtensionTemplate<TextInputManager>, public QtWaylandServer::wl_text_input_manager +class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandTextInputManagerPrivate : public QWaylandExtensionTemplatePrivate, public QtWaylandServer::zwp_text_input_manager_v2 { - Q_OBJECT + Q_DECLARE_PUBLIC(QWaylandTextInputManager) public: - TextInputManager(QWaylandCompositor *compositor); - ~TextInputManager(); + QWaylandTextInputManagerPrivate(); protected: - void text_input_manager_create_text_input(Resource *resource, uint32_t id) Q_DECL_OVERRIDE; - -private: - QWaylandCompositor *m_compositor; + void zwp_text_input_manager_v2_get_text_input(Resource *resource, uint32_t id, struct ::wl_resource *seat) Q_DECL_OVERRIDE; }; -} // namespace QtWayland - QT_END_NAMESPACE -#endif // QTWAYLAND_QWLTEXTINPUTMANAGER_P_H +#endif // QWAYLANDTEXTINPUTMANAGER_P_H diff --git a/src/compositor/extensions/qwlinputmethod.cpp b/src/compositor/extensions/qwlinputmethod.cpp deleted file mode 100644 index 6cf23bcb1..000000000 --- a/src/compositor/extensions/qwlinputmethod.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwlinputmethod_p.h" - -#include <QtWaylandCompositor/QWaylandCompositor> -#include <QtWaylandCompositor/QWaylandKeyboard> -#include <QtWaylandCompositor/QWaylandInputDevice> -#include "qwlinputmethodcontext_p.h" -#include "qwlinputpanel_p.h" -#include "qwltextinput_p.h" - -QT_BEGIN_NAMESPACE - -namespace QtWayland { - -InputMethod::InputMethod(QWaylandInputDevice *seat) - : QWaylandExtensionTemplate<InputMethod>(seat) - , QtWaylandServer::wl_input_method(seat->compositor()->display(), 1) - , m_seat(seat) - , m_resource(0) - , m_textInput() - , m_context() -{ - connect(seat->keyboard(), &QWaylandKeyboard::focusChanged, this, &InputMethod::focusChanged); -} - -InputMethod::~InputMethod() -{ -} - -void InputMethod::activate(TextInput *textInput) -{ - if (!m_resource) { - qDebug("Cannot activate (no input method running)."); - return; - } - - if (m_textInput) { - Q_ASSERT(m_textInput != textInput); - m_textInput->deactivate(this); - } - m_textInput = textInput; - m_context = new InputMethodContext(m_resource->client(), textInput); - - send_activate(m_resource->handle, m_context->resource()->handle); - - QWaylandInputPanelPrivate *panel = QWaylandInputPanelPrivate::findIn(compositor()); - if (panel) { - panel->setFocus(textInput->focus()); - panel->setCursorRectangle(textInput->cursorRectangle()); - panel->setInputPanelVisible(textInput->inputPanelVisible()); - } -} - -void InputMethod::deactivate() -{ - if (!m_resource) { - qDebug("Cannot deactivate (no input method running)."); - return; - } - - send_deactivate(m_resource->handle, m_context->resource()->handle); - m_textInput = 0; - m_context = 0; - - QWaylandInputPanelPrivate *panel = QWaylandInputPanelPrivate::findIn(compositor()); - if (panel) { - panel->setFocus(0); - panel->setCursorRectangle(QRect()); - panel->setInputPanelVisible(false); - } -} - -void InputMethod::focusChanged(QWaylandSurface *surface) -{ - if (!m_textInput) - return; - - if (!surface || m_textInput->focus() != surface) { - m_textInput->deactivate(this); - } -} - -bool InputMethod::isBound() const -{ - return m_resource != 0; -} - -InputMethodContext *InputMethod::context() const -{ - return m_context; -} - -TextInput *InputMethod::textInput() const -{ - return m_textInput; -} - -void InputMethod::input_method_bind_resource(Resource *resource) -{ - if (m_resource) { - wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, "interface object already bound"); - wl_resource_destroy(resource->handle); - return; - } - - m_resource = resource; -} - -void InputMethod::input_method_destroy_resource(Resource *resource) -{ - Q_ASSERT(resource == m_resource); - m_resource = 0; -} - -} // namespace QtWayland - -QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwlinputmethod_p.h b/src/compositor/extensions/qwlinputmethod_p.h deleted file mode 100644 index 69348df6c..000000000 --- a/src/compositor/extensions/qwlinputmethod_p.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTWAYLAND_QWLINPUTMETHOD_H -#define QTWAYLAND_QWLINPUTMETHOD_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtWaylandCompositor/private/qwayland-server-input-method.h> -#include <QtWaylandCompositor/QWaylandExtension> -#include <QtWaylandCompositor/QWaylandInputDevice> - -#include <QObject> -#include <QScopedPointer> - -#include <QtWaylandCompositor/QWaylandSurface> - -QT_BEGIN_NAMESPACE - -class QWaylandInputDevice; -class QWaylandCompositor; - -namespace QtWayland { - -class InputMethodContext; -class TextInput; - -class InputMethod : public QWaylandExtensionTemplate<InputMethod> , public QtWaylandServer::wl_input_method -{ - Q_OBJECT -public: - explicit InputMethod(QWaylandInputDevice *seat); - ~InputMethod(); - - QWaylandCompositor *compositor() const { return m_seat->compositor(); } - - void activate(TextInput *textInput); - void deactivate(); - - bool isBound() const; - - InputMethodContext *context() const; - TextInput *textInput() const; - -protected: - void input_method_bind_resource(Resource *resource); - void input_method_destroy_resource(Resource *resource); - -private Q_SLOTS: - void focusChanged(QWaylandSurface *surface); - -private: - QWaylandInputDevice *m_seat; - Resource *m_resource; - TextInput *m_textInput; - InputMethodContext *m_context; -}; - -} // namespace QtWayland - -QT_END_NAMESPACE - -#endif // QTWAYLAND_QWLINPUTMETHOD_H diff --git a/src/compositor/extensions/qwlinputmethodcontext.cpp b/src/compositor/extensions/qwlinputmethodcontext.cpp deleted file mode 100644 index 6421d5e76..000000000 --- a/src/compositor/extensions/qwlinputmethodcontext.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwlinputmethodcontext_p.h" - -#include "qwltextinput_p.h" - -QT_BEGIN_NAMESPACE - -namespace QtWayland { - -InputMethodContext::InputMethodContext(wl_client *client, TextInput *textInput) - : QtWaylandServer::wl_input_method_context(client, 0, 1) - , m_textInput(textInput) -{ -} - -InputMethodContext::~InputMethodContext() -{ -} - -void InputMethodContext::input_method_context_destroy_resource(Resource *) -{ - delete this; -} - -void InputMethodContext::input_method_context_destroy(Resource *resource) -{ - wl_resource_destroy(resource->handle); -} - -void InputMethodContext::input_method_context_commit_string(Resource *, uint32_t serial, const QString &text) -{ - m_textInput->send_commit_string(serial, text); -} - -void InputMethodContext::input_method_context_cursor_position(Resource *, int32_t index, int32_t anchor) -{ - m_textInput->send_cursor_position(index, anchor); -} - -void InputMethodContext::input_method_context_delete_surrounding_text(Resource *, int32_t index, uint32_t length) -{ - m_textInput->send_delete_surrounding_text(index, length); -} - -void InputMethodContext::input_method_context_language(Resource *, uint32_t serial, const QString &language) -{ - m_textInput->send_language(serial, language); -} - -void InputMethodContext::input_method_context_keysym(Resource *, uint32_t serial, uint32_t time, uint32_t sym, uint32_t state, uint32_t modifiers) -{ - m_textInput->send_keysym(serial, time, sym, state, modifiers); -} - -void InputMethodContext::input_method_context_modifiers_map(Resource *, wl_array *map) -{ - QByteArray modifiersArray(static_cast<char *>(map->data), map->size); - m_textInput->send_modifiers_map(modifiersArray); -} - -void InputMethodContext::input_method_context_preedit_cursor(Resource *, int32_t index) -{ - m_textInput->send_preedit_cursor(index); -} - -void InputMethodContext::input_method_context_preedit_string(Resource *, uint32_t serial, const QString &text, const QString &commit) -{ - m_textInput->send_preedit_string(serial, text, commit); -} - -void InputMethodContext::input_method_context_preedit_styling(Resource *, uint32_t index, uint32_t length, uint32_t style) -{ - m_textInput->send_preedit_styling(index, length, style); -} - -void InputMethodContext::input_method_context_grab_keyboard(Resource *, uint32_t keyboard) -{ - Q_UNUSED(keyboard); -} - -void InputMethodContext::input_method_context_key(Resource *, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) -{ - Q_UNUSED(serial); - Q_UNUSED(time); - Q_UNUSED(key); - Q_UNUSED(state); -} - -void InputMethodContext::input_method_context_modifiers(Resource *, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) -{ - Q_UNUSED(serial); - Q_UNUSED(mods_depressed); - Q_UNUSED(mods_latched); - Q_UNUSED(mods_locked); - Q_UNUSED(group); -} - -} // namespace QtWayland - -QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwlinputmethodcontext_p.h b/src/compositor/extensions/qwlinputmethodcontext_p.h deleted file mode 100644 index febadc957..000000000 --- a/src/compositor/extensions/qwlinputmethodcontext_p.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTWAYLAND_QWLINPUTMETHODCONTEXT_P_H -#define QTWAYLAND_QWLINPUTMETHODCONTEXT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtWaylandCompositor/private/qwayland-server-input-method.h> - -QT_BEGIN_NAMESPACE - -namespace QtWayland { - -class TextInput; - -class InputMethodContext : public QtWaylandServer::wl_input_method_context -{ -public: - explicit InputMethodContext(struct ::wl_client *client, TextInput *textInput); - ~InputMethodContext(); - -protected: - void input_method_context_destroy_resource(Resource *resource) Q_DECL_OVERRIDE; - void input_method_context_destroy(Resource *resource) Q_DECL_OVERRIDE; - - void input_method_context_commit_string(Resource *resource, uint32_t serial, const QString &text) Q_DECL_OVERRIDE; - void input_method_context_cursor_position(Resource *resource, int32_t index, int32_t anchor) Q_DECL_OVERRIDE; - void input_method_context_delete_surrounding_text(Resource *resource, int32_t index, uint32_t length) Q_DECL_OVERRIDE; - void input_method_context_language(Resource *resource, uint32_t serial, const QString &language) Q_DECL_OVERRIDE; - void input_method_context_keysym(Resource *resource, uint32_t serial, uint32_t time, uint32_t sym, uint32_t state, uint32_t modifiers) Q_DECL_OVERRIDE; - void input_method_context_modifiers_map(Resource *resource, wl_array *map) Q_DECL_OVERRIDE; - void input_method_context_preedit_cursor(Resource *resource, int32_t index) Q_DECL_OVERRIDE; - void input_method_context_preedit_string(Resource *resource, uint32_t serial, const QString &text, const QString &commit) Q_DECL_OVERRIDE; - void input_method_context_preedit_styling(Resource *resource, uint32_t index, uint32_t length, uint32_t style) Q_DECL_OVERRIDE; - void input_method_context_grab_keyboard(Resource *resource, uint32_t keyboard) Q_DECL_OVERRIDE; - void input_method_context_key(Resource *resource, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) Q_DECL_OVERRIDE; - void input_method_context_modifiers(Resource *resource, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) Q_DECL_OVERRIDE; - -private: - TextInput *m_textInput; -}; - -} // namespace QtWayland - -QT_END_NAMESPACE - -#endif // QTWAYLAND_QWLINPUTMETHODCONTEXT_P_H diff --git a/src/compositor/extensions/qwlinputpanel.cpp b/src/compositor/extensions/qwlinputpanel.cpp deleted file mode 100644 index 8f41f0ca3..000000000 --- a/src/compositor/extensions/qwlinputpanel.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwlinputpanel_p.h" - -#include <QtWaylandCompositor/qwaylandinputpanel.h> -#include <QtWaylandCompositor/QWaylandCompositor> - -#include "qwlinputmethod_p.h" -#include "qwlinputpanelsurface_p.h" -#include "qwltextinput_p.h" - -QT_BEGIN_NAMESPACE - -QWaylandInputPanelPrivate::QWaylandInputPanelPrivate(QWaylandCompositor *compositor) - : QWaylandExtensionTemplatePrivate() - , QtWaylandServer::wl_input_panel() - , m_compositor(compositor) - , m_focus() - , m_inputPanelVisible(false) - , m_cursorRectangle() -{ - init(compositor->display(), 1); -} - -QWaylandInputPanelPrivate::~QWaylandInputPanelPrivate() -{ -} - -QWaylandInputPanel *QWaylandInputPanelPrivate::waylandInputPanel() const -{ - QWaylandInputPanel *panel = const_cast<QWaylandInputPanel *>(q_func()); - return panel; -} - -QWaylandSurface *QWaylandInputPanelPrivate::focus() const -{ - return m_focus; -} - -void QWaylandInputPanelPrivate::setFocus(QWaylandSurface *focus) -{ - Q_Q(QWaylandInputPanel); - if (m_focus == focus) - return; - - m_focus = focus; - - Q_EMIT q->focusChanged(); -} - -bool QWaylandInputPanelPrivate::inputPanelVisible() const -{ - return m_inputPanelVisible; -} - -void QWaylandInputPanelPrivate::setInputPanelVisible(bool inputPanelVisible) -{ - Q_Q(QWaylandInputPanel); - if (m_inputPanelVisible == inputPanelVisible) - return; - - m_inputPanelVisible = inputPanelVisible; - - q->visibleChanged(); -} - -QRect QWaylandInputPanelPrivate::cursorRectangle() const -{ - return m_cursorRectangle; -} - -void QWaylandInputPanelPrivate::setCursorRectangle(const QRect &cursorRectangle) -{ - Q_Q(QWaylandInputPanel); - if (m_cursorRectangle == cursorRectangle) - return; - - m_cursorRectangle = cursorRectangle; - - Q_EMIT q->cursorRectangleChanged(); -} - -QWaylandInputPanelPrivate *QWaylandInputPanelPrivate::findIn(QWaylandObject *container) -{ - QWaylandInputPanel *panel = QWaylandInputPanel::findIn(container); - if (!panel) - return Q_NULLPTR; - return panel->d_func(); -} - -void QWaylandInputPanelPrivate::input_panel_get_input_panel_surface(Resource *resource, uint32_t id, wl_resource *surface) -{ - new QtWayland::InputPanelSurface(resource->client(), id, QWaylandSurface::fromResource(surface)); -} - -QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwlinputpanel_p.h b/src/compositor/extensions/qwlinputpanel_p.h deleted file mode 100644 index 97720f050..000000000 --- a/src/compositor/extensions/qwlinputpanel_p.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTWAYLAND_QWLINPUTPANEL_P_H -#define QTWAYLAND_QWLINPUTPANEL_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtWaylandCompositor/qwaylandexport.h> -#include <QtWaylandCompositor/qwaylandinputpanel.h> - -#include <QtWaylandCompositor/private/qwaylandextension_p.h> -#include <QtWaylandCompositor/private/qwayland-server-input-method.h> - -#include <QRect> -#include <QScopedPointer> - -QT_BEGIN_NAMESPACE - -namespace QtWayland { -class TextInput; -} - - -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandInputPanelPrivate : public QWaylandExtensionTemplatePrivate, public QtWaylandServer::wl_input_panel -{ - Q_DECLARE_PUBLIC(QWaylandInputPanel) -public: - QWaylandInputPanelPrivate(QWaylandCompositor *compositor); - ~QWaylandInputPanelPrivate(); - - QWaylandInputPanel *waylandInputPanel() const; - - QWaylandSurface *focus() const; - void setFocus(QWaylandSurface *focus); - - bool inputPanelVisible() const; - void setInputPanelVisible(bool inputPanelVisible); - - QRect cursorRectangle() const; - void setCursorRectangle(const QRect &cursorRectangle); - - static QWaylandInputPanelPrivate *findIn(QWaylandObject *container); -protected: - void input_panel_get_input_panel_surface(Resource *resource, uint32_t id, struct ::wl_resource *surface) Q_DECL_OVERRIDE; - -private: - QWaylandCompositor *m_compositor; - - QWaylandSurface *m_focus; - bool m_inputPanelVisible; - QRect m_cursorRectangle; -}; - -QT_END_NAMESPACE - -#endif // QTWAYLAND_QWLINPUTPANEL_P_H diff --git a/src/compositor/extensions/qwlinputpanelsurface.cpp b/src/compositor/extensions/qwlinputpanelsurface.cpp deleted file mode 100644 index c54520aad..000000000 --- a/src/compositor/extensions/qwlinputpanelsurface.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwlinputpanelsurface_p.h" - -#include <QtWaylandCompositor/private/qwaylandsurface_p.h> -#include <QtWaylandCompositor/QWaylandOutput> - -QT_BEGIN_NAMESPACE - -namespace QtWayland { - -InputPanelSurface::InputPanelSurface(wl_client *client, int id, QWaylandSurface *surface) - : QtWaylandServer::wl_input_panel_surface(client, id, 1) - , m_surface(surface) - , m_type(Invalid) - , m_output(0) - , m_position() -{ - QWaylandSurfacePrivate::get(surface)->setInputPanelSurface(this); -} - -InputPanelSurface::Type InputPanelSurface::type() const -{ - return m_type; -} - -QWaylandOutput *InputPanelSurface::output() const -{ - return m_output; -} - -QtWaylandServer::wl_input_panel_surface::position InputPanelSurface::position() const -{ - return m_position; -} - -void InputPanelSurface::input_panel_surface_set_overlay_panel(Resource *) -{ - m_type = OverlayPanel; -} - -void InputPanelSurface::input_panel_surface_set_toplevel(Resource *, wl_resource *output_resource, uint32_t position) -{ - m_type = Toplevel; - m_output = QWaylandOutput::fromResource(output_resource); - m_position = static_cast<wl_input_panel_surface::position>(position); -} - -QT_END_NAMESPACE - -} // namespace QtWayland diff --git a/src/compositor/extensions/qwltextinput.cpp b/src/compositor/extensions/qwltextinput.cpp deleted file mode 100644 index 7546ab6a0..000000000 --- a/src/compositor/extensions/qwltextinput.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwltextinput_p.h" - -#include "qwlinputmethod_p.h" -#include "qwlinputmethodcontext_p.h" -#include "qwlinputpanel_p.h" -#include <QtWaylandCompositor/QWaylandInputPanel> -#include <QtWaylandCompositor/QWaylandCompositor> -#include <QtWaylandCompositor/private/qwaylandinput_p.h> - -#include <algorithm> - -QT_BEGIN_NAMESPACE - -namespace QtWayland { - -TextInput::TextInput(QWaylandObject *container, QWaylandCompositor *compositor, struct ::wl_client *client, int id) - : QWaylandExtensionTemplate(container) - , wl_text_input(client, id, 1) - , m_compositor(compositor) - , m_focus() - , m_inputPanelVisible() - , m_cursorRectangle() -{ -} - -QWaylandSurface *TextInput::focus() const -{ - return m_focus; -} - -bool TextInput::inputPanelVisible() const -{ - return m_inputPanelVisible; -} - -QRect TextInput::cursorRectangle() const -{ - return m_cursorRectangle; -} - -void TextInput::deactivate(InputMethod *inputMethod) -{ - if (m_activeInputMethods.removeOne(inputMethod)) - inputMethod->deactivate(); - - if (m_activeInputMethods.isEmpty()) - send_leave(); -} - -void TextInput::text_input_destroy_resource(Resource *) -{ - Q_FOREACH (InputMethod *inputMethod, m_activeInputMethods) { - deactivate(inputMethod); - } - - delete this; -} - -void TextInput::text_input_activate(Resource *, wl_resource *seat, wl_resource *surface) -{ - QWaylandSurface *oldSurface = m_focus; - m_focus = QWaylandSurface::fromResource(surface); - - if (oldSurface != m_focus) - send_leave(); - - bool wasEmpty = m_activeInputMethods.isEmpty(); - - InputMethod *inputMethod = InputMethod::findIn(QWaylandInputDevice::fromSeatResource(seat)); - - if (inputMethod && !m_activeInputMethods.contains(inputMethod)) { - m_activeInputMethods.append(inputMethod); - inputMethod->activate(this); - } - - if (wasEmpty || oldSurface != m_focus) - send_enter(surface); -} - -void TextInput::text_input_deactivate(Resource *, wl_resource *seat) -{ - InputMethod *inputMethod = InputMethod::findIn(QWaylandInputDevice::fromSeatResource(seat)); - - if (inputMethod) - deactivate(inputMethod); -} - -static bool isInputMethodBound(InputMethod *inputMethod) -{ - return inputMethod->isBound(); -} - -void TextInput::text_input_show_input_panel(Resource *) -{ - m_inputPanelVisible = true; - - if (std::find_if(m_activeInputMethods.cbegin(), m_activeInputMethods.cend(), isInputMethodBound) != m_activeInputMethods.cend()){ - QWaylandInputPanelPrivate *panel = QWaylandInputPanelPrivate::findIn(m_compositor); - if (panel) - panel->setInputPanelVisible(true); - } -} - -void TextInput::text_input_hide_input_panel(Resource *) -{ - m_inputPanelVisible = false; - - if (std::find_if(m_activeInputMethods.cbegin(), m_activeInputMethods.cend(), isInputMethodBound) != m_activeInputMethods.cend()) { - QWaylandInputPanelPrivate *panel = QWaylandInputPanelPrivate::findIn(m_compositor); - if (panel) - panel->setInputPanelVisible(false); - } -} - -void TextInput::text_input_set_cursor_rectangle(Resource *, int32_t x, int32_t y, int32_t width, int32_t height) -{ - m_cursorRectangle = QRect(x, y, width, height); - - if (!m_activeInputMethods.isEmpty()) { - QWaylandInputPanelPrivate *panel = QWaylandInputPanelPrivate::findIn(m_compositor); - if (panel) - panel->setCursorRectangle(m_cursorRectangle); - } -} - -void TextInput::text_input_reset(Resource *) -{ - Q_FOREACH (InputMethod *inputMethod, m_activeInputMethods) { - if (inputMethod->context()) - inputMethod->context()->send_reset(); - } -} - -void TextInput::text_input_commit_state(Resource *, uint32_t serial) -{ - Q_FOREACH (InputMethod *inputMethod, m_activeInputMethods) { - if (inputMethod->context()) - inputMethod->context()->send_commit_state(serial); - } -} - -void TextInput::text_input_set_content_type(Resource *, uint32_t hint, uint32_t purpose) -{ - Q_FOREACH (InputMethod *inputMethod, m_activeInputMethods) { - if (inputMethod->context()) - inputMethod->context()->send_content_type(hint, purpose); - } -} - -void TextInput::text_input_set_preferred_language(Resource *, const QString &language) -{ - Q_FOREACH (InputMethod *inputMethod, m_activeInputMethods) { - if (inputMethod->context()) - inputMethod->context()->send_preferred_language(language); - } -} - -void TextInput::text_input_set_surrounding_text(Resource *, const QString &text, uint32_t cursor, uint32_t anchor) -{ - Q_FOREACH (InputMethod *inputMethod, m_activeInputMethods) { - if (inputMethod->context()) - inputMethod->context()->send_surrounding_text(text, cursor, anchor); - } -} - -void TextInput::text_input_invoke_action(Resource *, uint32_t button, uint32_t index) -{ - Q_FOREACH (InputMethod *inputMethod, m_activeInputMethods) { - if (inputMethod->context()) - inputMethod->context()->send_invoke_action(button, index); - } -} - -} // namespace QtWayland - -QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwltextinput_p.h b/src/compositor/extensions/qwltextinput_p.h deleted file mode 100644 index 02adc5cae..000000000 --- a/src/compositor/extensions/qwltextinput_p.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Klarälvdalens Datakonsult AB (KDAB). -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTWAYLAND_QWLTEXTINPUT_P_H -#define QTWAYLAND_QWLTEXTINPUT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtWaylandCompositor/QWaylandExtension> -#include <QtWaylandCompositor/private/qwayland-server-text.h> - -#include <QRect> - -QT_BEGIN_NAMESPACE - -class QWaylandSurface; -class QWaylandCompositor; - -namespace QtWayland { - -class InputMethod; - -class TextInput : public QWaylandExtensionTemplate<TextInput>, public QtWaylandServer::wl_text_input -{ -public: - explicit TextInput(QWaylandObject *container, QWaylandCompositor *compositor, struct ::wl_client *client, int id); - - QWaylandSurface *focus() const; - - bool inputPanelVisible() const; - QRect cursorRectangle() const; - - void deactivate(InputMethod *inputMethod); - -protected: - void text_input_destroy_resource(Resource *resource) Q_DECL_OVERRIDE; - - void text_input_activate(Resource *resource, wl_resource *seat, wl_resource *surface) Q_DECL_OVERRIDE; - void text_input_deactivate(Resource *resource, wl_resource *seat) Q_DECL_OVERRIDE; - void text_input_show_input_panel(Resource *resource) Q_DECL_OVERRIDE; - void text_input_hide_input_panel(Resource *resource) Q_DECL_OVERRIDE; - void text_input_reset(Resource *resource) Q_DECL_OVERRIDE; - void text_input_commit_state(Resource *resource, uint32_t serial) Q_DECL_OVERRIDE; - void text_input_set_content_type(Resource *resource, uint32_t hint, uint32_t purpose) Q_DECL_OVERRIDE; - void text_input_set_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) Q_DECL_OVERRIDE; - void text_input_set_preferred_language(Resource *resource, const QString &language) Q_DECL_OVERRIDE; - void text_input_set_surrounding_text(Resource *resource, const QString &text, uint32_t cursor, uint32_t anchor) Q_DECL_OVERRIDE; - void text_input_invoke_action(Resource *resource, uint32_t button, uint32_t index) Q_DECL_OVERRIDE; - -private: - QWaylandCompositor *m_compositor; - QList<InputMethod*> m_activeInputMethods; - QWaylandSurface *m_focus; - - bool m_inputPanelVisible; - QRect m_cursorRectangle; - -}; - -} // namespace QtWayland - -QT_END_NAMESPACE - -#endif // QTWAYLAND_QWLTEXTINPUT_P_H |