File indexing completed on 2024-05-12 05:32:18

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 KWin
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. In particular,
0027  * the signal @link Display::clientConnected @endlink will be emitted.
0028  *
0029  * @see Display
0030  */
0031 class KWIN_EXPORT ClientConnection : public QObject
0032 {
0033     Q_OBJECT
0034 public:
0035     virtual ~ClientConnection();
0036 
0037     /**
0038      * Flushes the connection to this client. Ensures that all events are pushed to the client.
0039      */
0040     void flush();
0041     /**
0042      * Get the wl_resource associated with the given @p id.
0043      */
0044     wl_resource *getResource(quint32 id) const;
0045 
0046     /**
0047      * @returns the native wl_client this ClientConnection represents.
0048      */
0049     wl_client *client() const;
0050     /**
0051      * @returns The Display this ClientConnection is connected to
0052      */
0053     Display *display() const;
0054 
0055     /**
0056      * The pid of the ClientConnection endpoint.
0057      *
0058      * Please note: if the ClientConnection got created with @link Display::createClient @endlink
0059      * the pid will be identical to the process running the KWin::Display.
0060      *
0061      * @returns The pid of the connection.
0062      */
0063     pid_t processId() const;
0064     /**
0065      * The uid of the ClientConnection endpoint.
0066      *
0067      * Please note: if the ClientConnection got created with @link Display::createClient @endlink
0068      * the uid will be identical to the process running the KWin::Display.
0069      *
0070      * @returns The uid of the connection.
0071      */
0072     uid_t userId() const;
0073     /**
0074      * The gid of the ClientConnection endpoint.
0075      *
0076      * Please note: if the ClientConnection got created with @link Display::createClient @endlink
0077      * the gid will be identical to the process running the KWin::Display.
0078      *
0079      * @returns The gid of the connection.
0080      */
0081     gid_t groupId() const;
0082 
0083     /**
0084      * The absolute path to the executable.
0085      *
0086      * Please note: if the ClientConnection got created with @link Display::createClient @endlink
0087      * the executablePath will be identical to the process running the KWin::Display.
0088      *
0089      * If the executable path cannot be resolved an empty QString is returned.
0090      *
0091      * @see processId
0092      */
0093     QString executablePath() const;
0094 
0095     /**
0096      * Cast operator the native wl_client this ClientConnection represents.
0097      */
0098     operator wl_client *();
0099     /**
0100      * Cast operator the native wl_client this ClientConnection represents.
0101      */
0102     operator wl_client *() const;
0103 
0104     /**
0105      * Destroys this ClientConnection.
0106      * This is a convenient wrapper around wl_client_destroy. The use case is in combination
0107      * with ClientConnections created through @link Display::createClient @endlink. E.g. once
0108      * the process for the ClientConnection exited, the ClientConnection needs to be destroyed, too.
0109      */
0110     void destroy();
0111 
0112     /**
0113      * Set an additional mapping between kwin's logical co-ordinate space and
0114      * the client's logical co-ordinate space.
0115      *
0116      * This is used in the same way as if the client was setting the
0117      * surface.buffer_scale on every surface i.e a value of 2.0 will make
0118      * the windows appear smaller on a regular DPI monitor.
0119      *
0120      * Only the minimal set of protocols used by xwayland have support.
0121      *
0122      * Buffer sizes are unaffected.
0123      */
0124     void setScaleOverride(qreal scaleOverride);
0125     qreal scaleOverride() const;
0126 
0127     void setSecurityContextAppId(const QString &appId);
0128     QString securityContextAppId() const;
0129 
0130 Q_SIGNALS:
0131     /**
0132      * This signal is emitted when the client is about to be destroyed.
0133      */
0134     void aboutToBeDestroyed();
0135     /**
0136      * Signal emitted when the ClientConnection got disconnected from the server.
0137      */
0138     void disconnected(KWin::ClientConnection *);
0139 
0140     void scaleOverrideChanged();
0141 
0142 private:
0143     friend class Display;
0144     explicit ClientConnection(wl_client *c, Display *parent);
0145     std::unique_ptr<ClientConnectionPrivate> d;
0146 };
0147 
0148 }
0149 
0150 Q_DECLARE_METATYPE(KWin::ClientConnection *)