Skip to content

Commit

Permalink
Get mod state via lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
czlabinger committed Oct 24, 2024
1 parent 71a7f9f commit 177b727
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/debug/HyprCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,15 @@ std::string configErrorsRequest(eHyprCtlOutputFormat format, std::string request
std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) {
std::string result = "";

auto getModState = [](SP<IKeyboard> keyboard, const char* xkbModName) -> bool {
auto IDX = xkb_keymap_mod_get_index(keyboard->xkbKeymap, xkbModName);

if (IDX == XKB_MOD_INVALID)
return false;

return (keyboard->modifiersState.locked & (1 << IDX)) > 0;
};

if (format == eHyprCtlOutputFormat::FORMAT_JSON) {
result += "{\n";
result += "\"mice\": [\n";
Expand Down Expand Up @@ -586,15 +595,7 @@ std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) {
}},)#",
(uintptr_t)k.get(), escapeJSONStrings(k->hlName), escapeJSONStrings(k->currentRules.rules), escapeJSONStrings(k->currentRules.model),
escapeJSONStrings(k->currentRules.layout), escapeJSONStrings(k->currentRules.variant), escapeJSONStrings(k->currentRules.options), escapeJSONStrings(KM),
(((xkb_keymap_mod_get_index(k->xkbKeymap, XKB_MOD_NAME_CAPS)) != XKB_MOD_INVALID &&
(k->modifiersState.locked & (1 << xkb_keymap_mod_get_index(k->xkbKeymap, XKB_MOD_NAME_CAPS))) > 0) ?
"true" :
"false"),
(((xkb_keymap_mod_get_index(k->xkbKeymap, XKB_MOD_NAME_NUM)) != XKB_MOD_INVALID &&
(k->modifiersState.locked & (1 << xkb_keymap_mod_get_index(k->xkbKeymap, XKB_MOD_NAME_NUM))) > 0) ?
"true" :
"false"),
(k->active ? "true" : "false"));
(getModState(k, XKB_MOD_NAME_CAPS) ? "true" : "false"), (getModState(k, XKB_MOD_NAME_NUM) ? "true" : "false"), (k->active ? "true" : "false"));
}

trimTrailingComma(result);
Expand Down Expand Up @@ -678,19 +679,11 @@ std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) {

for (auto const& k : g_pInputManager->m_vKeyboards) {
const auto KM = k->getActiveLayout();
result += std::format("\tKeyboard at {:x}:\n\t\t{}\n\t\t\trules: r \"{}\", m \"{}\", l \"{}\", v \"{}\", o \"{}\"\n\t\t\tactive keymap: {}\n\t\t\tcapsLock: "
"{}\n\t\t\tnumLock: {}\n\t\t\tmain: {}\n",
(uintptr_t)k.get(), k->hlName, k->currentRules.rules, k->currentRules.model, k->currentRules.layout, k->currentRules.variant,
k->currentRules.options, KM,
(((xkb_keymap_mod_get_index(k->xkbKeymap, XKB_MOD_NAME_CAPS)) != XKB_MOD_INVALID &&
(k->modifiersState.locked & (1 << xkb_keymap_mod_get_index(k->xkbKeymap, XKB_MOD_NAME_CAPS))) > 0) ?
"yes" :
"no"),
(((xkb_keymap_mod_get_index(k->xkbKeymap, XKB_MOD_NAME_NUM)) != XKB_MOD_INVALID &&
(k->modifiersState.locked & (1 << xkb_keymap_mod_get_index(k->xkbKeymap, XKB_MOD_NAME_NUM))) > 0) ?
"yes" :
"no"),
(k->active ? "yes" : "no"));
result +=
std::format("\tKeyboard at {:x}:\n\t\t{}\n\t\t\trules: r \"{}\", m \"{}\", l \"{}\", v \"{}\", o \"{}\"\n\t\t\tactive keymap: {}\n\t\t\tcapsLock: "
"{}\n\t\t\tnumLock: {}\n\t\t\tmain: {}\n",
(uintptr_t)k.get(), k->hlName, k->currentRules.rules, k->currentRules.model, k->currentRules.layout, k->currentRules.variant, k->currentRules.options,
KM, (getModState(k, XKB_MOD_NAME_CAPS) ? "yes" : "no"), (getModState(k, XKB_MOD_NAME_NUM) ? "yes" : "no"), (k->active ? "yes" : "no"));
}

result += "\n\nTablets:\n";
Expand Down

0 comments on commit 177b727

Please sign in to comment.