File indexing completed on 2024-12-22 05:09:26
0001 /* 0002 SPDX-FileCopyrightText: 2018 David Edmundson <kde@davidedmundson.co.uk> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 #ifndef KWAYLAND_CLIENT_XDGOUTPUT_H 0007 #define KWAYLAND_CLIENT_XDGOUTPUT_H 0008 0009 #include <QObject> 0010 #include <QPoint> 0011 #include <QSize> 0012 0013 #include "KWayland/Client/kwaylandclient_export.h" 0014 0015 struct zxdg_output_manager_v1; 0016 struct zxdg_output_v1; 0017 0018 namespace KWayland 0019 { 0020 namespace Client 0021 { 0022 class EventQueue; 0023 class XdgOutput; 0024 class Output; 0025 0026 /** 0027 * @short Wrapper for the zxdg_output_manager_v1 interface. 0028 * 0029 * This class provides a convenient wrapper for the zxdg_output_manager_v1 interface. 0030 * 0031 * This provides the logical size of the output. This is useful in case it doesn't match the 0032 * pixelSize / outputScale. 0033 * 0034 * To use this class one needs to interact with the Registry. There are two 0035 * possible ways to create the XdgOutputManager interface: 0036 * @code 0037 * XdgOutputManager *c = registry->createXdgOutputManager(name, version); 0038 * @endcode 0039 * 0040 * This creates the XdgOutputManager and sets it up directly. As an alternative this 0041 * can also be done in a more low level way: 0042 * @code 0043 * XdgOutputManager *c = new XdgOutputManager; 0044 * c->setup(registry->bindXdgOutputManager(name, version)); 0045 * @endcode 0046 * 0047 * The XdgOutputManager can be used as a drop-in replacement for any zxdg_output_manager_v1 0048 * pointer as it provides matching cast operators. 0049 * 0050 * @since 5.47 0051 * 0052 * @see Registry 0053 **/ 0054 class KWAYLANDCLIENT_EXPORT XdgOutputManager : public QObject 0055 { 0056 Q_OBJECT 0057 public: 0058 /** 0059 * Creates a new XdgOutputManager. 0060 * Note: after constructing the XdgOutputManager it is not yet valid and one needs 0061 * to call setup. In order to get a ready to use XdgOutputManager prefer using 0062 * Registry::createXdgOutputManager. 0063 **/ 0064 explicit XdgOutputManager(QObject *parent = nullptr); 0065 ~XdgOutputManager() override; 0066 0067 /** 0068 * Setup this XdgOutputManager to manage the @p xdgoutputmanager. 0069 * When using Registry::createXdgOutputManager there is no need to call this 0070 * method. 0071 **/ 0072 void setup(zxdg_output_manager_v1 *xdgoutputmanager); 0073 /** 0074 * @returns @c true if managing a zxdg_output_manager_v1. 0075 **/ 0076 bool isValid() const; 0077 /** 0078 * Releases the zxdg_output_manager_v1 interface. 0079 * After the interface has been released the XdgOutputManager instance is no 0080 * longer valid and can be setup with another zxdg_output_manager_v1 interface. 0081 **/ 0082 void release(); 0083 /** 0084 * Destroys the data held by this XdgOutputManager. 0085 * This method is supposed to be used when the connection to the Wayland 0086 * server goes away. If the connection is not valid anymore, it's not 0087 * possible to call release anymore as that calls into the Wayland 0088 * connection and the call would fail. This method cleans up the data, so 0089 * that the instance can be deleted or set up to a new zxdg_output_manager_v1 interface 0090 * once there is a new connection available. 0091 * 0092 * It is suggested to connect this method to ConnectionThread::connectionDied: 0093 * @code 0094 * connect(connection, &ConnectionThread::connectionDied, xdgoutputmanager, &XdgOutputManager::destroy); 0095 * @endcode 0096 * 0097 * @see release 0098 **/ 0099 void destroy(); 0100 0101 /** 0102 * Sets the @p queue to use for creating objects with this XdgOutputManager. 0103 **/ 0104 void setEventQueue(EventQueue *queue); 0105 /** 0106 * @returns The event queue to use for creating objects with this XdgOutputManager. 0107 **/ 0108 EventQueue *eventQueue(); 0109 0110 XdgOutput *getXdgOutput(Output *output, QObject *parent = nullptr); 0111 0112 operator zxdg_output_manager_v1 *(); 0113 operator zxdg_output_manager_v1 *() const; 0114 0115 Q_SIGNALS: 0116 /** 0117 * The corresponding global for this interface on the Registry got removed. 0118 * 0119 * This signal gets only emitted if the XdgOutputManager got created by 0120 * Registry::createXdgOutputManager 0121 **/ 0122 void removed(); 0123 0124 private: 0125 class Private; 0126 QScopedPointer<Private> d; 0127 }; 0128 0129 /** 0130 * @short Wrapper for the zxdg_output_v1 interface. 0131 * 0132 * This class provides a convenient wrapper for the zxdg_output_v1 interface. 0133 * 0134 * The XdgOutputManager can be used as a drop-in replacement for any zxdg_output_v1 0135 * pointer as it provides matching cast operators. 0136 * 0137 * This protocol provides a potentially more correct size and position of the screen 0138 * than Output with respect to scaling. 0139 * 0140 * @see Registry 0141 **/ 0142 0143 class KWAYLANDCLIENT_EXPORT XdgOutput : public QObject 0144 { 0145 Q_OBJECT 0146 public: 0147 ~XdgOutput() override; 0148 0149 /** 0150 * Setup this XdgOutput to manage the @p xdgoutput. 0151 * When using XdgOutputManager::createXdgOutput there is no need to call this 0152 * method. 0153 **/ 0154 void setup(zxdg_output_v1 *xdgoutput); 0155 /** 0156 * @returns @c true if managing a zxdg_output_v1. 0157 **/ 0158 bool isValid() const; 0159 /** 0160 * Releases the zxdg_output_v1 interface. 0161 * After the interface has been released the XdgOutput instance is no 0162 * longer valid and can be setup with another zxdg_output_v1 interface. 0163 **/ 0164 void release(); 0165 /** 0166 * Destroys the data held by this XdgOutput. 0167 * This method is supposed to be used when the connection to the Wayland 0168 * server goes away. If the connection is not valid anymore, it's not 0169 * possible to call release anymore as that calls into the Wayland 0170 * connection and the call would fail. This method cleans up the data, so 0171 * that the instance can be deleted or set up to a new zxdg_output_v1 interface 0172 * once there is a new connection available. 0173 * 0174 * It is suggested to connect this method to ConnectionThread::connectionDied: 0175 * @code 0176 * connect(connection, &ConnectionThread::connectionDied, xdgoutput, &XdgOutput::destroy); 0177 * @endcode 0178 * 0179 * @see release 0180 **/ 0181 void destroy(); 0182 0183 operator zxdg_output_v1 *(); 0184 operator zxdg_output_v1 *() const; 0185 0186 /** 0187 * The top left position of the output in compositor coordinates 0188 */ 0189 QPoint logicalPosition() const; 0190 0191 /** 0192 * The size of the output in compositor coordinates 0193 * (i.e pixel size / output scale) 0194 */ 0195 QSize logicalSize() const; 0196 0197 /** 0198 * A consistent unique name for this monitor 0199 * @since 5.XDGOUTPUT 0200 */ 0201 QString name() const; 0202 0203 /** 0204 * A longer human readable description 0205 * @since 5.XDGOUTPUT 0206 */ 0207 QString description() const; 0208 0209 Q_SIGNALS: 0210 /** 0211 * Emitted when any of the attributes have changed 0212 */ 0213 void changed(); 0214 0215 private: 0216 friend class XdgOutputManager; 0217 explicit XdgOutput(QObject *parent = nullptr); 0218 class Private; 0219 QScopedPointer<Private> d; 0220 }; 0221 0222 } 0223 } 0224 0225 #endif