Directory: | ./ |
---|---|
File: | server/server_decoration_palette.cpp |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 54 | 58 | 93.1% |
Branches: | 11 | 22 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /**************************************************************************** | ||
2 | Copyright 2020 Adrien Faveraux <ad1rie3@hotmail.fr> | ||
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_p.h" | ||
21 | |||
22 | #include <QtGlobal> | ||
23 | |||
24 | namespace Wrapland::Server | ||
25 | { | ||
26 | |||
27 | const struct org_kde_kwin_server_decoration_palette_manager_interface | ||
28 | ServerSideDecorationPaletteManager::Private::s_interface | ||
29 | = { | ||
30 | cb<createCallback>, | ||
31 | }; | ||
32 | |||
33 | 2 | ServerSideDecorationPaletteManager::Private::Private(Display* display, | |
34 | ServerSideDecorationPaletteManager* qptr) | ||
35 | 1 | : ServerSideDecorationPaletteManagerGlobal( | |
36 | 1 | qptr, | |
37 | 1 | display, | |
38 | &org_kde_kwin_server_decoration_palette_manager_interface, | ||
39 | &s_interface) | ||
40 | 1 | { | |
41 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | create(); |
42 | 1 | } | |
43 | |||
44 | 1 | void ServerSideDecorationPaletteManager::Private::createCallback( | |
45 | ServerSideDecorationPaletteManagerBind* bind, | ||
46 | uint32_t id, | ||
47 | wl_resource* wlSurface) | ||
48 | { | ||
49 | 1 | auto priv = bind->global()->handle->d_ptr.get(); | |
50 | 1 | auto surface = Wayland::Resource<Surface>::get_handle(wlSurface); | |
51 | |||
52 | 1 | auto palette | |
53 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | = new ServerSideDecorationPalette(bind->client->handle, bind->version, id, surface); |
54 | |||
55 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!palette->d_ptr->resource) { |
56 | ✗ | bind->post_no_memory(); | |
57 | ✗ | delete palette; | |
58 | ✗ | return; | |
59 | } | ||
60 | |||
61 | 1 | priv->palettes.push_back(palette); | |
62 | |||
63 | 2 | QObject::connect(palette, &ServerSideDecorationPalette::resourceDestroyed, priv->handle, [=]() { | |
64 | 2 | priv->palettes.erase(std::remove(priv->palettes.begin(), priv->palettes.end(), palette), | |
65 | 1 | priv->palettes.end()); | |
66 | 1 | }); | |
67 | |||
68 | 1 | Q_EMIT priv->handle->paletteCreated(palette); | |
69 | 1 | } | |
70 | |||
71 | 1 | ServerSideDecorationPaletteManager::ServerSideDecorationPaletteManager(Display* display) | |
72 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | : d_ptr(new Private(display, this)) |
73 | 1 | { | |
74 | 1 | } | |
75 | |||
76 | 2 | ServerSideDecorationPaletteManager::~ServerSideDecorationPaletteManager() = default; | |
77 | |||
78 | 3 | ServerSideDecorationPalette* ServerSideDecorationPaletteManager::paletteForSurface(Surface* surface) | |
79 | { | ||
80 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | for (ServerSideDecorationPalette* menu : d_ptr->palettes) { |
81 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (menu->surface() == surface) { |
82 | 1 | return menu; | |
83 | } | ||
84 | } | ||
85 | 2 | return nullptr; | |
86 | 3 | } | |
87 | |||
88 | const struct org_kde_kwin_server_decoration_palette_interface | ||
89 | ServerSideDecorationPalette::Private::s_interface | ||
90 | = { | ||
91 | setPaletteCallback, | ||
92 | destroyCallback, | ||
93 | }; | ||
94 | |||
95 | 1 | void ServerSideDecorationPalette::Private::setPaletteCallback([[maybe_unused]] wl_client* wlClient, | |
96 | wl_resource* wlResource, | ||
97 | char const* palette) | ||
98 | { | ||
99 | 1 | auto priv = get_handle(wlResource)->d_ptr; | |
100 | |||
101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (priv->palette == QLatin1String(palette)) { |
102 | ✗ | return; | |
103 | } | ||
104 | 1 | priv->palette = QString::fromUtf8(palette); | |
105 | 1 | Q_EMIT priv->handle->paletteChanged(priv->palette); | |
106 | 1 | } | |
107 | |||
108 | 2 | ServerSideDecorationPalette::Private::Private(Client* client, | |
109 | uint32_t version, | ||
110 | uint32_t id, | ||
111 | Surface* surface, | ||
112 | ServerSideDecorationPalette* qptr) | ||
113 | 1 | : Wayland::Resource<ServerSideDecorationPalette>( | |
114 | 1 | client, | |
115 | 1 | version, | |
116 | 1 | id, | |
117 | &org_kde_kwin_server_decoration_palette_interface, | ||
118 | &s_interface, | ||
119 | 1 | qptr) | |
120 | 1 | , surface(surface) | |
121 | 1 | { | |
122 | 1 | } | |
123 | |||
124 | 1 | ServerSideDecorationPalette::ServerSideDecorationPalette(Client* client, | |
125 | uint32_t version, | ||
126 | uint32_t id, | ||
127 | Surface* surface) | ||
128 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | : d_ptr(new Private(client, version, id, surface, this)) |
129 | 1 | { | |
130 | 1 | } | |
131 | |||
132 | 2 | QString ServerSideDecorationPalette::palette() const | |
133 | { | ||
134 | 2 | return d_ptr->palette; | |
135 | } | ||
136 | |||
137 | 1 | Surface* ServerSideDecorationPalette::surface() const | |
138 | { | ||
139 | 1 | return d_ptr->surface; | |
140 | } | ||
141 | |||
142 | } | ||
143 |