File indexing completed on 2024-05-19 16:35:21

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