diff --git a/src/plugins/buttonrebinds/buttonrebindsfilter.cpp b/src/plugins/buttonrebinds/buttonrebindsfilter.cpp index 0408e52ee0..e8d312a205 100644 --- a/src/plugins/buttonrebinds/buttonrebindsfilter.cpp +++ b/src/plugins/buttonrebinds/buttonrebindsfilter.cpp @@ -93,26 +93,6 @@ bool InputDevice::isTouchpad() const return false; } -static std::optional keycodeFromKeysym(xkb_keysym_t keysym) -{ - auto xkb = KWin::input()->keyboard()->xkb(); - auto layout = xkb_state_serialize_layout(xkb->state(), XKB_STATE_LAYOUT_EFFECTIVE); - const xkb_keycode_t max = xkb_keymap_max_keycode(xkb->keymap()); - for (xkb_keycode_t keycode = xkb_keymap_min_keycode(xkb->keymap()); keycode < max; keycode++) { - uint levelCount = xkb_keymap_num_levels_for_key(xkb->keymap(), keycode, layout); - for (uint currentLevel = 0; currentLevel < levelCount; currentLevel++) { - const xkb_keysym_t *syms; - uint num_syms = xkb_keymap_key_get_syms_by_level(xkb->keymap(), keycode, layout, currentLevel, &syms); - for (uint sym = 0; sym < num_syms; sym++) { - if (syms[sym] == keysym) { - return {keycode - 8}; - } - } - } - } - return {}; -} - ButtonRebindsFilter::ButtonRebindsFilter() : KWin::Plugin() , KWin::InputEventFilter() @@ -170,7 +150,7 @@ bool ButtonRebindsFilter::pointerEvent(QMouseEvent *event, quint32 nativeButton) return false; } // KKeyServer returns upper case syms, lower it to not confuse modifiers handling - auto keyCode = keycodeFromKeysym(sym); + auto keyCode = KWin::input()->keyboard()->xkb()->keycodeFromKeysym(sym); if (!keyCode) { qCWarning(KWIN_BUTTONREBINDS) << "Could not convert" << keys << "sym: " << sym << "to keycode"; return false; diff --git a/src/xkb.cpp b/src/xkb.cpp index cd2e1f54d9..99cca415d0 100644 --- a/src/xkb.cpp +++ b/src/xkb.cpp @@ -619,4 +619,22 @@ void Xkb::setSeat(KWaylandServer::SeatInterface *seat) m_seat = QPointer(seat); } +std::optional Xkb::keycodeFromKeysym(xkb_keysym_t keysym) +{ + auto layout = xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE); + const xkb_keycode_t max = xkb_keymap_max_keycode(m_keymap); + for (xkb_keycode_t keycode = xkb_keymap_min_keycode(m_keymap); keycode < max; keycode++) { + uint levelCount = xkb_keymap_num_levels_for_key(m_keymap, keycode, layout); + for (uint currentLevel = 0; currentLevel < levelCount; currentLevel++) { + const xkb_keysym_t *syms; + uint num_syms = xkb_keymap_key_get_syms_by_level(m_keymap, keycode, layout, currentLevel, &syms); + for (uint sym = 0; sym < num_syms; sym++) { + if (syms[sym] == keysym) { + return {keycode - EVDEV_OFFSET}; + } + } + } + } + return {}; +} } diff --git a/src/xkb.h b/src/xkb.h index f3ab8e7db8..853fff93b1 100644 --- a/src/xkb.h +++ b/src/xkb.h @@ -16,6 +16,9 @@ #include #include + +#include + Q_DECLARE_LOGGING_CATEGORY(KWIN_XKB) struct xkb_context; @@ -104,6 +107,8 @@ public: void setSeat(KWaylandServer::SeatInterface *seat); QByteArray keymapContents() const; + std::optional keycodeFromKeysym(xkb_keysym_t keysym); + Q_SIGNALS: void ledsChanged(const LEDs &leds); void modifierStateChanged();