From 327ccffcf477ded6bcf866c6094c792cfefa5b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 16 Nov 2016 11:18:36 +0100 Subject: [PATCH] Add a keyboard tab to the debug console Summary: A little bit debug information about the current keyboard state is useful. Thus a new tab is added to show information about xkbcommon. It shows: * layouts in the keymap * currently active layout * supported modifiers in key map * currently active modifiers in state * supported leds in key map * currently active leds in state Whenever a key is pressed/released the complete ui is updated to reflect the latest state. That is pressing/releasing a modifier is directly reflected in the ui. This UI can extended as needed for further debug information about the keymap state. Reviewers: #kwin, #plasma_on_wayland Subscribers: plasma-devel, kwin Tags: #plasma_on_wayland, #kwin Differential Revision: https://phabricator.kde.org/D3379 --- debug_console.cpp | 50 +++++++++++++++++ debug_console.h | 1 + debug_console.ui | 137 ++++++++++++++++++++++++++++++++++++++++++++++ keyboard_input.h | 12 ++++ 4 files changed, 200 insertions(+) diff --git a/debug_console.cpp b/debug_console.cpp index f57d3f0c7f..63c17f2526 100644 --- a/debug_console.cpp +++ b/debug_console.cpp @@ -49,6 +49,11 @@ along with this program. If not, see . #include #include +// xkb +#include + +#include + namespace KWin { @@ -503,6 +508,10 @@ DebugConsole::DebugConsole() m_inputFilter.reset(new DebugConsoleFilter(m_ui->inputTextEdit)); input()->prepandInputEventFilter(m_inputFilter.data()); } + if (index == 5) { + updateKeyboardTab(); + connect(input(), &InputRedirection::keyStateChanged, this, &DebugConsole::updateKeyboardTab); + } } ); @@ -556,6 +565,47 @@ void DebugConsole::initGLTab() m_ui->openGLExtensionsLabel->setText(extensionsString(openGLExtensions())); } +template +QString keymapComponentToString(xkb_keymap *map, const T &count, std::function f) +{ + QString text = QStringLiteral("
    "); + for (T i = 0; i < count; i++) { + text.append(QStringLiteral("
  • %1
  • ").arg(QString::fromLocal8Bit(f(map, i)))); + } + text.append(QStringLiteral("
")); + return text; +} + +template +QString stateActiveComponents(xkb_state *state, const T &count, std::function f, std::function name) +{ + QString text = QStringLiteral("
    "); + xkb_keymap *map = xkb_state_get_keymap(state); + for (T i = 0; i < count; i++) { + if (f(state, i) == 1) { + text.append(QStringLiteral("
  • %1
  • ").arg(QString::fromLocal8Bit(name(map, i)))); + } + } + text.append(QStringLiteral("
")); + return text; +} + +void DebugConsole::updateKeyboardTab() +{ + auto xkb = input()->keyboard()->xkb(); + xkb_keymap *map = xkb->keymap(); + xkb_state *state = xkb->state(); + m_ui->layoutsLabel->setText(keymapComponentToString(map, xkb_keymap_num_layouts(map), &xkb_keymap_layout_get_name)); + m_ui->currentLayoutLabel->setText(xkb_keymap_layout_get_name(map, xkb->currentLayout())); + m_ui->modifiersLabel->setText(keymapComponentToString(map, xkb_keymap_num_mods(map), &xkb_keymap_mod_get_name)); + m_ui->ledsLabel->setText(keymapComponentToString(map, xkb_keymap_num_leds(map), &xkb_keymap_led_get_name)); + m_ui->activeLedsLabel->setText(stateActiveComponents(state, xkb_keymap_num_leds(map), &xkb_state_led_index_is_active, &xkb_keymap_led_get_name)); + + using namespace std::placeholders; + auto modActive = std::bind(xkb_state_mod_index_is_active, _1, _2, XKB_STATE_MODS_EFFECTIVE); + m_ui->activeModifiersLabel->setText(stateActiveComponents(state, xkb_keymap_num_mods(map), modActive, &xkb_keymap_mod_get_name)); +} + void DebugConsole::showEvent(QShowEvent *event) { QWidget::showEvent(event); diff --git a/debug_console.h b/debug_console.h index fe80d1b0e7..220ebe6f12 100644 --- a/debug_console.h +++ b/debug_console.h @@ -106,6 +106,7 @@ protected: private: void initGLTab(); + void updateKeyboardTab(); QScopedPointer m_ui; QScopedPointer m_inputFilter; diff --git a/debug_console.ui b/debug_console.ui index 0d0a1935f2..38ff6cdba8 100644 --- a/debug_console.ui +++ b/debug_console.ui @@ -302,6 +302,143 @@ + + + Keyboard + + + + + + QFrame::Plain + + + 0 + + + true + + + + + 0 + 0 + 564 + 495 + + + + + + + Keymap Layouts + + + + + + + + + + + + + Qt::Horizontal + + + + + + + + + Current Layout: + + + + + + + + + + + + + + + + + + + Modifiers + + + + + + + + + + + + + + + + Active Modifiers + + + + + + + + + + + + + + + + LEDs + + + + + + + + + + + + + + + + Active LEDs + + + + + + + + + + + + + + + + + + diff --git a/keyboard_input.h b/keyboard_input.h index 5b3e6d074e..4e16fece12 100644 --- a/keyboard_input.h +++ b/keyboard_input.h @@ -82,6 +82,18 @@ public: return m_leds; } + xkb_keymap *keymap() const { + return m_keymap; + } + + xkb_state *state() const { + return m_state; + } + + quint32 currentLayout() const { + return m_currentLayout; + } + private: xkb_keymap *loadKeymapFromConfig(); xkb_keymap *loadDefaultKeymap();