From bc7f33db57c4eeb205e2eda5382c551aefd789a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 19 Feb 2016 14:31:53 +0100 Subject: [PATCH] Notify org.kde.osdService about keyboard layout changes KWin starts to track which is the current layout and in case it changes notifies the org.kde.osdService about the change through DBus. KWin has a better knowledge about changes than the KeyboardDaemon could have, so it's better to do in KWin. E.g. KWin can also notice changes not triggered by the global shortcut, but by the keymap itself. --- keyboard_input.cpp | 17 ++++++++++++++++- keyboard_input.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/keyboard_input.cpp b/keyboard_input.cpp index 3c96d09c9d..c1747f6860 100644 --- a/keyboard_input.cpp +++ b/keyboard_input.cpp @@ -179,6 +179,7 @@ void Xkb::updateKeymap(xkb_keymap *keymap) m_controlModifier = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_CTRL); m_altModifier = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_ALT); m_metaModifier = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_LOGO); + m_currentLayout = xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE); createKeymapFile(); } @@ -280,10 +281,24 @@ void Xkb::updateModifiers() mods |= Qt::MetaModifier; } m_modifiers = mods; + const xkb_layout_index_t layout = xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE); + if (layout != m_currentLayout) { + m_currentLayout = layout; + // notify OSD service about the new layout + QDBusMessage msg = QDBusMessage::createMethodCall( + QStringLiteral("org.kde.plasmashell"), + QStringLiteral("/org/kde/osdService"), + QStringLiteral("org.kde.osdService"), + QStringLiteral("kbdLayoutChanged")); + + msg << QString::fromLocal8Bit(xkb_keymap_layout_get_name(m_keymap, layout)); + + QDBusConnection::sessionBus().asyncCall(msg); + } waylandServer()->seat()->updateKeyboardModifiers(xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_DEPRESSED)), xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LATCHED)), xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LOCKED)), - xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE)); + layout); } xkb_keysym_t Xkb::toKeysym(uint32_t key) diff --git a/keyboard_input.h b/keyboard_input.h index 3835d212a4..85a5ce3e6d 100644 --- a/keyboard_input.h +++ b/keyboard_input.h @@ -79,6 +79,7 @@ private: uint pressCount = 0; Qt::KeyboardModifier modifier = Qt::NoModifier; } m_modOnlyShortcut; + quint32 m_currentLayout = 0; }; class KeyboardInputRedirection : public QObject