File indexing completed on 2024-05-19 16:35:30
0001 /* 0002 SPDX-FileCopyrightText: 2022 Xuetian Weng <wengxt@gmail.com> 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 "wayland/seat_interface.h" 0010 #include "wayland/seat_interface_p.h" 0011 #include "wayland/surface_interface.h" 0012 #include "wayland/textinput_v1_interface.h" 0013 0014 #include <QPointer> 0015 #include <QRect> 0016 #include <QSet> 0017 #include <QVector> 0018 0019 #include <qwayland-server-text-input-unstable-v1.h> 0020 0021 namespace KWaylandServer 0022 { 0023 class TextInputManagerV1InterfacePrivate : public QtWaylandServer::zwp_text_input_manager_v1 0024 { 0025 public: 0026 TextInputManagerV1InterfacePrivate(TextInputManagerV1Interface *_q, Display *display); 0027 0028 TextInputManagerV1Interface *q; 0029 Display *display; 0030 std::unique_ptr<TextInputV1Interface> textInputV1; 0031 0032 protected: 0033 void zwp_text_input_manager_v1_create_text_input(Resource *resource, uint32_t id) override; 0034 }; 0035 0036 class TextInputV1InterfacePrivate : public QtWaylandServer::zwp_text_input_v1 0037 { 0038 public: 0039 TextInputV1InterfacePrivate(SeatInterface *seat, TextInputV1Interface *_q); 0040 0041 void sendEnter(SurfaceInterface *surface); 0042 void sendLeave(SurfaceInterface *surface); 0043 void preEdit(const QString &text, const QString &commit); 0044 void preEditStyling(quint32 index, uint32_t length, uint32_t style); 0045 void commitString(const QString &text); 0046 void deleteSurroundingText(qint32 index, quint32 length); 0047 void setTextDirection(Qt::LayoutDirection direction); 0048 void setPreEditCursor(qint32 index); 0049 void setCursorPosition(qint32 index, qint32 anchor); 0050 void keysymPressed(quint32 time, quint32 keysym, quint32 modifiers); 0051 void keysymReleased(quint32 time, quint32 keysym, quint32 modifiers); 0052 void sendInputPanelState(); 0053 void sendLanguage(); 0054 void sendModifiersMap(); 0055 0056 template<typename T> 0057 void forActivatedResource(const T &callback) 0058 { 0059 if (auto resource = activated.value(surface)) { 0060 callback(resource); 0061 } 0062 } 0063 0064 QList<Resource *> textInputsForClient(ClientConnection *client) const; 0065 static TextInputV1InterfacePrivate *get(TextInputV1Interface *inputInterface) 0066 { 0067 return inputInterface->d.get(); 0068 } 0069 0070 QString preferredLanguage; 0071 QRect cursorRectangle; 0072 TextInputContentHints contentHints = TextInputContentHint::None; 0073 TextInputContentPurpose contentPurpose = TextInputContentPurpose::Normal; 0074 QPointer<SeatInterface> seat; 0075 QPointer<SurfaceInterface> surface; 0076 QString surroundingText; 0077 qint32 surroundingTextCursorPosition = 0; 0078 qint32 surroundingTextSelectionAnchor = 0; 0079 bool inputPanelVisible = false; 0080 QRect overlappedSurfaceArea; 0081 QString language; 0082 QByteArray modifiersMap; 0083 TextInputV1Interface *q; 0084 // Based on weston reference implementation, one surface can have only one activated text input. 0085 QHash<SurfaceInterface *, Resource *> activated; 0086 QHash<Resource *, quint32> serialHash; 0087 0088 protected: 0089 void zwp_text_input_v1_bind_resource(Resource *resource) override; 0090 void zwp_text_input_v1_destroy_resource(Resource *resource) override; 0091 void zwp_text_input_v1_activate(Resource *resource, struct wl_resource *seat, struct wl_resource *surface) override; 0092 void zwp_text_input_v1_deactivate(Resource *resource, wl_resource *seat) override; 0093 void zwp_text_input_v1_show_input_panel(Resource *resource) override; 0094 void zwp_text_input_v1_hide_input_panel(Resource *resource) override; 0095 void zwp_text_input_v1_reset(Resource *resource) override; 0096 void zwp_text_input_v1_set_surrounding_text(Resource *resource, const QString &text, uint32_t cursor, uint32_t anchor) override; 0097 void zwp_text_input_v1_set_content_type(Resource *resource, uint32_t hint, uint32_t purpose) override; 0098 void zwp_text_input_v1_set_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override; 0099 void zwp_text_input_v1_set_preferred_language(Resource *resource, const QString &language) override; 0100 void zwp_text_input_v1_commit_state(Resource *resource, uint32_t serial) override; 0101 void zwp_text_input_v1_invoke_action(Resource *resource, uint32_t button, uint32_t index) override; 0102 }; 0103 0104 }