KWayland

outputmanagement_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3  SPDX-FileCopyrightText: 2015 Sebastian Kügler <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 #include "outputmanagement_interface.h"
8 #include "outputconfiguration_interface.h"
9 #include "display.h"
10 #include "global_p.h"
11 
12 #include <wayland-server.h>
13 #include "wayland-output-management-server-protocol.h"
14 
15 #include <QHash>
16 
17 namespace KWayland
18 {
19 namespace Server
20 {
21 
22 class OutputManagementInterface::Private : public Global::Private
23 {
24 public:
25  Private(OutputManagementInterface *q, Display *d);
26 
27 private:
28  void bind(wl_client *client, uint32_t version, uint32_t id) override;
29 
30  static void unbind(wl_resource *resource);
31  static Private *cast(wl_resource *r) {
32  return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
33  }
34  void createConfiguration(wl_client *client, wl_resource *resource, uint32_t id);
35 
36  static void createConfigurationCallback(wl_client *client, wl_resource *resource, uint32_t id);
37 
38  OutputManagementInterface *q;
39  static const struct org_kde_kwin_outputmanagement_interface s_interface;
40  static const quint32 s_version;
41 
43 };
44 
45 const quint32 OutputManagementInterface::Private::s_version = 2;
46 
47 const struct org_kde_kwin_outputmanagement_interface OutputManagementInterface::Private::s_interface = {
48  createConfigurationCallback
49 };
50 
51 OutputManagementInterface::OutputManagementInterface(Display *display, QObject *parent)
52 : Global(new Private(this, display), parent)
53 {
54 }
55 
56 OutputManagementInterface::~OutputManagementInterface()
57 {
58 }
59 
60 void OutputManagementInterface::Private::createConfigurationCallback(wl_client *client, wl_resource *resource, uint32_t id)
61 {
62  cast(resource)->createConfiguration(client, resource, id);
63 }
64 
65 void OutputManagementInterface::Private::createConfiguration(wl_client* client, wl_resource* resource, uint32_t id)
66 {
67  auto config = new OutputConfigurationInterface(q, resource);
68  config->create(display->getConnection(client), wl_resource_get_version(resource), id);
69  if (!config->resource()) {
70  wl_resource_post_no_memory(resource);
71  delete config;
72  return;
73  }
74 
75  configurationInterfaces[resource] = config;
76  connect(config, &QObject::destroyed, [this, resource] {
77  configurationInterfaces.remove(resource);
78  });
79 }
80 
81 OutputManagementInterface::Private::Private(OutputManagementInterface *q, Display *d)
82 : Global::Private(d, &org_kde_kwin_outputmanagement_interface, s_version)
83 , q(q)
84 {
85 }
86 
87 void OutputManagementInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
88 {
89  auto c = display->getConnection(client);
90  wl_resource *resource = c->createResource(&org_kde_kwin_outputmanagement_interface, qMin(version, s_version), id);
91  if (!resource) {
92  wl_client_post_no_memory(client);
93  return;
94  }
95  wl_resource_set_implementation(resource, &s_interface, this, unbind);
96  // TODO: should we track?
97 }
98 
99 void OutputManagementInterface::Private::unbind(wl_resource *resource)
100 {
101  Q_UNUSED(resource)
102  // TODO: implement?
103 }
104 
105 }
106 }
KSharedConfigPtr config()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void destroyed(QObject *obj)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.