2020-07-23 14:36:01 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "inputmethod_v1_interface.h"
|
|
|
|
#include "display.h"
|
2021-05-31 18:14:58 +00:00
|
|
|
#include "keyboard_interface.h"
|
|
|
|
#include "keyboard_interface_p.h"
|
2020-07-23 14:36:01 +00:00
|
|
|
#include "output_interface.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "seat_interface.h"
|
|
|
|
#include "surface_interface.h"
|
2020-07-23 14:36:01 +00:00
|
|
|
#include "surfacerole_p.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "utils/common.h"
|
2022-08-16 15:31:41 +00:00
|
|
|
#include "utils/ramfile.h"
|
2020-07-23 14:36:01 +00:00
|
|
|
|
|
|
|
#include <QHash>
|
2021-05-31 18:14:58 +00:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2020-08-31 14:53:44 +00:00
|
|
|
|
2020-07-23 14:36:01 +00:00
|
|
|
#include "qwayland-server-input-method-unstable-v1.h"
|
2020-08-31 14:53:44 +00:00
|
|
|
#include "qwayland-server-text-input-unstable-v1.h"
|
2021-05-31 18:14:58 +00:00
|
|
|
#include "qwayland-server-wayland.h"
|
2020-07-23 14:36:01 +00:00
|
|
|
|
|
|
|
namespace KWaylandServer
|
|
|
|
{
|
|
|
|
static int s_version = 1;
|
|
|
|
|
2021-05-31 18:14:58 +00:00
|
|
|
class InputKeyboardV1InterfacePrivate : public QtWaylandServer::wl_keyboard
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InputKeyboardV1InterfacePrivate()
|
2021-08-29 05:11:06 +00:00
|
|
|
{
|
|
|
|
}
|
2021-05-31 18:14:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
InputMethodGrabV1::InputMethodGrabV1(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, d(new InputKeyboardV1InterfacePrivate)
|
2021-08-29 05:11:06 +00:00
|
|
|
{
|
|
|
|
}
|
2021-05-31 18:14:58 +00:00
|
|
|
|
|
|
|
InputMethodGrabV1::~InputMethodGrabV1()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputMethodGrabV1::sendKeymap(const QByteArray &keymap)
|
|
|
|
{
|
2022-08-16 15:31:41 +00:00
|
|
|
KWin::RamFile keymapFile("kwin-xkb-input-method-grab-keymap", keymap.constData(), keymap.size() + 1); // include QByteArray null terminator
|
2021-05-31 18:14:58 +00:00
|
|
|
|
|
|
|
const auto resources = d->resourceMap();
|
|
|
|
for (auto r : resources) {
|
2022-08-16 15:31:41 +00:00
|
|
|
d->send_keymap(r->handle, QtWaylandServer::wl_keyboard::keymap_format::keymap_format_xkb_v1, keymapFile.fd(), keymapFile.size());
|
2021-05-31 18:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputMethodGrabV1::sendKey(quint32 serial, quint32 timestamp, quint32 key, KeyboardKeyState state)
|
|
|
|
{
|
|
|
|
const auto resources = d->resourceMap();
|
|
|
|
for (auto r : resources) {
|
|
|
|
d->send_key(r->handle, serial, timestamp, key, quint32(state));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputMethodGrabV1::sendModifiers(quint32 serial, quint32 depressed, quint32 latched, quint32 locked, quint32 group)
|
|
|
|
{
|
|
|
|
const auto resources = d->resourceMap();
|
|
|
|
for (auto r : resources) {
|
2021-12-13 07:49:44 +00:00
|
|
|
d->send_modifiers(r->handle, serial, depressed, latched, locked, group);
|
2021-05-31 18:14:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 14:36:01 +00:00
|
|
|
class InputMethodContextV1InterfacePrivate : public QtWaylandServer::zwp_input_method_context_v1
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InputMethodContextV1InterfacePrivate(InputMethodContextV1Interface *q)
|
|
|
|
: zwp_input_method_context_v1()
|
|
|
|
, q(q)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
~InputMethodContextV1InterfacePrivate()
|
|
|
|
{
|
|
|
|
}
|
2021-05-31 18:14:58 +00:00
|
|
|
|
2020-07-23 14:36:01 +00:00
|
|
|
void zwp_input_method_context_v1_commit_string(Resource *, uint32_t serial, const QString &text) override
|
|
|
|
{
|
|
|
|
Q_EMIT q->commitString(serial, text);
|
|
|
|
}
|
|
|
|
void zwp_input_method_context_v1_preedit_string(Resource *, uint32_t serial, const QString &text, const QString &commit) override
|
|
|
|
{
|
|
|
|
Q_EMIT q->preeditString(serial, text, commit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void zwp_input_method_context_v1_preedit_styling(Resource *, uint32_t index, uint32_t length, uint32_t style) override
|
|
|
|
{
|
|
|
|
Q_EMIT q->preeditStyling(index, length, style);
|
|
|
|
}
|
|
|
|
void zwp_input_method_context_v1_preedit_cursor(Resource *, int32_t index) override
|
|
|
|
{
|
|
|
|
Q_EMIT q->preeditCursor(index);
|
|
|
|
}
|
|
|
|
void zwp_input_method_context_v1_delete_surrounding_text(Resource *, int32_t index, uint32_t length) override
|
|
|
|
{
|
|
|
|
Q_EMIT q->deleteSurroundingText(index, length);
|
|
|
|
}
|
|
|
|
void zwp_input_method_context_v1_cursor_position(Resource *, int32_t index, int32_t anchor) override
|
|
|
|
{
|
|
|
|
Q_EMIT q->cursorPosition(index, anchor);
|
|
|
|
}
|
|
|
|
void zwp_input_method_context_v1_modifiers_map(Resource *, wl_array *map) override
|
|
|
|
{
|
2021-09-30 20:36:43 +00:00
|
|
|
const auto mods = QByteArray::fromRawData(static_cast<const char *>(map->data), map->size);
|
|
|
|
|
|
|
|
Q_EMIT q->modifiersMap(mods);
|
2020-07-23 14:36:01 +00:00
|
|
|
}
|
|
|
|
void zwp_input_method_context_v1_keysym(Resource *, uint32_t serial, uint32_t time, uint32_t sym, uint32_t state, uint32_t modifiers) override
|
|
|
|
{
|
2021-09-30 20:36:43 +00:00
|
|
|
Q_EMIT q->keysym(serial, time, sym, state == WL_KEYBOARD_KEY_STATE_PRESSED, modifiers);
|
2020-07-23 14:36:01 +00:00
|
|
|
}
|
2021-05-31 18:14:58 +00:00
|
|
|
void zwp_input_method_context_v1_grab_keyboard(Resource *resource, uint32_t id) override
|
2020-07-23 14:36:01 +00:00
|
|
|
{
|
2021-05-31 18:14:58 +00:00
|
|
|
m_keyboardGrab.reset(new InputMethodGrabV1(q));
|
|
|
|
m_keyboardGrab->d->add(resource->client(), id, 1);
|
2022-08-01 21:29:02 +00:00
|
|
|
Q_EMIT q->keyboardGrabRequested(m_keyboardGrab.get());
|
2020-07-23 14:36:01 +00:00
|
|
|
}
|
|
|
|
void zwp_input_method_context_v1_key(Resource *, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) override
|
|
|
|
{
|
|
|
|
Q_EMIT q->key(serial, time, key, state == WL_KEYBOARD_KEY_STATE_PRESSED);
|
|
|
|
}
|
2021-08-29 05:11:06 +00:00
|
|
|
void zwp_input_method_context_v1_modifiers(Resource *,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t mods_depressed,
|
|
|
|
uint32_t mods_latched,
|
|
|
|
uint32_t mods_locked,
|
|
|
|
uint32_t group) override
|
2020-07-23 14:36:01 +00:00
|
|
|
{
|
2020-10-15 04:56:01 +00:00
|
|
|
Q_EMIT q->modifiers(serial, mods_depressed, mods_latched, mods_locked, group);
|
2020-07-23 14:36:01 +00:00
|
|
|
}
|
|
|
|
void zwp_input_method_context_v1_language(Resource *, uint32_t serial, const QString &language) override
|
|
|
|
{
|
|
|
|
Q_EMIT q->language(serial, language);
|
|
|
|
}
|
|
|
|
void zwp_input_method_context_v1_text_direction(Resource *, uint32_t serial, uint32_t direction) override
|
|
|
|
{
|
|
|
|
Qt::LayoutDirection qtDirection;
|
|
|
|
switch (direction) {
|
2020-07-28 15:39:13 +00:00
|
|
|
case ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_LTR:
|
2020-07-23 14:36:01 +00:00
|
|
|
qtDirection = Qt::LeftToRight;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_RTL:
|
2020-07-23 14:36:01 +00:00
|
|
|
qtDirection = Qt::RightToLeft;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case ZWP_TEXT_INPUT_V1_TEXT_DIRECTION_AUTO:
|
2020-07-23 14:36:01 +00:00
|
|
|
qtDirection = Qt::LayoutDirectionAuto;
|
|
|
|
break;
|
2021-09-01 17:26:46 +00:00
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
break;
|
2020-07-23 14:36:01 +00:00
|
|
|
}
|
|
|
|
Q_EMIT q->textDirection(serial, qtDirection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void zwp_input_method_context_v1_destroy(Resource *resource) override
|
|
|
|
{
|
|
|
|
wl_resource_destroy(resource->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
InputMethodContextV1Interface *const q;
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<InputMethodGrabV1> m_keyboardGrab;
|
2020-07-23 14:36:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
InputMethodContextV1Interface::InputMethodContextV1Interface(InputMethodV1Interface *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, d(new InputMethodContextV1InterfacePrivate(this))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InputMethodContextV1Interface::~InputMethodContextV1Interface() = default;
|
|
|
|
|
|
|
|
void InputMethodContextV1Interface::sendCommitState(uint32_t serial)
|
|
|
|
{
|
|
|
|
for (auto r : d->resourceMap()) {
|
|
|
|
d->send_commit_state(r->handle, serial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-28 15:39:13 +00:00
|
|
|
void InputMethodContextV1Interface::sendContentType(TextInputContentHints hint, TextInputContentPurpose purpose)
|
2020-07-23 14:36:01 +00:00
|
|
|
{
|
2020-08-31 14:53:44 +00:00
|
|
|
quint32 contentHint = QtWaylandServer::zwp_text_input_v1::content_hint_none;
|
|
|
|
quint32 contentPurpose;
|
|
|
|
|
2020-07-28 15:39:13 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::AutoCapitalization)) {
|
2020-08-31 14:53:44 +00:00
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_auto_capitalization;
|
|
|
|
}
|
2020-07-28 15:39:13 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::AutoCorrection)) {
|
2020-08-31 14:53:44 +00:00
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_auto_correction;
|
|
|
|
}
|
2021-05-21 17:16:57 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::AutoCompletion)) {
|
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_auto_completion;
|
2020-08-31 14:53:44 +00:00
|
|
|
}
|
2020-07-28 15:39:13 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::LowerCase)) {
|
2020-08-31 14:53:44 +00:00
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_lowercase;
|
|
|
|
}
|
2020-07-28 15:39:13 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::UpperCase)) {
|
2020-08-31 14:53:44 +00:00
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_uppercase;
|
|
|
|
}
|
2020-07-28 15:39:13 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::TitleCase)) {
|
2020-08-31 14:53:44 +00:00
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_titlecase;
|
|
|
|
}
|
2020-07-28 15:39:13 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::HiddenText)) {
|
2020-08-31 14:53:44 +00:00
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_hidden_text;
|
|
|
|
}
|
2020-07-28 15:39:13 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::SensitiveData)) {
|
2020-08-31 14:53:44 +00:00
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_lowercase;
|
|
|
|
}
|
2020-07-28 15:39:13 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::Latin)) {
|
2020-08-31 14:53:44 +00:00
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_latin;
|
|
|
|
}
|
2020-07-28 15:39:13 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::MultiLine)) {
|
2020-08-31 14:53:44 +00:00
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_multiline;
|
|
|
|
}
|
2020-07-28 15:39:13 +00:00
|
|
|
if (hint.testFlag(TextInputContentHint::None)) {
|
2020-08-31 14:53:44 +00:00
|
|
|
contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_none;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (purpose) {
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Alpha:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_alpha;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Digits:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_digits;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Number:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_number;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Phone:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_phone;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Url:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_url;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Email:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_email;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Name:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_name;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Password:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_password;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Date:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_date;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Time:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_time;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::DateTime:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_datetime;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Terminal:
|
2020-08-31 14:53:44 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_terminal;
|
|
|
|
break;
|
2020-07-28 15:39:13 +00:00
|
|
|
case TextInputContentPurpose::Normal:
|
2020-08-31 14:53:44 +00:00
|
|
|
default:
|
2021-05-21 18:27:19 +00:00
|
|
|
contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_normal;
|
2020-08-31 14:53:44 +00:00
|
|
|
}
|
2020-07-28 15:39:13 +00:00
|
|
|
|
2020-07-23 14:36:01 +00:00
|
|
|
for (auto r : d->resourceMap()) {
|
2020-08-31 14:53:44 +00:00
|
|
|
d->send_content_type(r->handle, contentHint, contentPurpose);
|
2020-07-23 14:36:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputMethodContextV1Interface::sendInvokeAction(uint32_t button, uint32_t index)
|
|
|
|
{
|
|
|
|
for (auto r : d->resourceMap()) {
|
|
|
|
d->send_invoke_action(r->handle, button, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputMethodContextV1Interface::sendPreferredLanguage(const QString &language)
|
|
|
|
{
|
|
|
|
for (auto r : d->resourceMap()) {
|
|
|
|
d->send_preferred_language(r->handle, language);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputMethodContextV1Interface::sendReset()
|
|
|
|
{
|
|
|
|
for (auto r : d->resourceMap()) {
|
|
|
|
d->send_reset(r->handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputMethodContextV1Interface::sendSurroundingText(const QString &text, uint32_t cursor, uint32_t anchor)
|
|
|
|
{
|
|
|
|
for (auto r : d->resourceMap()) {
|
|
|
|
d->send_surrounding_text(r->handle, text, cursor, anchor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 18:14:58 +00:00
|
|
|
InputMethodGrabV1 *InputMethodContextV1Interface::keyboardGrab() const
|
|
|
|
{
|
|
|
|
return d->m_keyboardGrab.get();
|
|
|
|
}
|
|
|
|
|
2020-07-23 14:36:01 +00:00
|
|
|
class InputPanelSurfaceV1InterfacePrivate : public QtWaylandServer::zwp_input_panel_surface_v1, public SurfaceRole
|
|
|
|
{
|
|
|
|
friend class InputPanelSurfaceV1Interface;
|
2021-08-29 05:11:06 +00:00
|
|
|
|
2020-07-23 14:36:01 +00:00
|
|
|
public:
|
|
|
|
InputPanelSurfaceV1InterfacePrivate(SurfaceInterface *surface, quint32 id, InputPanelSurfaceV1Interface *q)
|
|
|
|
: zwp_input_panel_surface_v1()
|
2020-10-30 18:40:14 +00:00
|
|
|
, SurfaceRole(surface, QByteArrayLiteral("input_panel_surface_v1"))
|
2020-07-23 14:36:01 +00:00
|
|
|
, q(q)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void zwp_input_panel_surface_v1_set_overlay_panel(Resource *) override
|
|
|
|
{
|
|
|
|
Q_EMIT q->overlayPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void zwp_input_panel_surface_v1_set_toplevel(Resource *, struct ::wl_resource *output, uint32_t position) override
|
|
|
|
{
|
|
|
|
Q_EMIT q->topLevel(OutputInterface::get(output), InputPanelSurfaceV1Interface::Position(position));
|
|
|
|
}
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
void commit() override
|
|
|
|
{
|
|
|
|
}
|
2020-07-23 14:36:01 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
void zwp_input_panel_surface_v1_destroy_resource(Resource *) override
|
|
|
|
{
|
2020-07-23 14:36:01 +00:00
|
|
|
delete q;
|
|
|
|
}
|
|
|
|
|
|
|
|
InputPanelSurfaceV1Interface *const q;
|
|
|
|
};
|
|
|
|
|
|
|
|
InputPanelSurfaceV1Interface::InputPanelSurfaceV1Interface(SurfaceInterface *surface, quint32 id, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, d(new InputPanelSurfaceV1InterfacePrivate(surface, id, this))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InputPanelSurfaceV1Interface::~InputPanelSurfaceV1Interface()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
class InputPanelV1InterfacePrivate : public QtWaylandServer::zwp_input_panel_v1
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InputPanelV1InterfacePrivate(InputPanelV1Interface *q, Display *d)
|
|
|
|
: zwp_input_panel_v1(*d, s_version)
|
|
|
|
, q(q)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void zwp_input_panel_v1_get_input_panel_surface(Resource *resource, uint32_t id, struct ::wl_resource *surfaceResource) override
|
|
|
|
{
|
|
|
|
auto surface = SurfaceInterface::get(surfaceResource);
|
2020-08-21 07:48:49 +00:00
|
|
|
|
|
|
|
SurfaceRole *surfaceRole = SurfaceRole::get(surface);
|
|
|
|
if (surfaceRole) {
|
2021-08-29 05:11:06 +00:00
|
|
|
wl_resource_post_error(resource->handle, 0, "the surface already has a role assigned %s", surfaceRole->name().constData());
|
2020-08-21 07:48:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-23 14:36:01 +00:00
|
|
|
auto interface = new InputPanelSurfaceV1Interface(surface, id, nullptr);
|
|
|
|
interface->d->init(resource->client(), id, resource->version());
|
|
|
|
|
|
|
|
Q_EMIT q->inputPanelSurfaceAdded(interface);
|
|
|
|
}
|
|
|
|
|
|
|
|
InputPanelV1Interface *const q;
|
|
|
|
};
|
|
|
|
|
|
|
|
InputPanelV1Interface::InputPanelV1Interface(Display *display, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, d(new InputPanelV1InterfacePrivate(this, display))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InputPanelV1Interface::~InputPanelV1Interface() = default;
|
|
|
|
|
|
|
|
SurfaceInterface *InputPanelSurfaceV1Interface::surface() const
|
|
|
|
{
|
|
|
|
return d->surface();
|
|
|
|
}
|
|
|
|
|
|
|
|
class InputMethodV1InterfacePrivate : public QtWaylandServer::zwp_input_method_v1
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InputMethodV1InterfacePrivate(Display *d, InputMethodV1Interface *q)
|
|
|
|
: zwp_input_method_v1(*d, s_version)
|
|
|
|
, q(q)
|
|
|
|
, m_display(d)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void zwp_input_method_v1_bind_resource(Resource *resource) override
|
|
|
|
{
|
|
|
|
if (!m_context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto addedResource = m_context->d->add(resource->client(), resource->version());
|
2021-02-20 12:47:25 +00:00
|
|
|
send_activate(resource->handle, addedResource->handle);
|
2020-07-23 14:36:01 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<InputMethodContextV1Interface> m_context;
|
2020-07-23 14:36:01 +00:00
|
|
|
InputMethodV1Interface *const q;
|
|
|
|
Display *const m_display;
|
|
|
|
};
|
|
|
|
|
|
|
|
InputMethodV1Interface::InputMethodV1Interface(Display *d, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, d(new InputMethodV1InterfacePrivate(d, this))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InputMethodV1Interface::~InputMethodV1Interface() = default;
|
|
|
|
|
|
|
|
void InputMethodV1Interface::sendActivate()
|
|
|
|
{
|
2021-02-20 12:47:25 +00:00
|
|
|
if (d->m_context) {
|
2020-07-23 14:36:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-21 17:15:58 +00:00
|
|
|
d->m_context.reset(new InputMethodContextV1Interface(this));
|
2020-07-23 14:36:01 +00:00
|
|
|
|
|
|
|
for (auto resource : d->resourceMap()) {
|
|
|
|
auto connection = d->m_context->d->add(resource->client(), resource->version());
|
|
|
|
d->send_activate(resource->handle, connection->handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputMethodV1Interface::sendDeactivate()
|
|
|
|
{
|
2021-02-20 12:47:25 +00:00
|
|
|
if (!d->m_context) {
|
2020-07-23 14:36:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-20 12:47:25 +00:00
|
|
|
for (auto resource : d->resourceMap()) {
|
|
|
|
auto connection = d->m_context->d->resourceMap().value(resource->client());
|
|
|
|
if (connection) {
|
2020-07-23 14:36:01 +00:00
|
|
|
d->send_deactivate(resource->handle, connection->handle);
|
|
|
|
}
|
|
|
|
}
|
2021-05-21 17:15:58 +00:00
|
|
|
d->m_context.reset();
|
2020-07-23 14:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InputMethodContextV1Interface *InputMethodV1Interface::context() const
|
|
|
|
{
|
2021-05-21 17:15:58 +00:00
|
|
|
return d->m_context.get();
|
2020-07-23 14:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|