hyprctl: add an active layout index field in devices (#11531)

This commit is contained in:
Levizor 2025-09-09 15:19:51 +02:00 committed by GitHub
parent ecc9e4d8cd
commit 150d693fe7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 64 additions and 23 deletions

View file

@ -266,6 +266,19 @@ void IKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) {
xkb_context_unref(PCONTEXT);
}
std::optional<xkb_layout_index_t> IKeyboard::getActiveLayoutIndex() {
const auto KEYMAP = m_xkbKeymap;
const auto STATE = m_xkbState;
const auto LAYOUTSNUM = xkb_keymap_num_layouts(KEYMAP);
for (xkb_layout_index_t i = 0; i < LAYOUTSNUM; ++i) {
if (xkb_state_layout_index_is_active(STATE, i, XKB_STATE_LAYOUT_EFFECTIVE) == 1)
return i;
}
return {};
}
std::string IKeyboard::getActiveLayout() {
const auto KEYMAP = m_xkbKeymap;
const auto STATE = m_xkbState;