File indexing completed on 2024-04-28 16:44:33

0001 /*
0002  * SPDX-FileCopyrightText: 2014 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 #pragma once
0007 
0008 #include "decoration.h"
0009 #include "decorationdefines.h"
0010 #include <kdecoration2/kdecoration2_export.h>
0011 
0012 #include <QFont>
0013 #include <QIcon>
0014 #include <QObject>
0015 #include <QPalette>
0016 #include <QPointer>
0017 #include <QtGui/qwindowdefs.h>
0018 
0019 #include <memory>
0020 
0021 namespace KDecoration2
0022 {
0023 class DecorationBridge;
0024 class DecoratedClientPrivate;
0025 
0026 /**
0027  * @brief The Client which gets decorated.
0028  *
0029  * The DecoratedClient provides access to all the properties relevant for decorating the Client.
0030  * Each DecoratedClient is bound to one Decoration and each Decoration is bound to this one
0031  * DecoratedClient.
0032  *
0033  * The DecoratedClient only exports properties, it does not provide any means to change the state.
0034  * To change state one needs to call the methods on Decoration. This is as the backend might
0035  * disallow state changes. Therefore any changes should be bound to the change signals of the
0036  * DecoratedClient and not be bound to state changes of input elements (such as a button).
0037  */
0038 class KDECORATIONS2_EXPORT DecoratedClient : public QObject
0039 {
0040     Q_OBJECT
0041     /**
0042      * The Decoration of this DecoratedClient
0043      **/
0044     Q_PROPERTY(KDecoration2::Decoration *decoration READ decoration CONSTANT)
0045     /**
0046      * Whether the DecoratedClient is active (has focus) or is inactive.
0047      **/
0048     Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
0049     /**
0050      * The caption of the DecoratedClient.
0051      **/
0052     Q_PROPERTY(QString caption READ caption NOTIFY captionChanged)
0053     /**
0054      * The virtual desktop of the DecoratedClient. The special value @c -1 means on all
0055      * desktops. For this prefer using the property onAllDesktops.
0056      **/
0057     Q_PROPERTY(int desktop READ desktop NOTIFY desktopChanged)
0058     /**
0059      * Whether the DecoratedClient is on all desktops or on just one.
0060      **/
0061     Q_PROPERTY(bool onAllDesktops READ isOnAllDesktops NOTIFY onAllDesktopsChanged)
0062     /**
0063      * Whether the DecoratedClient is shaded. Shaded means that the actual content is
0064      * not visible, only the Decoration is visible.
0065      **/
0066     Q_PROPERTY(bool shaded READ isShaded NOTIFY shadedChanged)
0067     /**
0068      * The icon of the DecoratedClient. This can be used as the icon for the window menu button.
0069      **/
0070     Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
0071     /**
0072      * Whether the DecoratedClient is maximized. A DecoratedClient is maximized if it is both
0073      * maximizedHorizontally and maximizedVertically. The Decoration of a maximized DecoratedClient
0074      * should only consist of the title bar area.
0075      **/
0076     Q_PROPERTY(bool maximized READ isMaximized NOTIFY maximizedChanged)
0077     /**
0078      * Whether the DecoratedClient is maximized horizontally. A horizontally maximized DecoratedClient
0079      * uses the maximal possible width.
0080      **/
0081     Q_PROPERTY(bool maximizedHorizontally READ isMaximizedHorizontally NOTIFY maximizedHorizontallyChanged)
0082     /**
0083      * Whether the DecoratedClient is maximized vertically. A vertically maximized DecoratedClient
0084      * uses the maximal possible height.
0085      **/
0086     Q_PROPERTY(bool maximizedVertically READ isMaximizedVertically NOTIFY maximizedVerticallyChanged)
0087     /**
0088      * Whether the DecoratedClient is set to be kept above other DecoratedClients. There can be multiple
0089      * DecoratedClients which are set to be kept above.
0090      **/
0091     Q_PROPERTY(bool keepAbove READ isKeepAbove NOTIFY keepAboveChanged)
0092     /**
0093      * Whether the DecoratedClient is set to be kept below other DecoratedClients. There can be multiple
0094      * DecoratedClients which are set to be kept below.
0095      **/
0096     Q_PROPERTY(bool keepBelow READ isKeepBelow NOTIFY keepBelowChanged)
0097 
0098     /**
0099      * Whether the DecoratedClient can be closed. If this property is @c false a DecorationButton
0100      * for closing the DecoratedClient should be disabled.
0101      **/
0102     Q_PROPERTY(bool closeable READ isCloseable NOTIFY closeableChanged)
0103     /**
0104      * Whether the DecoratedClient can be maximized. If this property is @c false a DecorationButton
0105      * for maximizing the DecoratedClient should be disabled.
0106      **/
0107     Q_PROPERTY(bool maximizeable READ isMaximizeable NOTIFY maximizeableChanged)
0108     /**
0109      * Whether the DecoratedClient can be minimized. If this property is @c false a DecorationButton
0110      * for minimizing the DecoratedClient should be disabled.
0111      **/
0112     Q_PROPERTY(bool minimizeable READ isMinimizeable NOTIFY minimizeableChanged)
0113     /**
0114      * Whether the DecoratedClient provides context help.
0115      * The Decoration should only show a context help button if this property is @c true.
0116      **/
0117     Q_PROPERTY(bool providesContextHelp READ providesContextHelp NOTIFY providesContextHelpChanged)
0118     /**
0119      * Whether the DecoratedClient is a modal dialog.
0120      **/
0121     Q_PROPERTY(bool modal READ isModal CONSTANT)
0122     /**
0123      * Whether the DecoratedClient can be shaded. If this property is @c false a DecorationButton
0124      * for shading the DecoratedClient should be disabled.
0125      **/
0126     Q_PROPERTY(bool shadeable READ isShadeable NOTIFY shadeableChanged)
0127     /**
0128      * Whether the DecoratedClient can be moved.
0129      **/
0130     Q_PROPERTY(bool moveable READ isMoveable NOTIFY moveableChanged)
0131     /**
0132      * Whether the DecoratedClient can be resized.
0133      **/
0134     Q_PROPERTY(bool resizeable READ isResizeable NOTIFY resizeableChanged)
0135 
0136     /**
0137      * The width of the DecoratedClient.
0138      **/
0139     Q_PROPERTY(int width READ width NOTIFY widthChanged)
0140     /**
0141      * The height of the DecoratedClient.
0142      **/
0143     Q_PROPERTY(int height READ height NOTIFY heightChanged)
0144     /**
0145      * The size of the DecoratedClient.
0146      **/
0147     Q_PROPERTY(QSize size READ size NOTIFY sizeChanged)
0148     /**
0149      * The palette this DecoratedClient uses. The palette might be different for each
0150      * DecoratedClient and the Decoration should honor the palette.
0151      **/
0152     Q_PROPERTY(QPalette palette READ palette NOTIFY paletteChanged)
0153     /**
0154      * The Edges which are adjacent to a screen edge. E.g. for a maximized DecoratedClient this
0155      * will include all Edges. The Decoration can use this information to hide borders.
0156      **/
0157     Q_PROPERTY(Qt::Edges adjacentScreenEdges READ adjacentScreenEdges NOTIFY adjacentScreenEdgesChanged)
0158     /**
0159      * Whether the DecoratedClient has an application menu
0160      * @since 5.9
0161      */
0162     Q_PROPERTY(bool hasApplicationMenu READ hasApplicationMenu NOTIFY hasApplicationMenuChanged)
0163     /**
0164      * Whether the application menu for this DecoratedClient is currently shown to the user
0165      * The Decoration can use this information to highlight the respective button.
0166      * @since 5.9
0167      */
0168     Q_PROPERTY(bool applicationMenuActive READ isApplicationMenuActive NOTIFY applicationMenuActiveChanged)
0169 
0170     // TODO: properties for windowId and decorationId?
0171 
0172 public:
0173     DecoratedClient() = delete;
0174     ~DecoratedClient() override;
0175     bool isActive() const;
0176     QString caption() const;
0177     int desktop() const;
0178     bool isOnAllDesktops() const;
0179     bool isShaded() const;
0180     QIcon icon() const;
0181     bool isMaximized() const;
0182     bool isMaximizedHorizontally() const;
0183     bool isMaximizedVertically() const;
0184     bool isKeepAbove() const;
0185     bool isKeepBelow() const;
0186 
0187     bool isCloseable() const;
0188     bool isMaximizeable() const;
0189     bool isMinimizeable() const;
0190     bool providesContextHelp() const;
0191     bool isModal() const;
0192     bool isShadeable() const;
0193     bool isMoveable() const;
0194     bool isResizeable() const;
0195 
0196     Qt::Edges adjacentScreenEdges() const;
0197 
0198     WId windowId() const;
0199     WId decorationId() const;
0200 
0201     QString windowClass() const;
0202 
0203     int width() const;
0204     int height() const;
0205     QSize size() const;
0206 
0207     QPointer<Decoration> decoration() const;
0208     QPalette palette() const;
0209     /**
0210      * Used to get colors in QPalette.
0211      * @param group The color group
0212      * @param role The color role
0213      * @return palette().color(group, role)
0214      * @since 5.3
0215      **/
0216     QColor color(QPalette::ColorGroup group, QPalette::ColorRole role) const;
0217     /**
0218      * Used to get additional colors that are not in QPalette.
0219      * @param group The color group
0220      * @param role The color role
0221      * @return The color if provided for combination of group and role, otherwise invalid QColor.
0222      * @since 5.3
0223      **/
0224     QColor color(ColorGroup group, ColorRole role) const;
0225 
0226     /**
0227      * Whether the DecoratedClient has an application menu
0228      * @since 5.9
0229      */
0230     bool hasApplicationMenu() const;
0231     /**
0232      * Whether the application menu for this DecoratedClient is currently shown to the user
0233      * The Decoration can use this information to highlight the respective button.
0234      * @since 5.9
0235      */
0236     bool isApplicationMenuActive() const;
0237 
0238     /**
0239      * Request the application menu to be shown to the user
0240      * @param actionId The DBus menu ID of the action that should be highlighted, 0 for none.
0241      */
0242     void showApplicationMenu(int actionId);
0243 
0244 Q_SIGNALS:
0245     void activeChanged(bool);
0246     void captionChanged(QString);
0247     void desktopChanged(int);
0248     void onAllDesktopsChanged(bool);
0249     void shadedChanged(bool);
0250     void iconChanged(QIcon);
0251     void maximizedChanged(bool);
0252     void maximizedHorizontallyChanged(bool);
0253     void maximizedVerticallyChanged(bool);
0254     void keepAboveChanged(bool);
0255     void keepBelowChanged(bool);
0256 
0257     void closeableChanged(bool);
0258     void maximizeableChanged(bool);
0259     void minimizeableChanged(bool);
0260     void providesContextHelpChanged(bool);
0261     void shadeableChanged(bool);
0262     void moveableChanged(bool);
0263     void resizeableChanged(bool);
0264 
0265     void widthChanged(int);
0266     void heightChanged(int);
0267     void sizeChanged(const QSize &size);
0268     void paletteChanged(const QPalette &palette);
0269     void adjacentScreenEdgesChanged(Qt::Edges edges);
0270 
0271     void hasApplicationMenuChanged(bool);
0272     void applicationMenuActiveChanged(bool);
0273 
0274 private:
0275     friend class Decoration;
0276     DecoratedClient(Decoration *parent, DecorationBridge *bridge);
0277     const std::unique_ptr<DecoratedClientPrivate> d;
0278 };
0279 
0280 } // namespace