Commit c4252569 authored by Andrey Butirsky's avatar Andrey Butirsky Committed by David Edmundson

Remove a basic SNI for keyboard layout

Reverts major part of fe561c5c

We now have platform-agnostic QML applet with superior functional, so
this one doesn't needed any more.

CCBUG: 390079
parent c81fe56d
......@@ -12,17 +12,14 @@
#include "input_event.h"
#include "main.h"
#include "platform.h"
#include "utils.h"
#include <KConfigGroup>
#include <KGlobalAccel>
#include <KLocalizedString>
#include <KNotifications/KStatusNotifierItem>
#include <QAction>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCall>
#include <QMenu>
namespace KWin
{
......@@ -30,7 +27,6 @@ namespace KWin
KeyboardLayout::KeyboardLayout(Xkb *xkb)
: QObject()
, m_xkb(xkb)
, m_notifierItem(nullptr)
{
}
......@@ -84,52 +80,6 @@ void KeyboardLayout::initDBusInterface()
connect(this, &KeyboardLayout::layoutsReconfigured, m_dbusInterface, &KeyboardLayoutDBusInterface::layoutListChanged);
}
void KeyboardLayout::initNotifierItem()
{
bool showNotifier = true;
bool showSingle = false;
if (m_config) {
const auto config = m_config->group(QStringLiteral("Layout"));
showNotifier = config.readEntry("ShowLayoutIndicator", true);
showSingle = config.readEntry("ShowSingle", false);
}
const bool shouldShow = showNotifier && (showSingle || m_xkb->numberOfLayouts() > 1);
if (shouldShow) {
if (m_notifierItem) {
return;
}
} else {
delete m_notifierItem;
m_notifierItem = nullptr;
return;
}
m_notifierItem = new KStatusNotifierItem(this);
m_notifierItem->setCategory(KStatusNotifierItem::Hardware);
m_notifierItem->setStatus(KStatusNotifierItem::Passive);
m_notifierItem->setToolTipTitle(i18nc("tooltip title", "Keyboard Layout"));
m_notifierItem->setTitle(i18nc("tooltip title", "Keyboard Layout"));
m_notifierItem->setToolTipIconByName(QStringLiteral("input-keyboard"));
m_notifierItem->setStandardActionsEnabled(false);
// TODO: proper icon
m_notifierItem->setIconByName(QStringLiteral("input-keyboard"));
connect(m_notifierItem, &KStatusNotifierItem::activateRequested, this, &KeyboardLayout::switchToNextLayout);
connect(m_notifierItem, &KStatusNotifierItem::scrollRequested, this,
[this] (int delta, Qt::Orientation orientation) {
if (orientation == Qt::Horizontal) {
return;
}
if (delta > 0) {
switchToNextLayout();
} else {
switchToPreviousLayout();
}
}
);
}
void KeyboardLayout::switchToNextLayout()
{
const quint32 previousLayout = m_xkb->currentLayout();
......@@ -171,9 +121,6 @@ void KeyboardLayout::reconfigure()
void KeyboardLayout::resetLayout()
{
m_layout = m_xkb->currentLayout();
initNotifierItem();
updateNotifier();
reinitNotifierMenu();
loadShortcuts();
initDBusInterface();
......@@ -213,7 +160,6 @@ void KeyboardLayout::checkLayoutChange(quint32 previousLayout)
if (m_layout != layout || previousLayout != layout) {
m_layout = layout;
notifyLayoutChange();
updateNotifier();
emit layoutChanged();
}
}
......@@ -232,48 +178,6 @@ void KeyboardLayout::notifyLayoutChange()
QDBusConnection::sessionBus().asyncCall(msg);
}
void KeyboardLayout::updateNotifier()
{
if (!m_notifierItem) {
return;
}
m_notifierItem->setToolTipSubTitle(translatedLayout(m_xkb->layoutName()));
// TODO: update icon
}
void KeyboardLayout::reinitNotifierMenu()
{
if (!m_notifierItem) {
return;
}
const auto layouts = m_xkb->layoutNames();
QMenu *menu = new QMenu;
for (auto it = layouts.begin(); it != layouts.end(); it++) {
menu->addAction(translatedLayout(it.value()), std::bind(&KeyboardLayout::switchToLayout, this, it.key()));
}
menu->addSeparator();
menu->addAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure Layouts..."), this,
[this] {
// TODO: introduce helper function to start kcmshell5
QProcess *p = new Process(this);
p->setArguments(QStringList{QStringLiteral("--args=--tab=layouts"), QStringLiteral("kcm_keyboard")});
p->setProcessEnvironment(kwinApp()->processStartupEnvironment());
p->setProgram(QStringLiteral("kcmshell5"));
connect(p, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), p, &QProcess::deleteLater);
connect(p, &QProcess::errorOccurred, this, [](QProcess::ProcessError e) {
if (e == QProcess::FailedToStart) {
qCDebug(KWIN_CORE) << "Failed to start kcmshell5";
}
});
p->start();
}
);
m_notifierItem->setContextMenu(menu);
}
static const QString s_keyboardService = QStringLiteral("org.kde.keyboard");
static const QString s_keyboardObject = QStringLiteral("/Layouts");
......
......@@ -16,7 +16,6 @@
#include <KSharedConfig>
typedef uint32_t xkb_layout_index_t;
class KStatusNotifierItem;
class QAction;
namespace KWin
......@@ -46,7 +45,6 @@ public:
void switchToNextLayout();
void switchToPreviousLayout();
void resetLayout();
void updateNotifier();
Q_SIGNALS:
void layoutChanged();
......@@ -58,13 +56,10 @@ private Q_SLOTS:
private:
void initDBusInterface();
void notifyLayoutChange();
void initNotifierItem();
void switchToLayout(xkb_layout_index_t index);
void reinitNotifierMenu();
void loadShortcuts();
Xkb *m_xkb;
xkb_layout_index_t m_layout = 0;
KStatusNotifierItem *m_notifierItem;
KSharedConfigPtr m_config;
QVector<QAction*> m_layoutShortcuts;
KeyboardLayoutDBusInterface *m_dbusInterface = nullptr;
......
......@@ -37,7 +37,6 @@ void Policy::setLayout(quint32 layout)
const quint32 previousLayout = m_xkb->currentLayout();
m_xkb->switchToLayout(layout);
if (previousLayout != m_xkb->currentLayout()) {
m_layout->updateNotifier();
emit m_layout->layoutChanged();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment