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