summaryrefslogtreecommitdiff
path: root/src/devices/IKeyboard.cpp
diff options
context:
space:
mode:
authorLevizor <levizorri@gmail.com>2025-09-09 15:19:51 +0200
committerGitHub <noreply@github.com>2025-09-09 14:19:51 +0100
commit150d693fe794a01aab762a18d2d8a2c8bc54b43c (patch)
treebf3bb839bc32d621aa54c597bae5267198e37f84 /src/devices/IKeyboard.cpp
parentecc9e4d8cd7a86f5f7d7541bee9b092122d2fa83 (diff)
hyprctl: add an active layout index field in devices (#11531)
Diffstat (limited to 'src/devices/IKeyboard.cpp')
-rw-r--r--src/devices/IKeyboard.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/devices/IKeyboard.cpp b/src/devices/IKeyboard.cpp
index 4f2281b7..ad9e40d8 100644
--- a/src/devices/IKeyboard.cpp
+++ b/src/devices/IKeyboard.cpp
@@ -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;