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:
@@ -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());
|
||||
});
|
||||
}
|
||||
@@ -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();
|
||||
};
|
||||
Reference in New Issue
Block a user