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

0001 /*
0002     SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
0003     SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 #pragma once
0008 
0009 #include "kwin_export.h"
0010 
0011 #include <QObject>
0012 #include <memory>
0013 
0014 class QSize;
0015 struct wl_resource;
0016 
0017 namespace KWaylandServer
0018 {
0019 class Display;
0020 class SurfaceInterface;
0021 class PlasmaShellSurfaceInterface;
0022 
0023 class PlasmaShellInterfacePrivate;
0024 class PlasmaShellSurfaceInterfacePrivate;
0025 
0026 /**
0027  * @brief Global for the org_kde_plasma_shell interface.
0028  *
0029  * The PlasmaShellInterface allows to add additional information to a SurfaceInterface.
0030  * It goes beyond what a ShellSurfaceInterface provides and is adjusted toward the needs
0031  * of the Plasma desktop.
0032  *
0033  * A server providing this interface should think about how to restrict access to it as
0034  * it allows to perform absolute window positioning.
0035  */
0036 class KWIN_EXPORT PlasmaShellInterface : public QObject
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041     explicit PlasmaShellInterface(Display *display, QObject *parent);
0042     virtual ~PlasmaShellInterface();
0043 
0044 Q_SIGNALS:
0045     /**
0046      * Emitted whenever a PlasmaShellSurfaceInterface got created.
0047      */
0048     void surfaceCreated(KWaylandServer::PlasmaShellSurfaceInterface *);
0049 
0050 private:
0051     std::unique_ptr<PlasmaShellInterfacePrivate> d;
0052 };
0053 
0054 /**
0055  * @brief Resource for the org_kde_plasma_shell_surface interface.
0056  *
0057  * PlasmaShellSurfaceInterface gets created by PlasmaShellInterface.
0058  */
0059 class KWIN_EXPORT PlasmaShellSurfaceInterface : public QObject
0060 {
0061     Q_OBJECT
0062 public:
0063     virtual ~PlasmaShellSurfaceInterface();
0064 
0065     /**
0066      * @returns the SurfaceInterface this PlasmaShellSurfaceInterface got created for
0067      */
0068     SurfaceInterface *surface() const;
0069     /**
0070      * @returns the requested position in global coordinates.
0071      */
0072     QPoint position() const;
0073     /**
0074      * @returns Whether a global position has been requested.
0075      */
0076     bool isPositionSet() const;
0077 
0078     /**
0079      * @returns Whether the surface has requested to be opened under the cursor.
0080      */
0081     bool wantsOpenUnderCursor() const;
0082 
0083     /**
0084      * Describes possible roles this PlasmaShellSurfaceInterface can have.
0085      * The role can be used by the server to e.g. change the stacking order accordingly.
0086      */
0087     enum class Role {
0088         Normal, ///< A normal surface
0089         Desktop, ///< The surface represents a desktop, normally stacked below all other surfaces
0090         Panel, ///< The surface represents a panel (dock), normally stacked above normal surfaces
0091         OnScreenDisplay, ///< The surface represents an on screen display, like a volume changed notification
0092         Notification, ///< The surface represents a notification
0093         ToolTip, ///< The surface represents a tooltip
0094         CriticalNotification, ///< The surface represents a critical notification, like battery is running out
0095         AppletPopup, ///< The surface represents an applet popup window
0096     };
0097     /**
0098      * @returns The requested role, default value is @c Role::Normal.
0099      */
0100     Role role() const;
0101     /**
0102      * Describes how a PlasmaShellSurfaceInterface with role @c Role::Panel should behave.
0103      */
0104     enum class PanelBehavior {
0105         AlwaysVisible, ///< The panel should be always visible
0106         AutoHide, ///< The panel auto hides at a screen edge and returns on mouse press against edge
0107         WindowsCanCover, ///< Windows are allowed to go above the panel, it raises on mouse press against screen edge
0108         WindowsGoBelow, ///< Window are allowed to go below the panel
0109     };
0110     /**
0111      * @returns The PanelBehavior for a PlasmaShellSurfaceInterface with role @c Role::Panel
0112      * @see role
0113      */
0114     PanelBehavior panelBehavior() const;
0115 
0116     /**
0117      * @returns true if this window doesn't want to be listed
0118      * in the taskbar
0119      */
0120     bool skipTaskbar() const;
0121 
0122     /**
0123      * @returns true if this window doesn't want to be listed
0124      * in a window switcher
0125      */
0126     bool skipSwitcher() const;
0127 
0128     /**
0129      * Informs the PlasmaShellSurfaceInterface that the auto-hiding panel got hidden.
0130      * Once it is shown again the method {@link showAutoHidingPanel} should be used.
0131      *
0132      * @see showAutoHidingPanel
0133      * @see panelAutoHideHideRequested
0134      * @see panelAutoHideShowRequested
0135      */
0136     void hideAutoHidingPanel();
0137 
0138     /**
0139      * Informs the PlasmaShellSurfaceInterface that the auto-hiding panel got shown again.
0140      *
0141      * @see hideAutoHidingPanel
0142      * @see panelAutoHideHideRequested
0143      * @see panelAutoHideShowRequested
0144      * @see 5.28
0145      */
0146     void showAutoHidingPanel();
0147 
0148     /**
0149      * Whether a PlasmaShellSurfaceInterface wants to have focus.
0150      *
0151      * By default some PlasmaShell roles do not get focus, but the PlasmaShellSurfaceInterface can
0152      * request that it wants to have focus. The compositor can use this information to
0153      * pass focus to the surface.
0154      */
0155     // TODO KF6 rename to something generic
0156     bool panelTakesFocus() const;
0157 
0158     /**
0159      * @returns The PlasmaShellSurfaceInterface for the @p native resource.
0160      */
0161     static PlasmaShellSurfaceInterface *get(wl_resource *native);
0162     static PlasmaShellSurfaceInterface *get(SurfaceInterface *surface);
0163 
0164 Q_SIGNALS:
0165     /**
0166      * A change of global position has been requested.
0167      */
0168     void positionChanged();
0169 
0170     /**
0171      * The surface has requested to be initially shown under the cursor. Can only occur
0172      * before any buffer has been attached.
0173      */
0174     void openUnderCursorRequested();
0175     /**
0176      * A change of the role has been requested.
0177      */
0178     void roleChanged();
0179     /**
0180      * A change of the panel behavior has been requested.
0181      */
0182     void panelBehaviorChanged();
0183     /**
0184      * A change in the skip taskbar property has been requested
0185      */
0186     void skipTaskbarChanged();
0187     /**
0188      * A change in the skip switcher property has been requested
0189      */
0190     void skipSwitcherChanged();
0191 
0192     /**
0193      * A surface with Role Panel and PanelBehavior AutoHide requested to be hidden.
0194      *
0195      * The compositor should inform the PlasmaShellSurfaceInterface about the actual change.
0196      * Once the surface is hidden it should invoke {@link hideAutoHidingPanel}. If the compositor
0197      * cannot hide the surface (e.g. because it doesn't border a screen edge) it should inform
0198      * the surface through invoking {@link showAutoHidingPanel}. This method should also be invoked
0199      * whenever the surface gets shown again due to triggering the screen edge.
0200      *
0201      * @see hideAutoHidingPanel
0202      * @see showAutoHidingPanel
0203      * @see panelAutoHideShowRequested
0204      */
0205     void panelAutoHideHideRequested();
0206 
0207     /**
0208      * A surface with Role Panel and PanelBehavior AutoHide requested to be shown.
0209      *
0210      * The compositor should inform the PlasmaShellSurfaceInterface about the actual change.
0211      * Once the surface is shown it should invoke {@link showAutoHidingPanel}.
0212      *
0213      * @see hideAutoHidingPanel
0214      * @see showAutoHidingPanel
0215      * @see panelAutoHideHideRequested
0216      */
0217     void panelAutoHideShowRequested();
0218 
0219     /*
0220      * Emitted when panelTakesFocus changes
0221      * @see panelTakesFocus
0222      */
0223     void panelTakesFocusChanged();
0224 
0225 private:
0226     friend class PlasmaShellInterfacePrivate;
0227     explicit PlasmaShellSurfaceInterface(SurfaceInterface *surface, wl_resource *resource);
0228     std::unique_ptr<PlasmaShellSurfaceInterfacePrivate> d;
0229 };
0230 
0231 }
0232 
0233 Q_DECLARE_METATYPE(KWaylandServer::PlasmaShellSurfaceInterface::Role)
0234 Q_DECLARE_METATYPE(KWaylandServer::PlasmaShellSurfaceInterface::PanelBehavior)