File indexing completed on 2024-05-12 05:33:48

0001 /*
0002  *   SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0003  *   SPDX-FileCopyrightText: 2018 Drew DeVault <sir@cmpwn.com>
0004  *
0005  *   SPDX-License-Identifier: LGPL-3.0-or-later
0006  */
0007 
0008 #ifndef LAYERSHELLQTWINDOW_H
0009 #define LAYERSHELLQTWINDOW_H
0010 
0011 #include <QObject>
0012 #include <QScreen>
0013 #include <QWindow>
0014 
0015 #include "layershellqt_export.h"
0016 
0017 namespace LayerShellQt
0018 {
0019 class WindowPrivate;
0020 
0021 class LAYERSHELLQT_EXPORT Window : public QObject
0022 {
0023     Q_OBJECT
0024     Q_PROPERTY(Anchors anchors READ anchors WRITE setAnchors NOTIFY anchorsChanged)
0025     Q_PROPERTY(QString scope READ scope WRITE setScope)
0026     Q_PROPERTY(QMargins margins READ margins WRITE setMargins NOTIFY marginsChanged)
0027     Q_PROPERTY(qint32 exclusionZone READ exclusionZone WRITE setExclusiveZone NOTIFY exclusionZoneChanged)
0028     Q_PROPERTY(Layer layer READ layer WRITE setLayer NOTIFY layerChanged)
0029     Q_PROPERTY(KeyboardInteractivity keyboardInteractivity READ keyboardInteractivity WRITE setKeyboardInteractivity NOTIFY keyboardInteractivityChanged)
0030     Q_PROPERTY(ScreenConfiguration screenConfiguration READ screenConfiguration WRITE setScreenConfiguration)
0031 
0032 public:
0033     ~Window() override;
0034 
0035     enum Anchor {
0036         AnchorNone = 0,
0037         AnchorTop = 1, ///< The top edge of the anchor rectangle
0038         AnchorBottom = 2, ///< The bottom edge of the anchor rectangle
0039         AnchorLeft = 4, ///< The left edge of the anchor rectangle
0040         AnchorRight = 8, ///< The right edge of the anchor rectangle
0041     };
0042     Q_ENUM(Anchor);
0043     Q_DECLARE_FLAGS(Anchors, Anchor)
0044 
0045     /**
0046      * This enum type is used to specify the layer where a surface can be put in.
0047      */
0048     enum Layer {
0049         LayerBackground = 0,
0050         LayerBottom = 1,
0051         LayerTop = 2,
0052         LayerOverlay = 3,
0053     };
0054     Q_ENUM(Layer)
0055 
0056     /**
0057      * This enum type is used to specify how the layer surface handles keyboard focus.
0058      */
0059     enum KeyboardInteractivity {
0060         KeyboardInteractivityNone = 0,
0061         KeyboardInteractivityExclusive = 1,
0062         KeyboardInteractivityOnDemand = 2,
0063     };
0064     Q_ENUM(KeyboardInteractivity)
0065 
0066     /**
0067      * This enum type is used to specify which screen to place the surface on.
0068      * ScreenFromQWindow (the default) reads QWindow::screen() while ScreenFromCompositor
0069      * passes nil and lets the compositor decide.
0070      */
0071     enum ScreenConfiguration {
0072         ScreenFromQWindow = 0,
0073         ScreenFromCompositor = 1,
0074     };
0075     Q_ENUM(ScreenConfiguration)
0076 
0077     void setAnchors(Anchors anchor);
0078     Anchors anchors() const;
0079 
0080     void setExclusiveZone(int32_t zone);
0081     int32_t exclusionZone() const;
0082 
0083     void setExclusiveEdge(Window::Anchor edge);
0084     Window::Anchor exclusiveEdge() const;
0085 
0086     void setMargins(const QMargins &margins);
0087     QMargins margins() const;
0088 
0089     void setKeyboardInteractivity(KeyboardInteractivity interactivity);
0090     KeyboardInteractivity keyboardInteractivity() const;
0091 
0092     void setLayer(Layer layer);
0093     Layer layer() const;
0094 
0095     void setScreenConfiguration(ScreenConfiguration screenConfiguration);
0096     ScreenConfiguration screenConfiguration() const;
0097 
0098     /**
0099      * Sets a string based identifier for this window.
0100      * This may be used by a compositor to determine stacking
0101      * order within a given layer.
0102      *
0103      * May also be referred to as a role
0104      */
0105     void setScope(const QString &scope);
0106     QString scope() const;
0107 
0108     /**
0109      * Whether the QWindow should be closed when the layer surface is dismissed by the compositor.
0110      * For example, if the associated screen has been removed.
0111      *
0112      * This can be used to map the window on another screen.
0113      */
0114     void setCloseOnDismissed(bool close);
0115     bool closeOnDismissed() const;
0116 
0117     /**
0118      * Gets the LayerShell Window for a given Qt Window
0119      * Ownership is not transferred
0120      */
0121     static Window *get(QWindow *window);
0122 
0123     static Window *qmlAttachedProperties(QObject *object);
0124 
0125 Q_SIGNALS:
0126     void anchorsChanged();
0127     void exclusionZoneChanged();
0128     void exclusiveEdgeChanged();
0129     void marginsChanged();
0130     void keyboardInteractivityChanged();
0131     void layerChanged();
0132 
0133 private:
0134     Window(QWindow *window);
0135     QScopedPointer<WindowPrivate> d;
0136 };
0137 
0138 }
0139 
0140 #endif