File indexing completed on 2024-05-19 16:35:20

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