Only way to figure out whether a key is a modifier key is to press it, check if a modifier changed state and then release it again. Luckily xkbcommon allows us to do this in a separate state.
| 190 | // check if a modifier changed state and then release it again. |
| 191 | // Luckily xkbcommon allows us to do this in a separate state. |
| 192 | void EiKeyState::assignGeneratedModifiers(std::uint32_t keycode, deskflow::KeyMap::KeyItem &item) |
| 193 | { |
| 194 | xkb_mod_mask_t xkbModMask = 0; |
| 195 | auto state = xkb_state_new(m_xkbKeymap); |
| 196 | |
| 197 | if (enum xkb_state_component changed = xkb_state_update_key(state, keycode, XKB_KEY_DOWN); changed) { |
| 198 | for (xkb_mod_index_t m = 0; m < xkb_keymap_num_mods(m_xkbKeymap); m++) { |
| 199 | if (xkb_state_mod_index_is_active(state, m, XKB_STATE_MODS_LOCKED)) |
| 200 | item.m_lock = true; |
| 201 | |
| 202 | if (xkb_state_mod_index_is_active(state, m, XKB_STATE_MODS_EFFECTIVE)) { |
| 203 | xkbModMask |= (1 << m); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | xkb_state_update_key(state, keycode, XKB_KEY_UP); |
| 208 | xkb_state_unref(state); |
| 209 | |
| 210 | item.m_generates = convertModMask(xkbModMask); |
| 211 | } |
| 212 | |
| 213 | void EiKeyState::getKeyMap(deskflow::KeyMap &keyMap) |
| 214 | { |
nothing calls this directly
no outgoing calls
no test coverage detected