File indexing completed on 2025-03-16 11:21:43
0001 /* 0002 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 #pragma once 0007 0008 #include "kwin_export.h" 0009 0010 #include <sys/types.h> 0011 0012 #include <QObject> 0013 #include <memory> 0014 0015 struct wl_client; 0016 struct wl_resource; 0017 0018 namespace KWaylandServer 0019 { 0020 class ClientConnectionPrivate; 0021 class Display; 0022 0023 /** 0024 * @brief Convenient Class which represents a wl_client. 0025 * 0026 * The ClientConnection gets automatically created for a wl_client when a wl_client is 0027 * first used in the context of KWaylandServer. In particular the signal 0028 * @link Display::clientConnected @endlink will be emitted. 0029 * 0030 * @see Display 0031 */ 0032 class KWIN_EXPORT ClientConnection : public QObject 0033 { 0034 Q_OBJECT 0035 public: 0036 virtual ~ClientConnection(); 0037 0038 /** 0039 * Flushes the connection to this client. Ensures that all events are pushed to the client. 0040 */ 0041 void flush(); 0042 /** 0043 * Get the wl_resource associated with the given @p id. 0044 */ 0045 wl_resource *getResource(quint32 id) const; 0046 0047 /** 0048 * @returns the native wl_client this ClientConnection represents. 0049 */ 0050 wl_client *client() const; 0051 /** 0052 * @returns The Display this ClientConnection is connected to 0053 */ 0054 Display *display() const; 0055 0056 /** 0057 * The pid of the ClientConnection endpoint. 0058 * 0059 * Please note: if the ClientConnection got created with @link Display::createClient @endlink 0060 * the pid will be identical to the process running the KWaylandServer::Display. 0061 * 0062 * @returns The pid of the connection. 0063 */ 0064 pid_t processId() const; 0065 /** 0066 * The uid of the ClientConnection endpoint. 0067 * 0068 * Please note: if the ClientConnection got created with @link Display::createClient @endlink 0069 * the uid will be identical to the process running the KWaylandServer::Display. 0070 * 0071 * @returns The uid of the connection. 0072 */ 0073 uid_t userId() const; 0074 /** 0075 * The gid of the ClientConnection endpoint. 0076 * 0077 * Please note: if the ClientConnection got created with @link Display::createClient @endlink 0078 * the gid will be identical to the process running the KWaylandServer::Display. 0079 * 0080 * @returns The gid of the connection. 0081 */ 0082 gid_t groupId() const; 0083 0084 /** 0085 * The absolute path to the executable. 0086 * 0087 * Please note: if the ClientConnection got created with @link Display::createClient @endlink 0088 * the executablePath will be identical to the process running the KWaylandServer::Display. 0089 * 0090 * If the executable path cannot be resolved an empty QString is returned. 0091 * 0092 * @see processId 0093 */ 0094 QString executablePath() const; 0095 0096 /** 0097 * Cast operator the native wl_client this ClientConnection represents. 0098 */ 0099 operator wl_client *(); 0100 /** 0101 * Cast operator the native wl_client this ClientConnection represents. 0102 */ 0103 operator wl_client *() const; 0104 0105 /** 0106 * Destroys this ClientConnection. 0107 * This is a convenient wrapper around wl_client_destroy. The use case is in combination 0108 * with ClientConnections created through @link Display::createClient @endlink. E.g. once 0109 * the process for the ClientConnection exited, the ClientConnection needs to be destroyed, too. 0110 */ 0111 void destroy(); 0112 0113 /** 0114 * Set an additional mapping between kwin's logical co-ordinate space and 0115 * the client's logical co-ordinate space. 0116 * 0117 * This is used in the same way as if the client was setting the 0118 * surface.buffer_scale on every surface i.e a value of 2.0 will make 0119 * the windows appear smaller on a regular DPI monitor. 0120 * 0121 * Only the minimal set of protocols used by xwayland have support. 0122 * 0123 * Buffer sizes are unaffected. 0124 */ 0125 void setScaleOverride(qreal scaleOverride); 0126 qreal scaleOverride() const; 0127 0128 Q_SIGNALS: 0129 /** 0130 * This signal is emitted when the client is about to be destroyed. 0131 */ 0132 void aboutToBeDestroyed(); 0133 /** 0134 * Signal emitted when the ClientConnection got disconnected from the server. 0135 */ 0136 void disconnected(KWaylandServer::ClientConnection *); 0137 0138 void scaleOverrideChanged(); 0139 0140 private: 0141 friend class Display; 0142 explicit ClientConnection(wl_client *c, Display *parent); 0143 std::unique_ptr<ClientConnectionPrivate> d; 0144 }; 0145 0146 } 0147 0148 Q_DECLARE_METATYPE(KWaylandServer::ClientConnection *)