inputmethod: improve the integration of the SNI

* Adds a context menu to choose virtual keyboards.
* Notifies when there is no virtual keyboard selected.
This commit is contained in:
Aleix Pol 2021-04-27 21:18:17 +02:00 committed by Aleix Pol Gonzalez
parent 050ce24247
commit baa246fbb7

View file

@ -32,6 +32,7 @@
#include <QDBusConnection>
#include <QDBusPendingCall>
#include <QDBusMessage>
#include <QMenu>
#include <linux/input-event-codes.h>
#include <xkbcommon/xkbcommon-keysyms.h>
@ -81,11 +82,20 @@ void InputMethod::init()
}
qCDebug(KWIN_VIRTUALKEYBOARD) << "Registering the SNI";
QMenu *sniMenu = new QMenu;
sniMenu->addAction(i18n("Configure virtual keyboards..."), this, [] {
QProcess::startDetached("systemsettings5", {"kcm_virtualkeyboard"});
});
m_sni = new KStatusNotifierItem(QStringLiteral("kwin-virtual-keyboard"), this);
m_sni->setStandardActionsEnabled(false);
m_sni->setCategory(KStatusNotifierItem::Hardware);
m_sni->setStatus(KStatusNotifierItem::Passive);
m_sni->setTitle(i18n("Virtual Keyboard"));
m_sni->setToolTipTitle(i18n("Whether to show the virtual keyboard on demand."));
m_sni->setStandardActionsEnabled(false);
m_sni->setContextMenu(sniMenu);
updateSni();
connect(m_sni, &KStatusNotifierItem::activateRequested, this,
[this] {
@ -508,14 +518,19 @@ void InputMethod::updateSni()
if (!m_sni) {
return;
}
if (m_enabled) {
if (m_inputMethodCommand.isEmpty()) {
m_sni->setIconByName(QStringLiteral("input-keyboard-virtual-on"));
m_sni->setOverlayIconByName(QStringLiteral("emblem-unavailable"));
m_sni->setTitle(i18n("No Virtual Keyboard configured"));
} else if (m_enabled) {
m_sni->setIconByName(QStringLiteral("input-keyboard-virtual-on"));
m_sni->setTitle(i18n("Virtual Keyboard: enabled"));
m_sni->setOverlayIconByName({});
} else {
m_sni->setIconByName(QStringLiteral("input-keyboard-virtual-off"));
m_sni->setTitle(i18n("Virtual Keyboard: disabled"));
m_sni->setOverlayIconByName({});
}
m_sni->setToolTipTitle(i18n("Whether to show the virtual keyboard on demand."));
}
void InputMethod::updateInputPanelState()
@ -547,6 +562,7 @@ void InputMethod::setInputMethodCommand(const QString &command)
if (m_enabled) {
startInputMethod();
}
updateSni();
}
void InputMethod::stopInputMethod()