File indexing completed on 2024-04-21 16:17:34

0001 /*
0002  *  SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
0003  *  SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
0004  *
0005  *  SPDX-License-Identifier: LGPL-2.1-or-later
0006  */
0007 
0008 #ifndef OUTPUT_CONFIG_H
0009 #define OUTPUT_CONFIG_H
0010 
0011 #include "kscreen_export.h"
0012 #include "types.h"
0013 
0014 #include <QDebug>
0015 #include <QMetaType>
0016 #include <QObject>
0017 #include <QPoint>
0018 #include <QSize>
0019 #include <QStringList>
0020 
0021 namespace KScreen
0022 {
0023 class Edid;
0024 class Mode;
0025 
0026 class KSCREEN_EXPORT Output : public QObject
0027 {
0028     Q_OBJECT
0029     Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
0030 public:
0031     Q_PROPERTY(int id READ id CONSTANT)
0032     Q_PROPERTY(QString name READ name WRITE setName NOTIFY outputChanged)
0033     Q_PROPERTY(Type type READ type WRITE setType NOTIFY outputChanged)
0034     Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY outputChanged)
0035     Q_PROPERTY(ModeList modes READ modes NOTIFY modesChanged)
0036     Q_PROPERTY(QPoint pos READ pos WRITE setPos NOTIFY posChanged)
0037     Q_PROPERTY(QSize size READ size WRITE setSize NOTIFY sizeChanged)
0038     Q_PROPERTY(Rotation rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
0039     Q_PROPERTY(QString currentModeId READ currentModeId WRITE setCurrentModeId NOTIFY currentModeIdChanged)
0040     Q_PROPERTY(QString preferredModeId READ preferredModeId CONSTANT)
0041     Q_PROPERTY(bool connected READ isConnected WRITE setConnected NOTIFY isConnectedChanged)
0042     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY isEnabledChanged)
0043     Q_PROPERTY(bool primary READ isPrimary WRITE setPrimary NOTIFY priorityChanged)
0044     Q_PROPERTY(uint32_t priority READ priority WRITE setPriority NOTIFY priorityChanged)
0045     Q_PROPERTY(QList<int> clones READ clones WRITE setClones NOTIFY clonesChanged)
0046     Q_PROPERTY(int replicationSource READ replicationSource WRITE setReplicationSource NOTIFY replicationSourceChanged)
0047     Q_PROPERTY(KScreen::Edid *edid READ edid CONSTANT)
0048     Q_PROPERTY(QSize sizeMm READ sizeMm CONSTANT)
0049     Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
0050     Q_PROPERTY(bool followPreferredMode READ followPreferredMode WRITE setFollowPreferredMode NOTIFY followPreferredModeChanged)
0051     Q_PROPERTY(QSizeF explicitLogicalSize READ explicitLogicalSize WRITE setExplicitLogicalSize NOTIFY explicitLogicalSizeChanged)
0052     Q_PROPERTY(Capabilities capabilities READ capabilities NOTIFY capabilitiesChanged)
0053     Q_PROPERTY(uint32_t overscan READ overscan WRITE setOverscan NOTIFY overscanChanged)
0054     Q_PROPERTY(VrrPolicy vrrPolicy READ vrrPolicy WRITE setVrrPolicy NOTIFY vrrPolicyChanged)
0055     Q_PROPERTY(RgbRange rgbRange READ rgbRange WRITE setRgbRange NOTIFY rgbRangeChanged)
0056 
0057     enum Type {
0058         Unknown,
0059         VGA,
0060         DVI,
0061         DVII,
0062         DVIA,
0063         DVID,
0064         HDMI,
0065         Panel,
0066         TV,
0067         TVComposite,
0068         TVSVideo,
0069         TVComponent,
0070         TVSCART,
0071         TVC4,
0072         DisplayPort,
0073     };
0074     Q_ENUM(Type)
0075 
0076     enum Rotation {
0077         None = 1,
0078         Left = 2,
0079         Inverted = 4,
0080         Right = 8,
0081     };
0082     Q_ENUM(Rotation)
0083 
0084     enum class Capability {
0085         Overscan = 0x1,
0086         Vrr = 0x2,
0087         RgbRange = 0x4,
0088     };
0089     Q_ENUM(Capability)
0090     Q_DECLARE_FLAGS(Capabilities, Capability)
0091     Q_FLAG(Capabilities)
0092 
0093     enum class VrrPolicy {
0094         Never = 0,
0095         Always = 1,
0096         Automatic = 2,
0097     };
0098     Q_ENUM(VrrPolicy)
0099 
0100     enum class RgbRange {
0101         Automatic = 0,
0102         Full = 1,
0103         Limited = 2,
0104     };
0105     Q_ENUM(RgbRange)
0106 
0107     explicit Output();
0108     ~Output() override;
0109 
0110     OutputPtr clone() const;
0111 
0112     int id() const;
0113     void setId(int id);
0114 
0115     QString name() const;
0116     void setName(const QString &name);
0117 
0118     /**
0119      * Returns an identifying hash for this output.
0120      *
0121      * The hash is calculated either via the edid hash or if no
0122      * edid is available by the output name.
0123      *
0124      * @return identifying hash of this output
0125      * @since 5.15
0126      * @deprecated
0127      * @see hashMd5
0128      */
0129     QString hash() const;
0130 
0131     /**
0132      * Returns an identifying hex encoded MD5-hash for this output.
0133      *
0134      * The hash is calculated either via the edid hash or if no
0135      * edid is available by the output name, which is hashed as well.
0136      *
0137      * @return identifying hash of this output
0138      * @since 5.17
0139      */
0140     QString hashMd5() const;
0141 
0142     Type type() const;
0143     QString typeName() const;
0144     void setType(Type type);
0145 
0146     QString icon() const;
0147     void setIcon(const QString &icon);
0148 
0149     Q_INVOKABLE ModePtr mode(const QString &id) const;
0150     ModeList modes() const;
0151     void setModes(const ModeList &modes);
0152 
0153     QString currentModeId() const;
0154     void setCurrentModeId(const QString &mode);
0155     Q_INVOKABLE ModePtr currentMode() const;
0156 
0157     void setPreferredModes(const QStringList &modes);
0158     QStringList preferredModes() const;
0159     /**
0160      * Returns the preferred mode with higher resolution and refresh
0161      */
0162     Q_INVOKABLE QString preferredModeId() const;
0163     /**
0164      * Returns KScreen::Mode associated with preferredModeId()
0165      */
0166     Q_INVOKABLE ModePtr preferredMode() const;
0167 
0168     QPoint pos() const;
0169     void setPos(const QPoint &pos);
0170 
0171     /***
0172      * Returns actual size being rendered in the output
0173      *
0174      * The returned valued is after transformations have been applied to
0175      * the resolution of the current mode.
0176      *
0177      * For example if currentMode is 1280x800 but it is a vertical screen
0178      * the returned size will be 800x1280.
0179      *
0180      * If that same resolution (1280x800) is transformed and scale x2, the
0181      * value returned will be 2560x1600.
0182      *
0183      * This property reflects the currently active output configuration and
0184      * is not affected by current mode or orientation change made by user
0185      * until the config is applied.
0186      *
0187      * @since 5.4
0188      */
0189     QSize size() const;
0190     void setSize(const QSize &size);
0191 
0192     /**
0193      * Returns either current mode size or if not available preferred one or if also not
0194      * available the first one in the ModeList.
0195      *
0196      * @return mode size
0197      */
0198     QSize enforcedModeSize() const;
0199 
0200     Rotation rotation() const;
0201     void setRotation(Rotation rotation);
0202     /**
0203      * A comfortable function that returns true when output is not rotated
0204      * or is rotated upside down.
0205      */
0206     Q_INVOKABLE inline bool isHorizontal() const
0207     {
0208         return ((rotation() == Output::None) || (rotation() == Output::Inverted));
0209     }
0210 
0211     bool isConnected() const;
0212     void setConnected(bool connected);
0213 
0214     bool isEnabled() const;
0215     void setEnabled(bool enabled);
0216 
0217     bool isPrimary() const;
0218     void setPrimary(bool primary);
0219 
0220     uint32_t priority() const;
0221     void setPriority(uint32_t priority);
0222 
0223     /**
0224      * @brief Immutable clones because of hardware restrictions
0225      *
0226      * Clones are set symmetrically on all outputs. The list contains ids
0227      * for all other outputs being clones of this output.
0228      *
0229      * @return List of output ids being clones of each other.
0230      */
0231     QList<int> clones() const;
0232     /**
0233      * @brief Set the clones list.
0234      *
0235      * When this output is part of a configuration this call is followed by
0236      * similar calls on other outputs making the lists in all outputs
0237      * symmetric.
0238      * @param outputlist
0239      */
0240     void setClones(const QList<int> &outputlist);
0241 
0242     /**
0243      * @brief Provides the source for an ongoing replication
0244      *
0245      * If the returned output id is non-null this output is a replica of the
0246      * returned output. If null is returned the output is no replica of any
0247      * other output.
0248      *
0249      * @return Replication source output id of this output
0250      */
0251     int replicationSource() const;
0252     /**
0253      * @brief Set the replication source.
0254      * @param source
0255      */
0256     void setReplicationSource(int source);
0257 
0258     void setEdid(const QByteArray &rawData);
0259 
0260     /**
0261      * edid returns the output's EDID information if available.
0262      *
0263      * The output maintains ownership of the returned Edid, so the caller should not delete it.
0264      * Note that the edid is only valid as long as the output is alive.
0265      */
0266     Edid *edid() const;
0267 
0268     /**
0269      * Returns the physical size of the screen in milimeters.
0270      *
0271      * @note Some broken GPUs or monitors return the size in centimeters instead
0272      * of millimeters. KScreen at the moment is not sanitizing the values.
0273      */
0274     QSize sizeMm() const;
0275     void setSizeMm(const QSize &size);
0276 
0277     /**
0278      * Returns if the output needs to be taken account for in the overall compositor/screen
0279      * space and if it should be depicted on its own in a graphical view for repositioning.
0280      *
0281      * @return true if the output is positionable in compositor/screen space.
0282      *
0283      * @since 5.17
0284      */
0285     bool isPositionable() const;
0286 
0287     /**
0288      * Returns a rectangle containing the currently set output position and
0289      * size.
0290      *
0291      * The geometry also reflects current orientation (i.e. if current mode
0292      * is 1920x1080 and orientation is @p KScreen::Output::Left, then the
0293      * size of the returned rectangle will be 1080x1920.
0294      *
0295      * This property contains the current settings stored in the particular
0296      * Output object, so it is updated even when user changes current mode
0297      * or orientation without applying the whole config/
0298      */
0299     QRect geometry() const;
0300 
0301     /**
0302      * returns the scaling factor to use for this output
0303      *
0304      * @since 5.9
0305      */
0306     qreal scale() const;
0307 
0308     /**
0309      * Set the scaling factor for this output.
0310      *
0311      * @arg factor Scale factor to use for this output, the backend may or may not
0312      * be able to deal with non-integer values, in that case, the factor gets rounded.
0313      *
0314      * @since 5.9
0315      */
0316     void setScale(qreal factor);
0317 
0318     /**
0319      * The logical size is the output's representation internal to the display server and its
0320      * overall screen geometry.
0321      *
0322      * returns the explicitly set logical size of this output, is an invalid size if not set
0323      *
0324      * @since 5.18
0325      */
0326     QSizeF explicitLogicalSize() const;
0327 
0328     /**
0329      * Specifies explicitly the logical size of this output and by that overrides any other
0330      * logical size calculation through mode and scale. To enable this instead again call this
0331      * function with an invalid size as argument.
0332      *
0333      * @param size of this output in logical space
0334      *
0335      * @since 5.24
0336      */
0337     void setExplicitLogicalSize(const QSizeF &size);
0338 
0339     /**
0340      * @returns whether the mode should be changed to the new preferred mode
0341      * once it changes
0342      *
0343      * @since 5.15
0344      */
0345     bool followPreferredMode() const;
0346 
0347     /**
0348      * Set whether the preferred mode should be followed through @arg follow
0349      *
0350      * @since 5.15
0351      */
0352     void setFollowPreferredMode(bool follow);
0353 
0354     /**
0355      * @returns the capabilities of this output
0356      * @since 5.22
0357      */
0358     Capabilities capabilities() const;
0359 
0360     /**
0361      * sets the capabilities of this output
0362      * @since 5.22
0363      */
0364     void setCapabilities(Capabilities capabilities);
0365 
0366     /**
0367      * @returns the overscan value of this output in %
0368      * @since 5.22
0369      */
0370     uint32_t overscan() const;
0371 
0372     /**
0373      * Set the overscan for this output
0374      * @param overscan the overscan value in %
0375      * @since 5.22
0376      */
0377     void setOverscan(uint32_t overscan);
0378 
0379     /**
0380      * @returns when variable refresh rate should be used on this output
0381      *
0382      * @since 5.22
0383      */
0384     VrrPolicy vrrPolicy() const;
0385 
0386     /**
0387      * Set when variable refresh rate should be used on this output
0388      *
0389      * @since 5.22
0390      */
0391     void setVrrPolicy(VrrPolicy policy);
0392 
0393     /**
0394      * @returns which rgb range the output is using
0395      * @since 5.23
0396      */
0397     RgbRange rgbRange() const;
0398 
0399     /**
0400      * Set which rgb range the output should use
0401      * @since 5.23
0402      */
0403     void setRgbRange(RgbRange rgbRange);
0404 
0405     void apply(const OutputPtr &other);
0406 
0407 Q_SIGNALS:
0408     void outputChanged();
0409     void posChanged();
0410     void sizeChanged();
0411     void currentModeIdChanged();
0412     void rotationChanged();
0413     void isConnectedChanged();
0414     void isEnabledChanged();
0415     void priorityChanged();
0416     void clonesChanged();
0417     void replicationSourceChanged();
0418     void scaleChanged();
0419     void explicitLogicalSizeChanged();
0420     void followPreferredModeChanged(bool followPreferredMode);
0421     void capabilitiesChanged();
0422     void overscanChanged();
0423     void vrrPolicyChanged();
0424     void rgbRangeChanged();
0425 
0426     /** The mode list changed.
0427      *
0428      * This may happen when a mode is added or changed.
0429      *
0430      * @since 5.8.3
0431      */
0432     void modesChanged();
0433 
0434 private:
0435     Q_DISABLE_COPY(Output)
0436 
0437     class Private;
0438     Private *const d;
0439 
0440     explicit Output(Private *dd);
0441 };
0442 
0443 } // KScreen namespace
0444 
0445 KSCREEN_EXPORT QDebug operator<<(QDebug dbg, const KScreen::OutputPtr &output);
0446 
0447 Q_DECLARE_METATYPE(KScreen::OutputList)
0448 Q_DECLARE_METATYPE(KScreen::Output::Rotation)
0449 Q_DECLARE_METATYPE(KScreen::Output::Type)
0450 
0451 #endif // OUTPUT_H