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 "display.h"
9 #include "global_p.h"
10 #include "outputconfiguration_interface.h"
11 
12 #include "wayland-output-management-server-protocol.h"
13 #include <wayland-server.h>
14 
15 #include <QHash>
16 
17 namespace KWayland
18 {
19 namespace Server
20 {
21 class OutputManagementInterface::Private : public Global::Private
22 {
23 public:
24  Private(OutputManagementInterface *q, Display *d);
25 
26 private:
27  void bind(wl_client *client, uint32_t version, uint32_t id) override;
28 
29  static void unbind(wl_resource *resource);
30  static Private *cast(wl_resource *r)
31  {
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 
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 = {createConfigurationCallback};
48 
49 OutputManagementInterface::OutputManagementInterface(Display *display, QObject *parent)
50  : Global(new Private(this, display), parent)
51 {
52 }
53 
54 OutputManagementInterface::~OutputManagementInterface()
55 {
56 }
57 
58 void OutputManagementInterface::Private::createConfigurationCallback(wl_client *client, wl_resource *resource, uint32_t id)
59 {
60  cast(resource)->createConfiguration(client, resource, id);
61 }
62 
63 void OutputManagementInterface::Private::createConfiguration(wl_client *client, wl_resource *resource, uint32_t id)
64 {
65  auto config = new OutputConfigurationInterface(q, resource);
66  config->create(display->getConnection(client), wl_resource_get_version(resource), id);
67  if (!config->resource()) {
68  wl_resource_post_no_memory(resource);
69  delete config;
70  return;
71  }
72 
73  configurationInterfaces[resource] = config;
74  connect(config, &QObject::destroyed, [this, resource] {
75  configurationInterfaces.remove(resource);
76  });
77 }
78 
79 OutputManagementInterface::Private::Private(OutputManagementInterface *q, Display *d)
80  : Global::Private(d, &org_kde_kwin_outputmanagement_interface, s_version)
81  , q(q)
82 {
83 }
84 
85 void OutputManagementInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
86 {
87  auto c = display->getConnection(client);
88  wl_resource *resource = c->createResource(&org_kde_kwin_outputmanagement_interface, qMin(version, s_version), id);
89  if (!resource) {
90  wl_client_post_no_memory(client);
91  return;
92  }
93  wl_resource_set_implementation(resource, &s_interface, this, unbind);
94  // TODO: should we track?
95 }
96 
97 void OutputManagementInterface::Private::unbind(wl_resource *resource)
98 {
99  Q_UNUSED(resource)
100  // TODO: implement?
101 }
102 
103 }
104 }
void destroyed(QObject *obj)
KSharedConfigPtr config()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:56:21 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.