File indexing completed on 2025-03-23 11:14:45
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 "kwin_export.h" 0010 0011 #include <QObject> 0012 #include <QSharedDataPointer> 0013 #include <memory> 0014 0015 struct wl_resource; 0016 0017 namespace KWaylandServer 0018 { 0019 class Display; 0020 class OutputInterface; 0021 class SeatInterface; 0022 class SurfaceInterface; 0023 class XdgShellInterfacePrivate; 0024 class XdgSurfaceInterfacePrivate; 0025 class XdgToplevelInterfacePrivate; 0026 class XdgPopupInterfacePrivate; 0027 class XdgPositionerData; 0028 class XdgToplevelInterface; 0029 class XdgPopupInterface; 0030 class XdgSurfaceInterface; 0031 0032 /** 0033 * The XdgShellInterface class represents an extension for destrop-style user interfaces. 0034 * 0035 * The XdgShellInterface class provides a way for a client to extend a regular Wayland surface 0036 * with functionality required to construct user interface elements, e.g. toplevel windows or 0037 * menus. 0038 * 0039 * XdgShellInterface corresponds to the WaylandInterface \c xdg_wm_base. 0040 */ 0041 class KWIN_EXPORT XdgShellInterface : public QObject 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 /** 0047 * Constructs an XdgShellInterface object with the given wayland display \a display. 0048 */ 0049 XdgShellInterface(Display *display, QObject *parent = nullptr); 0050 /** 0051 * Destructs the XdgShellInterface object. 0052 */ 0053 ~XdgShellInterface() override; 0054 0055 /** 0056 * Returns the wayland display of the XdgShellInterface. 0057 */ 0058 Display *display() const; 0059 0060 /** 0061 * Sends a ping event to the client with the given xdg-surface \a surface. If the client 0062 * replies to the event within a reasonable amount of time, pongReceived signal will be 0063 * emitted. 0064 */ 0065 quint32 ping(XdgSurfaceInterface *surface); 0066 0067 Q_SIGNALS: 0068 /** 0069 * This signal is emitted when a new XdgToplevelInterface object is created. 0070 */ 0071 void toplevelCreated(XdgToplevelInterface *toplevel); 0072 0073 /** 0074 * This signal is emitted when a new XdgPopupInterface object is created. 0075 */ 0076 void popupCreated(XdgPopupInterface *popup); 0077 0078 /** 0079 * This signal is emitted when the client has responded to a ping event with serial \a serial. 0080 */ 0081 void pongReceived(quint32 serial); 0082 0083 /** 0084 * @todo Drop this signal. 0085 * 0086 * This signal is emitted when the client has not responded to a ping event with serial 0087 * \a serial within a reasonable amount of time and the compositor gave up on it. 0088 */ 0089 void pingTimeout(quint32 serial); 0090 0091 /** 0092 * This signal is emitted when the client has not responded to a ping event with serial 0093 * \a serial within a reasonable amount of time. 0094 */ 0095 void pingDelayed(quint32 serial); 0096 0097 private: 0098 std::unique_ptr<XdgShellInterfacePrivate> d; 0099 friend class XdgShellInterfacePrivate; 0100 }; 0101 0102 /** 0103 * The XdgSurfaceInterface class provides a base set of functionality required to construct 0104 * user interface elements. 0105 * 0106 * XdgSurfaceInterface corresponds to the Wayland interface \c xdg_surface. 0107 */ 0108 class KWIN_EXPORT XdgSurfaceInterface : public QObject 0109 { 0110 Q_OBJECT 0111 0112 public: 0113 /** 0114 * Constructs an XdgSurfaceInterface for the given \a shell and \a surface. 0115 */ 0116 XdgSurfaceInterface(XdgShellInterface *shell, SurfaceInterface *surface, ::wl_resource *resource); 0117 /** 0118 * Destructs the XdgSurfaceInterface object. 0119 */ 0120 ~XdgSurfaceInterface() override; 0121 0122 /** 0123 * Returns the XdgToplevelInterface associated with this XdgSurfaceInterface. 0124 * 0125 * This method will return \c null if no xdg_toplevel object is associated with this surface. 0126 */ 0127 XdgToplevelInterface *toplevel() const; 0128 0129 /** 0130 * Returns the XdgPopupInterface associated with this XdgSurfaceInterface. 0131 * 0132 * This method will return \c null if no xdg_popup object is associated with this surface. 0133 */ 0134 XdgPopupInterface *popup() const; 0135 0136 /** 0137 * Returns the XdgShellInterface associated with this XdgSurfaceInterface. 0138 */ 0139 XdgShellInterface *shell() const; 0140 0141 /** 0142 * Returns the SurfaceInterface assigned to this XdgSurfaceInterface. 0143 */ 0144 SurfaceInterface *surface() const; 0145 0146 /** 0147 * Returns \c true if the surface has been configured; otherwise returns \c false. 0148 */ 0149 bool isConfigured() const; 0150 0151 /** 0152 * Returns the window geometry of the XdgSurfaceInterface. 0153 * 0154 * This method will return an invalid QRect if the window geometry is not set by the client. 0155 */ 0156 QRect windowGeometry() const; 0157 0158 /** 0159 * Returns the XdgSurfaceInterface for the specified wayland resource object \a resource. 0160 */ 0161 static XdgSurfaceInterface *get(::wl_resource *resource); 0162 0163 Q_SIGNALS: 0164 /** 0165 * This signal is emitted when the xdg-surface is about to be destroyed. 0166 */ 0167 void aboutToBeDestroyed(); 0168 0169 /** 0170 * This signal is emitted when a configure event with serial \a serial has been acknowledged. 0171 */ 0172 void configureAcknowledged(quint32 serial); 0173 0174 /** 0175 * This signal is emitted when the window geometry has been changed. 0176 */ 0177 void windowGeometryChanged(const QRect &rect); 0178 0179 /** 0180 * This signal is emitted when the surface has been unmapped and its state has been reset. 0181 */ 0182 void resetOccurred(); 0183 0184 private: 0185 std::unique_ptr<XdgSurfaceInterfacePrivate> d; 0186 friend class XdgSurfaceInterfacePrivate; 0187 }; 0188 0189 /** 0190 * The XdgToplevelInterface class represents a surface with window-like functionality such 0191 * as maximize, fullscreen, resizing, minimizing, etc. 0192 * 0193 * XdgToplevelInterface corresponds to the Wayland interface \c xdg_toplevel. 0194 */ 0195 class KWIN_EXPORT XdgToplevelInterface : public QObject 0196 { 0197 Q_OBJECT 0198 0199 public: 0200 enum State { 0201 MaximizedHorizontal = 0x1, 0202 MaximizedVertical = 0x2, 0203 FullScreen = 0x4, 0204 Resizing = 0x8, 0205 Activated = 0x10, 0206 TiledLeft = 0x20, 0207 TiledTop = 0x40, 0208 TiledRight = 0x80, 0209 TiledBottom = 0x100, 0210 Maximized = MaximizedHorizontal | MaximizedVertical, 0211 }; 0212 Q_DECLARE_FLAGS(States, State) 0213 0214 enum class ResizeAnchor { 0215 None = 0, 0216 Top = 1, 0217 Bottom = 2, 0218 Left = 4, 0219 TopLeft = 5, 0220 BottomLeft = 6, 0221 Right = 8, 0222 TopRight = 9, 0223 BottomRight = 10, 0224 }; 0225 Q_ENUM(ResizeAnchor) 0226 0227 /** 0228 * Constructs an XdgToplevelInterface for the given xdg-surface \a surface. 0229 */ 0230 XdgToplevelInterface(XdgSurfaceInterface *surface, ::wl_resource *resource); 0231 /** 0232 * Destructs the XdgToplevelInterface object. 0233 */ 0234 ~XdgToplevelInterface() override; 0235 0236 /** 0237 * Returns the XdgShellInterface for this XdgToplevelInterface. 0238 * 0239 * This is equivalent to xdgSurface()->shell(). 0240 */ 0241 XdgShellInterface *shell() const; 0242 0243 /** 0244 * Returns the XdgSurfaceInterface associated with the XdgToplevelInterface. 0245 */ 0246 XdgSurfaceInterface *xdgSurface() const; 0247 0248 /** 0249 * Returns the SurfaceInterface associated with the XdgToplevelInterface. 0250 */ 0251 SurfaceInterface *surface() const; 0252 0253 /** 0254 * Returns the parent XdgToplevelInterface above which this toplevel is stacked. 0255 */ 0256 XdgToplevelInterface *parentXdgToplevel() const; 0257 0258 /** 0259 * Returns \c true if the toplevel has been configured; otherwise returns \c false. 0260 */ 0261 bool isConfigured() const; 0262 0263 /** 0264 * Returns the window title of the toplevel surface. 0265 */ 0266 QString windowTitle() const; 0267 0268 /** 0269 * Returns the window class of the toplevel surface. 0270 */ 0271 QString windowClass() const; 0272 0273 /** 0274 * Returns the minimum window geometry size of the toplevel surface. 0275 */ 0276 QSize minimumSize() const; 0277 0278 /** 0279 * Returns the maximum window geometry size of the toplevel surface. 0280 */ 0281 QSize maximumSize() const; 0282 0283 /** 0284 * Sends a configure event to the client. \a size specifies the new window geometry size. A size 0285 * of zero means the client should decide its own window dimensions. 0286 */ 0287 quint32 sendConfigure(const QSize &size, const States &states); 0288 0289 /** 0290 * Sends a close event to the client. The client may choose to ignore this request. 0291 */ 0292 void sendClose(); 0293 0294 /** 0295 * Sends an event to the client specifying the maximum bounds for the surface size. Must be 0296 * called before sendConfigure(). 0297 */ 0298 void sendConfigureBounds(const QSize &size); 0299 0300 /** 0301 * Returns the XdgToplevelInterface for the specified wayland resource object \a resource. 0302 */ 0303 static XdgToplevelInterface *get(::wl_resource *resource); 0304 0305 Q_SIGNALS: 0306 /** 0307 * This signal is emitted when the xdg-toplevel is about to be destroyed. 0308 */ 0309 void aboutToBeDestroyed(); 0310 0311 /** 0312 * This signal is emitted when the xdg-toplevel has commited the initial state and wants to 0313 * be configured. After initializing the toplevel, you must send a configure event. 0314 */ 0315 void initializeRequested(); 0316 0317 /** 0318 * This signal is emitted when the toplevel has been unmapped and its state has been reset. 0319 */ 0320 void resetOccurred(); 0321 0322 /** 0323 * This signal is emitted when the toplevel's title has been changed. 0324 */ 0325 void windowTitleChanged(const QString &windowTitle); 0326 0327 /** 0328 * This signal is emitted when the toplevel's application id has been changed. 0329 */ 0330 void windowClassChanged(const QString &windowClass); 0331 0332 /** 0333 * This signal is emitted when the toplevel has requested the window menu to be shown at 0334 * \a pos. The \a seat and the \a serial indicate the user action that triggerred the request. 0335 */ 0336 void windowMenuRequested(KWaylandServer::SeatInterface *seat, const QPoint &pos, quint32 serial); 0337 0338 /** 0339 * This signal is emitted when the toplevel's minimum size has been changed. 0340 */ 0341 void minimumSizeChanged(const QSize &size); 0342 0343 /** 0344 * This signal is emitted when the toplevel's maximum size has been changed. 0345 */ 0346 void maximumSizeChanged(const QSize &size); 0347 0348 /** 0349 * This signal is emitted when the toplevel wants to be interactively moved. The \a seat and 0350 * the \a serial indicate the user action in response to which this request has been issued. 0351 */ 0352 void moveRequested(KWaylandServer::SeatInterface *seat, quint32 serial); 0353 0354 /** 0355 * This signal is emitted when the toplevel wants to be interactively resized by dragging 0356 * the specified \a anchor. The \a seat and the \a serial indicate the user action 0357 * in response to which this request has been issued. 0358 */ 0359 void resizeRequested(KWaylandServer::SeatInterface *seat, KWaylandServer::XdgToplevelInterface::ResizeAnchor anchor, quint32 serial); 0360 0361 /** 0362 * This signal is emitted when the toplevel surface wants to become maximized. 0363 */ 0364 void maximizeRequested(); 0365 0366 /** 0367 * This signal is emitted when the toplevel surface wants to become unmaximized. 0368 */ 0369 void unmaximizeRequested(); 0370 0371 /** 0372 * This signal is emitted when the toplevel wants to be shown in the full screen mode. 0373 */ 0374 void fullscreenRequested(KWaylandServer::OutputInterface *output); 0375 0376 /** 0377 * This signal is emitted when the toplevel surface wants to leave the full screen mode. 0378 */ 0379 void unfullscreenRequested(); 0380 0381 /** 0382 * This signal is emitted when the toplevel wants to be iconified. 0383 */ 0384 void minimizeRequested(); 0385 0386 /** 0387 * This signal is emitted when the parent toplevel has changed. 0388 */ 0389 void parentXdgToplevelChanged(); 0390 0391 private: 0392 std::unique_ptr<XdgToplevelInterfacePrivate> d; 0393 friend class XdgToplevelInterfacePrivate; 0394 }; 0395 0396 /** 0397 * The XdgPositioner class provides a collection of rules for the placement of a popup surface. 0398 * 0399 * XdgPositioner corresponds to the Wayland interface \c xdg_positioner. 0400 */ 0401 class KWIN_EXPORT XdgPositioner 0402 { 0403 public: 0404 /** 0405 * Constructs an incomplete XdgPositioner object. 0406 */ 0407 XdgPositioner(); 0408 /** 0409 * Constructs a copy of the XdgPositioner object. 0410 */ 0411 XdgPositioner(const XdgPositioner &other); 0412 /** 0413 * Destructs the XdgPositioner object. 0414 */ 0415 ~XdgPositioner(); 0416 0417 /** 0418 * Assigns the value of \a other to this XdgPositioner object. 0419 */ 0420 XdgPositioner &operator=(const XdgPositioner &other); 0421 0422 /** 0423 * Returns \c true if the positioner object is complete; otherwise returns \c false. 0424 * 0425 * An xdg positioner considered complete if it has a valid size and a valid anchor rect. 0426 */ 0427 bool isComplete() const; 0428 0429 /** 0430 * Returns the set of orientations along which the compositor may slide the popup to ensure 0431 * that it is entirely inside the compositor's defined "work area." 0432 */ 0433 Qt::Orientations slideConstraintAdjustments() const; 0434 0435 /** 0436 * Returns the set of orientations along which the compositor may flip the popup to ensure 0437 * that it is entirely inside the compositor's defined "work area." 0438 */ 0439 Qt::Orientations flipConstraintAdjustments() const; 0440 0441 /** 0442 * Returns the set of orientations along which the compositor can resize the popup to ensure 0443 * that it is entirely inside the compositor's defined "work area." 0444 */ 0445 Qt::Orientations resizeConstraintAdjustments() const; 0446 0447 /** 0448 * Returns the set of edges on the anchor rectangle that the surface should be positioned 0449 * around. 0450 */ 0451 Qt::Edges anchorEdges() const; 0452 0453 /** 0454 * Returns the direction in which the surface should be positioned, relative to the anchor 0455 * point of the parent surface. 0456 */ 0457 Qt::Edges gravityEdges() const; 0458 0459 /** 0460 * Returns the window geometry size of the surface that is to be positioned. 0461 */ 0462 QSize size() const; 0463 0464 /** 0465 * Returns the anchor rectangle relative to the upper left corner of the window geometry of 0466 * the parent surface that the popup should be positioned around. 0467 */ 0468 QRect anchorRect() const; 0469 0470 /** 0471 * Returns the surface position offset relative to the position of the anchor on the anchor 0472 * rectangle and the anchor on the surface. 0473 */ 0474 QPoint offset() const; 0475 0476 /** 0477 * Returns whether the surface should respond to movements in its parent window. 0478 */ 0479 bool isReactive() const; 0480 0481 /** 0482 * Returns the parent size to use when positioning the popup. 0483 */ 0484 QSize parentSize() const; 0485 0486 /** 0487 * Returns the serial of the configure event for the parent window. 0488 */ 0489 quint32 parentConfigure() const; 0490 0491 /** 0492 * Returns the current state of the xdg positioner object identified by \a resource. 0493 */ 0494 static XdgPositioner get(::wl_resource *resource); 0495 0496 private: 0497 XdgPositioner(const QSharedDataPointer<XdgPositionerData> &data); 0498 QSharedDataPointer<XdgPositionerData> d; 0499 }; 0500 0501 /** 0502 * The XdgPopupInterface class represents a surface that can be used to implement context menus, 0503 * popovers and other similar short-lived user interface elements. 0504 * 0505 * XdgPopupInterface corresponds to the Wayland interface \c xdg_popup. 0506 */ 0507 class KWIN_EXPORT XdgPopupInterface : public QObject 0508 { 0509 Q_OBJECT 0510 0511 public: 0512 XdgPopupInterface(XdgSurfaceInterface *surface, SurfaceInterface *parentSurface, const XdgPositioner &positioner, ::wl_resource *resource); 0513 /** 0514 * Destructs the XdgPopupInterface object. 0515 */ 0516 ~XdgPopupInterface() override; 0517 0518 XdgShellInterface *shell() const; 0519 0520 /** 0521 * Returns the parent surface for this popup surface. If the initial state hasn't been 0522 * committed yet, this function may return \c null. 0523 */ 0524 SurfaceInterface *parentSurface() const; 0525 0526 /** 0527 * Returns the XdgSurfaceInterface associated with the XdgPopupInterface. 0528 */ 0529 XdgSurfaceInterface *xdgSurface() const; 0530 0531 /** 0532 * Returns the SurfaceInterface associated with the XdgPopupInterface. 0533 */ 0534 SurfaceInterface *surface() const; 0535 0536 /** 0537 * Returns the XdgPositioner assigned to this XdgPopupInterface. 0538 */ 0539 XdgPositioner positioner() const; 0540 0541 /** 0542 * Returns \c true if the popup has been configured; otherwise returns \c false. 0543 */ 0544 bool isConfigured() const; 0545 0546 /** 0547 * Sends a configure event to the client and returns the serial number of the event. 0548 */ 0549 quint32 sendConfigure(const QRect &rect); 0550 0551 /** 0552 * Sends a popup done event to the client. 0553 */ 0554 void sendPopupDone(); 0555 0556 /** 0557 * Sends a popup repositioned event to the client. 0558 */ 0559 void sendRepositioned(quint32 token); 0560 0561 /** 0562 * Returns the XdgPopupInterface for the specified wayland resource object \a resource. 0563 */ 0564 static XdgPopupInterface *get(::wl_resource *resource); 0565 0566 Q_SIGNALS: 0567 /** 0568 * This signal is emitted when the xdg-popup is about to be destroyed. 0569 */ 0570 void aboutToBeDestroyed(); 0571 0572 /** 0573 * This signal is emitted when the xdg-popup has commited the initial state and wants to 0574 * be configured. After initializing the popup, you must send a configure event. 0575 */ 0576 void initializeRequested(); 0577 void grabRequested(SeatInterface *seat, quint32 serial); 0578 void repositionRequested(quint32 token); 0579 0580 private: 0581 std::unique_ptr<XdgPopupInterfacePrivate> d; 0582 friend class XdgPopupInterfacePrivate; 0583 }; 0584 0585 } // namespace KWaylandServer 0586 0587 Q_DECLARE_OPERATORS_FOR_FLAGS(KWaylandServer::XdgToplevelInterface::States) 0588 Q_DECLARE_METATYPE(KWaylandServer::XdgToplevelInterface::State) 0589 Q_DECLARE_METATYPE(KWaylandServer::XdgToplevelInterface::States)