Follow Plasma's virtual keyboard setting

KWin activates the input method for every text field; its policy (the
tray toggle) only gates the input panel, which sloposk doesn't use. sloposk
now asks KWin over D-Bus whether a focused field should show the
keyboard: never when off, only after touch or a pen by default.
"Always Show" and D-Bus Show/Toggle still show it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 17:31:13 +01:00
co-authored by Claude Opus 5.5
parent 499e5ee76e
commit b745e9da1b
8 changed files with 105 additions and 4 deletions
+30
View File
@@ -0,0 +1,30 @@
#include "KWinVirtualKeyboard.h"
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
namespace {
const QString Service = QStringLiteral("org.kde.KWin");
const QString Path = QStringLiteral("/VirtualKeyboard");
const QString Interface = QStringLiteral("org.kde.kwin.VirtualKeyboard");
} // namespace
KWinVirtualKeyboard::KWinVirtualKeyboard(QObject *parent)
: QObject(parent)
{
QDBusConnection::sessionBus().connect(Service, Path, Interface, QStringLiteral("modeChanged"), this,
SIGNAL(modeChanged()));
}
void KWinVirtualKeyboard::askShowOnActive(QObject *context, std::function<void(bool)> answer)
{
const QDBusMessage call = QDBusMessage::createMethodCall(Service, Path, Interface, QStringLiteral("willShowOnActive"));
auto *watcher = new QDBusPendingCallWatcher(QDBusConnection::sessionBus().asyncCall(call), context);
connect(watcher, &QDBusPendingCallWatcher::finished, context, [answer = std::move(answer)](QDBusPendingCallWatcher *watcher) {
watcher->deleteLater();
const QDBusPendingReply<bool> reply = *watcher;
answer(reply.isError() || reply.value());
});
}
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include <QObject>
#include <functional>
// KWin's virtual keyboard policy (the tray toggle, System Settings →
// Virtual Keyboard): KWin activates the input method for every text field
// and the policy only gates its input panel, which sloposk doesn't use, so
// sloposk asks it over org.kde.KWin /VirtualKeyboard instead.
class KWinVirtualKeyboard : public QObject
{
Q_OBJECT
public:
explicit KWinVirtualKeyboard(QObject *parent = nullptr);
// Calls `answer` with whether a field focused now should show the
// keyboard: never when it's off, only after touch or a pen in the
// default mode. True if KWin can't be asked.
void askShowOnActive(QObject *context, std::function<void(bool)> answer);
Q_SIGNALS:
void modeChanged();
};