From 0169bca6e003dbd353d2d9ea26ee9f6f24c745bf Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Mon, 19 Jul 2021 18:23:34 +0200 Subject: [PATCH] inputmethod sni: return early for readability --- src/inputmethod.cpp | 69 ++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/src/inputmethod.cpp b/src/inputmethod.cpp index 7ee5f84176..746328d19c 100644 --- a/src/inputmethod.cpp +++ b/src/inputmethod.cpp @@ -501,42 +501,41 @@ void InputMethod::adoptInputMethodContext() void InputMethod::updateSni() { - if (!m_inputMethodCommand.isEmpty()) { - if (!m_sni) { - qCDebug(KWIN_VIRTUALKEYBOARD) << "Registering the SNI"; - m_sni.reset(new KStatusNotifierItem(QStringLiteral("kwin-virtual-keyboard"), this)); - - connect(m_sni.get(), &KStatusNotifierItem::activateRequested, this, - [this] { - setEnabled(!m_enabled); - } - ); - } - 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); - - QMenu *sniMenu = new QMenu; - sniMenu->addAction(i18n("Configure virtual keyboards..."), this, [] { - QProcess::startDetached("systemsettings5", {"kcm_virtualkeyboard"}); - }); - - m_sni->setContextMenu(sniMenu); - - 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({}); - } - } else { + if (m_inputMethodCommand.isEmpty()) { m_sni.reset(); + return; + } + if (!m_sni) { + qCDebug(KWIN_VIRTUALKEYBOARD) << "Registering the SNI"; + m_sni.reset(new KStatusNotifierItem(QStringLiteral("kwin-virtual-keyboard"), this)); + + connect(m_sni.get(), &KStatusNotifierItem::activateRequested, this, + [this] { + setEnabled(!m_enabled); + } + ); + } + 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.")); + + QMenu *sniMenu = new QMenu; + sniMenu->addAction(i18n("Configure virtual keyboards..."), this, [] { + QProcess::startDetached("systemsettings5", {"kcm_virtualkeyboard"}); + }); + + m_sni->setContextMenu(sniMenu); + + 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({}); } }