File indexing completed on 2024-05-19 05:32:46

0001 /*
0002     SPDX-FileCopyrightText: 2020 Bhushan Shah <bshah@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #pragma once
0007 
0008 #include "clientconnection.h"
0009 #include "textinput_v3.h"
0010 
0011 #include <QHash>
0012 #include <QList>
0013 #include <QPointer>
0014 #include <QRect>
0015 
0016 #include <qwayland-server-text-input-unstable-v3.h>
0017 
0018 namespace KWin
0019 {
0020 class TextInputManagerV3InterfacePrivate : public QtWaylandServer::zwp_text_input_manager_v3
0021 {
0022 public:
0023     TextInputManagerV3InterfacePrivate(TextInputManagerV3Interface *_q, Display *display);
0024 
0025     TextInputManagerV3Interface *q;
0026 
0027 protected:
0028     void zwp_text_input_manager_v3_destroy(Resource *resource) override;
0029     void zwp_text_input_manager_v3_get_text_input(Resource *resource, uint32_t id, wl_resource *seat) override;
0030 };
0031 
0032 class TextInputV3InterfacePrivate : public QtWaylandServer::zwp_text_input_v3
0033 {
0034 public:
0035     TextInputV3InterfacePrivate(SeatInterface *seat, TextInputV3Interface *_q);
0036 
0037     // events
0038     void sendEnter(SurfaceInterface *surface);
0039     void sendLeave(SurfaceInterface *surface);
0040     void sendPreEdit(const QString &text, const quint32 cursorBegin, const quint32 cursorEnd);
0041     void commitString(const QString &text);
0042     void deleteSurroundingText(quint32 beforeLength, quint32 afterLength);
0043     void done();
0044 
0045     void updateEnabled();
0046 
0047     QList<TextInputV3InterfacePrivate::Resource *> textInputsForClient(ClientConnection *client) const;
0048     QList<TextInputV3InterfacePrivate::Resource *> enabledTextInputsForClient(ClientConnection *client) const;
0049 
0050     static TextInputV3InterfacePrivate *get(TextInputV3Interface *inputInterface)
0051     {
0052         return inputInterface->d.get();
0053     }
0054 
0055     QRect cursorRectangle;
0056     TextInputContentHints contentHints = TextInputContentHint::None;
0057     TextInputContentPurpose contentPurpose = TextInputContentPurpose::Normal;
0058 
0059     SeatInterface *seat = nullptr;
0060     QPointer<SurfaceInterface> surface;
0061 
0062     QString surroundingText;
0063     qint32 surroundingTextCursorPosition = 0;
0064     qint32 surroundingTextSelectionAnchor = 0;
0065     TextInputChangeCause surroundingTextChangeCause = TextInputChangeCause::InputMethod;
0066 
0067     QString preeditText;
0068     quint32 preeditCursorBegin = 0;
0069     quint32 preeditCursorEnd = 0;
0070 
0071     struct
0072     {
0073         QRect cursorRectangle;
0074         TextInputChangeCause surroundingTextChangeCause = TextInputChangeCause::InputMethod;
0075         TextInputContentHints contentHints = TextInputContentHint::None;
0076         TextInputContentPurpose contentPurpose = TextInputContentPurpose::Normal;
0077         bool enabled = false;
0078         QString surroundingText;
0079         qint32 surroundingTextCursorPosition = 0;
0080         qint32 surroundingTextSelectionAnchor = 0;
0081         QString preeditText;
0082         quint32 preeditCursorBegin = 0;
0083         quint32 preeditCursorEnd = 0;
0084     } pending;
0085 
0086     QHash<Resource *, quint32> serialHash;
0087     QHash<Resource *, bool> enabledHash;
0088 
0089     void defaultPending();
0090     void defaultPendingPreedit();
0091 
0092     TextInputV3Interface *q;
0093     bool isEnabled = false;
0094 
0095 protected:
0096     void zwp_text_input_v3_bind_resource(Resource *resource) override;
0097     void zwp_text_input_v3_destroy_resource(Resource *resource) override;
0098     void zwp_text_input_v3_destroy(Resource *resource) override;
0099     void zwp_text_input_v3_enable(Resource *resource) override;
0100     void zwp_text_input_v3_disable(Resource *resource) override;
0101     void zwp_text_input_v3_set_surrounding_text(Resource *resource, const QString &text, int32_t cursor, int32_t anchor) override;
0102     void zwp_text_input_v3_set_content_type(Resource *resource, uint32_t hint, uint32_t purpose) override;
0103     void zwp_text_input_v3_set_text_change_cause(Resource *resource, uint32_t cause) override;
0104     void zwp_text_input_v3_set_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
0105     void zwp_text_input_v3_commit(Resource *resource) override;
0106 };
0107 
0108 }