GCC Code Coverage Report


Directory: ./
File: server/kde_idle.cpp
Date: 2024-01-22 17:25:27
Exec Total Coverage
Lines: 47 50 94.0%
Branches: 7 16 43.8%

Line Branch Exec Source
1 /*
2 SPDX-FileCopyrightText: 2020 Faveraux Adrien <ad1rie3@hotmail.fr>
3 SPDX-FileCopyrightText: 2022 Roman Gilg <subdiff@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only
6 */
7 #include "display.h"
8 #include "kde_idle_p.h"
9 #include "seat_p.h"
10
11 namespace Wrapland::Server
12 {
13
14 const struct org_kde_kwin_idle_interface kde_idle::Private::s_interface = {
15 cb<get_idle_timeout_callback>,
16 };
17
18 2 kde_idle::Private::Private(Display* display, kde_idle* q_ptr)
19 2 : kde_idle_global(q_ptr, display, &org_kde_kwin_idle_interface, &s_interface)
20 2 {
21
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 create();
22 2 }
23
24 2 void kde_idle::Private::get_idle_timeout_callback(kde_idle_bind* bind,
25 uint32_t id,
26 wl_resource* wlSeat,
27 uint32_t timeout)
28 {
29 2 auto priv = bind->global()->handle->d_ptr.get();
30 2 auto seat = SeatGlobal::get_handle(wlSeat);
31
32 2 auto duration = std::max(std::chrono::milliseconds(timeout), std::chrono::milliseconds::zero());
33
34 2 auto idle_timeout
35
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 = new kde_idle_timeout(bind->client->handle, bind->version, id, duration, seat);
36
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!idle_timeout->d_ptr->resource) {
37 bind->post_no_memory();
38 delete idle_timeout;
39 return;
40 }
41
42 2 Q_EMIT priv->handle->timeout_created(idle_timeout);
43 2 }
44
45 2 kde_idle::kde_idle(Display* display)
46
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(display, this))
47 2 {
48 2 }
49
50 4 kde_idle::~kde_idle() = default;
51
52 const struct org_kde_kwin_idle_timeout_interface kde_idle_timeout::Private::s_interface = {
53 destroyCallback,
54 simulate_user_activity_callback,
55 };
56
57 2 kde_idle_timeout::Private::Private(Client* client,
58 uint32_t version,
59 uint32_t id,
60 std::chrono::milliseconds duration,
61 Seat* seat,
62 kde_idle_timeout* q_ptr)
63 4 : Wayland::Resource<kde_idle_timeout>(client,
64 2 version,
65 2 id,
66 &org_kde_kwin_idle_timeout_interface,
67 &s_interface,
68 2 q_ptr)
69 2 , duration{duration}
70 2 , seat{seat}
71 2 {
72 2 }
73
74 4 kde_idle_timeout::Private::~Private() = default;
75
76 1 void kde_idle_timeout::Private::simulate_user_activity_callback(wl_client* /*wlClient*/,
77 wl_resource* wlResource)
78 {
79 1 Q_EMIT get_handle(wlResource)->simulate_user_activity();
80 1 }
81
82 2 kde_idle_timeout::kde_idle_timeout(Client* client,
83 uint32_t version,
84 uint32_t id,
85 std::chrono::milliseconds duration,
86 Seat* seat)
87
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, duration, seat, this))
88 2 {
89 2 }
90
91 4 kde_idle_timeout::~kde_idle_timeout() = default;
92
93 1 std::chrono::milliseconds kde_idle_timeout::duration() const
94 {
95 1 return d_ptr->duration;
96 }
97
98 1 Seat* kde_idle_timeout::seat() const
99 {
100 1 return d_ptr->seat;
101 }
102
103 1 void kde_idle_timeout::idle()
104 {
105 1 d_ptr->send<org_kde_kwin_idle_timeout_send_idle>();
106 1 }
107
108 1 void kde_idle_timeout::resume()
109 {
110 1 d_ptr->send<org_kde_kwin_idle_timeout_send_resumed>();
111 1 }
112
113 }
114