File indexing completed on 2024-12-22 05:09:20

0001 /*
0002     SPDX-FileCopyrightText: 2017 Martin Flöser <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 KWAYLAND_CLIENT_IDLEINHIBIT_H
0007 #define KWAYLAND_CLIENT_IDLEINHIBIT_H
0008 
0009 #include <QObject>
0010 
0011 #include "KWayland/Client/kwaylandclient_export.h"
0012 
0013 struct zwp_idle_inhibit_manager_v1;
0014 struct zwp_idle_inhibitor_v1;
0015 
0016 namespace KWayland
0017 {
0018 namespace Client
0019 {
0020 class EventQueue;
0021 class Surface;
0022 class IdleInhibitor;
0023 
0024 /**
0025  * @short Wrapper for the zwp_idle_inhibit_manager_v1 interface.
0026  *
0027  * This class provides a convenient wrapper for the zwp_idle_inhibit_manager_v1 interface.
0028  *
0029  * To use this class one needs to interact with the Registry. There are two
0030  * possible ways to create the IdleInhibitManager interface:
0031  * @code
0032  * IdleInhibitManager *c = registry->createIdleInhibitManager(name, version);
0033  * @endcode
0034  *
0035  * This creates the IdleInhibitManager and sets it up directly. As an alternative this
0036  * can also be done in a more low level way:
0037  * @code
0038  * IdleInhibitManager *c = new IdleInhibitManager;
0039  * c->setup(registry->bindIdleInhibitManager(name, version));
0040  * @endcode
0041  *
0042  * The IdleInhibitManager can be used as a drop-in replacement for any zwp_idle_inhibit_manager_v1
0043  * pointer as it provides matching cast operators.
0044  *
0045  * @see Registry
0046  * @since 5.41
0047  **/
0048 class KWAYLANDCLIENT_EXPORT IdleInhibitManager : public QObject
0049 {
0050     Q_OBJECT
0051 public:
0052     /**
0053      * Creates a new IdleInhibitManager.
0054      * Note: after constructing the IdleInhibitManager it is not yet valid and one needs
0055      * to call setup. In order to get a ready to use IdleInhibitManager prefer using
0056      * Registry::createIdleInhibitManager.
0057      **/
0058     explicit IdleInhibitManager(QObject *parent = nullptr);
0059     ~IdleInhibitManager() override;
0060 
0061     /**
0062      * Setup this IdleInhibitManager to manage the @p idleinhibitmanager.
0063      * When using Registry::createIdleInhibitManager there is no need to call this
0064      * method.
0065      **/
0066     void setup(zwp_idle_inhibit_manager_v1 *idleinhibitmanager);
0067     /**
0068      * @returns @c true if managing a zwp_idle_inhibit_manager_v1.
0069      **/
0070     bool isValid() const;
0071     /**
0072      * Releases the zwp_idle_inhibit_manager_v1 interface.
0073      * After the interface has been released the IdleInhibitManager instance is no
0074      * longer valid and can be setup with another zwp_idle_inhibit_manager_v1 interface.
0075      **/
0076     void release();
0077     /**
0078      * Destroys the data held by this IdleInhibitManager.
0079      * This method is supposed to be used when the connection to the Wayland
0080      * server goes away. If the connection is not valid anymore, it's not
0081      * possible to call release anymore as that calls into the Wayland
0082      * connection and the call would fail. This method cleans up the data, so
0083      * that the instance can be deleted or set up to a new zwp_idle_inhibit_manager_v1 interface
0084      * once there is a new connection available.
0085      *
0086      * It is suggested to connect this method to ConnectionThread::connectionDied:
0087      * @code
0088      * connect(connection, &ConnectionThread::connectionDied, idleinhibitmanager, &IdleInhibitManager::destroy);
0089      * @endcode
0090      *
0091      * @see release
0092      **/
0093     void destroy();
0094 
0095     /**
0096      * Sets the @p queue to use for creating objects with this IdleInhibitManager.
0097      **/
0098     void setEventQueue(EventQueue *queue);
0099     /**
0100      * @returns The event queue to use for creating objects with this IdleInhibitManager.
0101      **/
0102     EventQueue *eventQueue();
0103 
0104     /**
0105      * Creates an IdleInhibitor for the given @p surface.
0106      * While the IdleInhibitor exists the @p surface is marked to inhibit idle.
0107      * @param surface The Surface which should have idle inhibited
0108      * @param parent The parent object for the IdleInhibitor
0109      * @returns The created IdleInhibitor
0110      **/
0111     IdleInhibitor *createInhibitor(Surface *surface, QObject *parent = nullptr);
0112 
0113     operator zwp_idle_inhibit_manager_v1 *();
0114     operator zwp_idle_inhibit_manager_v1 *() const;
0115 
0116 Q_SIGNALS:
0117     /**
0118      * The corresponding global for this interface on the Registry got removed.
0119      *
0120      * This signal gets only emitted if the IdleInhibitManager got created by
0121      * Registry::createIdleInhibitManager
0122      **/
0123     void removed();
0124 
0125 private:
0126     class Private;
0127     QScopedPointer<Private> d;
0128 };
0129 
0130 /**
0131  * An IdleInhibitor prevents the Output that the associated Surface is visible on from being
0132  * set to a state where it is not visually usable due to lack of user interaction
0133  * (e.g. blanked, dimmed, locked, set to power save, etc.)  Any screensaver processes are
0134  * also blocked from displaying.
0135  *
0136  * If the Surface is destroyed, unmapped, becomes occluded, loses visibility, or otherwise
0137  * becomes not visually relevant for the user, the IdleInhibitor will not be honored by
0138  * the compositor; if the Surface subsequently regains visibility the inhibitor takes effect
0139  * once again.
0140  * Likewise, the IdleInhibitor isn't honored if the system was already idled at the time the
0141  * IdleInhibitor was established, although if the system later de-idles and re-idles the
0142  * IdleInhibitor will take effect.
0143  *
0144  * @see IdleInhibitManager
0145  * @see Surface
0146  * @since 5.41
0147  **/
0148 class KWAYLANDCLIENT_EXPORT IdleInhibitor : public QObject
0149 {
0150     Q_OBJECT
0151 public:
0152     ~IdleInhibitor() override;
0153 
0154     /**
0155      * Setup this IdleInhibitor to manage the @p idleinhibitor.
0156      * When using IdleInhibitManager::createIdleInhibitor there is no need to call this
0157      * method.
0158      **/
0159     void setup(zwp_idle_inhibitor_v1 *idleinhibitor);
0160     /**
0161      * @returns @c true if managing a zwp_idle_inhibitor_v1.
0162      **/
0163     bool isValid() const;
0164     /**
0165      * Releases the zwp_idle_inhibitor_v1 interface.
0166      * After the interface has been released the IdleInhibitor instance is no
0167      * longer valid and can be setup with another zwp_idle_inhibitor_v1 interface.
0168      **/
0169     void release();
0170     /**
0171      * Destroys the data held by this IdleInhibitor.
0172      * This method is supposed to be used when the connection to the Wayland
0173      * server goes away. If the connection is not valid anymore, it's not
0174      * possible to call release anymore as that calls into the Wayland
0175      * connection and the call would fail. This method cleans up the data, so
0176      * that the instance can be deleted or set up to a new zwp_idle_inhibitor_v1 interface
0177      * once there is a new connection available.
0178      *
0179      * It is suggested to connect this method to ConnectionThread::connectionDied:
0180      * @code
0181      * connect(connection, &ConnectionThread::connectionDied, idleinhibitor, &IdleInhibitor::destroy);
0182      * @endcode
0183      *
0184      * @see release
0185      **/
0186     void destroy();
0187 
0188     operator zwp_idle_inhibitor_v1 *();
0189     operator zwp_idle_inhibitor_v1 *() const;
0190 
0191 private:
0192     friend class IdleInhibitManager;
0193     explicit IdleInhibitor(QObject *parent = nullptr);
0194     class Private;
0195     QScopedPointer<Private> d;
0196 };
0197 
0198 }
0199 }
0200 
0201 #endif