File indexing completed on 2024-05-19 05:32:36

0001 /*
0002     SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include "display.h"
0010 
0011 #include <QMargins>
0012 
0013 namespace KWin
0014 {
0015 class LayerShellV1InterfacePrivate;
0016 class LayerSurfaceV1Interface;
0017 class LayerSurfaceV1InterfacePrivate;
0018 class OutputInterface;
0019 class SurfaceInterface;
0020 class SurfaceRole;
0021 
0022 /**
0023  * The LayerShellV1Interface compositor extension allows to create desktop shell surfaces.
0024  *
0025  * The layer shell compositor extension provides a way to create surfaces that can serve as
0026  * building blocks for desktop environment elements such as panels, notifications, etc.
0027  *
0028  * The LayerShellV1Interface corresponds to the Wayland interface @c zwlr_layer_shell_v1.
0029  */
0030 class KWIN_EXPORT LayerShellV1Interface : public QObject
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     explicit LayerShellV1Interface(Display *display, QObject *parent = nullptr);
0036     ~LayerShellV1Interface() override;
0037 
0038     /**
0039      * Returns the Wayland display for the layer shell compositor extension.
0040      */
0041     Display *display() const;
0042 
0043 Q_SIGNALS:
0044     /**
0045      * This signal is emitted when a new layer surface @a surface has been created.
0046      */
0047     void surfaceCreated(LayerSurfaceV1Interface *surface);
0048 
0049 private:
0050     std::unique_ptr<LayerShellV1InterfacePrivate> d;
0051 };
0052 
0053 /**
0054  * The LayerSurfaceV1Interface class represents a desktop shell surface, e.g. panel, etc.
0055  *
0056  * The LayerSurfaceV1Interface corresponds to the Wayland interface @c zwlr_layer_surface_v1.
0057  */
0058 class KWIN_EXPORT LayerSurfaceV1Interface : public QObject
0059 {
0060     Q_OBJECT
0061 
0062 public:
0063     enum Layer {
0064         BackgroundLayer,
0065         BottomLayer,
0066         TopLayer,
0067         OverlayLayer,
0068     };
0069 
0070     LayerSurfaceV1Interface(LayerShellV1Interface *shell,
0071                             SurfaceInterface *surface,
0072                             OutputInterface *output,
0073                             Layer layer,
0074                             const QString &scope,
0075                             wl_resource *resource);
0076     ~LayerSurfaceV1Interface() override;
0077 
0078     static SurfaceRole *role();
0079 
0080     /**
0081      * Returns @c true if the initial commit has been performed; otherwise returns @c false.
0082      */
0083     bool isCommitted() const;
0084 
0085     /**
0086      * Returns the underlying Wayland surface for this layer shell surface.
0087      */
0088     SurfaceInterface *surface() const;
0089 
0090     /**
0091      * Returns the anchor point relative to which the surface will be positioned. If no edges
0092      * have been specified, the center of the screen is assumed to be the anchor point.
0093      */
0094     Qt::Edges anchor() const;
0095 
0096     /**
0097      * Returns the desired size for this layer shell surface, in the surface-local coordinates.
0098      */
0099     QSize desiredSize() const;
0100 
0101     /**
0102      * Returns the stacking order layer where this layer surface has to be rendered.
0103      */
0104     Layer layer() const;
0105 
0106     /**
0107      * Returns @c true if the surface accepts keyboard input; otherwise returns @c false.
0108      */
0109     bool acceptsFocus() const;
0110 
0111     /**
0112      * Returns the margins object that indicates the distance between an anchor edge and
0113      * the corresponding surface edge.
0114      */
0115     QMargins margins() const;
0116 
0117     /**
0118      * Returns the value of the left margin. This is equivalent to calling margins().left().
0119      */
0120     int leftMargin() const;
0121 
0122     /**
0123      * Returns the value of the right margin. This is equivalent to calling margins().right().
0124      */
0125     int rightMargin() const;
0126 
0127     /**
0128      * Returns the value of the top margin. This is equivalent to calling margins().top().
0129      */
0130     int topMargin() const;
0131 
0132     /**
0133      * Returns the value of the bottom margin. This is equivalent to calling margins().bottom().
0134      */
0135     int bottomMargin() const;
0136 
0137     /**
0138      * Returns the distance from the anchor edge that should not be occluded.
0139      *
0140      * An exlusive zone of 0 means that the layer surface has to be moved to avoid occluding
0141      * surfaces with a positive exclusion zone. If the exclusive zone is -1, the layer surface
0142      * indicates that it doesn't want to be moved to accomodate for other surfaces.
0143      */
0144     int exclusiveZone() const;
0145 
0146     /**
0147      * If the exclusive zone is positive, this function returns the corresponding exclusive
0148      * anchor edge, otherwise returns a Qt::Edge() value.
0149      */
0150     Qt::Edge exclusiveEdge() const;
0151 
0152     /**
0153      * Returns the output where the surface wants to be displayed. This function can return
0154      * @c null, in which case the compositor is free to choose the output where the surface
0155      * has to be placed.
0156      */
0157     OutputInterface *output() const;
0158 
0159     /**
0160      * Returns the scope of this layer surface. The scope defines the purpose of the surface.
0161      */
0162     QString scope() const;
0163 
0164     /**
0165      * Sends a configure event to the client. @a size contains the desired size in surface-local
0166      * coordinates. A size of zero means that the client is free to choose its own dimensions.
0167      *
0168      * @see configureAcknowledged()
0169      */
0170     quint32 sendConfigure(const QSize &size);
0171 
0172     /**
0173      * Sends a closed event to the client. The client should destroy the surface after receiving
0174      * this event. Further changes to the surface will be ignored.
0175      */
0176     void sendClosed();
0177 
0178 Q_SIGNALS:
0179     void aboutToBeDestroyed();
0180     void configureAcknowledged(quint32 serial);
0181     void acceptsFocusChanged();
0182     void layerChanged();
0183     void anchorChanged();
0184     void desiredSizeChanged();
0185     void exclusiveZoneChanged();
0186     void marginsChanged();
0187 
0188 private:
0189     std::unique_ptr<LayerSurfaceV1InterfacePrivate> d;
0190 };
0191 
0192 } // namespace KWin