1 /********************************************************************
2 Copyright © 2020 Roman Gilg <subdiff@gmail.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #include "output_management_v1.h"
21
22 #include "display.h"
23 #include "output_configuration_v1_p.h"
24
25 #include "wayland/global.h"
26
27 #include "wayland-output-management-v1-server-protocol.h"
28
29 #include <QHash>
30
31 namespace Wrapland::Server
32 {
33
34 constexpr uint32_t OutputManagementV1Version = 1;
35 using OutputManagementV1Global = Wayland::Global<OutputManagementV1, OutputManagementV1Version>;
36 using OutputManagementV1Bind = Wayland::Bind<OutputManagementV1Global>;
37
38 class OutputManagementV1::Private : public OutputManagementV1Global
39 {
40 public:
41 Private(OutputManagementV1* q, Display* display);
42 ~Private() override;
43
44 private:
45 static void createConfigurationCallback(OutputManagementV1Bind* bind, uint32_t id);
46
47 static const struct zkwinft_output_management_v1_interface s_interface;
48
49 std::vector<OutputConfigurationV1*> m_configurations;
50 };
51
52 struct zkwinft_output_management_v1_interface const OutputManagementV1::Private::s_interface
53 = {cb<createConfigurationCallback>};
54
Private(OutputManagementV1 * q,Display * display)55 OutputManagementV1::Private::Private(OutputManagementV1* q, Display* display)
56 : OutputManagementV1Global(q, display, &zkwinft_output_management_v1_interface, &s_interface)
57 {
58 create();
59 }
60
~Private()61 OutputManagementV1::Private::~Private()
62 {
63 std::for_each(m_configurations.cbegin(),
64 m_configurations.cend(),
65 [](OutputConfigurationV1* config) { config->d_ptr->manager = nullptr; });
66 }
67
createConfigurationCallback(OutputManagementV1Bind * bind,uint32_t id)68 void OutputManagementV1::Private::createConfigurationCallback(OutputManagementV1Bind* bind,
69 uint32_t id)
70 {
71 auto priv = bind->global()->handle()->d_ptr.get();
72
73 auto config
74 = new OutputConfigurationV1(bind->client()->handle(), bind->version(), id, priv->handle());
75 priv->m_configurations.push_back(config);
76
77 connect(config, &OutputConfigurationV1::resourceDestroyed, priv->handle(), [priv, config] {
78 auto& configs = priv->m_configurations;
79 configs.erase(std::remove(configs.begin(), configs.end(), config), configs.end());
80 });
81 }
82
OutputManagementV1(Display * display,QObject * parent)83 OutputManagementV1::OutputManagementV1(Display* display, QObject* parent)
84 : QObject(parent)
85 , d_ptr(new Private(this, display))
86 {
87 }
88
89 OutputManagementV1::~OutputManagementV1() = default;
90
91 }
92