File indexing completed on 2024-12-22 05:09:22
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_REGION_H 0007 #define WAYLAND_REGION_H 0008 0009 #include <QObject> 0010 0011 #include "KWayland/Client/kwaylandclient_export.h" 0012 0013 struct wl_region; 0014 0015 namespace KWayland 0016 { 0017 namespace Client 0018 { 0019 /** 0020 * @short Wrapper for the wl_region interface. 0021 * 0022 * This class is a convenient wrapper for the wl_region interface. 0023 * To create a Region call Compositor::createRegion. 0024 * 0025 * The main purpose of this class is to provide regions which can be 0026 * used to e.g. set the input region on a Surface. 0027 * 0028 * @see Compositor 0029 * @see Surface 0030 **/ 0031 class KWAYLANDCLIENT_EXPORT Region : public QObject 0032 { 0033 Q_OBJECT 0034 public: 0035 explicit Region(const QRegion ®ion, QObject *parent = nullptr); 0036 ~Region() override; 0037 0038 /** 0039 * Setup this Surface to manage the @p region. 0040 * When using Compositor::createRegion there is no need to call this 0041 * method. 0042 **/ 0043 void setup(wl_region *region); 0044 /** 0045 * Releases the wl_region interface. 0046 * After the interface has been released the Region instance is no 0047 * longer valid and can be setup with another wl_region interface. 0048 **/ 0049 void release(); 0050 /** 0051 * Destroys the data held by this Region. 0052 * This method is supposed to be used when the connection to the Wayland 0053 * server goes away. If the connection is not valid anymore, it's not 0054 * possible to call release anymore as that calls into the Wayland 0055 * connection and the call would fail. This method cleans up the data, so 0056 * that the instance can be deleted or set up to a new wl_region interface 0057 * once there is a new connection available. 0058 * 0059 * It is suggested to connect this method to ConnectionThread::connectionDied: 0060 * @code 0061 * connect(connection, &ConnectionThread::connectionDied, region, &Region::destroy); 0062 * @endcode 0063 * 0064 * @see release 0065 **/ 0066 void destroy(); 0067 /** 0068 * @returns @c true if managing a wl_region. 0069 **/ 0070 bool isValid() const; 0071 0072 /** 0073 * Adds the @p rect to this Region. 0074 **/ 0075 void add(const QRect &rect); 0076 /** 0077 * Adds the @p region to this Rregion. 0078 **/ 0079 void add(const QRegion ®ion); 0080 /** 0081 * Subtracts @p rect from this Region. 0082 **/ 0083 void subtract(const QRect &rect); 0084 /** 0085 * Subtracts @p region from this Region. 0086 **/ 0087 void subtract(const QRegion ®ion); 0088 0089 /** 0090 * The geometry of this Region. 0091 **/ 0092 QRegion region() const; 0093 0094 operator wl_region *(); 0095 operator wl_region *() const; 0096 0097 private: 0098 class Private; 0099 QScopedPointer<Private> d; 0100 }; 0101 0102 } 0103 } 0104 0105 #endif