1 /* 2 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org> 3 SPDX-FileCopyrightText: 2021 Roman Gilg <subdiff@gmail.com> 4 5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only 6 */ 7 #pragma once 8 9 #include "xdg_shell_popup.h" 10 #include "xdg_shell_positioner.h" 11 #include "xdg_shell_toplevel.h" 12 13 #include <QObject> 14 #include <QRect> 15 #include <QSize> 16 17 #include <Wrapland/Client/wraplandclient_export.h> 18 #include <memory> 19 20 struct xdg_wm_base; 21 22 namespace Wrapland::Client 23 { 24 25 class EventQueue; 26 class Surface; 27 28 /** 29 * @short Wrapper for the xdg_shell interface. 30 * 31 * This class provides a convenient wrapper for the xdg_shell interface. 32 * 33 * To use this class one needs to interact with the Registry. There are two 34 * possible ways to create the XdgShell interface: 35 * @code 36 * XdgShell *c = registry->createXdgShell(name, version); 37 * @endcode 38 * 39 * This creates the XdgShell and sets it up directly. As an alternative this 40 * can also be done in a more low level way: 41 * @code 42 * XdgShell *c = new XdgShell; 43 * c->setup(registry->bindXdgShell(name, version)); 44 * @endcode 45 * 46 * The XdgShell can be used as a drop-in replacement for any xdg_shell 47 * pointer as it provides matching cast operators. 48 * 49 * @see Registry 50 * @since 0.0.525 51 **/ 52 class WRAPLANDCLIENT_EXPORT XdgShell : public QObject 53 { 54 Q_OBJECT 55 public: 56 /** 57 * Creates a new XdgShell. 58 * Note: after constructing the XdgShell it is not yet valid and one needs 59 * to call setup. In order to get a ready to use XdgShell prefer using 60 * Registry::createXdgShell. 61 **/ 62 explicit XdgShell(QObject* parent = nullptr); 63 virtual ~XdgShell(); 64 65 /** 66 * Setup this XdgShell to manage the @p xdg_wm_base. 67 * When using Registry::createXdgShell there is no need to call this 68 * method. 69 **/ 70 void setup(xdg_wm_base* xdg_wm_base); 71 /** 72 * @returns @c true if managing a xdg_shell. 73 **/ 74 bool isValid() const; 75 /** 76 * Releases the xdg_shell interface. 77 * After the interface has been released the XdgShell instance is no 78 * longer valid and can be setup with another xdg_shell interface. 79 **/ 80 void release(); 81 82 /** 83 * Sets the @p queue to use for creating objects with this XdgShell. 84 **/ 85 void setEventQueue(EventQueue* queue); 86 /** 87 * @returns The event queue to use for creating objects with this XdgShell. 88 **/ 89 EventQueue* eventQueue(); 90 91 /** 92 * Creates a new XdgShellToplevel for the given @p surface. 93 **/ 94 XdgShellToplevel* create_toplevel(Surface* surface, QObject* parent = nullptr); 95 96 /** 97 * Creates a new XdgShellPopup for the given @p surface on top of @p parentSurface with the 98 * given @p positioner. 99 * @since 0.0.539 100 **/ 101 XdgShellPopup* create_popup(Surface* surface, 102 XdgShellToplevel* parentSurface, 103 XdgPositioner const& positioner, 104 QObject* parent = nullptr); 105 106 /** 107 * Creates a new XdgShellPopup for the given @p surface on top of @p parentSurface with the 108 * given @p positioner. 109 * @since 0.0.539 110 **/ 111 XdgShellPopup* create_popup(Surface* surface, 112 XdgShellPopup* parentSurface, 113 XdgPositioner const& positioner, 114 QObject* parent = nullptr); 115 116 /** 117 * Creates a new XdgShellPopup for the given @p surface with no parent directly specified and 118 * with the given @p positioner. 119 * @since 0.522.0 120 **/ 121 XdgShellPopup* 122 create_popup(Surface* surface, XdgPositioner const& positioner, QObject* parent = nullptr); 123 124 operator xdg_wm_base*(); 125 operator xdg_wm_base*() const; 126 127 Q_SIGNALS: 128 /** 129 * The corresponding global for this interface on the Registry got removed. 130 * 131 * This signal gets only emitted if the XdgShell got created by 132 * Registry::createXdgShell 133 **/ 134 void removed(); 135 136 private: 137 class Private; 138 std::unique_ptr<Private> d_ptr; 139 }; 140 141 } 142