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

0001 /*
0002     SPDX-FileCopyrightText: 2015 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 "kwin_export.h"
0009 
0010 #include <QObject>
0011 #include <memory>
0012 
0013 struct wl_resource;
0014 
0015 namespace KWin
0016 {
0017 class Display;
0018 class ServerSideDecorationInterface;
0019 class SurfaceInterface;
0020 class ServerSideDecorationManagerInterfacePrivate;
0021 class ServerSideDecorationInterfacePrivate;
0022 
0023 /**
0024  * @brief Manager to create ServerSideDecorationInterface.
0025  */
0026 class KWIN_EXPORT ServerSideDecorationManagerInterface : public QObject
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     explicit ServerSideDecorationManagerInterface(Display *display, QObject *parent = nullptr);
0032     ~ServerSideDecorationManagerInterface() override;
0033 
0034     /**
0035      * Decoration mode used for SurfaceInterfaces.
0036      */
0037     enum class Mode {
0038         /**
0039          * Undecorated: neither client, nor server provide decoration. Example: popups.
0040          */
0041         None,
0042         /**
0043          * The decoration is part of the surface.
0044          */
0045         Client,
0046         /**
0047          * The surface gets embedded into a decoration frame provided by the Server.
0048          */
0049         Server,
0050     };
0051 
0052     /**
0053      * Sets the default @p mode which is pushed to the Clients on creating a ServerSideDecorationInterface.
0054      * @param mode The new default mode.
0055      * @see defaultMode
0056      */
0057     void setDefaultMode(Mode mode);
0058     /**
0059      * @returns the current default mode.
0060      * @see setDefaultMode
0061      */
0062     Mode defaultMode() const;
0063 
0064 Q_SIGNALS:
0065     /**
0066      * Emitted whenever a new ServerSideDecorationInterface is created.
0067      */
0068     void decorationCreated(KWin::ServerSideDecorationInterface *);
0069 
0070 private:
0071     std::unique_ptr<ServerSideDecorationManagerInterfacePrivate> d;
0072 };
0073 
0074 /**
0075  * @brief Representing how a SurfaceInterface should be decorated.
0076  *
0077  * Created by ServerSideDecorationManagerInterface and emitted with decorationCreated signal.
0078  */
0079 class KWIN_EXPORT ServerSideDecorationInterface : public QObject
0080 {
0081     Q_OBJECT
0082 public:
0083     ~ServerSideDecorationInterface() override;
0084 
0085     /**
0086      * Sets the @p mode on the SurfaceInterface. A client might refuse the provided @p mode,
0087      * in that case modeRequested will be emitted.
0088      * @see mode
0089      * @see modeRequested
0090      */
0091     void setMode(ServerSideDecorationManagerInterface::Mode mode);
0092     /**
0093      * @returns the currently set mode, not the requested mode.
0094      * @see setMode
0095      * @see modeRequested
0096      */
0097     ServerSideDecorationManagerInterface::Mode mode() const;
0098     /**
0099      * Returns the preferred decoration mode as specified by the client.
0100      */
0101     ServerSideDecorationManagerInterface::Mode preferredMode() const;
0102 
0103     /**
0104      * @returns The SurfaceInterface this ServerSideDecorationInterface references.
0105      */
0106     SurfaceInterface *surface() const;
0107 
0108     /**
0109      * @returns The ServerSideDecorationInterface for the given @p surface, @c nullptr if there is none.
0110      */
0111     static ServerSideDecorationInterface *get(SurfaceInterface *surface);
0112 
0113 Q_SIGNALS:
0114     /**
0115      * The client requested the provided mode.
0116      * The server needs to acknowledge the requested mode by setting it through setMode.
0117      * @see setMode
0118      * @see mode
0119      */
0120     void preferredModeChanged();
0121 
0122 private:
0123     explicit ServerSideDecorationInterface(ServerSideDecorationManagerInterface *manager, SurfaceInterface *surface, wl_resource *resource);
0124     friend class ServerSideDecorationManagerInterfacePrivate;
0125 
0126     std::unique_ptr<ServerSideDecorationInterfacePrivate> d;
0127 };
0128 
0129 }
0130 
0131 Q_DECLARE_METATYPE(KWin::ServerSideDecorationInterface *)
0132 Q_DECLARE_METATYPE(KWin::ServerSideDecorationManagerInterface::Mode)