File indexing completed on 2024-05-12 09:36:15

0001 // SPDX-FileCopyrightText: 2016 Sebastian Kügler <sebas@kde.org>
0002 // SPDX-FileCopyrightText: 2022 Aleix Pol Gonzalez <aleixpol@kde.org>
0003 //
0004 // SPDX-License-Identifier: LGPL-2.1-or-later
0005 
0006 #pragma once
0007 
0008 #include <QScreen>
0009 
0010 #include "kscreendpms_export.h"
0011 
0012 namespace KScreen
0013 {
0014 
0015 class AbstractDpmsHelper;
0016 
0017 /**
0018  * @class Dpms, allows controlling the system's Display Power Management Signaling
0019  *
0020  * Provides an API to switch the system's mode on a per-display basis.
0021  *
0022  * It has backends for X11 and Wayland.
0023  */
0024 class KSCREENDPMS_EXPORT Dpms : public QObject
0025 {
0026     Q_OBJECT
0027     Q_PROPERTY(bool isSupported READ isSupported NOTIFY supportedChanged)
0028     Q_PROPERTY(bool hasPendingChanges READ hasPendingChanges NOTIFY hasPendingChangesChanged)
0029 
0030 public:
0031     explicit Dpms(QObject *parent = nullptr);
0032     ~Dpms() override;
0033 
0034     enum Mode {
0035         On,
0036         Standby,
0037         Suspend,
0038         Off,
0039         Toggle,
0040     };
0041     Q_ENUM(Mode)
0042 
0043     /**
0044      * @returns true if the DPMS system is supported
0045      */
0046     bool isSupported() const;
0047 
0048     /**
0049      * @returns true if there still are pending DPMS changes
0050      * This would happen after @m switchMode is called as most implementations will be async.
0051      */
0052     bool hasPendingChanges() const;
0053 
0054     /**
0055      * Switches the @p screens to @p mode
0056      *
0057      * If @p screens is empty, it will use all the screens as returned by QGuiApplication::screens()
0058      */
0059     Q_SCRIPTABLE void switchMode(Mode mode, const QList<QScreen *> &screen = {});
0060 
0061 Q_SIGNALS:
0062     /**
0063      * Notifies about the class being ready for usage
0064      */
0065     void supportedChanged(bool supported);
0066 
0067     /**
0068      * Tells which is the new @p mode that the @p screen just adopted
0069      */
0070     void modeChanged(Mode mode, QScreen *screen);
0071 
0072     void hasPendingChangesChanged(bool hasPendingChanges);
0073 
0074 private:
0075     QScopedPointer<AbstractDpmsHelper> m_helper;
0076 };
0077 
0078 } // namespace