8 #include "virtualkeyboardwatcher.h"
10 #ifdef KIRIGAMI_ENABLE_DBUS
11 #include "virtualkeyboard_interface.h"
12 #include <QDBusConnection>
13 #include <QDBusPendingCallWatcher>
16 #include "loggingcategory.h"
22 class Q_DECL_HIDDEN VirtualKeyboardWatcher::Private
25 Private(VirtualKeyboardWatcher *qq)
30 VirtualKeyboardWatcher *q;
32 #ifdef KIRIGAMI_ENABLE_DBUS
33 void getAllProperties();
35 void updateWillShowOnActive();
37 OrgKdeKwinVirtualKeyboardInterface *keyboardInterface =
nullptr;
38 OrgFreedesktopDBusPropertiesInterface *propertiesInterface =
nullptr;
43 bool available =
false;
47 bool willShowOnActive =
false;
49 static const QString serviceName;
50 static const QString objectName;
51 static const QString interfaceName;
54 const QString VirtualKeyboardWatcher::Private::serviceName = QStringLiteral(
"org.kde.KWin");
55 const QString VirtualKeyboardWatcher::Private::objectName = QStringLiteral(
"/VirtualKeyboard");
56 const QString VirtualKeyboardWatcher::Private::interfaceName = QStringLiteral(
"org.kde.kwin.VirtualKeyboard");
58 VirtualKeyboardWatcher::VirtualKeyboardWatcher(
QObject *parent)
60 , d(
std::make_unique<Private>(this))
62 #ifdef KIRIGAMI_ENABLE_DBUS
63 d->keyboardInterface =
new OrgKdeKwinVirtualKeyboardInterface(Private::serviceName, Private::objectName,
QDBusConnection::sessionBus(),
this);
64 d->propertiesInterface =
new OrgFreedesktopDBusPropertiesInterface(Private::serviceName, Private::objectName,
QDBusConnection::sessionBus(),
this);
66 connect(d->keyboardInterface, &OrgKdeKwinVirtualKeyboardInterface::availableChanged,
this, [
this]() {
67 d->getProperty(QStringLiteral(
"available"));
69 connect(d->keyboardInterface, &OrgKdeKwinVirtualKeyboardInterface::enabledChanged,
this, [
this]() {
70 d->getProperty(QStringLiteral(
"enabled"));
72 connect(d->keyboardInterface, &OrgKdeKwinVirtualKeyboardInterface::activeChanged,
this, [
this]() {
73 d->getProperty(QStringLiteral(
"active"));
75 connect(d->keyboardInterface, &OrgKdeKwinVirtualKeyboardInterface::visibleChanged,
this, [
this]() {
76 d->getProperty(QStringLiteral(
"visible"));
79 d->getAllProperties();
83 VirtualKeyboardWatcher::~VirtualKeyboardWatcher() =
default;
85 bool VirtualKeyboardWatcher::available()
const
90 bool VirtualKeyboardWatcher::enabled()
const
95 void VirtualKeyboardWatcher::setEnabled(
bool newEnabled)
97 if (newEnabled == d->enabled) {
101 d->enabled = newEnabled;
103 #ifdef KIRIGAMI_ENABLE_DBUS
104 d->propertiesInterface->Set(Private::interfaceName, QStringLiteral(
"enabled"),
QDBusVariant(newEnabled));
106 Q_EMIT enabledChanged();
110 bool VirtualKeyboardWatcher::active()
const
115 void VirtualKeyboardWatcher::setActive(
bool newActive)
117 if (newActive == d->active) {
121 d->active = newActive;
123 #ifdef KIRIGAMI_ENABLE_DBUS
124 d->propertiesInterface->Set(Private::interfaceName, QStringLiteral(
"active"),
QDBusVariant(newActive));
126 Q_EMIT activeChanged();
130 bool VirtualKeyboardWatcher::visible()
const
135 bool VirtualKeyboardWatcher::willShowOnActive()
const
137 #ifdef KIRIGAMI_ENABLE_DBUS
138 d->updateWillShowOnActive();
140 return d->willShowOnActive;
143 VirtualKeyboardWatcher *VirtualKeyboardWatcher::self()
145 return virtualKeyboardWatcherSelf();
148 #ifdef KIRIGAMI_ENABLE_DBUS
150 void VirtualKeyboardWatcher::Private::updateWillShowOnActive()
152 if (willShowOnActiveCall) {
160 qCDebug(KirigamiLog) << reply.error().message();
162 if (reply.value() != willShowOnActive) {
163 willShowOnActive = reply.value();
164 Q_EMIT q->willShowOnActiveChanged();
168 willShowOnActiveCall =
nullptr;
172 void VirtualKeyboardWatcher::Private::getAllProperties()
178 qCDebug(KirigamiLog) << reply.error().message();
180 auto value = reply.value();
181 available = value.value(QStringLiteral(
"available")).toBool();
182 enabled = value.value(QStringLiteral(
"enabled")).toBool();
183 active = value.value(QStringLiteral(
"active")).toBool();
184 visible = value.value(QStringLiteral(
"visible")).toBool();
188 Q_EMIT q->availableChanged();
189 Q_EMIT q->enabledChanged();
190 Q_EMIT q->activeChanged();
191 Q_EMIT q->visibleChanged();
195 void VirtualKeyboardWatcher::Private::getProperty(
const QString &propertyName)
201 qCDebug(KirigamiLog) << reply.error().message();
203 auto value = reply.value();
204 if (propertyName == QStringLiteral(
"available")) {
205 available = value.variant().toBool();
206 Q_EMIT q->availableChanged();
207 }
else if (propertyName == QStringLiteral(
"enabled")) {
208 enabled = value.variant().toBool();
209 Q_EMIT q->enabledChanged();
210 }
else if (propertyName == QStringLiteral(
"active")) {
211 active = value.variant().toBool();
212 Q_EMIT q->activeChanged();
213 }
else if (propertyName == QStringLiteral(
"visible")) {
214 visible = value.variant().toBool();
215 Q_EMIT q->visibleChanged();
225 #include "moc_virtualkeyboardwatcher.cpp"