| 1 | // Copyright (C) 2017 The Qt Company Ltd. |
| 2 | // Copyright (C) 2017 Eurogiciel, author: <philippe.coval@eurogiciel.fr> |
| 3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 | |
| 5 | #ifndef QWAYLANDXDGSHELL_H |
| 6 | #define QWAYLANDXDGSHELL_H |
| 7 | |
| 8 | // |
| 9 | // W A R N I N G |
| 10 | // ------------- |
| 11 | // |
| 12 | // This file is not part of the Qt API. It exists purely as an |
| 13 | // implementation detail. This header file may change from version to |
| 14 | // version without notice, or even be removed. |
| 15 | // |
| 16 | // We mean it. |
| 17 | // |
| 18 | |
| 19 | #include "qwayland-xdg-shell.h" |
| 20 | |
| 21 | #include "qwaylandxdgdecorationv1_p.h" |
| 22 | #include "qwaylandxdgactivationv1_p.h" |
| 23 | |
| 24 | #include <QtWaylandClient/qtwaylandclientglobal.h> |
| 25 | #include <QtWaylandClient/private/qwaylandshellsurface_p.h> |
| 26 | #include <QtWaylandClient/private/qwaylandwindow_p.h> |
| 27 | |
| 28 | #include <QtCore/QSize> |
| 29 | #include <QtGui/QRegion> |
| 30 | |
| 31 | QT_BEGIN_NAMESPACE |
| 32 | |
| 33 | class QWindow; |
| 34 | |
| 35 | namespace QtWaylandClient { |
| 36 | |
| 37 | class QWaylandDisplay; |
| 38 | class QWaylandInputDevice; |
| 39 | class QWaylandXdgShell; |
| 40 | class QWaylandXdgExportedV2; |
| 41 | class QWaylandXdgExporterV2; |
| 42 | class QWaylandXdgDialogWmV1; |
| 43 | class QWaylandXdgDialogV1; |
| 44 | |
| 45 | class Q_WAYLANDCLIENT_EXPORT QWaylandXdgSurface : public QWaylandShellSurface, public QtWayland::xdg_surface |
| 46 | { |
| 47 | Q_OBJECT |
| 48 | public: |
| 49 | QWaylandXdgSurface(QWaylandXdgShell *shell, ::xdg_surface *surface, QWaylandWindow *window); |
| 50 | ~QWaylandXdgSurface() override; |
| 51 | |
| 52 | bool resize(QWaylandInputDevice *inputDevice, Qt::Edges edges) override; |
| 53 | bool move(QWaylandInputDevice *inputDevice) override; |
| 54 | bool showWindowMenu(QWaylandInputDevice *seat) override; |
| 55 | void setTitle(const QString &title) override; |
| 56 | void setAppId(const QString &appId) override; |
| 57 | void setWindowFlags(Qt::WindowFlags flags) override; |
| 58 | |
| 59 | bool isExposed() const override; |
| 60 | bool handleExpose(const QRegion &) override; |
| 61 | bool handlesActiveState() const { return m_toplevel; } |
| 62 | void applyConfigure() override; |
| 63 | bool wantsDecorations() const override; |
| 64 | void propagateSizeHints() override; |
| 65 | void setWindowGeometry(const QRect &rect) override; |
| 66 | bool requestActivate() override; |
| 67 | bool requestActivateOnShow() override; |
| 68 | void setXdgActivationToken(const QString &token) override; |
| 69 | void requestXdgActivationToken(quint32 serial) override; |
| 70 | void setAlertState(bool enabled) override; |
| 71 | bool isAlertState() const override { return m_alertState; } |
| 72 | QString externWindowHandle() override; |
| 73 | void setWindowPosition(const QPoint &position) override; |
| 74 | |
| 75 | void setSizeHints(); |
| 76 | |
| 77 | void *nativeResource(const QByteArray &resource); |
| 78 | |
| 79 | std::any surfaceRole() const override; |
| 80 | |
| 81 | protected: |
| 82 | void requestWindowStates(Qt::WindowStates states) override; |
| 83 | void xdg_surface_configure(uint32_t serial) override; |
| 84 | |
| 85 | private: |
| 86 | class Toplevel: public QtWayland::xdg_toplevel |
| 87 | { |
| 88 | public: |
| 89 | Toplevel(QWaylandXdgSurface *xdgSurface); |
| 90 | ~Toplevel() override; |
| 91 | |
| 92 | void applyConfigure(); |
| 93 | bool wantsDecorations(); |
| 94 | |
| 95 | void xdg_toplevel_configure(int32_t width, int32_t height, wl_array *states) override; |
| 96 | void xdg_toplevel_close() override; |
| 97 | void xdg_toplevel_configure_bounds(int32_t width, int32_t height) override; |
| 98 | |
| 99 | void requestWindowFlags(Qt::WindowFlags flags); |
| 100 | void requestWindowStates(Qt::WindowStates states); |
| 101 | |
| 102 | static resize_edge convertToResizeEdges(Qt::Edges edges); |
| 103 | |
| 104 | struct { |
| 105 | QSize bounds = {0, 0}; |
| 106 | QSize size = {0, 0}; |
| 107 | Qt::WindowStates states = Qt::WindowNoState; |
| 108 | bool suspended = false; |
| 109 | } m_pending, m_applied; |
| 110 | QWaylandWindow::ToplevelWindowTilingStates m_toplevelStates = QWaylandWindow::WindowNoState; |
| 111 | QSize m_normalSize; |
| 112 | |
| 113 | QWaylandXdgSurface *m_xdgSurface = nullptr; |
| 114 | QWaylandXdgToplevelDecorationV1 *m_decoration = nullptr; |
| 115 | QScopedPointer<QWaylandXdgExportedV2> m_exported; |
| 116 | QScopedPointer<QWaylandXdgDialogV1> m_xdgDialog; |
| 117 | }; |
| 118 | |
| 119 | class Positioner : public QtWayland::xdg_positioner { |
| 120 | public: |
| 121 | Positioner(QWaylandXdgShell *xdgShell); |
| 122 | ~Positioner() override; |
| 123 | }; |
| 124 | |
| 125 | class Popup : public QtWayland::xdg_popup { |
| 126 | public: |
| 127 | Popup(QWaylandXdgSurface *xdgSurface, QWaylandWindow *parent, Positioner *positioner); |
| 128 | ~Popup() override; |
| 129 | |
| 130 | void applyConfigure(); |
| 131 | void resetConfiguration(); |
| 132 | |
| 133 | void grab(QWaylandInputDevice *seat, uint serial); |
| 134 | void xdg_popup_configure(int32_t x, int32_t y, int32_t width, int32_t height) override; |
| 135 | void xdg_popup_popup_done() override; |
| 136 | void xdg_popup_repositioned(uint32_t token) override; |
| 137 | |
| 138 | QWaylandXdgSurface *m_xdgSurface = nullptr; |
| 139 | QWaylandXdgSurface *m_parentXdgSurface = nullptr; |
| 140 | QWaylandWindow *m_parent = nullptr; |
| 141 | bool m_grabbing = false; |
| 142 | |
| 143 | QRect m_pendingGeometry; |
| 144 | bool m_waitingForReposition = false; |
| 145 | uint32_t m_waitingForRepositionSerial = 0; |
| 146 | }; |
| 147 | |
| 148 | void setToplevel(); |
| 149 | void setPopup(QWaylandWindow *parent); |
| 150 | void setGrabPopup(QWaylandWindow *parent, QWaylandInputDevice *device, int serial); |
| 151 | std::unique_ptr<Positioner> createPositioner(QWaylandWindow *parent); |
| 152 | |
| 153 | QWaylandXdgShell *m_shell = nullptr; |
| 154 | QWaylandWindow *m_window = nullptr; |
| 155 | Toplevel *m_toplevel = nullptr; |
| 156 | Popup *m_popup = nullptr; |
| 157 | bool m_configured = false; |
| 158 | uint m_pendingConfigureSerial = 0; |
| 159 | uint m_appliedConfigureSerial = 0; |
| 160 | QString m_activationToken; |
| 161 | QString m_appId; |
| 162 | bool m_alertState = false; |
| 163 | |
| 164 | friend class QWaylandXdgShell; |
| 165 | }; |
| 166 | |
| 167 | class Q_WAYLANDCLIENT_EXPORT QWaylandXdgShell |
| 168 | { |
| 169 | public: |
| 170 | QWaylandXdgShell(QWaylandDisplay *display, QtWayland::xdg_wm_base *xdg_wm_base); |
| 171 | ~QWaylandXdgShell(); |
| 172 | |
| 173 | QWaylandDisplay *display() const { return m_display; } |
| 174 | |
| 175 | QWaylandXdgDecorationManagerV1 *decorationManager() { return m_xdgDecorationManager.data(); } |
| 176 | QWaylandXdgActivationV1 *activation() const { return m_xdgActivation.data(); } |
| 177 | QWaylandXdgExporterV2 *exporter() const { return m_xdgExporter.data(); } |
| 178 | QWaylandXdgSurface *getXdgSurface(QWaylandWindow *window); |
| 179 | |
| 180 | private: |
| 181 | static void handleRegistryGlobal(void *data, ::wl_registry *registry, uint id, |
| 182 | const QString &interface, uint version); |
| 183 | |
| 184 | QWaylandDisplay *m_display = nullptr; |
| 185 | QtWayland::xdg_wm_base *m_xdgWmBase = nullptr; |
| 186 | QScopedPointer<QWaylandXdgDecorationManagerV1> m_xdgDecorationManager; |
| 187 | QScopedPointer<QWaylandXdgActivationV1> m_xdgActivation; |
| 188 | QScopedPointer<QWaylandXdgExporterV2> m_xdgExporter; |
| 189 | QScopedPointer<QWaylandXdgDialogWmV1> m_xdgDialogWm; |
| 190 | |
| 191 | friend class QWaylandXdgSurface; |
| 192 | }; |
| 193 | |
| 194 | QT_END_NAMESPACE |
| 195 | |
| 196 | } |
| 197 | |
| 198 | #endif // QWAYLANDXDGSHELL_H |
| 199 | |