File indexing completed on 2024-12-22 05:09:23
0001 /* 0002 SPDX-FileCopyrightText: 2014 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 #ifndef WAYLAND_SEAT_H 0007 #define WAYLAND_SEAT_H 0008 0009 #include <QObject> 0010 0011 #include "KWayland/Client/kwaylandclient_export.h" 0012 0013 struct wl_seat; 0014 struct wl_touch; 0015 0016 namespace KWayland 0017 { 0018 namespace Client 0019 { 0020 class EventQueue; 0021 class Keyboard; 0022 class Pointer; 0023 class Touch; 0024 0025 /** 0026 * @short Wrapper for the wl_seat interface. 0027 * 0028 * This class provides a convenient wrapper for the wl_seat interface. 0029 * It's main purpose is to provide the interfaces for Keyboard, Pointer and Touch. 0030 * 0031 * To use this class one needs to interact with the Registry. There are two 0032 * possible ways to create the Seat interface: 0033 * @code 0034 * Seat *s = registry->createSeat(name, version); 0035 * @endcode 0036 * 0037 * This creates the Seat and sets it up directly. As an alternative this 0038 * can also be done in a more low level way: 0039 * @code 0040 * Seat *s = new Seat; 0041 * s->setup(registry->bindSeat(name, version)); 0042 * @endcode 0043 * 0044 * The Seat can be used as a drop-in replacement for any wl_seat 0045 * pointer as it provides matching cast operators. 0046 * 0047 * @see Registry 0048 * @see Keyboard 0049 * @see Pointer 0050 **/ 0051 class KWAYLANDCLIENT_EXPORT Seat : public QObject 0052 { 0053 Q_OBJECT 0054 /** 0055 * The seat has pointer devices. Default value is @c false. 0056 **/ 0057 Q_PROPERTY(bool keyboard READ hasKeyboard NOTIFY hasKeyboardChanged) 0058 /** 0059 * The seat has pointer devices. Default value is @c false. 0060 **/ 0061 Q_PROPERTY(bool pointer READ hasPointer NOTIFY hasPointerChanged) 0062 /** 0063 * The seat has touch devices. Default value is @c false. 0064 **/ 0065 Q_PROPERTY(bool touch READ hasTouch NOTIFY hasTouchChanged) 0066 /** 0067 * In a multiseat configuration this can be used by the client to help identify 0068 * which physical devices the seat represents. 0069 * Based on the seat configuration used by the compositor. 0070 **/ 0071 Q_PROPERTY(QString name READ name NOTIFY nameChanged) 0072 public: 0073 explicit Seat(QObject *parent = nullptr); 0074 ~Seat() override; 0075 0076 /** 0077 * @returns @c true if managing a wl_seat. 0078 **/ 0079 bool isValid() const; 0080 /** 0081 * Setup this Seat to manage the @p seat. 0082 * When using Registry::createSeat there is no need to call this 0083 * method. 0084 **/ 0085 void setup(wl_seat *seat); 0086 /** 0087 * Releases the wl_seat interface. 0088 * After the interface has been released the Seat instance is no 0089 * longer valid and can be setup with another wl_seat interface. 0090 * 0091 * Right before the interface is released the signal interfaceAboutToBeReleased is emitted. 0092 * @see interfaceAboutToBeReleased 0093 **/ 0094 void release(); 0095 /** 0096 * Destroys the data held by this Seat. 0097 * This method is supposed to be used when the connection to the Wayland 0098 * server goes away. If the connection is not valid anymore, it's not 0099 * possible to call release anymore as that calls into the Wayland 0100 * connection and the call would fail. This method cleans up the data, so 0101 * that the instance can be deleted or set up to a new wl_shell interface 0102 * once there is a new connection available. 0103 * 0104 * This method is automatically invoked when the Registry which created this 0105 * Seat gets destroyed. 0106 * 0107 * Right before the data is destroyed the signal interfaceAboutToBeDestroyed is emitted. 0108 * 0109 * @see release 0110 * @see interfaceAboutToBeDestroyed 0111 **/ 0112 void destroy(); 0113 0114 /** 0115 * Sets the @p queue to use for creating Keyboard, Pointer and Touch. 0116 **/ 0117 void setEventQueue(EventQueue *queue); 0118 /** 0119 * @returns The event queue to use for creating Keyboard, Pointer and Touch. 0120 **/ 0121 EventQueue *eventQueue(); 0122 0123 bool hasKeyboard() const; 0124 bool hasPointer() const; 0125 bool hasTouch() const; 0126 QString name() const; 0127 operator wl_seat *(); 0128 operator wl_seat *() const; 0129 0130 /** 0131 * Creates a Keyboard. 0132 * 0133 * This method may only be called if the Seat has a keyboard. 0134 * 0135 * @param parent The parent to pass to the created Keyboard. 0136 * @returns The created Keyboard. 0137 **/ 0138 Keyboard *createKeyboard(QObject *parent = nullptr); 0139 /** 0140 * Creates a Pointer. 0141 * 0142 * This method may only be called if the Seat has a pointer. 0143 * 0144 * @param parent The parent to pass to the created Pointer. 0145 * @returns The created Pointer. 0146 **/ 0147 Pointer *createPointer(QObject *parent = nullptr); 0148 /** 0149 * Creates a Touch. 0150 * 0151 * This method may only be called if the Seat has touch support. 0152 * 0153 * @param parent The parent to pass to the created Touch. 0154 * @returns The created Touch. 0155 **/ 0156 Touch *createTouch(QObject *parent = nullptr); 0157 0158 Q_SIGNALS: 0159 void hasKeyboardChanged(bool); 0160 void hasPointerChanged(bool); 0161 void hasTouchChanged(bool); 0162 void nameChanged(const QString &name); 0163 0164 /** 0165 * This signal is emitted right before the interface is going to be released. 0166 **/ 0167 void interfaceAboutToBeReleased(); 0168 /** 0169 * This signal is emitted right before the data is going to be destroyed. 0170 **/ 0171 void interfaceAboutToBeDestroyed(); 0172 0173 /** 0174 * The corresponding global for this interface on the Registry got removed. 0175 * 0176 * This signal gets only emitted if the Compositor got created by 0177 * Registry::createSeat 0178 * 0179 * @since 5.5 0180 **/ 0181 void removed(); 0182 0183 private: 0184 class Private; 0185 QScopedPointer<Private> d; 0186 }; 0187 0188 } 0189 } 0190 0191 #endif