diff --git a/debug_console.h b/debug_console.h --- a/debug_console.h +++ b/debug_console.h @@ -106,6 +106,7 @@ private: void initGLTab(); + void updateKeyboardTab(); QScopedPointer m_ui; QScopedPointer m_inputFilter; diff --git a/debug_console.cpp b/debug_console.cpp --- a/debug_console.cpp +++ b/debug_console.cpp @@ -49,6 +49,11 @@ #include #include +// xkb +#include + +#include + namespace KWin { @@ -503,6 +508,10 @@ 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 @@ 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.ui b/debug_console.ui --- 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 --- a/keyboard_input.h +++ b/keyboard_input.h @@ -82,6 +82,18 @@ 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();