Changeset View
Changeset View
Standalone View
Standalone View
src/client/server_decoration_palette.cpp
- This file was added.
1 | /**************************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2017 David Edmundson <kde@davidedmundson.co.uk> | ||||
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 "server_decoration_palette.h" | ||||
21 | #include "event_queue.h" | ||||
22 | #include "surface.h" | ||||
23 | #include "wayland_pointer_p.h" | ||||
24 | | ||||
25 | #include <wayland-server-decoration-palette-client-protocol.h> | ||||
26 | | ||||
27 | #include <QDebug> | ||||
28 | | ||||
29 | namespace KWayland | ||||
30 | { | ||||
31 | namespace Client | ||||
32 | { | ||||
33 | | ||||
34 | class ServerSideDecorationPaletteManager::Private | ||||
35 | { | ||||
36 | public: | ||||
37 | Private() = default; | ||||
38 | | ||||
39 | void setup(org_kde_kwin_server_decoration_palette_manager *arg); | ||||
40 | | ||||
41 | WaylandPointer<org_kde_kwin_server_decoration_palette_manager, org_kde_kwin_server_decoration_palette_manager_destroy> serverdecomanager; | ||||
42 | EventQueue *queue = nullptr; | ||||
43 | }; | ||||
44 | | ||||
45 | ServerSideDecorationPaletteManager::ServerSideDecorationPaletteManager(QObject *parent) | ||||
46 | : QObject(parent) | ||||
47 | , d(new Private) | ||||
48 | { | ||||
49 | } | ||||
50 | | ||||
51 | void ServerSideDecorationPaletteManager::Private::setup(org_kde_kwin_server_decoration_palette_manager *arg) | ||||
52 | { | ||||
53 | Q_ASSERT(arg); | ||||
54 | Q_ASSERT(!serverdecomanager); | ||||
55 | serverdecomanager.setup(arg); | ||||
56 | } | ||||
57 | | ||||
58 | ServerSideDecorationPaletteManager::~ServerSideDecorationPaletteManager() | ||||
59 | { | ||||
60 | release(); | ||||
61 | } | ||||
62 | | ||||
63 | void ServerSideDecorationPaletteManager::setup(org_kde_kwin_server_decoration_palette_manager *serverdecomanager) | ||||
64 | { | ||||
65 | d->setup(serverdecomanager); | ||||
66 | } | ||||
67 | | ||||
68 | void ServerSideDecorationPaletteManager::release() | ||||
69 | { | ||||
70 | d->serverdecomanager.release(); | ||||
71 | } | ||||
72 | | ||||
73 | void ServerSideDecorationPaletteManager::destroy() | ||||
74 | { | ||||
75 | d->serverdecomanager.destroy(); | ||||
76 | } | ||||
77 | | ||||
78 | ServerSideDecorationPaletteManager::operator org_kde_kwin_server_decoration_palette_manager*() { | ||||
79 | return d->serverdecomanager; | ||||
80 | } | ||||
81 | | ||||
82 | ServerSideDecorationPaletteManager::operator org_kde_kwin_server_decoration_palette_manager*() const { | ||||
83 | return d->serverdecomanager; | ||||
84 | } | ||||
85 | | ||||
86 | bool ServerSideDecorationPaletteManager::isValid() const | ||||
87 | { | ||||
88 | return d->serverdecomanager.isValid(); | ||||
89 | } | ||||
90 | | ||||
91 | void ServerSideDecorationPaletteManager::setEventQueue(EventQueue *queue) | ||||
92 | { | ||||
93 | d->queue = queue; | ||||
94 | } | ||||
95 | | ||||
96 | EventQueue *ServerSideDecorationPaletteManager::eventQueue() | ||||
97 | { | ||||
98 | return d->queue; | ||||
99 | } | ||||
100 | | ||||
101 | ServerDecorationPalette *ServerSideDecorationPaletteManager::create(Surface *surface, QObject *parent) | ||||
102 | { | ||||
103 | Q_ASSERT(isValid()); | ||||
104 | auto p = new ServerDecorationPalette(parent); | ||||
105 | auto w = org_kde_kwin_server_decoration_palette_manager_create(d->serverdecomanager, *surface); | ||||
106 | if (d->queue) { | ||||
107 | d->queue->addProxy(w); | ||||
108 | } | ||||
109 | p->setup(w); | ||||
110 | | ||||
111 | return p; | ||||
112 | } | ||||
113 | | ||||
114 | class ServerDecorationPalette::Private | ||||
115 | { | ||||
116 | public: | ||||
117 | Private(ServerDecorationPalette *q); | ||||
118 | | ||||
119 | void setup(org_kde_kwin_server_decoration_palette *arg); | ||||
120 | | ||||
121 | WaylandPointer<org_kde_kwin_server_decoration_palette, org_kde_kwin_server_decoration_palette_release> decoration_palette; | ||||
122 | | ||||
123 | private: | ||||
124 | ServerDecorationPalette *q; | ||||
125 | }; | ||||
126 | | ||||
127 | ServerDecorationPalette::Private::Private(ServerDecorationPalette *q) | ||||
128 | : q(q) | ||||
129 | { | ||||
130 | } | ||||
131 | | ||||
132 | ServerDecorationPalette::ServerDecorationPalette(QObject *parent) | ||||
133 | : QObject(parent) | ||||
134 | , d(new Private(this)) | ||||
135 | { | ||||
136 | } | ||||
137 | | ||||
138 | void ServerDecorationPalette::Private::setup(org_kde_kwin_server_decoration_palette *arg) | ||||
139 | { | ||||
140 | Q_ASSERT(arg); | ||||
141 | Q_ASSERT(!decoration_palette); | ||||
142 | decoration_palette.setup(arg); | ||||
143 | } | ||||
144 | | ||||
145 | ServerDecorationPalette::~ServerDecorationPalette() | ||||
146 | { | ||||
147 | release(); | ||||
148 | } | ||||
149 | | ||||
150 | void ServerDecorationPalette::setup(org_kde_kwin_server_decoration_palette *decoration_palette) | ||||
151 | { | ||||
152 | d->setup(decoration_palette); | ||||
153 | } | ||||
154 | | ||||
155 | void ServerDecorationPalette::release() | ||||
156 | { | ||||
157 | d->decoration_palette.release(); | ||||
158 | } | ||||
159 | | ||||
160 | void ServerDecorationPalette::destroy() | ||||
161 | { | ||||
162 | d->decoration_palette.destroy(); | ||||
163 | } | ||||
164 | | ||||
165 | ServerDecorationPalette::operator org_kde_kwin_server_decoration_palette*() { | ||||
166 | return d->decoration_palette; | ||||
167 | } | ||||
168 | | ||||
169 | ServerDecorationPalette::operator org_kde_kwin_server_decoration_palette*() const { | ||||
170 | return d->decoration_palette; | ||||
171 | } | ||||
172 | | ||||
173 | bool ServerDecorationPalette::isValid() const | ||||
174 | { | ||||
175 | return d->decoration_palette.isValid(); | ||||
176 | } | ||||
177 | | ||||
178 | void ServerDecorationPalette::setPalette(const QString &palette) | ||||
179 | { | ||||
180 | Q_ASSERT(isValid()); | ||||
181 | org_kde_kwin_server_decoration_palette_set_palette(*this, palette.toUtf8()); | ||||
182 | } | ||||
183 | } | ||||
184 | } |