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