| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 | */ |
| 6 | #ifndef KWAYLAND_CLIENT_SLIDE_H |
| 7 | #define KWAYLAND_CLIENT_SLIDE_H |
| 8 | |
| 9 | #include <QObject> |
| 10 | |
| 11 | #include "KWayland/Client/kwaylandclient_export.h" |
| 12 | |
| 13 | struct org_kde_kwin_slide_manager; |
| 14 | struct org_kde_kwin_slide; |
| 15 | |
| 16 | namespace KWayland |
| 17 | { |
| 18 | namespace Client |
| 19 | { |
| 20 | class EventQueue; |
| 21 | class Slide; |
| 22 | class Surface; |
| 23 | |
| 24 | /** |
| 25 | * @short Wrapper for the org_kde_kwin_slide_manager interface. |
| 26 | * |
| 27 | * This class provides a convenient wrapper for the org_kde_kwin_slide_manager interface. |
| 28 | * |
| 29 | * Ask the compositor to move the surface from a location |
| 30 | * to another with a slide animation. |
| 31 | * |
| 32 | * The from argument provides a clue about where the slide |
| 33 | * animation begins, offset is the distance from screen |
| 34 | * edge to begin the animation. |
| 35 | * |
| 36 | * To use this class one needs to interact with the Registry. There are two |
| 37 | * possible ways to create the SlideManager interface: |
| 38 | * @code |
| 39 | * SlideManager *c = registry->createSlideManager(name, version); |
| 40 | * @endcode |
| 41 | * |
| 42 | * This creates the SlideManager and sets it up directly. As an alternative this |
| 43 | * can also be done in a more low level way: |
| 44 | * @code |
| 45 | * SlideManager *c = new SlideManager; |
| 46 | * c->setup(registry->bindSlideManager(name, version)); |
| 47 | * @endcode |
| 48 | * |
| 49 | * The SlideManager can be used as a drop-in replacement for any org_kde_kwin_slide_manager |
| 50 | * pointer as it provides matching cast operators. |
| 51 | * |
| 52 | * @see Registry |
| 53 | **/ |
| 54 | class KWAYLANDCLIENT_EXPORT SlideManager : public QObject |
| 55 | { |
| 56 | Q_OBJECT |
| 57 | public: |
| 58 | /** |
| 59 | * Creates a new SlideManager. |
| 60 | * Note: after constructing the SlideManager it is not yet valid and one needs |
| 61 | * to call setup. In order to get a ready to use SlideManager prefer using |
| 62 | * Registry::createSlideManager. |
| 63 | **/ |
| 64 | explicit SlideManager(QObject *parent = nullptr); |
| 65 | ~SlideManager() override; |
| 66 | |
| 67 | /** |
| 68 | * Setup this SlideManager to manage the @p slidemanager. |
| 69 | * When using Registry::createSlideManager there is no need to call this |
| 70 | * method. |
| 71 | **/ |
| 72 | void setup(org_kde_kwin_slide_manager *slidemanager); |
| 73 | /** |
| 74 | * @returns @c true if managing a org_kde_kwin_slide_manager. |
| 75 | **/ |
| 76 | bool isValid() const; |
| 77 | /** |
| 78 | * Releases the org_kde_kwin_slide_manager interface. |
| 79 | * After the interface has been released the SlideManager instance is no |
| 80 | * longer valid and can be setup with another org_kde_kwin_slide_manager interface. |
| 81 | **/ |
| 82 | void release(); |
| 83 | /** |
| 84 | * Destroys the data held by this SlideManager. |
| 85 | * This method is supposed to be used when the connection to the Wayland |
| 86 | * server goes away. If the connection is not valid anymore, it's not |
| 87 | * possible to call release anymore as that calls into the Wayland |
| 88 | * connection and the call would fail. This method cleans up the data, so |
| 89 | * that the instance can be deleted or set up to a new org_kde_kwin_slide_manager interface |
| 90 | * once there is a new connection available. |
| 91 | * |
| 92 | * This method is automatically invoked when the Registry which created this |
| 93 | * SlideManager gets destroyed. |
| 94 | * |
| 95 | * @see release |
| 96 | **/ |
| 97 | void destroy(); |
| 98 | |
| 99 | /** |
| 100 | * Sets the @p queue to use for creating objects with this SlideManager. |
| 101 | **/ |
| 102 | void setEventQueue(EventQueue *queue); |
| 103 | /** |
| 104 | * @returns The event queue to use for creating objects with this SlideManager. |
| 105 | **/ |
| 106 | EventQueue *eventQueue(); |
| 107 | |
| 108 | Slide *createSlide(Surface *surface, QObject *parent = nullptr); |
| 109 | |
| 110 | void removeSlide(Surface *surface); |
| 111 | |
| 112 | operator org_kde_kwin_slide_manager *(); |
| 113 | operator org_kde_kwin_slide_manager *() const; |
| 114 | |
| 115 | Q_SIGNALS: |
| 116 | /** |
| 117 | * The corresponding global for this interface on the Registry got removed. |
| 118 | * |
| 119 | * This signal gets only emitted if the SlideManager got created by |
| 120 | * Registry::createSlideManager |
| 121 | **/ |
| 122 | void removed(); |
| 123 | |
| 124 | private: |
| 125 | class Private; |
| 126 | QScopedPointer<Private> d; |
| 127 | }; |
| 128 | |
| 129 | /** |
| 130 | * TODO |
| 131 | */ |
| 132 | class KWAYLANDCLIENT_EXPORT Slide : public QObject |
| 133 | { |
| 134 | Q_OBJECT |
| 135 | public: |
| 136 | enum Location { |
| 137 | Left = 0, /**< Slide from the left edge of the screen */ |
| 138 | Top, /**< Slide from the top edge of the screen */ |
| 139 | Right, /**< Slide from the bottom edge of the screen */ |
| 140 | Bottom, /**< Slide from the bottom edge of the screen */ |
| 141 | }; |
| 142 | |
| 143 | ~Slide() override; |
| 144 | |
| 145 | /** |
| 146 | * Setup this Slide to manage the @p slide. |
| 147 | * When using SlideManager::createSlide there is no need to call this |
| 148 | * method. |
| 149 | **/ |
| 150 | void setup(org_kde_kwin_slide *slide); |
| 151 | |
| 152 | /** |
| 153 | * @returns @c true if managing a org_kde_kwin_slide. |
| 154 | **/ |
| 155 | bool isValid() const; |
| 156 | |
| 157 | /** |
| 158 | * Releases the org_kde_kwin_slide interface. |
| 159 | * After the interface has been released the Slide instance is no |
| 160 | * longer valid and can be setup with another org_kde_kwin_slide interface. |
| 161 | **/ |
| 162 | void release(); |
| 163 | |
| 164 | /** |
| 165 | * Destroys the data held by this Slide. |
| 166 | * This method is supposed to be used when the connection to the Wayland |
| 167 | * server goes away. If the connection is not valid anymore, it's not |
| 168 | * possible to call release anymore as that calls into the Wayland |
| 169 | * connection and the call would fail. This method cleans up the data, so |
| 170 | * that the instance can be deleted or set up to a new org_kde_kwin_slide interface |
| 171 | * once there is a new connection available. |
| 172 | * |
| 173 | * It is suggested to connect this method to ConnectionThread::connectionDied: |
| 174 | * @code |
| 175 | * connect(connection, &ConnectionThread::connectionDied, slide, &Slide::destroy); |
| 176 | * @endcode |
| 177 | * |
| 178 | * @see release |
| 179 | **/ |
| 180 | void destroy(); |
| 181 | |
| 182 | void commit(); |
| 183 | |
| 184 | /** |
| 185 | * Set the location of the screen to slide the window from |
| 186 | */ |
| 187 | void setLocation(Slide::Location location); |
| 188 | |
| 189 | /** |
| 190 | * Set the offset from the screen edge |
| 191 | * to make the window slide from |
| 192 | */ |
| 193 | void setOffset(qint32 offset); |
| 194 | |
| 195 | operator org_kde_kwin_slide *(); |
| 196 | operator org_kde_kwin_slide *() const; |
| 197 | |
| 198 | private: |
| 199 | friend class SlideManager; |
| 200 | explicit Slide(QObject *parent = nullptr); |
| 201 | class Private; |
| 202 | QScopedPointer<Private> d; |
| 203 | }; |
| 204 | |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | #endif |
| 209 | |