KWin
Loading...
Searching...
No Matches
clientconnection.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6#include "clientconnection.h"
7#include "display.h"
9// Qt
10#include <QFileInfo>
11#include <QList>
12// Wayland
13#include <wayland-server.h>
14
15namespace KWin
16{
18{
19public:
22
23 wl_client *client;
25 pid_t pid = 0;
26 uid_t user = 0;
27 gid_t group = 0;
30 qreal scaleOverride = 1.0;
31
32private:
33 static void destroyListenerCallback(wl_listener *listener, void *data);
34 static void destroyLateListenerCallback(wl_listener *listener, void *data);
36 wl_listener destroyListener;
37 wl_listener destroyLateListener;
38 static QList<ClientConnectionPrivate *> s_allClients;
39};
40
41QList<ClientConnectionPrivate *> ClientConnectionPrivate::s_allClients;
42
44 : client(c)
45 , display(display)
46 , q(q)
47{
48 s_allClients << this;
49
50 destroyListener.notify = destroyListenerCallback;
51 wl_client_add_destroy_listener(c, &destroyListener);
52
53 destroyLateListener.notify = destroyLateListenerCallback;
54 wl_client_add_destroy_late_listener(c, &destroyLateListener);
55
56 wl_client_get_credentials(client, &pid, &user, &group);
58}
59
61{
62 s_allClients.removeAt(s_allClients.indexOf(this));
63}
64
65void ClientConnectionPrivate::destroyListenerCallback(wl_listener *listener, void *data)
66{
67 wl_client *client = reinterpret_cast<wl_client *>(data);
68 auto it = std::find_if(s_allClients.constBegin(), s_allClients.constEnd(), [client](ClientConnectionPrivate *c) {
69 return c->client == client;
70 });
71 Q_ASSERT(it != s_allClients.constEnd());
72 auto p = (*it);
73 auto q = p->q;
74
75 Q_EMIT q->aboutToBeDestroyed();
76 wl_list_remove(&p->destroyListener.link);
77 Q_EMIT q->disconnected(q);
78}
79
80void ClientConnectionPrivate::destroyLateListenerCallback(wl_listener *listener, void *data)
81{
82 wl_client *client = reinterpret_cast<wl_client *>(data);
83 auto it = std::find_if(s_allClients.constBegin(), s_allClients.constEnd(), [client](ClientConnectionPrivate *c) {
84 return c->client == client;
85 });
86 Q_ASSERT(it != s_allClients.constEnd());
87 auto p = (*it);
88 auto q = p->q;
89
90 wl_list_remove(&p->destroyLateListener.link);
91 delete q;
92}
93
94ClientConnection::ClientConnection(wl_client *c, Display *parent)
95 : QObject(parent)
96 , d(new ClientConnectionPrivate(c, parent, this))
97{
98}
99
101
103{
104 wl_client_flush(d->client);
105}
106
108{
109 wl_client_destroy(d->client);
110}
111
112wl_resource *ClientConnection::getResource(quint32 id) const
113{
114 return wl_client_get_object(d->client, id);
115}
116
117wl_client *ClientConnection::client() const
118{
119 return d->client;
120}
121
122ClientConnection::operator wl_client *()
123{
124 return d->client;
125}
126
127ClientConnection::operator wl_client *() const
128{
129 return d->client;
130}
131
133{
134 return d->display;
135}
136
138{
139 return d->group;
140}
141
143{
144 return d->pid;
145}
146
148{
149 return d->user;
150}
151
153{
154 return d->executablePath;
155}
156
158{
159 Q_ASSERT(scaleOveride != 0);
160 d->scaleOverride = scaleOveride;
161 Q_EMIT scaleOverrideChanged();
162}
163
165{
166 return d->scaleOverride;
167}
168
170{
171 d->securityContextAppId = appId;
172}
173
175{
176 return d->securityContextAppId;
177}
178}
179
180#include "moc_clientconnection.cpp"
Convenient Class which represents a wl_client.
void setScaleOverride(qreal scaleOverride)
QString securityContextAppId() const
wl_resource * getResource(quint32 id) const
wl_client * client() const
void setSecurityContextAppId(const QString &appId)
void disconnected(KWin::ClientConnection *)
ClientConnectionPrivate(wl_client *c, Display *display, ClientConnection *q)
Class holding the Wayland server display loop.
Definition display.h:34
QString executablePathFromPid(pid_t)
struct _XDisplay Display