KWayland

filtered_display.cpp
1 /*
2  SPDX-FileCopyrightText: 2017 David Edmundson <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #include "filtered_display.h"
8 
9 #include <wayland-server.h>
10 
11 #include <QByteArray>
12 
13 namespace KWayland
14 {
15 namespace Server
16 {
17 class FilteredDisplay::Private
18 {
19 public:
20  Private(FilteredDisplay *_q);
21  FilteredDisplay *q;
22  static bool globalFilterCallback(const wl_client *client, const wl_global *global, void *data)
23  {
24  auto t = static_cast<FilteredDisplay::Private *>(data);
25  auto clientConnection = t->q->getConnection(const_cast<wl_client *>(client));
26  auto interface = wl_global_get_interface(global);
27  auto name = QByteArray::fromRawData(interface->name, strlen(interface->name));
28  return t->q->allowInterface(clientConnection, name);
29  };
30 };
31 
32 FilteredDisplay::Private::Private(FilteredDisplay *_q)
33  : q(_q)
34 {
35 }
36 
37 FilteredDisplay::FilteredDisplay(QObject *parent)
38  : Display(parent)
39  , d(new Private(this))
40 {
41  connect(this, &Display::runningChanged, [this](bool running) {
42  if (!running) {
43  return;
44  }
45  wl_display_set_global_filter(*this, Private::globalFilterCallback, d.data());
46  });
47 }
48 
49 FilteredDisplay::~FilteredDisplay()
50 {
51  wl_display_set_global_filter(*this, nullptr, nullptr);
52 }
53 
54 }
55 }
QByteArray fromRawData(const char *data, int size)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T * data() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Jan 30 2023 03:56:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.