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

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 "qwayland-server-xdg-shell.h"
0010 #include "xdgshell_interface.h"
0011 
0012 #include "surface_interface.h"
0013 #include "surfacerole_p.h"
0014 
0015 namespace KWaylandServer
0016 {
0017 class XdgToplevelDecorationV1Interface;
0018 
0019 class XdgShellInterfacePrivate : public QtWaylandServer::xdg_wm_base
0020 {
0021 public:
0022     XdgShellInterfacePrivate(XdgShellInterface *shell);
0023 
0024     Resource *resourceForXdgSurface(XdgSurfaceInterface *surface) const;
0025 
0026     void unregisterXdgSurface(XdgSurfaceInterface *surface);
0027 
0028     void registerPing(quint32 serial);
0029 
0030     static XdgShellInterfacePrivate *get(XdgShellInterface *shell);
0031 
0032     XdgShellInterface *q;
0033     Display *display;
0034     QMap<quint32, QTimer *> pings;
0035 
0036 protected:
0037     void xdg_wm_base_destroy_resource(Resource *resource) override;
0038     void xdg_wm_base_destroy(Resource *resource) override;
0039     void xdg_wm_base_create_positioner(Resource *resource, uint32_t id) override;
0040     void xdg_wm_base_get_xdg_surface(Resource *resource, uint32_t id, ::wl_resource *surface) override;
0041     void xdg_wm_base_pong(Resource *resource, uint32_t serial) override;
0042 
0043 private:
0044     QHash<XdgSurfaceInterface *, Resource *> xdgSurfaces;
0045 };
0046 
0047 class XdgPositionerData : public QSharedData
0048 {
0049 public:
0050     Qt::Orientations slideConstraintAdjustments;
0051     Qt::Orientations flipConstraintAdjustments;
0052     Qt::Orientations resizeConstraintAdjustments;
0053     Qt::Edges anchorEdges;
0054     Qt::Edges gravityEdges;
0055     QPoint offset;
0056     QSize size;
0057     QRect anchorRect;
0058     bool isReactive = false;
0059     QSize parentSize;
0060     quint32 parentConfigure;
0061 };
0062 
0063 class XdgPositionerPrivate : public QtWaylandServer::xdg_positioner
0064 {
0065 public:
0066     XdgPositionerPrivate(::wl_resource *resource);
0067 
0068     QSharedDataPointer<XdgPositionerData> data;
0069 
0070     static XdgPositionerPrivate *get(::wl_resource *resource);
0071 
0072 protected:
0073     void xdg_positioner_destroy_resource(Resource *resource) override;
0074     void xdg_positioner_destroy(Resource *resource) override;
0075     void xdg_positioner_set_size(Resource *resource, int32_t width, int32_t height) override;
0076     void xdg_positioner_set_anchor_rect(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
0077     void xdg_positioner_set_anchor(Resource *resource, uint32_t anchor) override;
0078     void xdg_positioner_set_gravity(Resource *resource, uint32_t gravity) override;
0079     void xdg_positioner_set_constraint_adjustment(Resource *resource, uint32_t constraint_adjustment) override;
0080     void xdg_positioner_set_offset(Resource *resource, int32_t x, int32_t y) override;
0081     void xdg_positioner_set_reactive(Resource *resource) override;
0082     void xdg_positioner_set_parent_size(Resource *resource, int32_t width, int32_t height) override;
0083     void xdg_positioner_set_parent_configure(Resource *resource, uint32_t serial) override;
0084 };
0085 
0086 struct XdgSurfaceState
0087 {
0088     QRect windowGeometry;
0089     quint32 acknowledgedConfigure;
0090     bool acknowledgedConfigureIsSet = false;
0091     bool windowGeometryIsSet = false;
0092 };
0093 
0094 class XdgSurfaceInterfacePrivate : public QtWaylandServer::xdg_surface
0095 {
0096 public:
0097     XdgSurfaceInterfacePrivate(XdgSurfaceInterface *xdgSurface);
0098 
0099     void commit();
0100     void reset();
0101 
0102     XdgSurfaceInterface *q;
0103     XdgShellInterface *shell;
0104     QPointer<XdgToplevelInterface> toplevel;
0105     QPointer<XdgPopupInterface> popup;
0106     QPointer<SurfaceInterface> surface;
0107     bool firstBufferAttached = false;
0108     bool isConfigured = false;
0109     bool isInitialized = false;
0110 
0111     XdgSurfaceState next;
0112     XdgSurfaceState current;
0113 
0114     static XdgSurfaceInterfacePrivate *get(XdgSurfaceInterface *surface);
0115 
0116 protected:
0117     void xdg_surface_destroy_resource(Resource *resource) override;
0118     void xdg_surface_destroy(Resource *resource) override;
0119     void xdg_surface_get_toplevel(Resource *resource, uint32_t id) override;
0120     void xdg_surface_get_popup(Resource *resource, uint32_t id, ::wl_resource *parent, ::wl_resource *positioner) override;
0121     void xdg_surface_set_window_geometry(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
0122     void xdg_surface_ack_configure(Resource *resource, uint32_t serial) override;
0123 };
0124 
0125 class XdgToplevelInterfacePrivate : public SurfaceRole, public QtWaylandServer::xdg_toplevel
0126 {
0127 public:
0128     XdgToplevelInterfacePrivate(XdgToplevelInterface *toplevel, XdgSurfaceInterface *surface);
0129 
0130     void commit() override;
0131     void reset();
0132 
0133     static XdgToplevelInterfacePrivate *get(XdgToplevelInterface *toplevel);
0134     static XdgToplevelInterfacePrivate *get(::wl_resource *resource);
0135 
0136     XdgToplevelInterface *q;
0137     QPointer<XdgToplevelInterface> parentXdgToplevel;
0138     QPointer<XdgToplevelDecorationV1Interface> decoration;
0139     XdgSurfaceInterface *xdgSurface;
0140 
0141     QString windowTitle;
0142     QString windowClass;
0143 
0144     struct State
0145     {
0146         QSize minimumSize;
0147         QSize maximumSize;
0148     };
0149 
0150     State next;
0151     State current;
0152 
0153 protected:
0154     void xdg_toplevel_destroy_resource(Resource *resource) override;
0155     void xdg_toplevel_destroy(Resource *resource) override;
0156     void xdg_toplevel_set_parent(Resource *resource, ::wl_resource *parent) override;
0157     void xdg_toplevel_set_title(Resource *resource, const QString &title) override;
0158     void xdg_toplevel_set_app_id(Resource *resource, const QString &app_id) override;
0159     void xdg_toplevel_show_window_menu(Resource *resource, ::wl_resource *seat, uint32_t serial, int32_t x, int32_t y) override;
0160     void xdg_toplevel_move(Resource *resource, ::wl_resource *seat, uint32_t serial) override;
0161     void xdg_toplevel_resize(Resource *resource, ::wl_resource *seat, uint32_t serial, uint32_t edges) override;
0162     void xdg_toplevel_set_max_size(Resource *resource, int32_t width, int32_t height) override;
0163     void xdg_toplevel_set_min_size(Resource *resource, int32_t width, int32_t height) override;
0164     void xdg_toplevel_set_maximized(Resource *resource) override;
0165     void xdg_toplevel_unset_maximized(Resource *resource) override;
0166     void xdg_toplevel_set_fullscreen(Resource *resource, ::wl_resource *output) override;
0167     void xdg_toplevel_unset_fullscreen(Resource *resource) override;
0168     void xdg_toplevel_set_minimized(Resource *resource) override;
0169 };
0170 
0171 class XdgPopupInterfacePrivate : public SurfaceRole, public QtWaylandServer::xdg_popup
0172 {
0173 public:
0174     static XdgPopupInterfacePrivate *get(XdgPopupInterface *popup);
0175 
0176     XdgPopupInterfacePrivate(XdgPopupInterface *popup, XdgSurfaceInterface *surface);
0177 
0178     void commit() override;
0179     void reset();
0180 
0181     XdgPopupInterface *q;
0182     SurfaceInterface *parentSurface;
0183     XdgSurfaceInterface *xdgSurface;
0184     XdgPositioner positioner;
0185 
0186 protected:
0187     void xdg_popup_destroy_resource(Resource *resource) override;
0188     void xdg_popup_destroy(Resource *resource) override;
0189     void xdg_popup_grab(Resource *resource, ::wl_resource *seat, uint32_t serial) override;
0190     void xdg_popup_reposition(Resource *resource, struct ::wl_resource *positioner, uint32_t token) override;
0191 };
0192 
0193 } // namespace KWaylandServer