Directory: | ./ |
---|---|
File: | src/client/keyboard_shortcuts_inhibit.cpp |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 70 | 84 | 83.3% |
Branches: | 12 | 24 | 50.0% |
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 "keyboard_shortcuts_inhibit_p.h" | ||
21 | |||
22 | namespace Wrapland::Client | ||
23 | { | ||
24 | |||
25 | 1 | KeyboardShortcutsInhibitManagerV1::KeyboardShortcutsInhibitManagerV1(QObject* parent) | |
26 | 1 | : QObject(parent) | |
27 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | , d_ptr(new Private) |
28 | 1 | { | |
29 | 1 | } | |
30 | |||
31 | 1 | void KeyboardShortcutsInhibitManagerV1::Private::setup( | |
32 | zwp_keyboard_shortcuts_inhibit_manager_v1* arg) | ||
33 | { | ||
34 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | Q_ASSERT(arg); |
35 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | Q_ASSERT(!idleinhibitmanager); |
36 | 1 | idleinhibitmanager.setup(arg); | |
37 | 1 | } | |
38 | |||
39 | 2 | KeyboardShortcutsInhibitManagerV1::~KeyboardShortcutsInhibitManagerV1() | |
40 | 2 | { | |
41 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | release(); |
42 | 2 | } | |
43 | |||
44 | 1 | void KeyboardShortcutsInhibitManagerV1::setup( | |
45 | zwp_keyboard_shortcuts_inhibit_manager_v1* idleinhibitmanager) | ||
46 | { | ||
47 | 1 | d_ptr->setup(idleinhibitmanager); | |
48 | 1 | } | |
49 | |||
50 | 1 | void KeyboardShortcutsInhibitManagerV1::release() | |
51 | { | ||
52 | 1 | d_ptr->idleinhibitmanager.release(); | |
53 | 1 | } | |
54 | |||
55 | ✗ | KeyboardShortcutsInhibitManagerV1::operator zwp_keyboard_shortcuts_inhibit_manager_v1*() | |
56 | { | ||
57 | ✗ | return d_ptr->idleinhibitmanager; | |
58 | } | ||
59 | |||
60 | ✗ | KeyboardShortcutsInhibitManagerV1::operator zwp_keyboard_shortcuts_inhibit_manager_v1*() const | |
61 | { | ||
62 | ✗ | return d_ptr->idleinhibitmanager; | |
63 | } | ||
64 | |||
65 | 5 | bool KeyboardShortcutsInhibitManagerV1::isValid() const | |
66 | { | ||
67 | 5 | return d_ptr->idleinhibitmanager.isValid(); | |
68 | } | ||
69 | |||
70 | 1 | void KeyboardShortcutsInhibitManagerV1::setEventQueue(EventQueue* queue) | |
71 | { | ||
72 | 1 | d_ptr->queue = queue; | |
73 | 1 | } | |
74 | |||
75 | ✗ | EventQueue* KeyboardShortcutsInhibitManagerV1::eventQueue() | |
76 | { | ||
77 | ✗ | return d_ptr->queue; | |
78 | } | ||
79 | |||
80 | KeyboardShortcutsInhibitorV1* | ||
81 | 4 | KeyboardShortcutsInhibitManagerV1::inhibitShortcuts(Surface* surface, Seat* seat, QObject* parent) | |
82 | { | ||
83 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | Q_ASSERT(isValid()); |
84 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | auto p = new KeyboardShortcutsInhibitorV1(parent); |
85 | 4 | auto w = zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts( | |
86 | 4 | d_ptr->idleinhibitmanager, *surface, *seat); | |
87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (d_ptr->queue) { |
88 | 4 | d_ptr->queue->addProxy(w); | |
89 | 4 | } | |
90 | 4 | p->setup(w); | |
91 | 4 | Q_EMIT inhibitorCreated(); | |
92 | 4 | return p; | |
93 | } | ||
94 | |||
95 | const zwp_keyboard_shortcuts_inhibitor_v1_listener KeyboardShortcutsInhibitorV1::Private::s_listener | ||
96 | = { | ||
97 | ActiveCallback, | ||
98 | InactiveCallback, | ||
99 | }; | ||
100 | |||
101 | 4 | KeyboardShortcutsInhibitorV1::Private::Private(KeyboardShortcutsInhibitorV1* q) | |
102 | 4 | : q(q) | |
103 | { | ||
104 | 4 | } | |
105 | |||
106 | 4 | void KeyboardShortcutsInhibitorV1::Private::ActiveCallback( | |
107 | void* data, | ||
108 | zwp_keyboard_shortcuts_inhibitor_v1* zwp_keyboard_shortcuts_inhibitor_v1) | ||
109 | { | ||
110 | Q_UNUSED(zwp_keyboard_shortcuts_inhibitor_v1) | ||
111 | 4 | auto priv = reinterpret_cast<Private*>(data); | |
112 | 4 | priv->inhibitor_active = true; | |
113 | 4 | Q_EMIT priv->q->inhibitorActive(); | |
114 | 4 | } | |
115 | |||
116 | 1 | void KeyboardShortcutsInhibitorV1::Private::InactiveCallback( | |
117 | void* data, | ||
118 | zwp_keyboard_shortcuts_inhibitor_v1* zwp_keyboard_shortcuts_inhibitor_v1) | ||
119 | { | ||
120 | Q_UNUSED(zwp_keyboard_shortcuts_inhibitor_v1) | ||
121 | 1 | auto priv = reinterpret_cast<Private*>(data); | |
122 | 1 | priv->inhibitor_active = false; | |
123 | 1 | Q_EMIT priv->q->inhibitorInactive(); | |
124 | 1 | } | |
125 | |||
126 | 4 | KeyboardShortcutsInhibitorV1::KeyboardShortcutsInhibitorV1(QObject* parent) | |
127 | 4 | : QObject(parent) | |
128 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
4 | , d_ptr(new Private(this)) |
129 | 4 | { | |
130 | 4 | } | |
131 | |||
132 | 4 | void KeyboardShortcutsInhibitorV1::Private::setup(zwp_keyboard_shortcuts_inhibitor_v1* arg) | |
133 | { | ||
134 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | Q_ASSERT(arg); |
135 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | Q_ASSERT(!idleinhibitor); |
136 | 4 | idleinhibitor.setup(arg); | |
137 | 4 | zwp_keyboard_shortcuts_inhibitor_v1_add_listener(arg, &s_listener, this); | |
138 | 4 | } | |
139 | |||
140 | 8 | KeyboardShortcutsInhibitorV1::~KeyboardShortcutsInhibitorV1() | |
141 | 8 | { | |
142 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | release(); |
143 | 8 | } | |
144 | |||
145 | ✗ | bool KeyboardShortcutsInhibitorV1::isActive() | |
146 | { | ||
147 | ✗ | return d_ptr->inhibitor_active; | |
148 | } | ||
149 | |||
150 | 4 | void KeyboardShortcutsInhibitorV1::setup(zwp_keyboard_shortcuts_inhibitor_v1* idleinhibitor) | |
151 | { | ||
152 | 4 | d_ptr->setup(idleinhibitor); | |
153 | 4 | } | |
154 | |||
155 | 4 | void KeyboardShortcutsInhibitorV1::release() | |
156 | { | ||
157 | 4 | d_ptr->idleinhibitor.release(); | |
158 | 4 | } | |
159 | |||
160 | ✗ | KeyboardShortcutsInhibitorV1::operator zwp_keyboard_shortcuts_inhibitor_v1*() | |
161 | { | ||
162 | ✗ | return d_ptr->idleinhibitor; | |
163 | } | ||
164 | |||
165 | ✗ | KeyboardShortcutsInhibitorV1::operator zwp_keyboard_shortcuts_inhibitor_v1*() const | |
166 | { | ||
167 | ✗ | return d_ptr->idleinhibitor; | |
168 | } | ||
169 | |||
170 | ✗ | bool KeyboardShortcutsInhibitorV1::isValid() const | |
171 | { | ||
172 | ✗ | return d_ptr->idleinhibitor.isValid(); | |
173 | } | ||
174 | |||
175 | } | ||
176 |