| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 | */ |
| 6 | #ifndef WAYLAND_REGION_H |
| 7 | #define WAYLAND_REGION_H |
| 8 | |
| 9 | #include <QObject> |
| 10 | |
| 11 | #include "KWayland/Client/kwaylandclient_export.h" |
| 12 | |
| 13 | struct wl_region; |
| 14 | |
| 15 | namespace KWayland |
| 16 | { |
| 17 | namespace Client |
| 18 | { |
| 19 | /** |
| 20 | * @short Wrapper for the wl_region interface. |
| 21 | * |
| 22 | * This class is a convenient wrapper for the wl_region interface. |
| 23 | * To create a Region call Compositor::createRegion. |
| 24 | * |
| 25 | * The main purpose of this class is to provide regions which can be |
| 26 | * used to e.g. set the input region on a Surface. |
| 27 | * |
| 28 | * @see Compositor |
| 29 | * @see Surface |
| 30 | **/ |
| 31 | class KWAYLANDCLIENT_EXPORT Region : public QObject |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | public: |
| 35 | explicit Region(const QRegion ®ion, QObject *parent = nullptr); |
| 36 | ~Region() override; |
| 37 | |
| 38 | /** |
| 39 | * Setup this Surface to manage the @p region. |
| 40 | * When using Compositor::createRegion there is no need to call this |
| 41 | * method. |
| 42 | **/ |
| 43 | void setup(wl_region *region); |
| 44 | /** |
| 45 | * Releases the wl_region interface. |
| 46 | * After the interface has been released the Region instance is no |
| 47 | * longer valid and can be setup with another wl_region interface. |
| 48 | **/ |
| 49 | void release(); |
| 50 | /** |
| 51 | * Destroys the data held by this Region. |
| 52 | * This method is supposed to be used when the connection to the Wayland |
| 53 | * server goes away. If the connection is not valid anymore, it's not |
| 54 | * possible to call release anymore as that calls into the Wayland |
| 55 | * connection and the call would fail. This method cleans up the data, so |
| 56 | * that the instance can be deleted or set up to a new wl_region interface |
| 57 | * once there is a new connection available. |
| 58 | * |
| 59 | * It is suggested to connect this method to ConnectionThread::connectionDied: |
| 60 | * @code |
| 61 | * connect(connection, &ConnectionThread::connectionDied, region, &Region::destroy); |
| 62 | * @endcode |
| 63 | * |
| 64 | * @see release |
| 65 | **/ |
| 66 | void destroy(); |
| 67 | /** |
| 68 | * @returns @c true if managing a wl_region. |
| 69 | **/ |
| 70 | bool isValid() const; |
| 71 | |
| 72 | /** |
| 73 | * Adds the @p rect to this Region. |
| 74 | **/ |
| 75 | void add(const QRect &rect); |
| 76 | /** |
| 77 | * Adds the @p region to this Rregion. |
| 78 | **/ |
| 79 | void add(const QRegion ®ion); |
| 80 | /** |
| 81 | * Subtracts @p rect from this Region. |
| 82 | **/ |
| 83 | void subtract(const QRect &rect); |
| 84 | /** |
| 85 | * Subtracts @p region from this Region. |
| 86 | **/ |
| 87 | void subtract(const QRegion ®ion); |
| 88 | |
| 89 | /** |
| 90 | * The geometry of this Region. |
| 91 | **/ |
| 92 | QRegion region() const; |
| 93 | |
| 94 | operator wl_region *(); |
| 95 | operator wl_region *() const; |
| 96 | |
| 97 | private: |
| 98 | class Private; |
| 99 | QScopedPointer<Private> d; |
| 100 | }; |
| 101 | |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | #endif |
| 106 | |