Directory: | ./ |
---|---|
File: | server/slide.cpp |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 44 | 50 | 88.0% |
Branches: | 7 | 16 | 43.8% |
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 "client.h" | ||
25 | #include "display.h" | ||
26 | #include "region.h" | ||
27 | #include "slide_p.h" | ||
28 | #include "surface.h" | ||
29 | #include "surface_p.h" | ||
30 | |||
31 | #include <wayland-server.h> | ||
32 | |||
33 | namespace Wrapland::Server | ||
34 | { | ||
35 | |||
36 | const struct org_kde_kwin_slide_manager_interface SlideManager::Private::s_interface = { | ||
37 | cb<createCallback>, | ||
38 | cb<unsetCallback>, | ||
39 | }; | ||
40 | |||
41 | 37 | SlideManager::Private::Private(Display* display, SlideManager* qptr) | |
42 | 37 | : SlideManagerGlobal(qptr, display, &org_kde_kwin_slide_manager_interface, &s_interface) | |
43 | 37 | { | |
44 |
1/2✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
|
37 | create(); |
45 | 37 | } | |
46 | |||
47 | 2 | void SlideManager::Private::createCallback(SlideManagerBind* bind, | |
48 | uint32_t id, | ||
49 | wl_resource* wlSurface) | ||
50 | { | ||
51 | 2 | auto surface = Wayland::Resource<Surface>::get_handle(wlSurface); | |
52 | |||
53 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | auto slide = new Slide(bind->client->handle, bind->version, id); |
54 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (!slide->d_ptr->resource) { |
55 | ✗ | bind->post_no_memory(); | |
56 | ✗ | delete slide; | |
57 | ✗ | return; | |
58 | } | ||
59 | |||
60 | 2 | surface->d_ptr->setSlide(slide); | |
61 | 2 | } | |
62 | |||
63 | ✗ | void SlideManager::Private::unsetCallback([[maybe_unused]] SlideManagerBind* bind, | |
64 | wl_resource* wlSurface) | ||
65 | { | ||
66 | ✗ | auto surface = Wayland::Resource<Surface>::get_handle(wlSurface); | |
67 | ✗ | surface->d_ptr->setSlide(nullptr); | |
68 | } | ||
69 | |||
70 | 37 | SlideManager::SlideManager(Display* display) | |
71 |
2/4✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
|
37 | : d_ptr(new Private(display, this)) |
72 | 37 | { | |
73 | 37 | } | |
74 | |||
75 | 74 | SlideManager::~SlideManager() = default; | |
76 | |||
77 | const struct org_kde_kwin_slide_interface Slide::Private::s_interface = { | ||
78 | commitCallback, | ||
79 | setLocationCallback, | ||
80 | setOffsetCallback, | ||
81 | destroyCallback, | ||
82 | }; | ||
83 | |||
84 | 2 | Slide::Private::Private(Client* client, uint32_t version, uint32_t id, Slide* qptr) | |
85 | 4 | : Wayland::Resource<Slide>(client, | |
86 | 2 | version, | |
87 | 2 | id, | |
88 | &org_kde_kwin_slide_interface, | ||
89 | &s_interface, | ||
90 | 2 | qptr) | |
91 | 2 | { | |
92 | 2 | } | |
93 | |||
94 | 2 | void Slide::Private::commitCallback([[maybe_unused]] wl_client* wlClient, wl_resource* wlResource) | |
95 | { | ||
96 | 2 | auto priv = get_handle(wlResource)->d_ptr; | |
97 | 2 | priv->currentLocation = priv->pendingLocation; | |
98 | 2 | priv->currentOffset = priv->pendingOffset; | |
99 | 2 | } | |
100 | |||
101 | 1 | void Slide::Private::setLocationCallback([[maybe_unused]] wl_client* wlClient, | |
102 | wl_resource* wlResource, | ||
103 | uint32_t location) | ||
104 | { | ||
105 | 1 | auto priv = get_handle(wlResource)->d_ptr; | |
106 | 1 | priv->pendingLocation = static_cast<Slide::Location>(location); | |
107 | 1 | } | |
108 | |||
109 | 1 | void Slide::Private::setOffsetCallback([[maybe_unused]] wl_client* wlClient, | |
110 | wl_resource* wlResource, | ||
111 | int32_t offset) | ||
112 | { | ||
113 | 1 | auto priv = get_handle(wlResource)->d_ptr; | |
114 | 1 | priv->pendingOffset = offset; | |
115 | 1 | } | |
116 | |||
117 | 2 | Slide::Slide(Client* client, uint32_t version, uint32_t id) | |
118 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | : d_ptr(new Private(client, version, id, this)) |
119 | 2 | { | |
120 | 2 | } | |
121 | |||
122 | 1 | Slide::Location Slide::location() const | |
123 | { | ||
124 | 1 | return d_ptr->currentLocation; | |
125 | } | ||
126 | |||
127 | 1 | uint32_t Slide::offset() const | |
128 | { | ||
129 | 1 | return d_ptr->currentOffset; | |
130 | } | ||
131 | |||
132 | } | ||
133 |