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

0001 /*
0002     SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@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_v2.h"
0010 
0011 #include <QList>
0012 #include <QPointer>
0013 #include <QRect>
0014 #include <QSet>
0015 
0016 #include <qwayland-server-text-input-unstable-v2.h>
0017 
0018 namespace KWin
0019 {
0020 class TextInputManagerV2InterfacePrivate : public QtWaylandServer::zwp_text_input_manager_v2
0021 {
0022 public:
0023     TextInputManagerV2InterfacePrivate(TextInputManagerV2Interface *_q, Display *display);
0024 
0025     TextInputManagerV2Interface *q;
0026 
0027 protected:
0028     void zwp_text_input_manager_v2_destroy(Resource *resource) override;
0029     void zwp_text_input_manager_v2_get_text_input(Resource *resource, uint32_t id, wl_resource *seat) override;
0030 };
0031 
0032 class TextInputV2InterfacePrivate : public QtWaylandServer::zwp_text_input_v2
0033 {
0034 public:
0035     TextInputV2InterfacePrivate(SeatInterface *seat, TextInputV2Interface *_q);
0036 
0037     void sendEnter(SurfaceInterface *surface, quint32 serial);
0038     void sendLeave(quint32 serial, SurfaceInterface *surface);
0039     void preEdit(const QString &text, const QString &commit);
0040     void preEditStyling(uint32_t index, uint32_t length, uint32_t style);
0041     void commitString(const QString &text);
0042     void deleteSurroundingText(quint32 beforeLength, quint32 afterLength);
0043     void setTextDirection(Qt::LayoutDirection direction);
0044     void setPreEditCursor(qint32 index);
0045     void setCursorPosition(qint32 index, qint32 anchor);
0046     void keysymPressed(quint32 keysym, quint32 modifiers);
0047     void keysymReleased(quint32 keysym, quint32 modifiers);
0048     void sendInputPanelState();
0049     void sendLanguage();
0050     void sendModifiersMap();
0051 
0052     QList<Resource *> textInputsForClient(ClientConnection *client) const;
0053     static TextInputV2InterfacePrivate *get(TextInputV2Interface *inputInterface)
0054     {
0055         return inputInterface->d.get();
0056     }
0057 
0058     QString preferredLanguage;
0059     QRect cursorRectangle;
0060     TextInputContentHints contentHints = TextInputContentHint::None;
0061     TextInputContentPurpose contentPurpose = TextInputContentPurpose::Normal;
0062     SeatInterface *seat = nullptr;
0063     QPointer<SurfaceInterface> surface;
0064     QString surroundingText;
0065     qint32 surroundingTextCursorPosition = 0;
0066     qint32 surroundingTextSelectionAnchor = 0;
0067     bool inputPanelVisible = false;
0068     QRect overlappedSurfaceArea;
0069     QString language;
0070     QByteArray modifiersMap;
0071     TextInputV2Interface *q;
0072     QSet<SurfaceInterface *> m_enabledSurfaces;
0073 
0074 protected:
0075     void zwp_text_input_v2_enable(Resource *resource, wl_resource *surface) override;
0076     void zwp_text_input_v2_disable(Resource *resource, wl_resource *surface) override;
0077     void zwp_text_input_v2_show_input_panel(Resource *resource) override;
0078     void zwp_text_input_v2_hide_input_panel(Resource *resource) override;
0079     void zwp_text_input_v2_set_surrounding_text(Resource *resource, const QString &text, int32_t cursor, int32_t anchor) override;
0080     void zwp_text_input_v2_set_content_type(Resource *resource, uint32_t hint, uint32_t purpose) override;
0081     void zwp_text_input_v2_set_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
0082     void zwp_text_input_v2_set_preferred_language(Resource *resource, const QString &language) override;
0083     void zwp_text_input_v2_update_state(Resource *resource, uint32_t serial, uint32_t reason) override;
0084 };
0085 
0086 }