From 769c8959d87792f85a7fb5f03106c720681aec4d Mon Sep 17 00:00:00 2001 From: Andrey Butirsky Date: Mon, 24 Aug 2020 16:51:43 +0300 Subject: [PATCH] fix: no OSD indication when switching keyboard layout with Application Policy When deciding do OSD or not, we need to consider not only last saved layout, but last actual layout also, when comparing it to current one. DIGEST: BUG: 425590 --- keyboard_input.cpp | 5 ++++- keyboard_layout.cpp | 36 ++++++++++++++++++------------------ keyboard_layout.h | 4 +--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/keyboard_input.cpp b/keyboard_input.cpp index 10f472911..e03026b7d 100644 --- a/keyboard_input.cpp +++ b/keyboard_input.cpp @@ -198,7 +198,9 @@ void KeyboardInputRedirection::processKey(uint32_t key, InputRedirection::Keyboa } if (!autoRepeat) { + const quint32 previousLayout = m_xkb->currentLayout(); m_xkb->updateKey(key, state); + m_keyboardLayout->checkLayoutChange(previousLayout); } const xkb_keysym_t keySym = m_xkb->currentKeysym(); @@ -227,10 +229,11 @@ void KeyboardInputRedirection::processModifiers(uint32_t modsDepressed, uint32_t if (!m_inited) { return; } + const quint32 previousLayout = m_xkb->currentLayout(); // TODO: send to proper Client and also send when active Client changes m_xkb->updateModifiers(modsDepressed, modsLatched, modsLocked, group); m_modifiersChangedSpy->updateModifiers(modifiers()); - m_keyboardLayout->checkLayoutChange(); + m_keyboardLayout->checkLayoutChange(previousLayout); } void KeyboardInputRedirection::processKeymapChange(int fd, uint32_t size) diff --git a/keyboard_layout.cpp b/keyboard_layout.cpp index 530c18b43..023f4c42e 100644 --- a/keyboard_layout.cpp +++ b/keyboard_layout.cpp @@ -132,20 +132,23 @@ void KeyboardLayout::initNotifierItem() void KeyboardLayout::switchToNextLayout() { + const quint32 previousLayout = m_xkb->currentLayout(); m_xkb->switchToNextLayout(); - checkLayoutChange(); + checkLayoutChange(previousLayout); } void KeyboardLayout::switchToPreviousLayout() { + const quint32 previousLayout = m_xkb->currentLayout(); m_xkb->switchToPreviousLayout(); - checkLayoutChange(); + checkLayoutChange(previousLayout); } void KeyboardLayout::switchToLayout(xkb_layout_index_t index) { + const quint32 previousLayout = m_xkb->currentLayout(); m_xkb->switchToLayout(index); - checkLayoutChange(); + checkLayoutChange(previousLayout); } void KeyboardLayout::reconfigure() @@ -200,23 +203,19 @@ void KeyboardLayout::loadShortcuts() } } -void KeyboardLayout::keyEvent(KeyEvent *event) -{ - if (!event->isAutoRepeat()) { - checkLayoutChange(); - } -} - -void KeyboardLayout::checkLayoutChange() +void KeyboardLayout::checkLayoutChange(quint32 previousLayout) { + // Get here on key event or DBus call. + // m_layout - layout saved last time OSD occurred + // previousLayout - actual layout just before potential layout change + // We need OSD if current layout deviates from any of these const auto layout = m_xkb->currentLayout(); - if (m_layout == layout) { - return; + if (m_layout != layout || previousLayout != layout) { + m_layout = layout; + notifyLayoutChange(); + updateNotifier(); + emit layoutChanged(); } - m_layout = layout; - notifyLayoutChange(); - updateNotifier(); - emit layoutChanged(); } void KeyboardLayout::notifyLayoutChange() @@ -304,8 +303,9 @@ bool KeyboardLayoutDBusInterface::setLayout(const QString &layout) if (it == layouts.end()) { return false; } + const quint32 previousLayout = m_xkb->currentLayout(); m_xkb->switchToLayout(it.key()); - m_keyboardLayout->checkLayoutChange(); + m_keyboardLayout->checkLayoutChange(previousLayout); return true; } diff --git a/keyboard_layout.h b/keyboard_layout.h index f44cc92e0..2b4729578 100644 --- a/keyboard_layout.h +++ b/keyboard_layout.h @@ -42,12 +42,10 @@ public: void init(); - void checkLayoutChange(); + void checkLayoutChange(quint32 previousLayout); void resetLayout(); void updateNotifier(); - void keyEvent(KeyEvent *event) override; - Q_SIGNALS: void layoutChanged(); void layoutsReconfigured();