File indexing completed on 2024-05-12 05:32:33
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.h" 0011 0012 #include "surface_p.h" 0013 0014 namespace KWin 0015 { 0016 class XdgToplevelDecorationV1Interface; 0017 0018 class XdgShellInterfacePrivate : public QtWaylandServer::xdg_wm_base 0019 { 0020 public: 0021 XdgShellInterfacePrivate(XdgShellInterface *shell); 0022 0023 Resource *resourceForXdgSurface(XdgSurfaceInterface *surface) const; 0024 0025 void unregisterXdgSurface(XdgSurfaceInterface *surface); 0026 0027 void registerPing(quint32 serial); 0028 0029 static XdgShellInterfacePrivate *get(XdgShellInterface *shell); 0030 0031 XdgShellInterface *q; 0032 Display *display = nullptr; 0033 QMap<quint32, QTimer *> pings; 0034 std::chrono::milliseconds pingTimeout = std::chrono::milliseconds(1000); 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 XdgSurfaceCommit 0087 { 0088 std::optional<QRect> windowGeometry; 0089 std::optional<quint32> acknowledgedConfigure; 0090 }; 0091 0092 struct XdgToplevelCommit : XdgSurfaceCommit 0093 { 0094 std::optional<QSize> minimumSize; 0095 std::optional<QSize> maximumSize; 0096 }; 0097 0098 struct XdgPopupCommit : XdgSurfaceCommit 0099 { 0100 }; 0101 0102 class XdgSurfaceInterfacePrivate : public QtWaylandServer::xdg_surface 0103 { 0104 public: 0105 XdgSurfaceInterfacePrivate(XdgSurfaceInterface *xdgSurface); 0106 0107 void apply(XdgSurfaceCommit *commit); 0108 void reset(); 0109 0110 // These two point into XdgSurfaceRole's state and are valid as long as a role is assigned. 0111 XdgSurfaceCommit *pending = nullptr; 0112 0113 XdgSurfaceInterface *q; 0114 XdgShellInterface *shell = nullptr; 0115 QPointer<XdgToplevelInterface> toplevel; 0116 QPointer<XdgPopupInterface> popup; 0117 QPointer<SurfaceInterface> surface; 0118 QRect windowGeometry; 0119 bool firstBufferAttached = false; 0120 bool isConfigured = false; 0121 bool isInitialized = false; 0122 0123 static XdgSurfaceInterfacePrivate *get(XdgSurfaceInterface *surface); 0124 0125 protected: 0126 void xdg_surface_destroy_resource(Resource *resource) override; 0127 void xdg_surface_destroy(Resource *resource) override; 0128 void xdg_surface_get_toplevel(Resource *resource, uint32_t id) override; 0129 void xdg_surface_get_popup(Resource *resource, uint32_t id, ::wl_resource *parent, ::wl_resource *positioner) override; 0130 void xdg_surface_set_window_geometry(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override; 0131 void xdg_surface_ack_configure(Resource *resource, uint32_t serial) override; 0132 }; 0133 0134 class XdgToplevelInterfacePrivate : public SurfaceExtension<XdgToplevelCommit>, public QtWaylandServer::xdg_toplevel 0135 { 0136 public: 0137 XdgToplevelInterfacePrivate(XdgToplevelInterface *toplevel, XdgSurfaceInterface *surface); 0138 0139 void apply(XdgToplevelCommit *commit) override; 0140 void reset(); 0141 0142 static XdgToplevelInterfacePrivate *get(XdgToplevelInterface *toplevel); 0143 static XdgToplevelInterfacePrivate *get(::wl_resource *resource); 0144 0145 XdgToplevelInterface *q; 0146 QPointer<XdgToplevelInterface> parentXdgToplevel; 0147 QPointer<XdgToplevelDecorationV1Interface> decoration; 0148 XdgSurfaceInterface *xdgSurface; 0149 QString windowTitle; 0150 QString windowClass; 0151 QSize minimumSize; 0152 QSize maximumSize; 0153 0154 protected: 0155 void xdg_toplevel_destroy_resource(Resource *resource) override; 0156 void xdg_toplevel_destroy(Resource *resource) override; 0157 void xdg_toplevel_set_parent(Resource *resource, ::wl_resource *parent) override; 0158 void xdg_toplevel_set_title(Resource *resource, const QString &title) override; 0159 void xdg_toplevel_set_app_id(Resource *resource, const QString &app_id) override; 0160 void xdg_toplevel_show_window_menu(Resource *resource, ::wl_resource *seat, uint32_t serial, int32_t x, int32_t y) override; 0161 void xdg_toplevel_move(Resource *resource, ::wl_resource *seat, uint32_t serial) override; 0162 void xdg_toplevel_resize(Resource *resource, ::wl_resource *seat, uint32_t serial, uint32_t edges) override; 0163 void xdg_toplevel_set_max_size(Resource *resource, int32_t width, int32_t height) override; 0164 void xdg_toplevel_set_min_size(Resource *resource, int32_t width, int32_t height) override; 0165 void xdg_toplevel_set_maximized(Resource *resource) override; 0166 void xdg_toplevel_unset_maximized(Resource *resource) override; 0167 void xdg_toplevel_set_fullscreen(Resource *resource, ::wl_resource *output) override; 0168 void xdg_toplevel_unset_fullscreen(Resource *resource) override; 0169 void xdg_toplevel_set_minimized(Resource *resource) override; 0170 }; 0171 0172 class XdgPopupInterfacePrivate : public SurfaceExtension<XdgPopupCommit>, public QtWaylandServer::xdg_popup 0173 { 0174 public: 0175 static XdgPopupInterfacePrivate *get(XdgPopupInterface *popup); 0176 0177 XdgPopupInterfacePrivate(XdgPopupInterface *popup, XdgSurfaceInterface *surface); 0178 0179 void apply(XdgPopupCommit *commit) override; 0180 void reset(); 0181 0182 XdgPopupInterface *q; 0183 SurfaceInterface *parentSurface = nullptr; 0184 XdgSurfaceInterface *xdgSurface; 0185 XdgPositioner positioner; 0186 0187 protected: 0188 void xdg_popup_destroy_resource(Resource *resource) override; 0189 void xdg_popup_destroy(Resource *resource) override; 0190 void xdg_popup_grab(Resource *resource, ::wl_resource *seat, uint32_t serial) override; 0191 void xdg_popup_reposition(Resource *resource, struct ::wl_resource *positioner, uint32_t token) override; 0192 }; 0193 0194 } // namespace KWin