File indexing completed on 2024-05-19 05:32:35
0001 /* 0002 SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #pragma once 0008 0009 #include "kwin_export.h" 0010 0011 #include <QList> 0012 #include <QObject> 0013 #include <memory> 0014 0015 #include "textinput.h" 0016 0017 namespace KWin 0018 { 0019 class OutputInterface; 0020 class SurfaceInterface; 0021 class SurfaceRole; 0022 class Display; 0023 class KeyboardInterface; 0024 class InputPanelSurfaceV1Interface; 0025 class InputMethodContextV1Interface; 0026 0027 class InputMethodV1InterfacePrivate; 0028 class InputMethodContextV1InterfacePrivate; 0029 class InputPanelV1InterfacePrivate; 0030 class InputPanelSurfaceV1InterfacePrivate; 0031 class InputMethodGrabV1; 0032 class InputKeyboardV1InterfacePrivate; 0033 0034 enum class KeyboardKeyState : quint32; 0035 0036 // This file's classes implment input_method_unstable_v1 0037 0038 /** 0039 * Implements zwp_input_method_v1 and allows to activate and deactivate a context 0040 * 0041 * When we activate, an @class InputMethodContextV1Interface becomes available 0042 */ 0043 class KWIN_EXPORT InputMethodV1Interface : public QObject 0044 { 0045 Q_OBJECT 0046 public: 0047 InputMethodV1Interface(Display *d, QObject *parent); 0048 ~InputMethodV1Interface() override; 0049 0050 /** 0051 * Activates the input method. 0052 */ 0053 void sendActivate(); 0054 0055 /** 0056 * Deactivates the input method, probably because we're not on some area 0057 * where we can write text. 0058 */ 0059 void sendDeactivate(); 0060 0061 InputMethodContextV1Interface *context() const; 0062 0063 private: 0064 std::unique_ptr<InputMethodV1InterfacePrivate> d; 0065 }; 0066 0067 /** 0068 * Implements zwp_input_method_context_v1, allows to describe the client's input state 0069 */ 0070 class KWIN_EXPORT InputMethodContextV1Interface : public QObject 0071 { 0072 Q_OBJECT 0073 public: 0074 ~InputMethodContextV1Interface() override; 0075 0076 void sendSurroundingText(const QString &text, quint32 cursor, quint32 anchor); 0077 void sendReset(); 0078 void sendContentType(KWin::TextInputContentHints hint, KWin::TextInputContentPurpose purpose); 0079 void sendInvokeAction(quint32 button, quint32 index); 0080 void sendCommitState(quint32 serial); 0081 void sendPreferredLanguage(const QString &language); 0082 0083 InputMethodGrabV1 *keyboardGrab() const; 0084 0085 Q_SIGNALS: 0086 void commitString(quint32 serial, const QString &text); 0087 void preeditString(quint32 serial, const QString &text, const QString &commit); 0088 void preeditStyling(quint32 index, quint32 length, quint32 style); 0089 void preeditCursor(qint32 index); 0090 void deleteSurroundingText(qint32 index, quint32 length); 0091 void cursorPosition(qint32 index, qint32 anchor); 0092 void keysym(quint32 serial, quint32 time, quint32 sym, bool pressed, quint32 modifiers); 0093 void key(quint32 serial, quint32 time, quint32 key, bool pressed); 0094 void modifiers(quint32 serial, quint32 mods_depressed, quint32 mods_latched, quint32 mods_locked, quint32 group); 0095 void language(quint32 serial, const QString &language); 0096 void textDirection(quint32 serial, Qt::LayoutDirection direction); 0097 void keyboardGrabRequested(InputMethodGrabV1 *keyboardGrab); 0098 void modifiersMap(const QByteArray &map); 0099 0100 private: 0101 friend class InputMethodV1Interface; 0102 friend class InputMethodV1InterfacePrivate; 0103 InputMethodContextV1Interface(InputMethodV1Interface *parent); 0104 std::unique_ptr<InputMethodContextV1InterfacePrivate> d; 0105 }; 0106 0107 /** 0108 * Implements zwp_input_panel_v1, tells us about the InputPanelSurfaceV1Interface that we might get 0109 */ 0110 class KWIN_EXPORT InputPanelV1Interface : public QObject 0111 { 0112 Q_OBJECT 0113 public: 0114 InputPanelV1Interface(Display *display, QObject *parent); 0115 ~InputPanelV1Interface() override; 0116 0117 Q_SIGNALS: 0118 void inputPanelSurfaceAdded(InputPanelSurfaceV1Interface *surface); 0119 0120 private: 0121 std::unique_ptr<InputPanelV1InterfacePrivate> d; 0122 }; 0123 0124 /** 0125 * Implements zwp_input_panel_surface_v1, it corresponds to each element shown so it can be placed. 0126 */ 0127 class KWIN_EXPORT InputPanelSurfaceV1Interface : public QObject 0128 { 0129 Q_OBJECT 0130 public: 0131 ~InputPanelSurfaceV1Interface() override; 0132 0133 static SurfaceRole *role(); 0134 0135 enum Position { 0136 CenterBottom = 0, 0137 }; 0138 Q_ENUM(Position) 0139 0140 SurfaceInterface *surface() const; 0141 0142 Q_SIGNALS: 0143 void topLevel(OutputInterface *output, Position position); 0144 void overlayPanel(); 0145 void aboutToBeDestroyed(); 0146 0147 private: 0148 InputPanelSurfaceV1Interface(SurfaceInterface *surface, quint32 id, QObject *parent); 0149 friend class InputPanelV1InterfacePrivate; 0150 std::unique_ptr<InputPanelSurfaceV1InterfacePrivate> d; 0151 }; 0152 0153 /** 0154 * Implements a wl_keyboard tailored for zwp_input_method_v1 use-cases 0155 */ 0156 class KWIN_EXPORT InputMethodGrabV1 : public QObject 0157 { 0158 Q_OBJECT 0159 public: 0160 ~InputMethodGrabV1() override; 0161 0162 void sendKeymap(const QByteArray &content); 0163 void sendKey(quint32 serial, quint32 timestamp, quint32 key, KeyboardKeyState state); 0164 void sendModifiers(quint32 serial, quint32 depressed, quint32 latched, quint32 locked, quint32 group); 0165 0166 private: 0167 InputMethodGrabV1(QObject *parent); 0168 friend class InputPanelV1InterfacePrivate; 0169 friend class InputMethodContextV1InterfacePrivate; 0170 std::unique_ptr<InputKeyboardV1InterfacePrivate> d; 0171 }; 0172 0173 } 0174 0175 Q_DECLARE_METATYPE(KWin::InputMethodV1Interface *) 0176 Q_DECLARE_METATYPE(KWin::InputMethodGrabV1 *)