From 359eec5a509f8281d9e6c08e48bbeab69f1b45e0 Mon Sep 17 00:00:00 2001 From: Andrey Butirsky Date: Tue, 17 Nov 2020 16:00:26 +0300 Subject: [PATCH] fix: Keyboard Layout plugin: wrong property for passing Short Name KWin Wayland initially misused the DBus API and passed Long layout Name via currentLayoutDisplayName() method which is wrong. Instead, the new currentLayoutLongName() property should be added, and Short Name be passed via currentLayoutDisplayName() as it is for X11. --- components/keyboardlayout/keyboardlayout.cpp | 55 ++++++++++++------- components/keyboardlayout/keyboardlayout.h | 36 +++--------- .../org.kde.KeyboardLayouts.xml | 2 +- 3 files changed, 42 insertions(+), 51 deletions(-) diff --git a/components/keyboardlayout/keyboardlayout.cpp b/components/keyboardlayout/keyboardlayout.cpp index d185a3766..c0d029781 100644 --- a/components/keyboardlayout/keyboardlayout.cpp +++ b/components/keyboardlayout/keyboardlayout.cpp @@ -19,8 +19,8 @@ void KeyboardLayout::requestDBusData() { if (mIface) requestDBusData(mIface->getLayoutDisplayName(mCurrentLayout), mCurrentLayoutDisplayName, &KeyboardLayout::currentLayoutDisplayNameChanged); } template<> -void KeyboardLayout::requestDBusData() -{ if (mIface) requestDBusData(mIface->getCurrentLayoutShortName(), mCurrentLayoutShortName, &KeyboardLayout::currentLayoutShortNameChanged); } +void KeyboardLayout::requestDBusData() +{ if (mIface) requestDBusData(mIface->getCurrentLayoutLongName(), mCurrentLayoutLongName, &KeyboardLayout::currentLayoutLongNameChanged); } template<> void KeyboardLayout::requestDBusData() @@ -42,37 +42,50 @@ KeyboardLayout::KeyboardLayout(QObject* parent) } connect(mIface, &OrgKdeKeyboardLayoutsInterface::currentLayoutChanged, - this, &KeyboardLayout::onCurrentLayoutChanged); + this, [this](const QString &newLayout) + { + mCurrentLayout = newLayout; + + requestDBusData(); + requestDBusData(); + }); connect(mIface, &OrgKdeKeyboardLayoutsInterface::layoutListChanged, - this, &KeyboardLayout::onLayoutListChanged); + this, [this]() + { + requestDBusData(); + requestDBusData(); + requestDBusData(); + }); connect(this, &KeyboardLayout::currentLayoutChanged, this, &KeyboardLayout::requestDBusData); - requestDBusData(); - requestDBusData(); - requestDBusData(); + emit mIface->OrgKdeKeyboardLayoutsInterface::layoutListChanged(); } KeyboardLayout::~KeyboardLayout() { } -void KeyboardLayout::onCurrentLayoutChanged(const QString &newLayout) -{ - mCurrentLayout = newLayout; - - requestDBusData(); - requestDBusData(); -} - -void KeyboardLayout::onLayoutListChanged() +void KeyboardLayout::setCurrentLayout(const QString &layout) { - requestDBusData(); - requestDBusData(); - requestDBusData(); + if (mIface) mIface->setLayout(layout); } -void KeyboardLayout::setCurrentLayout(const QString &layout) +template +void KeyboardLayout::requestDBusData(QDBusPendingReply pendingReply, T &out, void (KeyboardLayout::*notify)()) { - if (mIface) mIface->setLayout(layout); + const QDBusPendingCallWatcher * const watcher = new QDBusPendingCallWatcher(pendingReply, this); + connect(watcher, &QDBusPendingCallWatcher::finished, this, + [this, &out, notify](QDBusPendingCallWatcher *watcher) + { + QDBusPendingReply reply = *watcher; + if (reply.isError()) { + qCWarning(KEYBOARD_LAYOUT) << reply.error().message(); + } else { + out = reply.value(); + emit (this->*notify)(); + } + watcher->deleteLater(); + } + ); } diff --git a/components/keyboardlayout/keyboardlayout.h b/components/keyboardlayout/keyboardlayout.h index 61220ee46..0f57fac6a 100644 --- a/components/keyboardlayout/keyboardlayout.h +++ b/components/keyboardlayout/keyboardlayout.h @@ -27,9 +27,9 @@ class KeyboardLayout : public QObject MEMBER mCurrentLayoutDisplayName NOTIFY currentLayoutDisplayNameChanged) - Q_PROPERTY(QString currentLayoutShortName - MEMBER mCurrentLayoutShortName - NOTIFY currentLayoutShortNameChanged) + Q_PROPERTY(QString currentLayoutLongName + MEMBER mCurrentLayoutLongName + NOTIFY currentLayoutLongNameChanged) Q_PROPERTY(QStringList layouts MEMBER mLayouts @@ -42,46 +42,24 @@ public: Q_SIGNALS: void currentLayoutChanged(); void currentLayoutDisplayNameChanged(); - void currentLayoutShortNameChanged(); + void currentLayoutLongNameChanged(); void layoutsChanged(); private: void setCurrentLayout(const QString &layout); - enum DBusData {CurrentLayout, CurrentLayoutDisplayName, CurrentLayoutShortName, Layouts}; + enum DBusData {CurrentLayout, CurrentLayoutDisplayName, CurrentLayoutLongName, Layouts}; template void requestDBusData(QDBusPendingReply pendingReply, T &out, void (KeyboardLayout::*notify)()); template inline void requestDBusData(); - void onCurrentLayoutChanged(const QString &newLayout); - void onLayoutListChanged(); - - QStringList mLayouts; QString mCurrentLayout; QString mCurrentLayoutDisplayName; - QString mCurrentLayoutShortName; + QString mCurrentLayoutLongName; + QStringList mLayouts; OrgKdeKeyboardLayoutsInterface *mIface; }; -template -void KeyboardLayout::requestDBusData(QDBusPendingReply pendingReply, T &out, void (KeyboardLayout::*notify)()) -{ - const QDBusPendingCallWatcher * const watcher = new QDBusPendingCallWatcher(pendingReply, this); - connect(watcher, &QDBusPendingCallWatcher::finished, this, - [this, &out, notify](QDBusPendingCallWatcher *watcher) - { - QDBusPendingReply reply = *watcher; - if (reply.isError()) { - qCWarning(KEYBOARD_LAYOUT) << reply.error().message(); - } else { - out = reply.value(); - emit (this->*notify)(); - } - watcher->deleteLater(); - } - ); -} - #endif // KEYBOARDLAYOUT_H diff --git a/components/keyboardlayout/org.kde.KeyboardLayouts.xml b/components/keyboardlayout/org.kde.KeyboardLayouts.xml index ed47b66f8..70efe418a 100644 --- a/components/keyboardlayout/org.kde.KeyboardLayouts.xml +++ b/components/keyboardlayout/org.kde.KeyboardLayouts.xml @@ -14,7 +14,7 @@ - +