Commit 14aefcb3 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

xkb: Explain mystery constant

While looking at xkb code I found what this + 8 meant, figured we better
include it in our code so it feels less magical.
parent da8ad320
Pipeline #178998 passed with stage
in 15 minutes and 32 seconds
......@@ -30,6 +30,10 @@
Q_LOGGING_CATEGORY(KWIN_XKB, "kwin_xkbcommon", QtWarningMsg)
/* The offset between KEY_* numbering, and keycodes in the XKB evdev
* dataset. */
static const int EVDEV_OFFSET = 8;
namespace KWin
{
......@@ -353,7 +357,7 @@ void Xkb::updateKey(uint32_t key, InputRedirection::KeyboardKeyState state)
if (!m_keymap || !m_state) {
return;
}
xkb_state_update_key(m_state, key + 8, static_cast<xkb_key_direction>(state));
xkb_state_update_key(m_state, key + EVDEV_OFFSET, static_cast<xkb_key_direction>(state));
if (state == InputRedirection::KeyboardKeyPressed) {
const auto sym = toKeysym(key);
if (m_compose.state && xkb_compose_state_feed(m_compose.state, sym) == XKB_COMPOSE_FEED_ACCEPTED) {
......@@ -459,16 +463,16 @@ QString Xkb::layoutShortName(int index) const
void Xkb::updateConsumedModifiers(uint32_t key)
{
Qt::KeyboardModifiers mods = Qt::NoModifier;
if (xkb_state_mod_index_is_consumed2(m_state, key + 8, m_shiftModifier, XKB_CONSUMED_MODE_GTK) == 1) {
if (xkb_state_mod_index_is_consumed2(m_state, key + EVDEV_OFFSET, m_shiftModifier, XKB_CONSUMED_MODE_GTK) == 1) {
mods |= Qt::ShiftModifier;
}
if (xkb_state_mod_index_is_consumed2(m_state, key + 8, m_altModifier, XKB_CONSUMED_MODE_GTK) == 1) {
if (xkb_state_mod_index_is_consumed2(m_state, key + EVDEV_OFFSET, m_altModifier, XKB_CONSUMED_MODE_GTK) == 1) {
mods |= Qt::AltModifier;
}
if (xkb_state_mod_index_is_consumed2(m_state, key + 8, m_controlModifier, XKB_CONSUMED_MODE_GTK) == 1) {
if (xkb_state_mod_index_is_consumed2(m_state, key + EVDEV_OFFSET, m_controlModifier, XKB_CONSUMED_MODE_GTK) == 1) {
mods |= Qt::ControlModifier;
}
if (xkb_state_mod_index_is_consumed2(m_state, key + 8, m_metaModifier, XKB_CONSUMED_MODE_GTK) == 1) {
if (xkb_state_mod_index_is_consumed2(m_state, key + EVDEV_OFFSET, m_metaModifier, XKB_CONSUMED_MODE_GTK) == 1) {
mods |= Qt::MetaModifier;
}
m_consumedModifiers = mods;
......@@ -512,7 +516,7 @@ xkb_keysym_t Xkb::toKeysym(uint32_t key)
if (!m_state) {
return XKB_KEY_NoSymbol;
}
return xkb_state_key_get_one_sym(m_state, key + 8);
return xkb_state_key_get_one_sym(m_state, key + EVDEV_OFFSET);
}
QString Xkb::toString(xkb_keysym_t keysym)
......@@ -534,7 +538,7 @@ Qt::Key Xkb::toQtKey(xkb_keysym_t keySym,
bool superAsMeta) const
{
// FIXME: passing superAsMeta doesn't have impact due to bug in the Qt function, so handle it below
Qt::Key qtKey = Qt::Key(QXkbCommon::keysymToQtKey(keySym, modifiers, m_state, scanCode + 8, superAsMeta));
Qt::Key qtKey = Qt::Key(QXkbCommon::keysymToQtKey(keySym, modifiers, m_state, scanCode + EVDEV_OFFSET, superAsMeta));
// FIXME: workarounds for symbols currently wrong/not mappable via keysymToQtKey()
if (superAsMeta && (qtKey == Qt::Key_Super_L || qtKey == Qt::Key_Super_R)) {
......@@ -557,7 +561,7 @@ bool Xkb::shouldKeyRepeat(quint32 key) const
if (!m_keymap) {
return false;
}
return xkb_keymap_key_repeats(m_keymap, key + 8) != 0;
return xkb_keymap_key_repeats(m_keymap, key + EVDEV_OFFSET) != 0;
}
void Xkb::switchToNextLayout()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment