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

0001 /*
0002     SPDX-FileCopyrightText: 2015 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 KWAYLAND_CLIENT_DPMS_H
0007 #define KWAYLAND_CLIENT_DPMS_H
0008 
0009 #include <QObject>
0010 
0011 #include "KWayland/Client/kwaylandclient_export.h"
0012 
0013 struct org_kde_kwin_dpms;
0014 struct org_kde_kwin_dpms_manager;
0015 
0016 namespace KWayland
0017 {
0018 namespace Client
0019 {
0020 class EventQueue;
0021 class Dpms;
0022 class Output;
0023 
0024 /**
0025  * @short This class is a factory for Dpms instances.
0026  *
0027  * It is a convenience wrapper for the org_kde_kwin_dpms_manager interface.
0028  *
0029  * To use this class one needs to interact with the Registry. There are two
0030  * possible ways to create the DpmsManager interface:
0031  * @code
0032  * DpmsManager *m = registry->createDpmsManager(name, version);
0033  * @endcode
0034  *
0035  * This creates the DpmsManager and sets it up directly. As an alternative this
0036  * can also be done in a more low level way:
0037  * @code
0038  * DpmsManager *m = new DpmsManager;
0039  * m->setup(registry->bindDpmsManager(name, version));
0040  * @endcode
0041  *
0042  * The DpmsManager can be used as a drop-in replacement for any org_kde_kwin_dpms_manager
0043  * pointer as it provides matching cast operators.
0044  *
0045  * @see Registry, Dpms
0046  * @since 5.5
0047  **/
0048 class KWAYLANDCLIENT_EXPORT DpmsManager : public QObject
0049 {
0050     Q_OBJECT
0051 public:
0052     /**
0053      * Creates a new DpmsManager.
0054      * Note: after constructing the DpmsManager it is not yet valid and one needs
0055      * to call setup. In order to get a ready to use DpmsManager prefer using
0056      * Registry::createDpmsManager.
0057      **/
0058     explicit DpmsManager(QObject *parent = nullptr);
0059     ~DpmsManager() override;
0060 
0061     /**
0062      * @returns @c true if managing a org_kde_kwin_dpms_manager.
0063      **/
0064     bool isValid() const;
0065     /**
0066      * Setup this DpmsManager to manage the @p manager.
0067      * When using Registry::createDpmsManager there is no need to call this
0068      * method.
0069      **/
0070     void setup(org_kde_kwin_dpms_manager *manager);
0071     /**
0072      * Releases the org_kde_kwin_dpms_manager interface.
0073      * After the interface has been released the DpmsManager instance is no
0074      * longer valid and can be setup with another org_kde_kwin_dpms_manager interface.
0075      **/
0076     void release();
0077     /**
0078      * Destroys the data held by this DpmsManager.
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 org_kde_kwin_dpms_manager interface
0084      * once there is a new connection available.
0085      *
0086      * This method is automatically invoked when the Registry which created this
0087      * DPMS gets destroyed.
0088      *
0089      * @see release
0090      **/
0091     void destroy();
0092 
0093     /**
0094      * Sets the @p queue to use for creating a Dpms.
0095      **/
0096     void setEventQueue(EventQueue *queue);
0097     /**
0098      * @returns The event queue to use for creating a Dpms.
0099      **/
0100     EventQueue *eventQueue();
0101 
0102     Dpms *getDpms(Output *output, QObject *parent = nullptr);
0103 
0104     operator org_kde_kwin_dpms_manager *();
0105     operator org_kde_kwin_dpms_manager *() const;
0106 
0107 Q_SIGNALS:
0108     /**
0109      * The corresponding global for this interface on the Registry got removed.
0110      *
0111      * This signal gets only emitted if the DpmsManager got created by
0112      * Registry::createDpmsManager
0113      **/
0114     void removed();
0115 
0116 private:
0117     class Private;
0118     QScopedPointer<Private> d;
0119 };
0120 
0121 /**
0122  * @short Power management for monitors.
0123  *
0124  * Display Power Management Signaling allows power management for monitors.
0125  * This class is a convenient wrapper for the org_kde_kwin_dpms interface.
0126  * To create a Dpms call DpmsManager::getDpms.
0127  *
0128  * @see DpmsManager
0129  **/
0130 class KWAYLANDCLIENT_EXPORT Dpms : public QObject
0131 {
0132     Q_OBJECT
0133 public:
0134     ~Dpms() override;
0135 
0136     enum class Mode {
0137         On,
0138         Standby,
0139         Suspend,
0140         Off,
0141     };
0142 
0143     /**
0144      * Setup this Dpms to manage the @p dpms.
0145      * When using DpmsManager::createDpms there is no need to call this
0146      * method.
0147      **/
0148     void setup(org_kde_kwin_dpms *dpms);
0149     /**
0150      * Releases the org_kde_kwin_dpms interface.
0151      * After the interface has been released the Dpms instance is no
0152      * longer valid and can be setup with another org_kde_kwin_dpms interface.
0153      **/
0154     void release();
0155     /**
0156      * Destroys the data held by this Dpms.
0157      * This method is supposed to be used when the connection to the Wayland
0158      * server goes away. If the connection is not valid anymore, it's not
0159      * possible to call release anymore as that calls into the Wayland
0160      * connection and the call would fail. This method cleans up the data, so
0161      * that the instance can be deleted or set up to a new org_kde_kwin_dpms interface
0162      * once there is a new connection available.
0163      *
0164      * It is suggested to connect this method to ConnectionThread::connectionDied:
0165      * @code
0166      * connect(connection, &ConnectionThread::connectionDied, source, &Dpms::destroy);
0167      * @endcode
0168      *
0169      * @see release
0170      **/
0171     void destroy();
0172     /**
0173      * @returns @c true if managing a org_kde_kwin_dpms.
0174      **/
0175     bool isValid() const;
0176 
0177     /**
0178      * @returns the Output for which this Dpms got created
0179      **/
0180     QPointer<Output> output() const;
0181 
0182     /**
0183      * Whether Dpms is supported for the Output.
0184      * Initially set to @c false.
0185      * @returns whether Dpms is supported for the Output.
0186      * @see supportedChanged
0187      **/
0188     bool isSupported() const;
0189     /**
0190      * The current Dpms mode.
0191      * Initially set to @c Mode::On.
0192      * @returns the current Dpms mode of the Output
0193      * @see modeChanged
0194      **/
0195     Mode mode() const;
0196 
0197     /**
0198      * Request to change the Output into Dpms @p mode.
0199      * The Wayland compositor is not obliged to honor the request.
0200      * If the mode changes the client is notified and @link modeChanged @endlink gets emitted.
0201      * @param mode The requested Dpms mode.
0202      **/
0203     void requestMode(Mode mode);
0204 
0205     operator org_kde_kwin_dpms *();
0206     operator org_kde_kwin_dpms *() const;
0207 
0208 Q_SIGNALS:
0209     /**
0210      * Emitted if the supported state on the Output changes.
0211      * @see isSupported
0212      **/
0213     void supportedChanged();
0214     /**
0215      * Emitted if the Dpms mode on the Output changes.
0216      * @see mode
0217      **/
0218     void modeChanged();
0219 
0220 private:
0221     friend class DpmsManager;
0222     explicit Dpms(const QPointer<Output> &o, QObject *parent = nullptr);
0223     class Private;
0224     QScopedPointer<Private> d;
0225 };
0226 
0227 }
0228 }
0229 
0230 Q_DECLARE_METATYPE(KWayland::Client::Dpms::Mode)
0231 
0232 #endif